On this page

Processing discounts in the Lovat API

When it comes to working with the Lovat API, it is crucial to have a solid understanding of how to handle discounts for various merchant scenarios. Our API is designed to facilitate the application of discounts to orders seamlessly. Allow me to provide you with a comprehensive explanation.

Discount Communication at the line_items Level

Discounts within the Lovat API are communicated at the line_items level. If you need to apply a discount to a specific item, simply include the discount amount as a positive value using the “discount” parameter for that particular line_item. It is important to note that discounts are provided as a cumulative discount for the item, rather than on a per-unit basis.

For instance, let’s consider an item priced at $15 with a discount of $1.5. If the order contains a quantity of 4 for this item, you would indicate a total discount of $6 for that particular item.

Order-Wide Discounts

Now, let’s discuss discounts that are applicable to the entire order, rather than a single item. In such cases, the discount amount needs to be evenly distributed among the line_items. For example, if there is a $9 order-wide discount and three distinct items, you would assign a discount of $3 to each item.

To calculate the discounted price for each item, simply subtract the discount per item from its original price. It is a straightforward process. The provided code illustrates how to evenly distribute the order-wide discount among the 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 are ready to submit orders with discounts to Lovat using the “/v2/transactions/orders” endpoint, ensure that the discounts are included at the line_item level, as previously discussed. Moreover, for order-wide discounts, divide the discount amount equally among the line_items.

When you run the code, it will output the following:

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

Remember, when sending the order, the “amount” parameter you include should match the total of the line_items, along with the shipping cost. Assuming the shipping cost is $5 in our example, you would submit an amount of $55, taking the applied discount into account.

Benefits of Following the Guidelines

By adhering to these guidelines, you will effectively manage discounts within our API, enabling merchants to provide exceptional promotions and incentives to their customers.

If you wish to acquire further knowledge on integrating with Lovat, please refer to our Integrations Page, which provides an extensive list of available options.

Furthermore, if you have any questions or require assistance, please do not hesitate to contact our dedicated Lovat Support Service. Our team is here to address any inquiries you may have.