Have your say in Community Polls: What was/is your greatest motivation to start your own business?
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Re: Assistance Needed: Dynamic Suggested Refund Calculation Using GraphQL

Solved

Assistance Needed: Dynamic Suggested Refund Calculation Using GraphQL

Sudhir
Shopify Partner
7 1 0

Hello everyone,

 

We have a GraphQL query to fetch the suggested refund for an order without applying any taxes and duties. However, the SuggestedRefund endpoint doesn't accept the argument refundImportTaxes. Our goal is to dynamically obtain the suggested refund value based on the selection of items, shipping, duties, and taxes.

Is there a workaround to achieve this?

 

GraphQL (API Version: 2024-07)
endpoint: query SuggestedRefund.
Parameter used:
{
    "id": "gid://shopify/Order/12345678",
    "refundLineItems": [
        {
            "lineItemId": "gid://shopify/LineItem/13579876",
            "quantity": 1,
            "restockType": "CANCEL",
            "removal": true
        }
    ],
    "refundDuties": [],
    "refundImportTaxes": false,
    "refundAdditionalFees": [],
    "shippingAmount": {
        "amount": "0.0",
        "currencyCode": "USD"
    }
}
Accepted Solution (1)
Sudhir
Shopify Partner
7 1 0

This is an accepted solution.

Thanks for this. We have figured out with the SuggestedRefund API. The process is similar to what you have shared.

View solution in original post

Replies 5 (5)

conversionist
Shopify Partner
95 8 11

You can try this

  • Start by fetching the order details—you need to get the prices, taxes, and duties from the Shopify API.

  • Next, calculate the refund—take the total amount for the selected items and subtract the duties and taxes. This gives you the exact amount to refund without any extra charges.

  • Finally, create the refund—use your calculated amount to process the refund through Shopify’s API, ensuring that only the correct amount is refunded, excluding any duties and taxes.

 

Building 100 Shopify apps for that BMW M5 dream

Follow the journey at https://www.youtube.com/@conversinist
https://
conversionist.online/
Buy me a coffee
Sudhir
Shopify Partner
7 1 0

This is not what we intend to do. This is what we have already done. However we would like to utilize SuggestedRefund GraphQL endpoint to achieve those which is explained above in the query.

 

Sudhir
Shopify Partner
7 1 0

This is an accepted solution.

Thanks for this. We have figured out with the SuggestedRefund API. The process is similar to what you have shared.

PurpleMamba
Shopify Partner
126 1 18

@Sudhir can you elaborate on this for the rest of us with the same problem?

Sudhir
Shopify Partner
7 1 0

This is elaborated by @conversionist . That is the same process that we did using suggested refund api.