Discount Applications exposes line level discounts on the Order API

Ryan
Shopify Staff
Shopify Staff
499 42 120

Hi!

If you missed it at Unite this year, we've exposed line level discount information on the Order API with a new readable property: discount_applications.  Take a look at the updated Order API reference for all of the details.  This feature will enable more accurate accounting when discounts are involved in orders.

We look forward to seeing what features this enables, as always please leave questions and comments in the thread below.

Shopify Apps Team

Ryan | Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit the Shopify Help Center or the Shopify Blog

Replies 42 (42)
Félix
Shopify Staff (Retired)
Shopify Staff (Retired)
16 0 0

Hi Clement! Just wanted to give you an update. We fixed the issue and the amount allocations should be showing on that order now. Sorry about the inconvenience. 

ClementG
Shopify Partner
660 0 143

Thanks Felix, I can see this order is fixed.

To clarify, was it fixed across all orders or just that particular one?

I'm hoping the fix is for all orders but if it's just this one, we'll have to make sure our code doesn't blow up and can handle that situation should it arise with another order. 

Félix
Shopify Staff (Retired)
Shopify Staff (Retired)
16 0 0

It was a fix for all orders impacted by this defect, not just this single one. Note that the fix might take some time to take effect on all shards because of caching.

ClementG
Shopify Partner
660 0 143

Sweet! Thanks again for the quick turn around.

We are deploying today.

ClementG
Shopify Partner
660 0 143

Hi Felix,

We ended up deploying today only, but we have already come across another order for which the data doesn't add up.

Order.total_discounts is 0 even though there is a discount application of 3,400.

The order id is 186524172301. Can you please take a look?

ClementG
Shopify Partner
660 0 143

And now another order that doesn't add up came through. This time it appears to be a rounding error.

Order.total_discounts is 135.99 but there are two discounts application of 68.00.

(2 x 68 = 136) != 135.99

This is not great and I'd appreciate if you could look into this one as well.

Order id is 527794110523.

We've only deployed this change for a few minutes ago so I'm assuming more of these might come through.

I will not report them anymore if they look like similar to those two cases...

Félix
Shopify Staff (Retired)
Shopify Staff (Retired)
16 0 0

Sure I’ll take a look at both. Thanks for reporting those!

Félix
Shopify Staff (Retired)
Shopify Staff (Retired)
16 0 0

The first order was created with bad data using Orders API. total_discounts was sent alongside discount_codes.amount with different values. At the time, we did not do any validation / recalculation if the two values were not synced. In other words, the client could send anything and it would just be persisted as is. We changed that on April 9th, discount_codes.amount now has precendence and total_discounts is calculated from ther former so this won't happen with orders created after that date.

As for the second issue, we are working on a fix for all orders. I will keep you posted.

Félix
Shopify Staff (Retired)
Shopify Staff (Retired)
16 0 0

We found a fix for the penny rounding issue and it should be deployed tomorrow.

ClementG
Shopify Partner
660 0 143

Thanks Felix for another quick turn around.

We've noticed a few more discrepancies in our logs and almost of them are related to the rounding issue so we're glad a fix is coming.

Any reason the first issue will not get a fix as well to set total_discounts  = discount_codes.amount?

Félix
Shopify Staff (Retired)
Shopify Staff (Retired)
16 0 0

Hi Clement!

The penny allocation bug is now fixed. I checked with your order and the amounts add up.

As for the first issue you mentioned, we have decided to not backfill those orders at this time as those were created as is by clients and this could have unintended side-effects.

ClementG
Shopify Partner
660 0 143
ClementG
Shopify Partner
660 0 143

Hi again Felix,

We found another issue which is slightly different.

It concerns an order created with the API so I suspect it's a problem with the order data, but Shopify did let it through.

The order has a non zero order.total_discounts but it has no discount codes.

There are no discount applications. I guess it makes given your earlier comment that discount_codes.amount has precedence.

However, clearly, total_discounts was not calculated from discount_codes.amount, as you had also mentioned, and we end up with an inconsistent order.

The order id is 604345466923.

Félix
Shopify Staff (Retired)
Shopify Staff (Retired)
16 0 0

Hi Clement!

Good observation, discount_codes.amount has precendence when both are provided, but total_discounts can still be provided by clients even if there no actual discount on the order (total_discounts usually being the calculated sum of existing discounts). This has been the case for a long time as well as orders are usually imported "as is".

In best of worlds, clients should not be able to send total_discounts, but ignoring the field could be problematic.

We will come up with a solution and get back to you. One possibility I see would be to create a manual discount allocated across all line items if no discount is explicitly provided but total_discounts is.

 

ClementG
Shopify Partner
660 0 143

Ok. I guess it would be nice to have some consistency and invariants that always hold.

 

Félix
Shopify Staff (Retired)
Shopify Staff (Retired)
16 0 0
Chris156
Shopify Partner
11 0 6

Helllo all, do you guys a sample JSON request that makes use of the discount_applications and discount_allocations?  I have not yet been sucessuly been able to create one that works :-S

Félix
Shopify Staff (Retired)
Shopify Staff (Retired)
16 0 0

Hey Chris! The API is read-only. There is no way to write discount applications and allocations directly. You need to go through the existing interface for this which will end up creating a discount application.

Chris156
Shopify Partner
11 0 6

Thanks for the reply Felix. That is so unfortunate 😞  - I really wish the Shopify Reference guide was a bit more cleat as to what data elements are read-only vs not - and in which operations, it would have saved me a lot of time.  

Is Shopify Planing on making these APIs usable via the POST Order API any time soon? 

Klarna
Shopify Partner
4 0 0

Our integration of the Klarna Payments gateways uses the Shopify Checkout object to display order data (order total, discount, shipping, tax, etc.) on our hosted page and also to create the Klarna order.  In order to accurately support orders with Automatic Discounts, we need the automatic discount data to be available on the Checkout object prior to the customer completing the order.  Currently when a customer selects on of our gateways as a payment method, the customer is redirected to our hosted page, which uses the API data to display checkout prices.  Currently Automatic Discount data is not available in the Checkout object at the point in time when the customer is redirected to our hosted page.  As soon as the order is created in Shopify (which we create using the Shopify REST API), the Checkout object would then get updated with the discount data (in applied_discount field), but that is too late for our integration.  If helpful, feel free to see the flow at our Klarna Shopify demo store. Can you help us determine how we access the Automatic Discount data prior to the customer placing the order?  thanks!