refundPayment

Refunds a Payment via a ForageVaultElement (either a ForagePINEditText or a ForagePinPad). This method is only available for POS Terminal transactions. You must use ForageTerminalSDK.

  • On success, the response includes a Forage PaymentRefund object. (Example Refund and Receipt class)

  • 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(forageVaultElement: ForagePINEditText) = viewModelScope.launch {
val forageTerminalSdk = ForageTerminalSDK.init(...) // may throw!
val refundParams = RefundPaymentParams(
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 RefundPaymentParams model that passes a ForageVaultElement (either a ForagePINEditText or a ForagePinPad) instance and a paymentRef, returned by the Create a Payment endpoint, an amount, and a reason as the RefundPaymentParams.

See also

  • SDK errors for more information on error handling.