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()β
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()
}
}
}
PaymentSdkTransactionDetails.