deferPaymentCapture

Submits a card PIN via a ForagePINEditText Element and defers payment capture to the server.

  • On success, the data property of the ForageApiResponse.Success object resolves with an empty string.

  • On failure, for example in the case of expired_session_token errors, the response includes a list of ForageError objects that you can unpack to programmatically handle the error and display the appropriate customer-facing message based on the ForageError.code.

// Example deferPaymentCapture call in a DeferPaymentCaptureViewModel.kt
class DeferPaymentCaptureViewModel : ViewModel() {
val snapPaymentRef = "s0alzle0fal"
val merchantId = "mid/<merchant_id>"
val sessionToken = "<session_token>"

fun deferPaymentCapture(foragePinEditText: ForagePINEditText, paymentRef: String) =
viewModelScope.launch {
val response = ForageSDK().deferPaymentCapture(
DeferPaymentCaptureParams(
foragePinEditText = foragePinEditText,
paymentRef = snapPaymentRef
)
)

when (response) {
is ForageApiResponse.Success -> {
// there will be no financial affects upon success
// you need to capture from the server to formally
// capture the payment
}
is ForageApiResponse.Failure -> {
// handle an error response here
}
}
}
}

Return

A ForageApiResponse object.

Parameters

params

A DeferPaymentCaptureParams model that passes a foragePinEditText instance and a paymentRef, returned by the Create a Payment endpoint, as the DeferPaymentCaptureParams.

See also

Throws

If the ForageConfig is not set for the provided foragePinEditText.