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:
onPaymentFinish
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()
}
}
}
| Property | Data type |
|---|---|
| String |
The unique key for the transaction generated by the PayTabs. This field is required for creating tokenized (recurring) transactions. For more details about the transaction Reference through API integration, please click here. | |
| String |
The identification of the type of transaction. To 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 Enums - Transaction Types solution article. The default passed value is ".sale". | |
| String |
Indicates the cart/order id at the merchant end to easily relate the transaction to. | |
| String |
Indicates the cart/order description at the merchant end to easily relate the transaction to. | |
| String |
Indicates the cart currency, which the customer will be charged with. Noting that this currency must be configured first on your PayTabs account to accept payment with. | |
| String |
Indicates the amount of this transaction the customer is about to be charged. | |
| String |
Indicates the transaction status value in text name. | |
| PaymentSdkPaymentResult |
Object containing the payment result details. | |
| PaymentSdkPaymentInfo |
Object containing the payment information details. | |