Refund a customer via API with Shopify Checkout
There may be times when you need to incorporate refunds into you own application, or simply want to automate the refund process as opposed to issuing refunds via the Merchant Dashboard. You can use the Shopify API to issue refunds which will then be synced to Recharge.
Prerequisites
- Shopify Access Token
- A server environment to make authenticated API calls and receive the response
Obtain external ecommerce order ID
First obtain the Shopify ID for the Recharge for which you want to issue a refund. The Recharge Orders API ecommerce_order_ID
corresponds to the Shopify order ID.
Make a GET
to /orders/{order_id}
to obtain the Shopify order ID.
Response
...
"external_order_id": {
"ecommerce": "123496878536413"
}
...
See the Orders API object for a full example of the response body.
Now that you have the Shopify order ID, you can move to the next step.
Calculate the refund
To calculate the refund, Shopify provides the /calculate/ endpoint to determine which line items and/or shipping costs are to be refunded. Pass in the line item refund_line_items.line_item_id
POST
to /admin/api/2022-01/orders/{id}/refunds/calculate.json
Response
{
"refund": {
"shipping": {
"amount": "5.00",
"tax": "0.00",
"maximum_refundable": "5.00"
},
"duties": [],
"total_duties_set": {
"shop_money": {
"amount": "0.00",
"currency_code": "USD"
},
"presentment_money": {
"amount": "0.00",
"currency_code": "USD"
}
},
"additional_fees": [],
"total_additional_fees_set": {
"shop_money": {
"amount": "0.00",
"currency_code": "USD"
},
"presentment_money": {
"amount": "0.00",
"currency_code": "USD"
}
},
"refund_line_items": [
{
"quantity": 1,
"line_item_id": 518995019,
"location_id": null,
"restock_type": "no_restock",
"price": "199.00",
"subtotal": "195.67",
"total_tax": "3.98",
"discounted_price": "199.00",
"discounted_total_price": "199.00",
"total_cart_discount_amount": "3.33"
}
],
"transactions": [
{
"order_id": 450789469,
"kind": "suggested_refund",
"gateway": "bogus",
"parent_id": 801038806,
"amount": "41.94",
"currency": "USD",
"maximum_refundable": "41.94"
}
],
"currency": "USD"
}
}
Create refund
You can use the response you received from the previous step to then generate an accurate refund. Use the Shopify /refunds/ endpoint.
POST
to /admin/api/2022-01/orders/{id}/refunds.json
Refund within Recharge
The Order will reflect the refunded amount under the total_refunds
property.
The corresponding Recharge Charge should now reflect a status
property with the value refunded
.
Charges response
...
"status": "queued",
"subtotal_price": "12.00",
"tags": "Subscription",
...
The order will appear as refunded in the Customer Portal.
Updated over 1 year ago