Mobile SDK
...
Transactions
Purchase
3 min
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%)") } )toro starttransaction( 1000, // £10 00 transactiontype purchase, currencycode gbp, new transactionmetadata( "order 123", 0, null, collections emptymap() ), result > { // handle successful transaction system out println("transaction completed " + result); return null; }, cancellationtype > { if (cancellationtype == cancellationtype attendant) { system out println("transaction cancelled in app"); } else if (cancellationtype == cancellationtype customer) { system out println("transaction cancelled on miura device"); } return null; }, error > { if (error instanceof toroexception devicenotselected) { handledeviceerror((toroexception devicenotselected) error); } else if (error instanceof toroexception deviceconnectionfailed) { reconnectdevice(); } else if (error instanceof toroexception devicedisconnected) { showreconnectionprompt(); } else { showerrormessage(error getmessage()); } return null; }, (gratuityamount, gratuitypercentage) > { // handle gratuity confirmation system out println("gratuity added £" + (gratuityamount / 100 0) + " (" + gratuitypercentage + "%)"); return null; } ); 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 docid\ lhf0wyi0idkqdsmvsmeca 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
