Purchase
Starting a purchase
Once a device has been selected, you can start a transaction using the startTransaction method on your ToroClient instance:
toro.startTransaction(
amount = 1000, // £10.00
type = TransactionType.Purchase
currencyCode = CurrencyCode.GBP,
metadata = TransactionMetadata(
saleReferenceId = "ORDER-123",
),
onCompleted = { receipt ->
// Handle successful transaction
println("Transaction completed: ${receipt.transactionId}")
},
onCancelled = { cancellationType ->
when (cancellationType) {
CancellationType.ATTENDANT -> println("Transaction cancelled in app")
CancellationType.CUSTOMER -> println("Transaction cancelled on Miura device")
}
},
onError = { error ->
when (error) {
is DeviceNotSelected -> handleDeviceError(error)
is DeviceConnectionFailed -> reconnectDevice()
is DeviceDisconnected -> showReconnectionPrompt()
else -> showErrorMessage(error.message)
}
},
onGratuityConfirmed = { gratuityAmount, gratuityPercentage ->
// Handle gratuity confirmation
println("Gratuity added: £${gratuityAmount / 100.0} ($gratuityPercentage%)")
}
)
Parameters
Parameter | Type | Description |
|---|---|---|
amount | Int | The total amount to charge in the smallest unit of the currency (e.g., pence for GBP, cents for EUR/USD). For example, £10.00 would be passed as 1000. |
type | TransactionType | Type of transaction to be performed. Currently only Purchase and Refund are supported. |
currencyCode | CurrencyCode | The currency code for the transaction (e.g., CurrencyCode.GBP, CurrencyCode.EUR). |
metadata | TransactionMetadata? | Optional metadata to be included with the transaction. Can include reference numbers, order IDs, or other transaction-specific data. |
onCompleted | (TransactionReceipt) -> Unit | Callback triggered when the transaction successfully completes. Provides a TransactionReceipt containing transaction details. |
onCancelled | (CancellationType) -> Unit | Callback triggered when the transaction is cancelled. The CancellationType indicates whether it was user-initiated or due to a timeout. |
onError | (ToroException) -> Unit | Callback triggered when an error occurs during the transaction. See Exceptions section for possible error types. |
onGratuityConfirmed | ((Int, Int) -> Unit)? | Optional callback triggered when gratuity is confirmed. Provides both the gratuity amount and percentage. Only called when gratuity is enabled in ToroConfig. |