Skip to content
payrocdevelopers

Add a line item

Add itemized product details to a Tap to Pay on iPhone sale using the CoreLineItem object, including a per-item tax.

Prerequisites: Authentication · Run a sale

To provide more information about a sale, you can add individual line items. Create a CoreLineItem object for each item, and assign the collection to the CoreSale object's lineItems array.

The CoreLineItem object includes the following fields:

FieldDescription
commodityCodeCommodity code of the item.
productCodeProduct code of the item.
itemDescriptionDescription of the item.
unitOfMeasureUnit of measure. A three-letter code used in international trade. For more information about the values that you can use, go to Units of measurement.
unitPricePrice for each unit of measure before any taxes or discounts
quantityNumber of units.
discountRateDiscount percentage to apply to the item.
taxesThe list of taxes to apply to the item. For more information, go to Add a tax to a line item.

Important: The SDK doesn't calculate the sale amount from the line items for you. Set sale.amount to the subtotal of all your line items. The subtotal is the unit price multiplied by the quantity, minus any discount.

The following example adds a line item to a sale:

Swift

swift
let item = CoreLineItem()
item.commodityCode = "AA"
item.productCode = "BB"
item.itemDescription = "Bread"
item.unitOfMeasure = EA
item.unitPrice = 2.00
item.quantity = 2
item.discountRate = 0
item.taxes = []

let lineItems = NSMutableArray()
lineItems.add(item)

let sale = CoreSale()
sale.amount = NSNumber(value: 4.00)
sale.transactionInputMethod = TAP
sale.lineItems = lineItems

terminal.processSale(sale)

Objective-C

objectivec
CoreLineItem *item = [[CoreLineItem alloc] init];
item.commodityCode = @"AA";
item.productCode = @"BB";
item.itemDescription = @"Bread";
item.unitOfMeasure = EA;
item.unitPrice = @2.00;
item.quantity = @2;
item.discountRate = @0;
item.taxes = [NSMutableArray array];

NSMutableArray *lineItems = [NSMutableArray array];
[lineItems addObject:item];

CoreSale *sale = [[CoreSale alloc] init];
sale.amount = @4.00;
sale.transactionInputMethod = TAP;
sale.lineItems = lineItems;

[[WTPSTerminal singleton] processSale:sale];

Add a tax to a line item

To apply a tax to an individual line item, add a CoreTax to the item's taxes array. To calculate the tax amount from a percentage, use CoreUtil, and then set a global CoreTax on the sale with the total tax amount.

Swift

swift
let tax = CoreTax()
tax.percentage = 10
let taxAmount = (CoreUtil.singleton() as! CoreUtil).calcTax(
    tax.percentage,
    withAmount: item.unitPrice,
    with: terminal.currency
)
tax.amount = taxAmount
item.taxes = [tax]

let globalTax = CoreTax()
globalTax.amount = taxAmount
globalTax.name = "Item tax"
sale.tax = globalTax

Objective-C

objectivec
CoreTax *tax = [[CoreTax alloc] init];
tax.percentage = @10;
NSNumber *taxAmount = [[CoreUtil singleton] calcTax:tax.percentage
                                        withAmount:item.unitPrice
                                      withCurrency:[[WTPSTerminal singleton] getCurrency]];
tax.amount = taxAmount;
item.taxes = [NSMutableArray arrayWithObject:tax];

CoreTax *globalTax = [[CoreTax alloc] init];
globalTax.amount = taxAmount;
globalTax.name = @"Item tax";
sale.tax = globalTax;

Note: If you want to apply a tax to the whole sale instead of a single line item, go to Add a tax.

The following example runs a complete sale with a line item and a tax applied to that line item:

Swift

swift
guard terminal.getDevice() != NODEVICE else {
    return
}

let item = CoreLineItem()
item.commodityCode = "AA"
item.productCode = "BB"
item.itemDescription = "Bread"
item.unitOfMeasure = EA
item.unitPrice = 2.00
item.quantity = 2
item.discountRate = 0

let tax = CoreTax()
tax.percentage = 10
tax.amount = (CoreUtil.singleton() as! CoreUtil).calcTax(
    tax.percentage,
    withAmount: item.unitPrice,
    with: terminal.currency
)
item.taxes = [tax]

let lineItems = NSMutableArray()
lineItems.add(item)

let globalTax = CoreTax()
globalTax.amount = tax.amount
globalTax.name = "Item tax"

let sale = CoreSale()
sale.amount = 4.00
sale.transactionInputMethod = TAP
sale.orderId = "YOUR_ORDER_REFERENCE"
sale.lineItems = lineItems
sale.tax = globalTax

terminal.processSale(sale)

Objective-C

objectivec
if ([[WTPSTerminal singleton] getDevice] == NODEVICE) {
    return;
}

CoreLineItem *item = [[CoreLineItem alloc] init];
item.commodityCode = @"AA";
item.productCode = @"BB";
item.itemDescription = @"Bread";
item.unitOfMeasure = EA;
item.unitPrice = @2.00;
item.quantity = @2;
item.discountRate = @0;

CoreTax *tax = [[CoreTax alloc] init];
tax.percentage = @10;
tax.amount = [[CoreUtil singleton] calcTax:tax.percentage
                                withAmount:item.unitPrice
                              withCurrency:[[WTPSTerminal singleton] getCurrency]];
item.taxes = [NSMutableArray arrayWithObject:tax];

NSMutableArray *lineItems = [NSMutableArray array];
[lineItems addObject:item];

CoreTax *globalTax = [[CoreTax alloc] init];
globalTax.amount = tax.amount;
globalTax.name = @"Item tax";

CoreSale *sale = [[CoreSale alloc] init];
sale.amount = @4.00;
sale.transactionInputMethod = TAP;
sale.orderId = @"YOUR_ORDER_REFERENCE";
sale.lineItems = lineItems;
sale.tax = globalTax;

[[WTPSTerminal singleton] processSale:sale];

Browse guides

Search documentation

API reference169
Guides118
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