capture Payment
Immediately captures a payment via a com.joinforage.forage.android.ui.ForagePINEditText Element.
On success, the object confirms the transaction. The response includes a Forage
Payment
object.On failure, for example in the case of
card_not_reusable
orebt_error_51
errors, the response includes a list of com.joinforage.forage.android.core.services.forageapi.network.ForageError objects that you can unpack to programmatically handle the error and display the appropriate customer-facing message based on theForageError.code
.
// Example capturePayment call in a PaymentCaptureViewModel.kt
class PaymentCaptureViewModel : ViewModel() {
val snapPaymentRef = "s0alzle0fal"
val merchantId = "<merchant_id>"
val sessionToken = "<session_token>"
fun capturePayment(foragePinEditText: ForagePINEditText, paymentRef: String) =
viewModelScope.launch {
val response = ForageSDK().capturePayment(
CapturePaymentParams(
foragePinEditText = foragePinEditText,
paymentRef = snapPaymentRef
)
)
when (response) {
is ForageApiResponse.Success -> {
val payment = response.toPayment()
// Unpack payment.ref, payment.receipt, etc.
}
is ForageApiResponse.Failure -> {
val error = response.error
// handle Insufficient Funds error
if (error.code == "ebt_error_51") {
val details = error.details as ForageErrorDetails.EbtError51Details
val (snapBalance, cashBalance) = details
// display balance to the customer...
}
}
}
}
}
Return
A ForageApiResponse object. Use toPayment() to convert the data
string to a Payment.
Parameters
A CapturePaymentParams model that passes a foragePinEditText
instance and a paymentRef
, returned by the Create a Payment endpoint, that Forage uses to capture a payment.
See also
SDK errors for more information on error handling.
Test EBT Cards to trigger payment capture exceptions during testing.
Throws
If the ForageConfig is not set for the provided foragePinEditText
.