question

webforte avatar image
webforte asked David Marginian Deactivated edited

Order discount not working using rest api

Hi,
I am able to apply a discount on an order but when we make payment its takes full payment of the order, not the remaining amount.
Also when we are adding the remaining amount in pay API then able to pay the pending amount but the order status shows partially_paid.

Please refer to this screenshot:- https://prnt.sc/245regu
ex.

If a Line item's price is $15 and applied a discount coupon of $5 then the user should pay only $10.
But order-pay API charges the user $15.

Thanks

OrdersPaymentsDiscounts
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

David Marginian avatar image
David Marginian Deactivated answered

What API are you using to add the discount? Can you provide the request you are making minus any sensitive information (access tokens). Can you provide an order id?

10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

webforte avatar image
webforte answered

https://api.clover.com/v3/merchants/6ZA5DNC74X5S1/orders/XTQK4G3W583M8/discounts
Body json - { "discount":{ "id":"X2FF8YFS0G48C"},"amount":-1000,"name":"testing"}


Order ID - XTQK4G3W583M8

Order Receipt - https://prnt.sc/249ztz1

10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

webforte avatar image
webforte answered David Marginian Deactivated converted comment to answer

When paying for an order which has a discount coupon applied using this API
https://scl.clover.com/v1/orders/XTQK4G3W583M8/pay

{ "amount":499,"ecomind":"ecom","source":"clv_1TSTS4YVkU6TCArfCPWaaZt7" }

If the amount parameter is set for the remaining amount then the payment status shows as "Partially Paid"

But if the amount parameter is removed from body JSON then the user gets charged for the full amount of $14.99.
{ "ecomind":"ecom","source":"clv_1TSTS4YVkU6TCArfCPWaaZt7" }


10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

David Marginian avatar image
David Marginian Deactivated answered David Marginian Deactivated edited

The ecomm API will properly calculate the total ONLY if the order doesn't already have a total set. So, this is likely happening because you are setting the order's total to a value that doesn't account for the discount (setting the total, adding the discount, not updating the total to account for the discount). Please see https://community.clover.com/questions/29313/rest-api-applied-discounts-on-a-order-doesnt-affec.html for a similar issue. I would recommend that you use the atomic order endpoint to create the order which allows you to create an order in a single request (including discounts) and properly calculates and sets the total for you. Alternatively, you will need to either properly calculate the total after all adjustments have been made (total must account for discount, etc. see https://docs.clover.com/docs/calculating-order-totals) or not set a total so that the ecomm API can calculate and set it for you. With either of these solutions you should not be passing an amount in the order/pay request to pay for the order in full.

10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Welcome to the
Clover Developer Community