Call startRefund() to process a referenced refund against a previous transaction.
Function signature
fun startRefund(
idempotencyId: String? = null,
transactionId: String,
refundAmount: Long,
refundCallback: MPOSRefundCallback,
)| Parameter | Type | Required | Description |
|---|---|---|---|
idempotencyId | String? | No | Optional identifier used to idempotently identify refund requests. |
transactionId | String | Yes | The ID of the original transaction to refund. |
refundAmount | Long | Yes | Amount to refund in cents. Cannot exceed the original transaction amount. |
refundCallback | MPOSRefundCallback | Yes | Callback receiving the refund result or error. |
MPOSRefundCallback
interface MPOSRefundCallback {
fun onSuccess(result: RefundResult?)
fun onError(errorMessage: String)
}| Callback | Trigger |
|---|---|
onSuccess | Refund accepted. result.state is SUCCEEDED or PENDING. See RefundResult. |
onError | Refund failed. Check errorMessage for details. Refunds in any other state, such as FAILED, are reported here. |
RefundResult shape
data class RefundResult(
val id: String? = null,
val amount: Long? = null,
val traceId: String? = null,
val state: String? = null,
val failureCode: String? = null,
val failureMessage: String? = null,
)| Field | Type | Description |
|---|---|---|
id | String? | The ID of the refund. |
amount | Long? | The refunded amount in cents. |
traceId | String? | The trace ID of the refund. |
state | String? | The state of the refund, either SUCCEEDED or PENDING. A PENDING refund is accepted, but its funds have not moved yet. Check this field before you tell the cardholder their refund is on the way. For more information, see Pending refunds. |
failureCode | String? | The failure code returned by Finix, if any. Normally null for an accepted refund. |
failureMessage | String? | The failure message returned by Finix, if any. Normally null for an accepted refund. |
mpos.startRefund(
idempotencyId = null,
transactionId = "TRxxxxxx",
refundAmount = 500L,
refundCallback = object : MPOSRefundCallback {
override fun onSuccess(result: RefundResult?) { }
override fun onError(errorMessage: String) { }
}
)
mpos.startRefund(
idempotencyId = null,
transactionId = "TRxxxxxx",
refundAmount = 500L,
refundCallback = object : MPOSRefundCallback {
override fun onSuccess(result: RefundResult?) {
// refund accepted
}
override fun onError(errorMessage: String) {
// refund failed
}
}
)
mpos.startRefund(
idempotencyId = null,
transactionId = "TRxxxxxx",
refundAmount = 500L,
refundCallback = object : MPOSRefundCallback {
override fun onSuccess(result: RefundResult?) {
when (result?.state) {
"PENDING" -> { /* refund accepted, funds have not moved yet */ }
"SUCCEEDED" -> { /* refund succeeded */ }
else -> { /* missing or unexpected state; do not treat as succeeded */ }
}
}
override fun onError(errorMessage: String) { }
}
)