Follow the steps below to integrate All-in-One SDK in your Ionic app:
Steps for Capacitor Project
-
Add the line below to ‘repositories’ section of your project level build.gradle file.
maven {
url "https://artifactory.paytm.in/libs-release-local"
}
-
Add the line below to 'dependencies' section of your app build.gradle.
implementation 'com.paytm.appinvokesdk:appinvokesdk:1.5.3'
-
Add AllInOneSDKPlugin class in project (see Appendix at the end of this document), and then in the MainActivity, use add function in OnCreate ( add(AllInOneSDKPlugin.class) ).
-
Update setResult method in AllInOneSDKPlugin class as per your response requirement in the ionic app.
-
Call startTransaction method from your Ionic app to invoke Paytm module.
For further queries visit the SDK based integration documentation.
Steps for Ionic Project
- Using plugin from ‘@capacitor/core’ fetch AllInOneSDKPlugin class.
import { Plugins } from "@capacitor/core";
const { AllInOneSDKPlugin } = Plugins;
- Start the process by calling AllInOneSDKPlugin.startTransaction with the appropriate parameters.
let response = await AllInOneSDKPlugin.startTransaction({
mid: mid, orderId: orderId, txnToken: txnToken, amount: amount,
isStaging: isStaging, callbackUrl: callbackUrl
});
Attributes |
Description |
Mandatory |
mid
String(20)
|
This is a unique identifier provided to every merchant by Paytm. MID is part of your account credentials and is different on staging and production environment. |
Yes |
orderid
String(50)
|
Unique reference ID for a transaction which is generated by merchant Special characters allowed in Order ID are: "@" "-" "_" ".". |
Yes |
txnToken
String
|
Transaction token received from calling Initiate Transaction API (Note - pass same order id in SDK which was used for initiateTransaction). |
Yes |
amount
String
|
Amount in INR payable by the customer. Should contain digits up to two decimal points. The amount should not include any separator like (",") |
Yes |
IsStaging
Boolean
|
IsStaging is to define staging or production server (True for staging and False for production) |
Yes |
callbackurl
String(255)
|
On completion of transaction, Paytm payment gateway will send the response on this URL. This can be a static response URL as mentioned below:
- Staging Environment: "https://securegw-stage.paytm.in/theia/paytmCallback?ORDER_ID=<order_id>"
- Production Environment: "https://securegw.paytm.in/theia/paytmCallback?ORDER_ID=<order_id>"
|
Yes |
- Callback will be received in the above “response” object in JSObject format.
Sample Response:
Bundle[
{
STATUS=TXN_SUCCESS,
ORDERID="Order Id",
CHARGEAMOUNT=0.00,
TXNAMOUNT=1.00,
TXNDATE=2020-07-21 19:00:05.0,
MID="Merchant Id",
TXNID="Transaction Value",
RESPCODE=01,
PAYMENTMODE=UPI,
BANKTXNID="Bank transaction Id",
CURRENCY=INR,
GATEWAYNAME=ICICI,
RESPMSG=Txn Success
}]
-
Verifying Payment
-
You should validate the transaction response via a server-side request using the Transaction Status API. This API requires checksumhash in request and response. You must verify the Order ID and Amount with your data. The status should be treated as the final status of the transaction in all cases.
-
Paytm provides payment response on both Callback URL and Webhook URL. Please refer to the sample response for different payment sources here.
Appendix
AllInOneSDKPlugin class
package;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
import com.getcapacitor.JSObject;
import com.getcapacitor.NativePlugin;
import com.getcapacitor.Plugin;
import com.getcapacitor.PluginCall;
import com.getcapacitor.PluginMethod;
import com.paytm.pgsdk.PaytmOrder;
import com.paytm.pgsdk.PaytmPaymentTransactionCallback;
import com.paytm.pgsdk.TransactionManager;
@NativePlugin(requestCodes = {AllInOneSDKPlugin.REQ_CODE})
public class AllInOneSDKPlugin extends Plugin {
protected static final int REQ_CODE = 0;
@PluginMethod
public void startTransaction(PluginCall call) {
saveCall(call);
String orderId = call.getString("orderId");
String mid = call.getString("mid");
String txnToken = call.getString("txnToken");
String amount = call.getString("amount");
String callbackUrl = call.getString("callbackUrl");
boolean isStaging = call.getBoolean("isStaging");
if (orderId == null || mid == null || txnToken == null || amount == null ||
orderId.isEmpty() || mid.isEmpty() || txnToken.isEmpty() || amount.isEmpty()) {
if (txnToken == null || txnToken.isEmpty()) {
Toast.makeText(getContext(), "txnToken error", Toast.LENGTH_LONG).show();
}
else {
Toast.makeText(getContext(), "Please enter all field", Toast.LENGTH_LONG).show();
}
return;
}
String host = "https://securegw.paytm.in/";
if (isStaging) {
host = "https://securegw-stage.paytm.in/";
}
if(callbackUrl == null || callbackUrl.trim().isEmpty()) {
callbackUrl = host + "theia/paytmCallback?ORDER_ID=" + orderId;
}
PaytmOrder paytmOrder = new PaytmOrder(orderId, mid, txnToken, amount, callbackUrl);
TransactionManager transactionManager = new TransactionManager( paytmOrder, new PaytmPaymentTransactionCallback() {
@Override
public void onTransactionResponse(Bundle bundle) {
Log.d("LOG", "Payment Transaction is successful " + bundle);
setResult("Payment Transaction response " + bundle.toString(), call);
}
@Override
public void networkNotAvailable() {
setResult("networkNotAvailable", call);
}
@Override
public void onErrorProceed>(String s) {
setResult(s, call);
}
@Override
public void clientAuthenticationFailed(String s) {
setResult(s, call);
}
@Override
public void someUIErrorOccurred(String s) {
setResult(s, call);
}
@Override
public void onErrorLoadingWebPageString inFailingUrl) {
setResult(inErrorMessage, call);
}
@Override
public void onBackPressedCancelTransaction() {
setResult("onBackPressedCancelTransaction", call);
}
@Override
public void onTransactionCancel(String s, Bundle bundle) {
setResult(s + " " + bundle, call);
}
});
transactionManager.setShowPaymentUrl(host + "theia/api/v1/showPaymentPage");
transactionManager.startTransaction(getActivity(), REQ_CODE);
}
@Override
protected void handleOnActivityResult(int requestCode, int resultCode, Intent data) {
super.handleOnActivityResult(requestCode, resultCode, data);
if (requestCode == REQ_CODE && data != null) {
PluginCall call = getSavedCall();
setResult(data.getStringExtra("nativeSdkForMerchantMessage") +
data.getStringExtra("response"), call);
}
}
private void setResult(String message, PluginCall call) {
if (call != null) {
JSObject result = new JSObject();
result.put("result", message);
call.resolve(result);
}
else {
Toast.makeText(getContext(), "call is null", Toast.LENGTH_LONG).show();
}
}
}