Prerequisites: Authentication · Run a sale
If you want to add a tip to a sale, you can add a tip that you've predefined in the terminal, or you can add a custom tip amount.
Note: A sale can include only one tip at a time. If you assign a predefined tip, it replaces any tip amount that you previously set, including a custom tip amount.
Add a predefined tip
You can use the SDK to add a tip that you've already set up in the terminal. Your predefined tips are available in terminal.settings.tipListArray. Each entry is a CoreTip with a tipType of either PERCENTAGE or FIXED_AMOUNT. You don't need to carry out any calculations. Our gateway automatically adds the tip amount for you.
Note: tipListArray can be empty if there are no predefined tips in your terminal. Check that a tip is available before you select one. To create a tip, go to Create a predefined tip on the Self-Care Portal.
In your app, let the customer choose which tip to apply to the sale. The following code selects the first tip in the list:
Swift
if let tips = terminal.settings.tipListArray, tips.count > 0 {
sale.tip = tips[0] as? CoreTip
}
Objective-C
sale.tip = [[WTPSTerminal singleton] getSettings].tipListArray.firstObject;
The following example runs a complete sale with a predefined tip:
Swift
guard terminal.getDevice() != NODEVICE else {
return
}
let sale = CoreSale()
sale.amount = 42.00
sale.transactionInputMethod = TAP
sale.orderId = "YOUR_ORDER_REFERENCE"
if let tips = terminal.settings.tipListArray, tips.count > 0 {
sale.tip = tips[0] as? CoreTip
}
terminal.processSale(sale)
Objective-C
if ([[WTPSTerminal singleton] getDevice] == NODEVICE) {
return;
}
CoreSale *sale = [[CoreSale alloc] init];
sale.amount = [NSNumber numberWithDouble:42.00];
sale.transactionInputMethod = TAP;
sale.orderId = @"YOUR_ORDER_REFERENCE";
sale.tip = [[WTPSTerminal singleton] getSettings].tipListArray.firstObject;
[[WTPSTerminal singleton] processSale:sale];
Add a custom tip
You can use the SDK to add a custom tip that's specific to each sale. The SDK accepts only an amount for a custom tip, and doesn't accept a percentage. To specify the value of the custom tip, use addTipWithAmount. The following example adds a tip amount of $5.00 to a sale:
Swift
sale.addTip(withAmount: 5.00)
Objective-C
[sale addTipWithAmount:@5.00];
The following example runs a complete sale with a custom tip:
Swift
guard terminal.getDevice() != NODEVICE else {
return
}
let sale = CoreSale()
sale.amount = 42.00
sale.transactionInputMethod = TAP
sale.orderId = "YOUR_ORDER_REFERENCE"
sale.addTip(withAmount: 5.00)
terminal.processSale(sale)
Objective-C
if ([[WTPSTerminal singleton] getDevice] == NODEVICE) {
return;
}
CoreSale *sale = [[CoreSale alloc] init];
sale.amount = [NSNumber numberWithDouble:42.00];
sale.transactionInputMethod = TAP;
sale.orderId = @"YOUR_ORDER_REFERENCE";
[sale addTipWithAmount:[NSNumber numberWithDouble:5.00]];
[[WTPSTerminal singleton] processSale:sale];