We are refunding an order but the item being refunded has return shipping cost (a variable we use on our side), so we are subtracting that from the amount.
This is failing on a productive shop, but if we use test mode or bogus payment method the error wont appear and the refund will be created.
In the tests environments the refund is created with an order_adjustment
. In the other hand when we try refunding in productive shops neither the refund nor the order_adjustment
are created.
Shopify shopify-api-ruby issue
EXAMPLE:
return_shipping_cost_cents = 1 USD
maximum_refundable = 20 USD
amount = 19 USD
shopify_api
version: 21.4.1Shopify should create the adjustment to the order and refund the amount.
The error message: {"errors"=>{"base"=>["Arbitrary refund not allowed"]}}
order_id
and line_item_id
from an order with a real payment (not a test mode payment)/orders/#{order_id}/refunds/calculate
endpoint (POST)
Sample payload:{
"refund_line_items"=>[
{
"line_item_id"=>"11922901111117",
"quantity"=>1,
"restock_type"=>"no_restock"
}
],
"shipping"=>{
"full_refund"=>false
}
}
amount - return_shipping_cost_cents
)
Sample payload refunds endpoint:return_shipping_cost_cents = 6,95
{
"shipping": {
"amount": "0.00",
"tax": "0.00",
"maximum_refundable": "0.00"
},
"duties": [],
"total_duties_set": {
"shop_money": {
"amount": "0.00",
"currency_code": "USD"
},
"presentment_money": {
"amount": "0.00",
"currency_code": "USD"
}
},
"return": null,
"refund_line_items":
[
{
"quantity": 1,
"line_item_id": 11922901111117,
"location_id": null,
"restock_type": "no_restock",
"price": "62.97",
"subtotal": "62.97",
"total_tax": "4.25",
"discounted_price": "62.97",
"discounted_total_price": "62.97",
"total_cart_discount_amount": "0.00"
}
],
"transactions":
[
{
"order_id": 4786111111837,
"kind": "refund",
"gateway": "shopify_payments",
"parent_id": 6017111111269,
"amount": 60.27,
"currency": "USD",
"maximum_refundable": "67.22"
}
],
"currency": "USD",
"note": "33HxxxYvLq"
}
orders/#{order_id}/refunds
:=> {"errors"=>{"base"=>["Arbitrary refund not allowed"]}}
We are trying to refund an order charging the return_shipping
, and we are expecting that Shopify creates the refund
with an order_adjustment
.
A potential thing that might be creating this error could be that the order has been payed out with a gateway that doesn't allow "partial refunds". Check the original gateway payment isn't one of: