Issuing customer refunds using the API for the Shopify Checkout Integration
This guide explains the process of manually issuing customer refunds via the API for orders created on stores using the Shopify Checkout Integration.
Use the Shopify API to issue order refunds, whether you need to incorporate refunds into your own application, or you want to automate the refund process outside of the Recharge merchant portal. Refunds issued manually via the API are synced in Recharge for future reference.
Platform:
- Shopify Checkout Integration
Before you start
You will need the following to issue customer refunds using the API:
- Shopify Access Token
- An environment to make authenticated API calls and receive the response
Step 1 - Access the Shopify order ID
Use the Recharge order ID to access the Shopify order ID for the order that needs refunding. The Recharge Orders API ecommerce_order_ID
corresponds to the Shopify order ID.
Make a GET
call to /orders/{order_id}
to obtain the Shopify order ID.
Response
...
"external_order_id": {
"ecommerce": "123496878536413"
}
...
See Orders API object in the Recharge API Reference for an example of the response body.
Move on to Step 2 after obtaining the Shopify order ID.
Step 2 - Calculate the refund
Shopify provides the /calculate/ endpoint to determine which line items and potential shipping costs need refunding. Use this information to calculate the exact refund amount.
Send a POST
to /admin/api/2022-01/orders/{id}/refunds/calculate.json
and pass in the line items refund_line_items.line_item_id
.
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"
}
}
Step 3 - Create refund
Use the response from Step 2 to generate an accurate refund using the Shopify /refunds/ endpoint.
Send a POST
to /admin/api/2022-01/orders/{id}/refunds.json
to issue the refund.
Step 4 - 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 also appears as refunded in the customer portal.
Updated 4 days ago