appliedDiscount - discrepancy between 'value' and amountSet.shopAmount

When I create (or calculate) a draftOrder, I use the ‘value’ field to pass the amount of a discount in store currency (here, 4007.26). In the output, I expect the storeMoney amount in the amountSet to be the same. But it’s different (4087.37).

The deprecated amountV2 and amount fields also show the wrong value and the biggest problem is that the value in presentment currency is calculated based on this value. Any idea why this happens and how I can add a fixed amount discount to a draft order?

Here is the response returned from the API:

Hey Lukasz,

Can you post the full query (with sensitive info removed) to check if there’s anything with the structure that could be causing this?

1 Like

Hi Liam,
thank you for the response! Here is the input passed to the draftOrderCalculate mutation:

{
  "input": {
    "acceptAutomaticDiscounts": false,
    "lineItems": [
      {
        "quantity": 2,
        "requiresShipping": true,
        "variantId": "gid://shopify/ProductVariant/41002340089952"
      }
    ],
    "note": "Related to order #1197",
    "presentmentCurrencyCode": "USD",
    "email": "redacted@gmail.com",
    "visibleToCustomer": true,
    "shippingAddress": {
      "address1": "Redacted",
      "address2": null,
      "city": "Redacted",
      "company": null,
      "countryCode": "US",
      "firstName": "Redacted",
      "lastName": "Redacted",
      "phone": null,
      "provinceCode": "CA",
      "zip": "Redacted"
    },
    "appliedDiscount": {
      "title": "Returned items",
      "description": "Order #1197",
      "value": 4007.26,
      "valueType": "FIXED_AMOUNT"
    },
    "purchasingEntity": {
      "customerId": "gid://shopify/Customer/6806789193824"
    }
  }
}

the the query was (after I added all the discount fields trying to figure this out):

mutation CalculateDraftOrder($input: DraftOrderInput!) {
    draftOrderCalculate(input: $input) {
        calculatedDraftOrder {
            totalPriceSet { ...PriceSetFields }
            totalDiscountsSet { ...PriceSetFields }
            totalDiscountsSet { ...PriceSetFields }
            subtotalPriceSet { ...PriceSetFields }
            appliedDiscount {
                amountSet { ...PriceSetFields }
                description
                title
                value
                valueType
                amount
                amountV2 {
                    amount
                    currencyCode
                }
            }
            lineItems {
                appliedDiscount {
                    amountSet { ...PriceSetFields }
                    description
                    title
                    value
                    valueType
                }
            }
            acceptAutomaticDiscounts
            discountCodes
            platformDiscounts {
                id
                code
                title
                totalAmountPriceSet { ...PriceSetFields }
            }
        }
        userErrors {
            field
            message
        }
    }
}

Hi - so the value field in the appliedDiscount object represents the discount amount in the store’s currency when valueType is set to FIXED_AMOUNT. You’ll want to check that the value is correctly formatted as a Float and matches the expectations of the store’s currency precision.

Shopify’s calculations might involve rounding or precision adjustments, especially when converting between currencies or applying discounts. This could explain why the storeMoney amount in the amountSet differs slightly from the input value.

To debug further, you could include detailed fields in the query to inspect the discount application and calculation. EG:

     mutation CalculateDraftOrder($input: DraftOrderInput!) {
       draftOrderCalculate(input: $input) {
         calculatedDraftOrder {
           totalPriceSet {
             shopMoney {
               amount
               currencyCode
             }
             presentmentMoney {
               amount
               currencyCode
             }
           }
           totalDiscountsSet {
             shopMoney {
               amount
               currencyCode
             }
             presentmentMoney {
               amount
               currencyCode
             }
           }
           appliedDiscount {
             amountSet {
               shopMoney {
                 amount
                 currencyCode
               }
               presentmentMoney {
                 amount
                 currencyCode
               }
             }
             value
             valueType
             description
             title
           }
           userErrors {
             field
             message
           }
         }
       }
     }

You could also consider applying the discount at the line item level instead of the draft order level. This can sometimes provide more control over how discounts are calculated and applied.

Hi Liam, please find the outputs below. The input is the same as above, with the amount changed to 1000.00. I can confirm that the store currency is SEK and the expected precision is two decimal places.

I notice that the difference is always ~2%, which is Shopify’s conversion fee outside the US. Is it possible that this fee is somehow applied to the discount? I think it would be a bug or a really unexpected behavior if it was since the discount value is being provided in the store currency.

I also notice that the discrepancy depends on the draft order presentment currency (see at the end of this message) and disappears when the two currencies are the same.

I can achieve the desired discount by putting in the (DESIRED_DISCOUNT / 1.02), e.g. if I put in 980.392157, a 1000 discount is applied. If this kind of workaround is required, I would appreciate some confirmation/documentation of where this behavior comes from and if it can be relied on long term.

