Category

Android

Category

Step 1: Sign up for a Paytm merchant account
To integrate the PayTM payment gateway, you need to sign up for a PayTM merchant account. Visit the PayTM Developer Portal (https://developer.paytm.com/) and follow the registration process to create your merchant account.

Step 2: Set up PayTM SDK in your project

  1. Open your Android project in Android Studio.
  2. Add the following dependency to your app-level build. gradle file:
implementation 'com.paytm:pgplussdk:1.4.3'
  1. Sync your project to download the PayTM SDK.

Step 3: Obtain merchant credentials
After signing up for a merchant account, you will receive the necessary credentials from PayTM. These include the merchant ID and merchant key, which you’ll need for integration.

Step 4: Create a PayTM activity
Create a new activity in your Android project to handle the PayTM payment process. For example, create a PaytmActivity.java file.

Step 5: Implement the PayTM payment process
In the PaytmActivity.java file, implement the following steps:

  1. Initialize the PayTM service in the onCreate() method:
PaytmPGService service = PaytmPGService.getStagingService(); // or PaytmPGService.getProductionService() for production environment
  1. Set up the payment parameters and listener:
HashMap<String, String> paramMap = new HashMap<>();
paramMap.put("MID", "YOUR_MERCHANT_ID");
paramMap.put("ORDER_ID", "UNIQUE_ORDER_ID");
paramMap.put("CUST_ID", "CUSTOMER_ID");
paramMap.put("CHANNEL_ID", "WAP");
paramMap.put("TXN_AMOUNT", "AMOUNT");
paramMap.put("WEBSITE", "WEBSTAGING"); // for staging environment, use "DEFAULT" for production
paramMap.put("INDUSTRY_TYPE_ID", "Retail");
paramMap.put("CALLBACK_URL", "CALLBACK_URL"); // the URL to which PayTM will send the payment response

PaytmOrder order = new PaytmOrder(paramMap);

service.initialize(order, null);

Replace the placeholders with the appropriate values from your merchant account.

  1. Start the payment transaction:
service.startPaymentTransaction(this, true, true, new PaytmPaymentTransactionCallback() {
    @Override
    public void onTransactionResponse(Bundle inResponse) {
        // Handle the payment response
    }

    @Override
    public void networkNotAvailable() {
        // Handle network error
    }

    @Override
    public void clientAuthenticationFailed(String inErrorMessage) {
        // Handle authentication error
    }

    @Override
    public void someUIErrorOccurred(String inErrorMessage) {
        // Handle UI error
    }

    @Override
    public void onErrorLoadingWebPage(int iniErrorCode, String inErrorMessage, String inFailingUrl) {
        // Handle web page loading error
    }

    @Override
    public void onBackPressedCancelTransaction() {
        // Handle transaction cancellation
    }

    @Override
    public void onTransactionCancel(String inErrorMessage, Bundle inResponse) {
        // Handle transaction cancellation
    }
});
  1. Handle the payment response in the onTransactionResponse() method:
@Override
public void onTransactionResponse(Bundle inResponse) {
    String status = inResponse.getString("STATUS");
    String message = inResponse.getString("RESPMSG");

    if (status != null && status.equals("TXN_SUCCESS")) {
        // Payment was successful
    } else {
        // Payment failed
    }
}

Step 6: Connect the PayTM activity to your app
Finally, you need to connect the PayTM activity to your e-commerce app. For example, you can add a button to the shopping cart screen and launch the PayTM activity when the user selects the payment option.

That’s it! You have now integrated the PayTM payment gateway into your Android e-commerce app. Remember to replace the placeholder values with your actual merchant credentials and customize the code according to your app’s requirements.

Please note that this guide provides a basic integration example. For a complete and detailed implementation, including error handling and additional features, you may need to refer to the official PayTM documentation or consult their support resources.