Mobile SDK for Android

Integrating PayHere with your Android Mobile App is super easy with our PayHere Mobile SDK for Android. You just have to include that in your Android app project & call its methods to initiate a payment & fetch the payment status just after the payment. The beauty is, this Mobile SDK allows you to accept a payment within your app, without redirecting your app user to the web browser.

Please refer the below steps to integrate PayHere Mobile SDK to your Android App.

1. Include PayHere Mobile SDK to your App

Add maven URL to main build.gradle file

 maven {
            url  ""

Example build.gradle after adding the line

allprojects {
    repositories {
        maven {
            url  ""

2. Add SDK dependency

Add PayHere Mobile SDK dependency to the necessary module with appcompat and gson libraries. In most cases .\app\build.gradle file

implementation 'lk.payhere.sdk:android-payment-sdk:1.0.0'
implementation '' // ignore if you have already added
implementation '' // ignore if you have already added

Example build.gradle after adding the line

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation ''
    implementation ''
    implementation 'lk.payhere.sdk:android-payment-sdk:0.1.6' // payhere payment sdk
    implementation ''
    testImplementation 'junit:junit:4.12'
    androidTestImplementation ''
    androidTestImplementation ''

3. Add Internet Permission to AndroidManifest.xml

<uses-permission android:name="android.permission.INTERNET" />

4. Initiate a Payment Request to PayHere Payment Gateway

InitRequest req = new InitRequest();
req.setMerchantId("1210251"); // Your Merchant ID
req.setMerchantSecret("bhasha2"); // Your Merchant secret
req.setAmount(1000.00); // Amount which the customer should pay
req.setCurrency("LKR"); // Currency
req.setOrderId("ItemNo12345"); // Unique ID for your payment transaction
req.setItemsDescription("Door bell wireless");  // Item title or Order/Invoice number
req.setCustom1("This is the custom message 1");
req.setCustom2("This is the custom message 2");
req.getCustomer().getAddress().setAddress("No.1, Galle Road,");
req.getCustomer().getAddress().setCountry("Sri Lanka");
req.getCustomer().getDeliveryAddress().setAddress("No.2, Kandy Road,");
req.getCustomer().getDeliveryAddress().setCountry("Sri Lanka");
req.getItems().add(new Item(null, "Door bell wireless", 1, 1000.0));

Intent intent = new Intent(this, PHMainActivity.class);
intent.putExtra(PHConstants.INTENT_EXTRA_DATA, req);
startActivityForResult(intent, PAYHERE_REQUEST); //unique request ID like private final static int PAYHERE_REQUEST = 11010;

5. Fetch the Payment Status

Example code

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        //TODO process response
        if (requestCode == PAYHERE_REQUEST && data != null && data.hasExtra(PHConstants.INTENT_EXTRA_RESULT)) {
            PHResponse<StatusResponse> response = (PHResponse<StatusResponse>) data.getSerializableExtra(PHConstants.INTENT_EXTRA_RESULT);
            String msg;
            if (response.isSuccess()) {
                msg = "Activity result:" + response.getData().toString();
                Log.d(TAG, msg);
            } else {
                msg = "Result:" + response.toString();
                Log.d(TAG, msg);

Mobile SDK for Android - PayHere Knowledge Base

Still need help? Get in touch!
Last updated on 12th Oct 2019