{
   "data":{
      "draftOrderCalculate":{
         "calculatedDraftOrder":{
            "totalPriceSet":{
               "shopMoney":{
                  "amount":"5105.06",
                  "currencyCode":"SEK"
               },
               "presentmentMoney":{
                  "amount":"488.41",
                  "currencyCode":"USD"
               }
            },
            "totalDiscountsSet":{
               "shopMoney":{
                  "amount":"1020.05",
                  "currencyCode":"SEK"
               },
               "presentmentMoney":{
                  "amount":"97.59",
                  "currencyCode":"USD"
               }
            },
            "appliedDiscount":{
               "amountSet":{
                  "shopMoney":{
                     "amount":"1020.05",
                     "currencyCode":"SEK"
                  },
                  "presentmentMoney":{
                     "amount":"97.59",
                     "currencyCode":"USD"
                  }
               },
               "value":1000,
               "valueType":"FIXED_AMOUNT",
               "description":"Order #1197",
               "title":"Returned items"
            },
            "lineItems":[
               {
                  "originalTotalSet":{
                     "presentmentMoney":{
                        "amount":"586.0",
                        "currencyCode":"USD"
                     },
                     "shopMoney":{
                        "amount":"6125.1",
                        "currencyCode":"SEK"
                     }
                  },
                  "discountedTotalSet":{
                     "presentmentMoney":{
                        "amount":"586.0",
                        "currencyCode":"USD"
                     },
                     "shopMoney":{
                        "amount":"6125.1",
                        "currencyCode":"SEK"
                     }
                  },
                  "appliedDiscount":null
               }
            ]
         },
         "userErrors":[
            
         ]
      }
   },
   "extensions":{
      "cost":{
         "requestedQueryCost":13,
         "actualQueryCost":13,
         "throttleStatus":{
            "maximumAvailable":2000,
            "currentlyAvailable":1987,
            "restoreRate":100
         }
      }
   }
}

Here is an attempt to add the discount to the line item - the same discrepancy is present:

{
   "data":{
      "draftOrderCalculate":{
         "calculatedDraftOrder":{
            "totalPriceSet":{
               "shopMoney":{
                  "amount":"4085.01",
                  "currencyCode":"SEK"
               },
               "presentmentMoney":{
                  "amount":"390.82",
                  "currencyCode":"USD"
               }
            },
            "totalDiscountsSet":{
               "shopMoney":{
                  "amount":"2040.1",
                  "currencyCode":"SEK"
               },
               "presentmentMoney":{
                  "amount":"195.18",
                  "currencyCode":"USD"
               }
            },
            "appliedDiscount":null,
            "lineItems":[
               {
                  "originalTotalSet":{
                     "presentmentMoney":{
                        "amount":"586.0",
                        "currencyCode":"USD"
                     },
                     "shopMoney":{
                        "amount":"6125.1",
                        "currencyCode":"SEK"
                     }
                  },
                  "discountedTotalSet":{
                     "presentmentMoney":{
                        "amount":"390.82",
                        "currencyCode":"USD"
                     },
                     "shopMoney":{
                        "amount":"4085.0",
                        "currencyCode":"SEK"
                     }
                  },
                  "appliedDiscount":{
                     "amountSet":{
                        "shopMoney":{
                           "amount":"2040.1",
                           "currencyCode":"SEK"
                        },
                        "presentmentMoney":{
                           "amount":"195.18",
                           "currencyCode":"USD"
                        }
                     },
                     "value":1000,
                     "valueType":"FIXED_AMOUNT",
                     "description":"Order #1197",
                     "title":"Returned items"
                  }
               }
            ]
         },
         "userErrors":[
            
         ]
      }
   },
   "extensions":{
      "cost":{
         "requestedQueryCost":13,
         "actualQueryCost":13,
         "throttleStatus":{
            "maximumAvailable":2000,
            "currentlyAvailable":1987,
            "restoreRate":100
         }
      }
   }
}

Now varying only the presentment currency of the draft order:

[appliedDiscount] => Array
(
    [amountSet] => Array
    (
        [shopMoney] => Array
        (
            [amount] => 1000.0
            [currencyCode] => SEK
        )

        [presentmentMoney] => Array
        (
            [amount] => 1000.0
            [currencyCode] => SEK
        )
    )

    [value] => 1000
    [valueType] => FIXED_AMOUNT
    [description] => Order #1197
    [title] => Returned items
)
[appliedDiscount] => Array
(
    [amountSet] => Array
    (
        [shopMoney] => Array
        (
            [amount] => 1020.0
            [currencyCode] => SEK
        )

        [presentmentMoney] => Array
        (
            [amount] => 2020.19
            [currencyCode] => MXN
        )
    )

    [value] => 1000
    [valueType] => FIXED_AMOUNT
    [description] => Order #1197
    [title] => Returned items
)
[appliedDiscount] => Array
(
    [amountSet] => Array
    (
        [shopMoney] => Array
        (
            [amount] => 1019.97
            [currencyCode] => SEK
        )

        [presentmentMoney] => Array
        (
            [amount] => 91.98
            [currencyCode] => EUR
        )
    )

    [value] => 1000
    [valueType] => FIXED_AMOUNT
    [description] => Order #1197
    [title] => Returned items
)

I don’t think so - this fee would just be applied when a checkout is completed, and a transaction occurs. In this case there would not be a transaction yet. If you try the draftOrderCreate mutation instead do you see the same effect?

Yes, exactly the same behavior.

Thanks for confirming this, another thing I’m thinking is if you change the stores default currency to EUR instead of SEK and in the mutation use EUR instead, do you see the same issue?

1 Like

I can confirm that the same happens regardless of the store currency. Tried with both EUR and USD.

I feel this could be related to currency conversions (and not payment processing fees) - have you reached out to direct support on this yet?

I see! No, I have not. To be honest, based on prior experiences, I have little hope that contacting Shopify support can bring a resolution. Are you suggesting to do it?