Client-Side Order Reporting on

Client-Side Order Reporting

You can report orders directly to Button's Order API within the Merchant Library using the reportOrder() method. In this guide, we'll:

Note: If reporting Orders directly from the client, there is no need to report orders server-side. However, you will need to periodically validate Orders via the Button Dashboard.


Create Order Object

Construct LineItems(s) and Customer objects and assign them to an Order.

// Create line items
let lineItem1 = Order.LineItem(identifier: "unique-item-id-1", total: 400)
let lineItem2 = Order.LineItem(identifier: "unique-item-id-2", total: 500)

// Create a customer (optional)
let customer = Order.Customer(id: "unique-customer-id")
customer.email = "1DDDE4A27FA6E869DBC99F25E392F1E1CB84A6FD1D13A9FF65491D8A0ED9BB4E" // SHA 256

// Create the order and add optional properties
let order = Order(id: "unique-order-id", purchaseDate: Date(), lineItems: [lineItem1, lineItem2])
order.customer = customer
// Create line items
LineItem *lineItem1 = [[LineItem alloc] initWithIdentifier:@"unique-item-id-1" total:400];
LineItem *lineItem2 = [[LineItem alloc] initWithIdentifier:@"unique-item-id-2" total:500];

// Create a customer (optional)
Customer *customer = [[Customer alloc] initWithId:@"unique-customer-id"];
customer.email = @"1DDDE4A27FA6E869DBC99F25E392F1E1CB84A6FD1D13A9FF65491D8A0ED9BB4E"; // SHA 256

// Create the order and add optional properties
Order *order = [[Order alloc] initWithId:@"unique-order-id" purchaseDate:[NSDate date] lineItems:@[lineItem1, lineItem2]];
order.customer = customer;

The required properties on each of the above objects are passed in the constructor. All optional fields can be set using dot notation.

IFA is used in conjunction with Button's Custom Audiences tool, which allows Brands to target and offer specific rates to particular users. IFA is reported by default with all orders. You can disable IFA reporting for Button orders using the Features module. However, this may prevent you from using the Custom Audiences tool.

// Disable usage of advertising id (IFA)
ButtonMerchant.features.includesIFA = false
// Disable usage of advertising id (IFA)
ButtonMerchant.features.includesIFA = NO;

Report the Order

After creating one or more LineItem objects, Customer, and Order you can then report your order to Button.

// Report the order directly to Button. The completion is optional.
ButtonMerchant.reportOrder(order) { error in
    // Handle error
}
// Report the order directly to Button. The completion is optional.
[ButtonMerchant reportOrder:order completion:^(NSError * _Nullable error) {
    // Handle error
}];

Validate Orders in the Dashboard

All orders reported from the client must be validated via the Button Dashboard. This is for security purposes and to prevent fraudulent orders.