PayTabs SDK makes the integration with the PayTabs payment gateway very easy by providing a ready-made payment screen that handles the card entry and, billing & shipping information and completes the missing details.


This article is dedicated to walking you through how to handle the payment response after performing it. Handling the response right will prevent your application from crashing on any unhandled response status or any missing case.


To perform such, you will need to navigate to your "CallbackPaymentInterface" inherited activity/fragment instance and start building your business case as shown in the below example:


override fun onError(error: PaymentSdkError) {
          // Implement according to your business needs
}

override fun onPaymentFinish(PaymentSdkTransactionDetails: PaymentSdkTransactionDetails) {
         // Use the checkers here according to your business needs
}

override fun onPaymentCancel() {
             // Implement according to your business needs
}

As you may be noticed in the example, within the delegate, you will override our event handlers' functions to handle the payment response accordingly:




It is important that you MUST validate that the response you received from our end in the below PaymentSdkTransactionDetails object is genuine by comparing it to the order/cart details stored already on your server-side in order to ensure that the original data that has been sent through the Mobile Application (client-side) has not been manipulated/intercepted.




onPaymentFinish()

 

Via this event handler, you will handle the payment response. Through the PaymentSdkTransactionDetails object, you will receive the PayTabs response that should be handled from your side according to your business needs depending on the sent information/parameters as clarified below:

  • override fun onPaymentFinish(PaymentSdkTransactionDetails: PaymentSdkTransactionDetails) 


PaymentSdkTransactionDetails Properties


PropertyData TypeUsage
tokenStringThe sent token for the tokenized payment requests. This field is required for creating tokenized (recurring) transactions. To know more, please check our sss solution article.
transactionReferenceStringThe unique key for the transaction generated by the PayTabs. 

This field is required for creating tokenized (recurring) transactions.
transactionTypeStringThe identification of the type of transactionTo know more about these types, please check our What is the "tran_type" (transaction type)? solution article. 
To know more about the only types that are supported in this SDK, please check our 2.3 Native IOS SDK | Enums solution article.

The default passed value is ".sale".
cartIDStringIndicates the cart/order id at the merchant end to easily relate the transaction to
cartDescriptionStringIndicates the cart/order description at the merchant end to easily relate the transaction to.
cartCurrencyStringIndicates the transaction currency, which the customer will be charged with. Noting that this currency must be configured first on your PayTabs account to accept payment with.
cartAmountStringIndicates the amount of this transaction the customer is about to be charged.
paymentResultPaymentSDK.PaymentResultViewModel ObjectresponseStatusStringIndicates the status of the performed transaction, which will be one from the list clarified in our What is: Response_code vs the Response_status? solution article.
responseCodeStringIndicates the code of the performed transaction, which will be one from the list clarified in our What is: Response_code vs the Response_status? solution article.
responseMessageString
transactionTimeString
acquirerMessageString
acquirerRRNString
paymentInfoPaymentSDK.PaymentInfoViewModel ObjectcardTypeString
cardSchemeString
paymentDescriptionString
billingDetails
PaymentSDK.PaymentSDKBillingDetails ObjectnameString
emailString
phoneString
addressLineString
cityString
stateString
countryCodeString
zipString
shippingDetails
PaymentSDK.PaymentSDKShippingDetails ObjectnameString
emailString
phoneString
addressLineString
cityString
stateString
countryCodeString
zipString



We also provide within the same PaymentSdkTransactionDetails object multiple checkers that can assist you through your system/business flow, as shown below, which highly recommend using them to handle the response in the PaymentManagerDelegate class:



It worth mentionting, that all the responses and statuses the following checkers relies on are the official supported one listed in our What is: Response_code vs the Response_status? solution article.


isAuthorized()


This function aims to check for you whether the payment status is "A", which indicates that the payment is successfully operated, authenticated, and registered on your PayTabs dashboard for both PayTabs and the acquirer bank/processor.


if the transaction is not successful then you will have to check for the corresponding failure code which you will receive in the transactionDetails?.paymentResult?.responseCode attribute.


It acts as like as shown below:

paymentResult?.responseStatus == "A"

isPending()


This function aims to check for you whether the payment status is "P", which indicates that the payment is successfully operated and registered on your PayTabs dashboard, however, its status on the acquirer bank/processer is pending. For example, cash payment such exists in the aman payment method will be marked as pending until the customer pays the transaction at one of the aman machines.


It acts as like as shown below:

paymentResult?.responseStatus == "P"

isOnHold()


This function aims to check for you whether the payment status is "H", which indicates that the payment is successfully operated/authenticated and registered on your PayTabs dashboard, however, its status on the acquirer bank/processer is on hold. For example, refunds that are operated manually by the Knet team will be marked as on hold.


It acts as like as shown below:

paymentResult?.responseStatus == "H"



isSuccess()


This function aims to check for you whether the payment has been performed successfully which means its status will be either "H", "P", or "A", which indicates that the payment is successfully operated/authenticated and registered on your PayTabs dashboard accordingly to each status clarification.


It acts as like as shown below:

isAuthorized() || isPending() || isOnHold()

isProcessed()


This function aims to check for you whether the payment has been processed in the first place or not. In some very rare cases, the acquirer bank/protocol doesn't immediately initiate the payment due to several reasons (such as an internal server error on their side), which lead that the transaction itself will be authenticated and registered a while after performing it (up to several hours in some cases), in this case, and as PayTabs didn't receive the response from the acquirer, the object will be returned with null.


In such cases, you will be notified once the transaction registered on the dashboard ONLY if you configured an IPN, to know more about how to handle IPNs please check our How to configure Instant payment notification (IPN)? solution article.


It acts as like as shown below:

paymentResult != null




OnError()


Via this event handler function, you will handle your sent request only if the payment doesn't exceed the validation. 

  • override fun onError(error: PaymentSdkError) 



onPaymentCancel()


Via this event handler function, you will handle your sent request only if the customer has triggered the cancel event, or in other words, the customer has canceled the payment. 

  • override fun onPaymentCancel() 



 




⌂ To get familiar with the whole process and the other steps, kindly navigate to our "The Native Android SDK Integration Manual" solution article.

 And to navigate to the previous step in the integration process "Step 4 - Accepting the payment" kindly click here.

Or you can navigate to the next step in the integration process " Step 6 - Handle the post-payment responses (notifications)" kindly click here.