I would like to see the amount of each discount code in the GraphQL query order results, but I see a mixed payload of amounts and percentages.
In the order update webhook, the payload arrives with discount codes in an array in the desired format:
“discount_codes”: [
{
"amount": "10.00",
"code": "discounttest",
"type": "fixed_amount"
},
{
"amount": "19.99",
"code": "foo",
"type": "percentage"
}
]
However, when I query the order data via GraphQL, the discountCodes array is just an array of strings and the discountApplications attribute only lists the percentage discount, not the actual value.
{
"index": 1,
"allocationMethod": "ACROSS",
"__typename": "DiscountCodeApplication",
"value": {
"percentage": 10.0,
"__typename": "PricingPercentageValue"
},
"targetType": "LINE_ITEM",
"targetSelection": "ALL",
"code": "foo"
}
Is there a way to extract the value for each discount in the GraphQL query without calculating it?
If I do end up calculating the discount (not my first choice), I’m also trying to understand the rounding rule Shopify applies to currency. In this example, 10% of the total order amount of 199.98 is 19.998. If I round to the nearest penny, I end up with a discount of 20.00. Shopify uses 19.99 and appears to truncate. What rule is Shopify using here and throughout?