Refunds can be easily accepted via the Tyro SDK.
Please familiarise yourself with the guide to Integrate the SDK, as the steps outlined in this document builds upon the existing integration.
The Embedded Payments reader must be connected to process refunds.
Create a Refund Request as soon as the refund amount is known.
// Swift Sample Code
class RefundViewController: UIViewController {
...
fun startRefund(refundId: String) -> PaymentRequest {
let refundRequest = TyroTapToPay.shared.createRefundRequest(amountCents: 1000, referenceId: refundId)
...
}
...
}Initiate a refund by invoking startRefund(refundRequest). Tyro will display the Embedded Payments screen and prompt the customer to tap the screen. Once the customer has tapped their card, the refund will automatically be processed through Tyro.
The refund result will be returned in the startRefund(..) response. Save the transactionID to your server as it is used to reference the refund. Display the refund result in your app.
An error will be thrown if the refund was unsuccessful.
// Swift Sample Code
class RefundViewController: UIViewController {
...
fun startRefund(refundRequest: RefundRequest) async {
do {
let paymentResult = try await TyroTapToPay.shared.startRefund(refundRequest)
let transactionId = paymentResult.transactionID
var outcomeMsg = "Status :: " + paymentResult.statusCode + " - " +
paymentResult.statusMessage + "\n"
outcomeMsg += "Reference ID :: " + paymentResult.referenceID + "\n"
outcomeMsg += "Amount auth :: " + paymentResult.amountAuthorized + "\n"
outcomeMsg += "Transaction ID :: " + paymentResult.transactionID + "\n"
outcomeMsg += "Transaction date :: " + paymentResult.transactionDate + "\n"
outcomeMsg += "Approval code :: " + paymentResult.approvalCode + "\n"
outcomeMsg += "Invoice no :: " + paymentResult.invoiceNo + "\n"
outcomeMsg += "AID :: " + paymentResult.aid + "\n"
outcomeMsg += "Card type :: " + paymentResult.cardType + "\n"
outcomeMsg += "Card number :: " + paymentResult.cardNo + "\n"
outcomeMsg += "RRN :: " + paymentResult.rrn
// Display success to user
print(outcomeMsg)
} catch {
// Display error to user
print("Transaction failed.(" + error!.code + ":" + error!.message + ")")
}
...
}
...
}The current refund or payment can be cancelled if the cancellation is submitted before the transaction has been fully processed.
Initiate a cancellation attempt of the current transaction by invoking cancelCurrentTransaction(). If the cancellation has succeed, true is returned, otherwise false is returned.
// Swift Sample Code
class CancelViewController: UIViewController {
...
fun cancelTransaction() {
let cancellationResult = TyroTapToPay.shared.cancelCurrentTransaction()
if cancellationResult {
print("Transaction successfully cancelled")
} else {
print("Cancellation failed")
}
...
}
...
}