Prerequisites: Authentication · Run a sale
Important: You can't run an unreferenced refund with the Tap to Pay on iPhone SDK. For more information about refund types, go to Refunds and reversals.
A referenced refund returns funds to the same card that the customer used for the original sale. You don't need the customer to tap their card again. If you refund a sale that hasn't settled yet, our gateway reverses the sale instead.
Before you begin, you need the uniqueRef of the sale that you want to refund. If you don't have it, go to Retrieve transactions.
Integration steps
Step 1. Register the refund listener
The SDK returns refund results to onRefundResponse: on your CoreAPIRefundListener. To register your refund listener when your view appears, and unregister it when the view disappears, use the following code:
Swift
// viewWillAppear:
terminal.register(self as CoreAPIRefundListener)
// viewWillDisappear:
terminal.unRegister(self as CoreAPIRefundListener)
Objective-C
// viewWillAppear:
[[WTPSTerminal singleton] registerCoreAPIRefundListener:self];
// viewWillDisappear:
[[WTPSTerminal singleton] unRegisterCoreAPIRefundListener:self];
Step 2. Run the refund
To run a refund, create a CoreRefund, and then call processRefund:.
CoreRefund includes the following properties:
| Property | Description | Required or optional |
|---|---|---|
uniqueRef | Unique ID of the sale that you want to refund. | Required |
reason | Reason for the refund. | Required |
amount | Amount that you want to refund. | Required |
orderId | Your identifier for the order. | Optional |
previousTxnDateTime | The date and time of the original transaction. | Optional |
autoCapture | Whether to capture the refund automatically. The default value is true. | Optional |
The following example refunds a sale:
Swift
let refund = CoreRefund()
refund.uniqueRef = "ORIGINAL_UNIQUE_REF"
refund.reason = "Customer request"
refund.amount = 42.00
terminal.processRefund(refund)
Objective-C
CoreRefund *refund = [[CoreRefund alloc] init];
refund.uniqueRef = @"ORIGINAL_UNIQUE_REF";
refund.reason = @"Customer request";
refund.amount = [NSNumber numberWithDouble:42.00];
[[WTPSTerminal singleton] processRefund:refund];
The SDK returns the result to onRefundResponse:.
Note: If the SDK reversed the sale instead of refunding it, onRefundResponse: returns a CoreSaleResponse instead of a CoreRefundResponse.
Refund errors
CoreAPIRefundListener uses the same onError:withDescription: signature as the sale listener. For more information, go to Handle errors.