Square-Applied Order Discounts

Pricing options configured for an order affect the way an order's price is calculated. For more information, see Square applies taxes and discounts. In this topic, you use the pricing option to have Square apply discounts based on pricing rules you defined in the catalog.

Link to section

Overview

First, create the products you want to sell. Define discounts on these items by creating a pricing rule. Using the Catalog API, do the following:

  • Create two products (CatalogItem objects). For this exercise, coffee and tea items are created.
  • Create a pricing rule that offers a 10% discount on these products:
    • Create a product set (CatalogProductSet object) consisting of the coffee and tea items. The pricing rule you create is applied by Square to items in the product set.
    • Create a discount (CatalogDiscount object) that defines the percentage discount (10%).
    • Create a pricing rule (CatalogPricingRule object) that identifies the discount and the product set to which the discount applies.

You then create example orders to explore how the Square-applied discounts affect the order's pricing calculation:

  • Create an order for the coffee and tea items. In the request, specify the pricing option (OrderPricingOptions) to request a Square-applied discount. The discount applies to all line items in the order.
  • Create an order to explore how the pricing list (OrderLineItemPricingBlocklists) is used to block Square from applying the discount to specific line items.
  • Update the order to remove the Square-applied discount from specific line items. You can explore how to use fields_to_clear in UpdateOrder to remove discounts from specific line items.

For more information, see How pricing rule-based discounts work.

Link to section

Step 1: Create two products for sale

Call BatchUpsertCatalogObjects to create two CatalogItem objects (coffee and tea items).

Batch upsert catalog objects

Verify the response. Note the following information:

  • You need the item IDs to create a product set.
  • You need the item variation IDs to place an order.

The following is an example response fragment:

Link to section

Step 2: Create a rule-based discount for the products

This step configures the products with a rule-based discount. The pricing rule you create applies to a product set. Therefore, you first create a product set consisting of the coffee and tea items:

Call BatchUpsertCatalogObjects to create all these items in a single request. Update the code by providing the IDs of the coffee and tea items for the product set.

Batch upsert catalog objects

The following is an example response fragment:

Link to section

Step 3: Test Square-applied discounts

Now you're ready to create orders and explore Square-applied discounts using pricing options.

Link to section

Step 3.1: Create an order with Square-applied discounts enabled

Call CreateOrder to create an order for a cup of coffee. The request includes the pricing_options with auto_apply_discounts enabled. Make sure you provide the variation ID of the small coffee in the request.

Create order

In the response, notice how pricing calculations are affected by the Square's application of the discounts configured for the items. For example:

  • The line item includes applied_discounts, which identifies the applied discount.
  • The order includes discounts, which provides details about the applied discount.

The following is an example response fragment:

Link to section

Step 3.2: Update an order to remove previously applied discounts

You can call UpdateOrder to remove discounts applied to specific line items. Add fields_to_clear to identify the line items and discounts you want to remove. Update the preceding order by removing the discount applied to the line item. Make sure you provide the order ID, location ID, line item ID, and ID of the discount you want to remove.

Update order

In the response, review the pricing calculation updates. For example:

  • The line item includes pricing_blocklists, which shows the discount that's blocked from being applied by Square.
  • The line item shows no discount and the order pricing is updated accordingly.
Link to section

Step 3.3: Create an order with Square-applied discounts enabled, but block specific line items

Create an order for both coffee and tea, but block one of the items from the Square-applied discount. In the following CreateOrder request:

  • pricing_options is specified to request Square-applied discounts.
  • One of the line items specifies pricing_blocklists and includes discount_catalog_object_id to block the discount from being applied.

Make sure you provide the coffee and tea item variation IDs, location ID, and the ID of the CatalogDiscount you created in step 2.

Create order

In the response, verify the pricing calculations. The discount is applied by Square to only one item. The following is an example response fragment: