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. | ||||
| String | |||
| String | |||
Transaction error code if exists. | ||||
| String | |||
Transaction error message if exists. | ||||
| String | |||
The sent token for the tokenized payment requests. This field is required for creating tokenized (recurring) transactions. To know more, please check our click here manual. | ||||
| PaymentSdkBillingDetails | |||
Indicates the billing details of the customer or card holder. |
| |||
| PaymentSdkShippingDetails | |||
Indicates the shipping details of the customer. | ||||
| Boolean | |||
This aims to check for you whether the payment has been performed successfully which means its status will be either | ||||
| Boolean | |||
This aims to check for you whether the payment status is | ||||
| Boolean | |||
This aims to check for you whether the payment status is | ||||
| Boolean | |||
This function aims to check for you whether the payment status is | ||||
| Boolean | |||
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. | ||||
| String | |||
Indicates the transaction currency, which the customer charged with. | ||||
| String | |||
Indicates the total amount the customer charged. | ||||
| String | |||
The transaction service ID. | ||||
| String | |||
The merchant ID you can get from your PayTabs dashboard. For more information please check our How to get your account information from PT Dashboard? solution article.. | ||||
| String | |||
The merchant Profile ID you can get from your PayTabs dashboard. For more information please check our How to get your account information from PT Dashboard? solution article.. | ||||
| String | |||
The merchant Profile ID you can get from your PayTabs dashboard. For more information please check our How to get your account information from PT Dashboard? solution article.. | ||||
onResult
import com.payment.paymentsdk.QuerySdkActivity
import com.payment.paymentsdk.sharedclasses.interfaces.CallbackQueryInterface
import com.payment.paymentsdk.sharedclasses.model.response.TransactionResponseBody
import com.payment.paymentsdk.integrationmodels.PaymentSDKQueryConfiguration
class MainActivity : ComponentActivity(), CallbackQueryInterface {
fun queryRequest(queryConfigData: PaymentSDKQueryConfiguration) {
QuerySdkActivity.queryTransaction(this, queryConfig, this)
}
override fun onResult(transactionResponseBody: TransactionResponseBody) {
showToast("Payment result received.")
}
}
| 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 amount of this transaction the customer is about to be charged. | |
| PaymentSdkPaymentResult |
Object containing the payment result details. | |
| PaymentSdkPaymentInfo |
Object containing the payment information details. | |
| String |
| String |
| String |
The sent token for the tokenized payment requests. This field is required for creating tokenized (recurring) transactions. To know more, please check our click here manual. | |
| PaymentSdkBillingDetails |
Indicates the billing details of the customer or card holder. | |
| PaymentSdkShippingDetails |
Indicates the shipping details of the customer. | |
| String |
Indicates the transaction currency, which the customer charged with. | |
| String |
Indicates the total amount the customer charged. | |
| String |
The transaction service ID. | |
| String |
The merchant ID you can get from your PayTabs dashboard. For more information please check our How to get your account information from PT Dashboard? solution article.. | |
| String |
The merchant Profile ID you can get from your PayTabs dashboard. For more information please check our How to get your account information from PT Dashboard? solution article.. | |
| Integer |
The merchant Profile ID you can get from your PayTabs dashboard. For more information please check our How to get your account information from PT Dashboard? solution article.. | |
| String |
The merchant Profile ID you can get from your PayTabs dashboard. For more information please check our How to get your account information from PT Dashboard? solution article.. |
onError
import com.payment.paymentsdk.sharedclasses.interfaces.CallbackPaymentInterface
import com.payment.paymentsdk.integrationmodels.PaymentSdkTransactionDetails
import android.widget.Toast
class MainActivity : ComponentActivity(), CallbackPaymentInterface {
override fun onError(error: PaymentSdkError) {
Toast.makeText(this, "${error.msg}", Toast.LENGTH_SHORT).show()
}
}
| Property | Data type |
|---|---|
| Integer |
The merchant Profile ID you can get from your PayTabs dashboard. For more information please check our How to get your account information from PT Dashboard? solution article.. | |
| String |
The merchant Profile ID you can get from your PayTabs dashboard. For more information please check our How to get your account information from PT Dashboard? solution article.. | |
| String |
The merchant Profile ID you can get from your PayTabs dashboard. For more information please check our How to get your account information from PT Dashboard? solution article.. |
onCancel
import com.payment.paymentsdk.sharedclasses.interfaces.CallbackPaymentInterface
import com.payment.paymentsdk.integrationmodels.PaymentSdkTransactionDetails
import android.widget.Toast
class MainActivity : ComponentActivity(), CallbackPaymentInterface {
override fun onPaymentCancel() {
Toast.makeText(this, "Payment attempt has been Cancelled", Toast.LENGTH_SHORT).show()
}
}