Skip to content
developers

Add a tax

Add a tax to a sale that you run through Mobile Sync.

Prerequisites: Authentication · Run a sale

To add a tax to a sale, send the tax rate, the subtotal, and the total amount with your sale request. The total amount is the subtotal plus the tax amount.

Our gateway uses the tax rate and the subtotal to calculate the tax amount, and then checks that it matches the total amount that you sent.

Before you begin

Add a tax to a sale

In your request, send the following parameters in the Payloads.sale object from Run a sale:

ParameterValue
taxRatePercentageThe tax rate as a percentage, for example, 10.0.
amountMinorUnitsThe subtotal, which is the amount before the tax.
totalAmountMinorUnitsThe subtotal plus the tax amount.

The subtotal and total amounts are in the currency's lowest denomination, also known as minor units. For example, if the subtotal is $10.00, the value is 1000 in minor units.

Our gateway uses banker's rounding, also known as round half to even. If a value is exactly halfway between two minor units, our gateway rounds it to the nearest even number. For example, 10.5 rounds to 10, and 11.5 rounds to 12.

If the amounts don't match, our gateway rejects the sale request.

Note: If you also add a tip, calculate a percentage tip on the subtotal plus the tax. For more information, go to Add a tip.

Example code

Add the following code to the pay() function from Run a sale, in place of the call to makeSalePayload. The code uses the client, terminalId, and orderId values from that function.

The code also uses banker's rounding to round the tax amount to the nearest even minor unit.

swift
import AppSwitchGatewayReference

let subtotal = 1000                                                            // $10.00
let taxRate = 10.0                                                             // percent
let tax = Int((Double(subtotal) * taxRate / 100).rounded(.toNearestOrEven))    // 100

let payload = Payloads.sale(
    amountMinorUnits: subtotal,                                                // the subtotal, before tax
    entryMethod: .deviceReadOrManualEntry,
    dialect: client.apiType,
    terminalId: terminalId,
    currency: "USD",
    taxRatePercentage: taxRate,
    totalAmountMinorUnits: subtotal + tax,                                     // 1100
    orderId: orderId
)

Browse guides

Search documentation

API reference169
Guides131
Knowledge38
legal1
Solutions32
Workflows74
↑↓highlight↵openView all search results

Menu

Theme

Sign out

Your saved plans remain in your organization. This browser’s private draft and account view will be cleared.

Talk to an engineer