Refund

A refund returns funds on an existing captured or settled payment where the processor supports it. Availability before settlement and supported refund amounts depend on the merchant configuration and processor rules.

For voiding a transaction before settlement, see Reverse.

Persist a separate eventId with your order before each operation below, and pass that saved value to the SDK. On a timeout or lost response, reconcile that ID instead of generating a new one. See Idempotency and Outcome Recovery.

Run Android reference operations from withContext(Dispatchers.IO). The examples unwrap Result with getOrThrow(); handle thrown errors at the UI boundary. Inspect the returned transaction status and operation amounts before displaying success. See the Android operation helpers.

Full Refund

iOS:

let response = try await KoardMerchantSDK.shared.refund(
    transactionId: transactionId,
    amount: 12875,
    eventId: eventId
)

Android:

val transaction = sdk.refund(
    transactionId = transactionId,
    amount = 12875,
    eventId = eventId
).getOrThrow()

Partial Refund

Refund a portion of the original transaction:

iOS:

let response = try await KoardMerchantSDK.shared.refund(
    transactionId: transactionId,
    amount: 5000,             // refund $50 of the original
    eventId: eventId
)

Android:

val transaction = sdk.refund(
    transactionId = transactionId,
    amount = 5000,
    eventId = eventId
).getOrThrow()

Tap-Based Refund (iOS)

For card-present refunds where the customer taps their card:

let response = try await KoardMerchantSDK.shared.refund(
    transactionId: transactionId,
    amount: 12875,
    eventId: eventId,
    withTap: true
)

Tap-based refunds require the card reader to be prepared. The customer taps their card to confirm the refund.

Tap-Based Refund (Android)

Use the Activity-based refund overload from a UI coroutine, with SDK work on IO:

val flow = withContext(Dispatchers.IO) {
    sdk.refund(
        activity = activity,
        transactionId = transactionId,
        amount = 12875,
        withTap = true,
        eventId = eventId
    )
}.flowOn(Dispatchers.IO)
flow.collect { response ->
    handleTransactionEvent(response) // Handler in Android Running Payments
}

refundEmv(...) is also supported as a tap-refund alias. Reference-based sdk.refund does not require an Activity or a new card tap. Wrap invocation and collection in the Running Payments error-handling pattern.

Surcharge Handling

When refunding a surcharged transaction, the surcharge is handled according to the processor's refund rules. Do not assume every processor prorates it automatically. Specify the intended refund amount and reconcile the returned refund and surcharge amounts.

Fiserv Nashville North (Global) refund breakdown

The amount you request is the total to return, including any tax and surcharge portion. Koard does not add another surcharge refund on top. For this route, Koard calculates the refund event's breakdown from the original payment; it does not rely on the processor to return that split.

Read the event with transaction_type: refund and the matching event_id in the operation response or transaction.refund webhook:

Field Meaning on the refund event
total_amount Amount returned by this refund
surcharge_amount Surcharge portion of this refund
tax_amount Tax portion of this refund
subtotal, tip_amount Remaining components of this refund
refunded Cumulative amount refunded across operations

These component fields describe the refund event, not the original sale. The SDK properties are surchargeAmount and taxAmount. A later transaction lookup can return a newer event, so retain the refund's event_id and use history or event lookup when reconciling it.

The surcharge portion is round_half_even(original_surcharge * refund_total / original_total), using the fee actually collected. Tax, tip and subtotal divide the remaining amount proportionally, with cent remainders allocated so the components sum to the refund total. The final refund returns any remaining surcharge cents from prior rounding.

For example, a payment with $100 subtotal, $10 tax, $20 tip and a $3 subtotal-based surcharge totals $133. A $66.50 refund returns $50 subtotal, $5 tax, $10 tip and $1.50 surcharge.

Parameters

Parameter Type Required Description
transactionId String Yes Original transaction to refund
amount Int? for reference refunds; Int for Android tap refunds Required for tap refunds Minor currency units; omit or pass null/nil for a full reference refund
eventId String? No Idempotency key
withTap iOS Bool, Android Boolean For the Android Activity overload Pass true for a card-present refund; iOS defaults to false
activity Activity For Android tap refunds Activity for a card-present refund; not required for reference-based refund

Result

This operation returns the transaction result. The Transaction Result lists the fields you can read from it.

See Also