refundPayment

Refunds a Payment via a ForagePinEditText Element. This method is only available for POS Terminal transactions. You must use ForageTerminalSDK.

  • On success, the response includes a Forage PaymentRefund object.

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

// Example refundPayment call in a PosRefundViewModel.kt
class PosRefundViewModel : ViewModel() {
var paymentRef: String = ""
var amount: Float = 0.0
var reason: String = ""
var metadata: HashMap? = null

fun refundPayment(foragePinEditText: ForagePINEditText) = viewModelScope.launch {
val forageTerminalSdk = ForageTerminalSDK.init(...) // may throw!
val refundParams = PosRefundPaymentParams(
foragePinEditText,
paymentRef,
amount,
reason,
metadata,
)
val response = forage.refundPayment(refundParams)

when (response) {
is ForageApiResponse.Success -> {
// do something with response.data
}
is ForageApiResponse.Failure -> {
// do something with response.errors
}
}
}
}

Return

A ForageApiResponse object.

Parameters

params

A PosRefundPaymentParams model that passes a foragePinEditText instance, a paymentRef, returned by the Create a Payment endpoint, an amount, and a reason as the PosRefundPaymentParams.

See also

  • SDK errors for more information on error handling.

Throws

If the PosForageConfig is not set for the provided foragePinEditText.