Skip to content

Refunds

Call startRefund() to process a referenced refund against a previous transaction.

Function signature

fun startRefund(
    idempotencyId: String? = null,
    transactionId: String,
    refundAmount: Long,
    refundCallback: MPOSRefundCallback,
)
ParameterTypeRequiredDescription
idempotencyIdString?NoOptional identifier used to idempotently identify refund requests.
transactionIdStringYesThe ID of the original transaction to refund.
refundAmountLongYesAmount to refund in cents. Cannot exceed the original transaction amount.
refundCallbackMPOSRefundCallbackYesCallback receiving the refund result or error.

Callback

MPOSRefundCallback

interface MPOSRefundCallback {
    fun onSuccess(result: RefundResult?)
    fun onError(errorMessage: String)
}
CallbackTrigger
onSuccessRefund accepted. result.state is SUCCEEDED or PENDING. See RefundResult.
onErrorRefund failed. Check errorMessage for details. Refunds in any other state, such as FAILED, are reported here.

RefundResult

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,
)
FieldTypeDescription
idString?The ID of the refund.
amountLong?The refunded amount in cents.
traceIdString?The trace ID of the refund.
stateString?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.
failureCodeString?The failure code returned by Finix, if any. Normally null for an accepted refund.
failureMessageString?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) { }
    }
)