Skip to main content

Transactions

Create a transaction

Create a TransactionIntent with the transaction type and an SDKTransactionListener implementation:

TransactionIntentFactory.createTransactionIntent(
type: .payment,
listener: transactionListener
) { result in
switch result {
case let .success(transactionIntent):
// Retain the transaction intent.
self.transaction = transactionIntent
case let .failure(error):
// Handle the creation error.
break
}
}

Supported transaction types are .payment, .refund, and .cancel.

The listener receives the states of both the reader and the transaction, and requests the data required to continue.

Listen to reader states

Use onReaderStateChanged to update your UI according to reader connectivity and reading progress:

func onReaderStateChanged(state: ReaderState) {
switch state {
case .notConnected:
break
case let .connecting(device):
break
case let .connected(device, readerInfo, status):
break
@unknown default:
break
}
}

Connected readers can be idle, waiting for a card, processing a read mode, or requesting an EMV PIN.

Listen to transaction states

Use onTransactionStateChanged to provide the selected reader and read configuration, and to handle transaction confirmation and result states:

func onTransactionStateChanged(state: SDKTransactionState) {
switch state {
case let .provideDevice(provideDeviceCallback: provideDeviceCallback):
provideDeviceCallback(selectedDevice)

case let .provideReadConfig(provideReadConfigCallback: provideReadConfigCallback):
let total = TransactionTotal(
gross: try! Money(amount: 100, currency: .ars)
)
let readConfig = ReadConfig(
readModes: [.swipe, .chip, .nfc],
timeout: 10,
transactionTotal: total
)
provideReadConfigCallback(readConfig)

case let .selectEMVApp(
availableAIDs: availableAIDs,
selectEMVAppCallback: selectEMVAppCallback
):
if let emvApp = availableAIDs.first {
selectEMVAppCallback(emvApp)
}

case let .confirmPayment(
card: card,
confirmCallback: confirmCallback,
rejectCallback: rejectCallback
):
// Provide payment confirmation data or reject the payment.
break

case let .confirmRefund(
card: card,
confirmCallback: confirmCallback,
rejectCallback: rejectCallback
):
// Provide refund confirmation data or reject the refund.
break

case let .confirmCancel(
card: card,
confirmCallback: confirmCallback,
rejectCallback: rejectCallback
):
// Provide cancellation confirmation data or reject the cancellation.
break

case let .approved(transactionApproved: transactionApproved):
// Handle an approved payment, refund, or cancellation.
break

case let .recoverableError(
error: error,
recoverCallback: recoverCallback
):
// Resolve the recoverable error and call recoverCallback.
break

case let .nonRecoverableError(error: error, message: message):
// Start a new transaction after handling the error.
break

@unknown default:
break
}
}

ReadConfig contains the amount and the supported card read modes for the transaction. The reader-specific flow starts after this configuration is provided.