This part of Custom UI SDK integration is regarding the transaction processing through the SDK. Before continuing with the steps mentioned below, please make sure that the integration steps mentioned in SDK initialisation and Account linking (if applicable) are already executed.
Custom UI SDK Integration - Transaction processing
-
Implement the interface
Implement the interface CardProcessTransactionListener for merchant powered bank pages(card payments) else implement PaytmSDKCallbackListener-
Implement the interface PaytmSDKCallbackListener
- onTransactionResponse: This will provide the response status data related to a transaction. The response will contain a JSON string of TxnInfo. Refer the following:
// get json string of txnInfo public void onTransactionResponse(TransactionInfo bundle) { if (bundle != null) { if (bundle.getTxnInfo() != null) { String s = new Gson().toJson(bundle.getTxnInfo()); Toast.makeText(this, s, Toast.LENGTH_LONG).show(); } } }
Sample TxnInfo data{ "ORDERID": "PARCEL15816826759", "MID": "AliSub58582630351896", "TXNID": "20200214111212800110168052313701129", "TXNAMOUNT": "1.00", "PAYMENTMODE": "CC", "CURRENCY": "INR", "TXNDATE": "2020-02-14 17:48:13.0", "STATUS": "TXN_SUCCESS", "RESPCODE": "01", "RESPMSG": "Txn Success", "MERC_UNQ_REF": "test4", "UDF_1": "test1", "UDF_2": "test2", "UDF_3": "test3", "ADDITIONAL_INFO": "test5", "GATEWAYNAME": "ICICIPAY", "BANKTXNID": "68568621250", "BANKNAME": "HSBC", "PROMO_CAMP_ID": "PROMO CODE", "PROMO_RESPCODE": "702", "PROMO_STATUS": "FAILURE" }
- TransactionInfo.ResultInfo: This will contain the status of a transaction, along with retry supported information in case payment can be retried for the same orderId. Status of the transaction can be obtained using ResultInfo.resultStatus contains the transaction status and has only three values: TXN_SUCCESS, TXN_FAILURE and PENDING.
- onBackPressedCancelTransaction: This method will be called if a user presses the Back button on any of the screens during the transaction such as the OTP page.
- onGenericError (String errorCode, String errorMsg): This method will be called if you report No Network cases or Timeouts.
Error code Error message 101 No Internet connection 103 TIMEOUT 104 UNKNOWN
- onTransactionResponse: This will provide the response status data related to a transaction. The response will contain a JSON string of TxnInfo. Refer the following:
-
Implement the interface CardProcessTransactionListener
- onCardProcessTransactionResponse : This will provide the response of the process transaction API in a JSON string.You can find all the details about Process Transaction API response and sample data forProcessTransactionInfo here
fun onCardProcessTransactionResponse(processTransactionInfo: ProcessTransactionInfo?) { }
- onCardProcessTransactionResponse : This will provide the response of the process transaction API in a JSON string.You can find all the details about Process Transaction API response and sample data forProcessTransactionInfo here
-
-
Generate transaction token from your backend
After the user adds the product in the cart and clicks the button to proceed for checkout, your app calls the backend server to get the order payout. Then, your backend server calls Initiate Transaction API from the backend to generate the Transaction Token.Note: In case you wish to use the custom Callback URL in Initiate Transaction API then please include the config setMerchantCallbackUrl during Initialization of SDK.
-
Fetch paytm user’s saved instruments
Using the Transaction token received above, your backend server calls the Fetch Payment Options API to receive the different payment options including the user's saved instruments and other instruments like CC/DC, NB, UPI, EMI etc.Note: In case you do not want to create order first, you may call the Fetch Payment Options API before Initiate Transaction. For more details please Get in touch with us.
-
PaytmSDK builder creation
Create PaytmSDK builder using the parameters mid, orderId, txnToken, and amount.
PaytmSDK.Builder builder = new PaytmSDK.Builder(this, mid, orderId, txnToken, amount /*PaytmSDKCallbackListener* or *CardProcessTransactionListener(for merchant powered bank pages)*/); builder.setMerchantCallbackUrl(Constants.callBackUrl); PaytmSDK paytmSDK = builder.build();
Method Parameters:
Attribute Type Description context Context Your application context mid String Merchant id identifying a merchant orderId String Unique identifier for current order txnToken String Transaction token to identify the current transaction received in response to Initiate Transaction API from Paytm. Refer to Step 1.ii.. double amount Order amount for the current transaction PaytmSDKCallbackListener
OR
CardProcessTransactionListenerInterface implementation to get the result of a payment transaction.
Refer to Step 1.i.
OR
Interface implementation to get the process transaction response for merchant powered bank pages in addition to result of a payment transaction.
Refer to Step 1.ii.Note: You can make changes for some of the optional configurations. Please refer to the Optional Methods.
-
5
Proceed for the Transaction
-
When a user clicks the Pay button after entering the payment instrument’s details in the selected payment method, you need to proceed with the transaction. Please follow the steps below for proceeding with the transaction.
- Create a model of
PaymentRequestModel
type based on the type of payment mode chosen by the user.
- Create a model of
Model name : CardRequestModel
Creation of Object:
CardRequestModel cardRequestModel = new CardRequestModel(paymentMode, paymentFlow,
cardNumber, cardId, cardCvv, cardExpiry, bankCode, channelCode, authMode, emiPlanId,
shouldSaveCard, isEligibleForCoFT, isUserConsentGiven, isCardPTCInfoRequired)
Constructor Attributes:
Attributes | Type | Description |
---|---|---|
paymentMode |
String (mandatory) |
type of card (DEBIT_CARD, CREDIT_CARD) |
paymentFlow | String (mandatory) | current payment flow (NONE, ADDNPAY) |
newCardNumber | String (conditional) | card number digits for a new card (null for the saved card) |
savedCardId | String (conditional) | cardId for a saved card (null for a new card) |
cardCvv | String (conditional) | CVV of the card (Mandatory for new cards Optional for saved cards whenever CVV is not required) |
cardExpiry | String (conditional) | card expiry date in the format MM/YY (eg. 11/19) |
channelCode | String (conditional) | channelCode of card obtained from fetchBinDetails API(eg. VISA, MASTER) |
bankCode | String (conditional) | bank code of card obtained from fetchBinDetails API(eg. ICICI, AXIS) |
authMode | String (mandatory) | the mode of 2FA chosen for a card(either by 'pin' or 'otp'), options obtained from fetchBinDetails API |
emiPlanId | String (conditional) | emiPlan id in case of an EMI transaction |
shouldSaveCard | Boolean (optional) | flag to indicate if the new card should be saved and tokenized at Paytm’s end. Default value is false |
isEligibleForCoFT | Boolean (optional) | COFT eligibility flag received in fetchBinDetails API for new card and fetchPaymenOptions API for saved card. Default value : false |
isUserConsentGiven | Boolean (optional) | flag to indicate if the saved card should be tokenized at Paytm’s end. Default value : false |
isCardPTCInfoRequired | Boolean (optional) | Flag to indicate if to provide support for merchant powered bank pages. Default value : false |
- Call
paytmSDK.startTransaction
to call the Process Transaction API. Once you have created the request model for the payment mode selected by the user, call the below method, to start a payment transaction.paytmSdk.startTransaction(Activity context, PaymentRequestModel paymentRequestModel)
Method Params:
Parameter Description Activity context SDK needs the context of activity as it might have to further launch new activities bank OTP pages/ website etc. based on payment mode selected. PaymentRequestModel paymentRequestModel The type of paymentRequestModel created for this transaction -
If
PaytmSDKCallbackListener
is implemented, the result of the transaction will be received viaPaytmSDKCallbackListener
Interface described in Step1. i.
IfCardProcessTransactionListener
is implemented and the booleanisCardPTCInfoRequired
is true, the response of Process Transaction will be received viaCardProcessTransactionListener
Interface described in Step1. ii. in case of card payments. In other cases (other than card payment) the result of the transaction will be received in a similar way to that ofPaytmSDKCallbackListener
-
Clean up SDK instance
After completing the transaction merchant should call the below method to clear payment SDK state when destroying the PG page.
PaytmSDK.clearPaytmSDKData()