Handle Payment Results
The SDK provides a callback interface that delivers the transaction's final status.
PaymentResultCallback
for Android.PaymentResult
for iOS.
This page will explore these callbacks in more detail, explaining their result methods and data structures.
Payment Callback
See the code block below for an example of the callback interface.
NayaxEcomSDK.startPayment(
context = context,
paymentData = paymentData,
callback = object : PaymentResultCallback {
override fun onPaymentComplete(data: PaymentCompleteData) {
// Handle successful payment
// Access: data.merchantTranId, data.sessionId, data.tokenId, data.resultCode
}
override fun onPaymentFail(data: PaymentFailData) {
// Handle payment failure
// Access: data.merchantTranId, data.sessionId, data.reason
}
override fun onError(error: EcomError) {
// Handle general error
// Access: error.code, error.key, error.message
}
})
public enum PaymentResult {
case complete(PaymentCompleteData)
case fail(PaymentFailData)
case error(EcomError)
}
public struct PaymentCompleteData {
public let merchantTranId: String?
public let sessionId: String?
public let tokenId: String?
public let resultCode: String
}
public struct PaymentFailData {
public let merchantTranId: String?
public let sessionId: String?
public let reason: DropInFailureReason
}
It includes three callback methods to handle the payment result:
- Successful Transaction (
onPaymentComplete
/.complete
): This indicates that the payment process was completed, and the billing provider approved the transaction. - Transaction Failure (
onPaymentFail
/.fail
): This signifies that the transaction failed due to an issue originating from the Drop-In UI or the billing provider's side, but not a general SDK error. - General Error (
onError
/.error
): This indicates that a more general error occurred during the transaction process, which might be related to the SDK's internal state, network issues, or authentication problems.
By implementing these callback mechanisms, your application can provide a robust and user-friendly payment experience, responding dynamically to all possible transaction outcomes.
Result Data Structures
The callback will return a data structure containing information related to the payment, depending on its outcome. See the sections below.
PaymentCompleteData
PaymentCompleteData
The PaymentCompleteData
data structure is received when a payment is successful and contains the following information:
Parameter | Description |
---|---|
merchantTranId | The unique merchant transaction identifier. |
sessionId | The session ID associated with the payment. |
tokenId | The token ID. |
resultCode | Result code from the payment processor. |
PaymentFailData
PaymentFailData
The PaymentFailData
data structure is received when a payment fails and contains the following information:
Parameter | Description |
---|---|
merchantTranId | The unique merchant transaction identifier. |
sessionId | The session ID for the payment. |
reason | Failure reason (user cancellation, refusal, etc.). |
Error Types
The SDK provides several error types to help diagnose issues during a transaction. You can find them in the table below:
Error Type | Description | Examples |
---|---|---|
EcomSdkError | Errors related to the SDK lifecycle. | not initialized |
PaymentError | Errors that occur during a payment. | AuthFailed , Timeout , NetworkError , GeneralError |
DropInFailureReason | Specific errors related to the payment checkout. | CanceledByUser , Refused |
See Also
Updated about 5 hours ago