Skip to main content

Step 5 – Handle the payment response

PayTabs Mobile SDKs streamline the integration process with the PayTabs payment gateway by offering a pre-configured payment interface. This interface efficiently manages card data entry, billing and shipping information, and automatically supplements any missing details required to complete the transaction flow.

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 implement the interface CallbackPaymentInterface within your entry point activity/fragment instance and start building your business case as shown in the below example:

import com.payment.paymentsdk.sharedclasses.interfaces.CallbackPaymentInterface
import com.payment.paymentsdk.integrationmodels.PaymentSdkError
import com.payment.paymentsdk.integrationmodels.PaymentSdkTransactionDetails

class MainActivity : ComponentActivity(), CallbackPaymentInterface {

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 activity, you will override our event handlers' functions to handle the payment response accordingly:

then()​

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

import com.payment.paymentsdk.sharedclasses.interfaces.CallbackPaymentInterface
import com.payment.paymentsdk.integrationmodels.PaymentSdkTransactionDetails
import android.widget.Toast

class MainActivity : ComponentActivity(), CallbackPaymentInterface {

override fun onPaymentFinish(PaymentSdkTransactionDetails: PaymentSdkTransactionDetails) {

if (paymentSdkTransactionDetails?.isSuccess) {
Toast.makeText(
this,
"Payment has been completed successfully.",
Toast.LENGTH_SHORT
).show()
}

}
}
No parameters found for manual class PaymentSdkTransactionDetails.

We are glad to be always in help. We aim to serve you better each time. As such, please spare a minute to share feedback about your recent experience with PayTabs Developers , on Trustpilot, or Google Reviews.