Sale

A sale authorizes and captures a payment in a single step it when the final amount is known when the customer pays.

Prerequisites

  • Authenticated merchant with login()
  • Active location selected in app settings via setActiveLocationID() (iOS) or setActiveLocation() (Android)
  • Account linking and reader preparation completed on iOS, or location selection, enrollment, and reader preparation completed on Android

Persist eventId before submission. Create Android payment flows on Dispatchers.IO, apply flowOn(Dispatchers.IO), and collect from a Main/UI coroutine. Handle the full reader event flow described in the Android guide.

Use the handleTransactionEvent implementation in Android Running Payments. It handles progress, failure, pending or partial results, surcharge confirmation, and final approval or decline. The UI callbacks run on the main dispatcher.

Basic Sale

iOS:

let breakdown = PaymentBreakdown(
    subtotal: 10000,          // $100.00 in cents
    taxRate: 8.75,            // 8.75% as a percent value
    taxAmount: 875,           // $8.75 in cents
    tipAmount: 2000,          // $20.00 tip
    tipType: .fixed
)

let currency = CurrencyCode(currencyCode: "USD", displayName: "US Dollar")

let response = try await KoardMerchantSDK.shared.sale(
    amount: 12875,            // subtotal + tax + tip
    breakdown: breakdown,
    currency: currency,
    eventId: eventId
)

Android:

val breakdown = PaymentBreakdown(
    subtotal = 10000,
    taxRate = 8.75,
    taxAmount = 875,
    tipAmount = 2000,
    tipType = "fixed"
)

val flow = withContext(Dispatchers.IO) {
    sdk.sale(
        activity = activity,
        amount = 12875,
        breakdown = breakdown,
        eventId = eventId
    )
}.flowOn(Dispatchers.IO)
flow.collect { event -> handleTransactionEvent(event) }

Sale with Surcharge

For a configured total surcharge basis, the surcharge percentage is applied to the full transaction amount (subtotal + tax + tip). Other configured bases differ. This example uses a fixed surcharge amount:

surcharge = (subtotal + taxAmount + tipAmount) × (surchargePercentage / 100)
         = (10000 + 875 + 2000) × (3.5 / 100)
         = 451 cents ($4.51)

iOS:

let breakdown = PaymentBreakdown(
    subtotal: 10000,
    taxRate: 8.75,
    taxAmount: 875,
    tipAmount: 2000,
    tipType: .fixed,
    surcharge: PaymentBreakdown.Surcharge(
        amount: 451       // surcharge on full amount
    )
)

let response = try await KoardMerchantSDK.shared.sale(
    amount: 13326,            // 12875 + 451 surcharge
    breakdown: breakdown,
    currency: currency,
    eventId: eventId
)

Android:

val breakdown = PaymentBreakdown(
    subtotal = 10000,
    taxRate = 8.75,
    taxAmount = 875,
    tipAmount = 2000,
    tipType = "fixed",
    surcharge = Surcharge(
        amount = 451
    )
)

val flow = withContext(Dispatchers.IO) {
    sdk.sale(
        activity = activity,
        amount = 13326,
        breakdown = breakdown,
        eventId = eventId
    )
}.flowOn(Dispatchers.IO)
flow.collect { event -> handleTransactionEvent(event) }

Surcharge Confirmation

When the configured sale flow requires cardholder surcharge confirmation, the response is surchargePending on iOS or surcharge_pending in REST. Present the disclosure and final amount, then confirm or decline through the supported SDK flow. Do not assume every surcharged sale requires confirmation.

iOS:

if let transaction = response.transaction, transaction.status == .surchargePending {
    let disclosure = response.transaction?.surchargeDisclosure ?? ""
    let approved = await showSurchargeDisclosure(disclosure)

    let confirmed = try await KoardMerchantSDK.shared.confirm(
        transaction: transaction.transactionId,
        confirm: approved,
        amount: nil,
        breakdown: nil,
        eventId: confirmationEventId
    )
    renderChargeResult(confirmed) // Inspect the returned KoardTransaction
}

Android: See the current Android reader and confirmation flow in the Android Running Payments guide.

Bypassing Automatic Surcharge

Set bypass: true to skip the processor's automatic surcharge. Useful for custom BIN-based surcharging:

iOS:

let breakdown = PaymentBreakdown(
    subtotal: 10000,
    taxRate: 8.75,
    taxAmount: 875,
    tipType: .fixed,
    surcharge: PaymentBreakdown.Surcharge(bypass: true)
)

Android:

val breakdown = PaymentBreakdown(
    subtotal = 10000,
    taxRate = 8.75,
    taxAmount = 875,
    tipType = "fixed",
    surcharge = Surcharge(bypass = true)
)

Parameters

Parameter Type Required Description
amount Int Yes Total amount in minor units (cents)
breakdown PaymentBreakdown? No Itemized breakdown (see below)
currency CurrencyCode Yes (iOS) Currency for the transaction
eventId String? No Idempotency key (UUID recommended)
activity Activity Yes (Android) Android activity for NFC access

PaymentBreakdown

Field Type Description
subtotal Int Base amount in minor units
taxRate Double? Tax rate as a percent value (8.75 = 8.75%)
taxAmount Int Calculated tax in minor units
tipAmount Int? Tip in minor units
tipRate Double? Tip rate as decimal (alternative to fixed tip)
tipType TipType .fixed / .percentage (iOS) or "fixed" / "percentage" (Android)
surcharge Surcharge? Nested surcharge object

Surcharge

Field Type Default Description
amount Int? nil Fixed surcharge in minor units
percentage Double? nil Whole percent units: 3.5 means 3.5%. Applied to the configured surcharge basis.
bypass Bool false Skip automatic surcharge calculation

Result

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

See Also