On this page

Processing discounts in the Lappa API

When working with the Lappa API, it’s essential to understand how discount logic operates across different merchant use cases. The API is built to support flexible discount application to orders in a straightforward manner. Below is a detailed breakdown of how this works.

Discount Communication at the line_items Level

Discounts in the Lappa API are applied at the line_items level. To apply a discount to a specific product, include the discount value as a positive number using the “discount” parameter within the corresponding line_item. Keep in mind that the discount represents the total reduction for the entire item quantity, not a per-unit figure.

For example, consider a product priced at $15 with a $1.5 discount per unit. If the order includes a quantity of 4 for that product, the total discount to be specified for that line item would be $6.

Order-Wide Discounts

When a discount applies to the entire order rather than a single product, the total discount amount must be distributed evenly across all line_items. For instance, if there is a $9 order-level discount spread across three items, each item should receive a $3 discount allocation.

To determine the final price for each item, deduct the per-item discount from its base price. The logic is simple and easy to implement. The sample code below demonstrates how to split an order-wide discount equally among all line items.

Command line

/order_discount = 9  # Order-wide discount
num_items = 3  # Number of items

discount_per_item = order_discount / num_items

for item in range(num_items):
    # Apply the discount to each item
    # Perform any necessary calculations or operations for each item
    item_price = 10  # Sample item price
    discounted_price = item_price - discount_per_item

    print(f"Item {item + 1} - Original Price: ${item_price}, Discounted Price: ${discounted_price}")

Including Discounts in Orders

When you’re ready to send orders containing discounts to Lappa via the /v2/transactions/orders endpoint, make sure all discounts are reflected at the line_item level as described above. For order-level discounts, divide the amount equally among the relevant line items before submission.

Running the code will produce the following output:

Command line

Item 1 - Original Price: $10, Discounted Price: $7.0
Item 2 - Original Price: $10, Discounted Price: $7.0
Item 3 - Original Price: $10, Discounted Price: $7.0

Ensuring Accurate Order Submission

When submitting the order, the “amount” field must equal the combined total of all line_items plus any applicable shipping charges. In the example above, with a $5 shipping cost, the submitted amount would be $55 — already accounting for the applied discount.

Benefits of Following the Guidelines

Following these guidelines ensures accurate discount handling within the API, allowing merchants to run effective promotions and deliver real value to their customers.

For more information on available integration options, visit the Integrations Page, which covers a wide range of supported platforms and tools.

If you have any questions or need technical assistance, feel free to reach out to the Lappa Support Team. We’re always ready to help.