Client-Side Order Reporting on
Android

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 invalidate Orders


Create Order Object

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

// Create line items
val lineItem1 = Order.LineItem.Builder("unique-item-id-1", 400).build()
val lineItem2 = Order.LineItem.Builder("unique-item-id-2", 500).build()
val lineItems = ArrayList<LineItem>()
lineItems.add(lineItem1)
lineItems.add(lineItem2)

// Create a customer (optional)
val customer = Order.Customer.Builder("unique-customer-id")
        .setEmail("1DDDE4A27FA6E869DBC99F25E392F1E1CB84A6FD1D13A9FF65491D8A0ED9BB4E") // SHA 256
        .build()

// Create the order and add optional properties
val order = Order.Builder("unique-order-id", Date(), lineItems)
        .setCustomer(customer)
        .build()
// Create line items
Order.LineItem lineItem1 = new Order.LineItem.Builder("unique-item-id-1", 400).build();
Order.LineItem lineItem2 = new Order.LineItem.Builder("unique-item-id-2", 500).build();
List<Order.LineItem> lineItems = new ArrayList<>();
lineItems.add(lineItem1);
lineItems.add(lineItem2);

// Create a customer (optional)
Order.Customer customer = new Order.Customer.Builder("unique-customer-id")
        .setEmail("1DDDE4A27FA6E869DBC99F25E392F1E1CB84A6FD1D13A9FF65491D8A0ED9BB4E") // SHA 256
        .build();

// Create the order and add optional properties
Order order = new Order.Builder("unique-order-id", new Date(), lineItems)
        .setCustomer(customer)
        .build();

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().setIncludesIfa(false);

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
ButtonMerchant.reportOrder(context, order) { throwable ->
    if (throwable == null) {
        // Report order success
        Log.d(TAG, "Report Order Success")
    } else {
        // Report order failed
        Log.e(TAG, "Report Order Failed", throwable)
    }
}
// Report the order directly to Button
ButtonMerchant.reportOrder(context, order, new OrderListener() {
    @Override
    public void onResult(@Nullable Throwable throwable) {
        if (throwable == null) {
            // Report order success
            Log.d(TAG, "Report Order Success");
        } else {
            // Report order failed
            Log.e(TAG, "Report Order Failed", throwable);
        }
    }
});

Invalidate Orders

To setup an invalidations process for orders reported from the client, reach out to your Button representative.