Back to Woocommerce

Refunds

docs/apis/rest-api/v2/order-refunds.mdx

10.9.0-dev15.8 KB
Original Source

import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem';

Refunds

The refunds API allows you to create, view, and delete individual refunds.

Order refund properties

AttributeTypeDescription
idintegerUnique identifier for the resource. READ-ONLY
date_createddate-timeThe date the order refund was created, in the site's timezone. READ-ONLY
date_created_gmtdate-timeThe date the order refund was created, as GMT. READ-ONLY
amountstringRefund amount.
reasonstringReason for refund.
refunded_byintegerUser ID of user who created the refund.
meta_dataarrayMeta data. See Order refund - Meta data properties
line_itemsarrayLine items data. See Order refund - Line items properties
api_refundbooleanWhen true, the payment gateway API is used to generate the refund. Default is true. WRITE-ONLY

Order refund - Meta data properties

AttributeTypeDescription
idintegerMeta ID. READ-ONLY
keystringMeta key.
valuestringMeta value.

Order refund - Line items properties

AttributeTypeDescription
idintegerItem ID. READ-ONLY
namestringProduct name.
product_idintegerProduct ID.
variation_idintegerVariation ID, if applicable.
quantityintegerQuantity ordered.
tax_classstringTax class of product.
subtotalstringLine subtotal (before discounts).
subtotal_taxstringLine subtotal tax (before discounts). READ-ONLY
totalstringLine total (after discounts).
total_taxstringLine total tax (after discounts). READ-ONLY
taxesarrayLine taxes. See Order refund line item - Taxes properties READ-ONLY
meta_dataarrayMeta data. See Order refund - Meta data properties
skustringProduct SKU. READ-ONLY
pricestringProduct price. READ-ONLY

Order refund line item - Taxes properties

AttributeTypeDescription
idintegerTax rate ID. READ-ONLY
totalstringTax total. READ-ONLY
subtotalstringTax subtotal. READ-ONLY

Create a refund

This API helps you to create a new refund for an order.

http
POST /wp-json/wc/v2/orders/<id>/refunds
<Tabs> <TabItem value="curl" label="cURL">
shell
curl -X POST https://example.com/wp-json/wc/v2/orders/723/refunds \
	-u consumer_key:consumer_secret \
	-H "Content-Type: application/json" \
	-d '{
  "amount": "10"
}'
</TabItem> <TabItem value="js" label="JavaScript">
javascript
const data = {
  amount: "10"
};

WooCommerce.post("orders/723/refunds", data)
  .then((response) => {
    console.log(response.data);
  })
  .catch((error) => {
    console.log(error.response.data);
  });
</TabItem> <TabItem value="php" label="PHP">
php
<?php
$data = [
    'amount' => '10'
];

print_r($woocommerce->post('orders/723/refunds', $data));
?>
</TabItem> <TabItem value="python" label="Python">
python
data = {
    "amount": "10"
}

print(wcapi.post("orders/723/refunds", data).json())
</TabItem> <TabItem value="ruby" label="Ruby">
ruby
data = {
  amount: "10"
}

woocommerce.post("orders/723/refunds", data).parsed_response
</TabItem> <TabItem value="response" label="JSON Response">
json
{
  "id": 726,
  "date_created": "2017-03-21T17:07:11",
  "date_created_gmt": "2017-03-21T20:07:11",
  "amount": "10.00",
  "reason": "",
  "meta_data": [],
  "line_items": [],
  "_links": {
    "self": [
      {
        "href": "https://example.com/wp-json/wc/v2/orders/723/refunds/726"
      }
    ],
    "collection": [
      {
        "href": "https://example.com/wp-json/wc/v2/orders/723/refunds"
      }
    ],
    "up": [
      {
        "href": "https://example.com/wp-json/wc/v2/orders/723"
      }
    ]
  }
}
</TabItem> </Tabs>

Retrieve a refund

This API lets you retrieve and view a specific refund from an order.

http
GET /wp-json/wc/v2/orders/<id>/refunds/<refund_id>
<Tabs> <TabItem value="curl" label="cURL">
shell
curl https://example.com/wp-json/wc/v2/orders/723/refunds/726 \
	-u consumer_key:consumer_secret
</TabItem> <TabItem value="js" label="JavaScript">
javascript
WooCommerce.get("orders/723/refunds/726")
  .then((response) => {
    console.log(response.data);
  })
  .catch((error) => {
    console.log(error.response.data);
  });
</TabItem> <TabItem value="php" label="PHP">
php
<?php print_r($woocommerce->get('orders/723/refunds/726')); ?>
</TabItem> <TabItem value="python" label="Python">
python
print(wcapi.get("orders/723/refunds/726").json())
</TabItem> <TabItem value="ruby" label="Ruby">
ruby
woocommerce.get("orders/723/refunds/726").parsed_response
</TabItem> <TabItem value="response" label="JSON Response">
json
{
  "id": 726,
  "date_created": "2017-03-21T17:07:11",
  "date_created_gmt": "2017-03-21T20:07:11",
  "amount": "10.00",
  "reason": "",
  "meta_data": [],
  "line_items": [],
  "_links": {
    "self": [
      {
        "href": "https://example.com/wp-json/wc/v2/orders/723/refunds/726"
      }
    ],
    "collection": [
      {
        "href": "https://example.com/wp-json/wc/v2/orders/723/refunds"
      }
    ],
    "up": [
      {
        "href": "https://example.com/wp-json/wc/v2/orders/723"
      }
    ]
  }
}
</TabItem> </Tabs>

Available parameters

ParameterTypeDescription
dpintegerNumber of decimal points to use in each resource.

List all refunds

This API helps you to view all the refunds from an order.

http
GET /wp-json/wc/v2/orders/<id>/refunds
<Tabs> <TabItem value="curl" label="cURL">
shell
curl https://example.com/wp-json/wc/v2/orders/723/refunds \
	-u consumer_key:consumer_secret
</TabItem> <TabItem value="js" label="JavaScript">
javascript
WooCommerce.get("orders/723/refunds")
  .then((response) => {
    console.log(response.data);
  })
  .catch((error) => {
    console.log(error.response.data);
  });
</TabItem> <TabItem value="php" label="PHP">
php
<?php print_r($woocommerce->get('orders/723/refunds')); ?>
</TabItem> <TabItem value="python" label="Python">
python
print(wcapi.get("orders/723/refunds").json())
</TabItem> <TabItem value="ruby" label="Ruby">
ruby
woocommerce.get("orders/723/refunds").parsed_response
</TabItem> <TabItem value="response" label="JSON Response">
json
[
  {
    "id": 726,
    "date_created": "2017-03-21T17:07:11",
    "date_created_gmt": "2017-03-21T20:07:11",
    "amount": "10.00",
    "reason": "",
    "refunded_by": 1,
    "meta_data": [],
    "line_items": [],
    "_links": {
      "self": [
        {
          "href": "https://example.com/wp-json/wc/v2/orders/723/refunds/726"
        }
      ],
      "collection": [
        {
          "href": "https://example.com/wp-json/wc/v2/orders/723/refunds"
        }
      ],
      "up": [
        {
          "href": "https://example.com/wp-json/wc/v2/orders/723"
        }
      ]
    }
  },
  {
    "id": 724,
    "date_created": "2017-03-21T16:55:37",
    "date_created_gmt": "2017-03-21T19:55:37",
    "amount": "9.00",
    "reason": "",
    "refunded_by": 1,
    "meta_data": [],
    "line_items": [
      {
        "id": 314,
        "name": "Woo Album #2",
        "product_id": 87,
        "variation_id": 0,
        "quantity": -1,
        "tax_class": "",
        "subtotal": "-9.00",
        "subtotal_tax": "0.00",
        "total": "-9.00",
        "total_tax": "0.00",
        "taxes": [],
        "meta_data": [
          {
            "id": 2076,
            "key": "_refunded_item_id",
            "value": "311"
          }
        ],
        "sku": "",
        "price": -9
      }
    ],
    "_links": {
      "self": [
        {
          "href": "https://example.com/wp-json/wc/v2/orders/723/refunds/724"
        }
      ],
      "collection": [
        {
          "href": "https://example.com/wp-json/wc/v2/orders/723/refunds"
        }
      ],
      "up": [
        {
          "href": "https://example.com/wp-json/wc/v2/orders/723"
        }
      ]
    }
  }
]
</TabItem> </Tabs>

Available parameters

ParameterTypeDescription
contextstringScope under which the request is made; determines fields present in response. Options: view and edit. Default is view.
pageintegerCurrent page of the collection. Default is 1.
per_pageintegerMaximum number of items to be returned in result set. Default is 10.
searchstringLimit results to those matching a string.
afterstringLimit response to resources published after a given ISO8601 compliant date.
beforestringLimit response to resources published before a given ISO8601 compliant date.
dates_are_gmtbooleanInterpret after and before as UTC dates when true.
excludearrayEnsure result set excludes specific IDs.
includearrayLimit result set to specific ids.
offsetintegerOffset the result set by a specific number of items.
orderstringOrder sort attribute ascending or descending. Options: asc and desc. Default is desc.
orderbystringSort collection by object attribute. Options: date, id, include, title and slug. Default is date.
parentarrayLimit result set to those of particular parent IDs.
parent_excludearrayLimit result set to all items except those of a particular parent ID.
dpintegerNumber of decimal points to use in each resource. Default is 2.

Delete a refund

This API helps you delete an order refund.

http
DELETE /wp-json/wc/v2/orders/<id>/refunds/<refund_id>
<Tabs> <TabItem value="curl" label="cURL">
shell
curl -X DELETE https://example.com/wp-json/wc/v2/orders/723/refunds/726?force=true \
	-u consumer_key:consumer_secret
</TabItem> <TabItem value="js" label="JavaScript">
javascript
WooCommerce.delete("orders/723/refunds/726", {
  force: true
})
  .then((response) => {
    console.log(response.data);
  })
  .catch((error) => {
    console.log(error.response.data);
  });
</TabItem> <TabItem value="php" label="PHP">
php
<?php print_r($woocommerce->delete('orders/723/refunds/726', ['force' => true])); ?>
</TabItem> <TabItem value="python" label="Python">
python
print(wcapi.delete("orders/723/refunds/726", params={"force": True}).json())
</TabItem> <TabItem value="ruby" label="Ruby">
ruby
woocommerce.delete("orders/723/refunds/726", force: true).parsed_response
</TabItem> <TabItem value="response" label="JSON Response">
json
{
  "id": 726,
  "date_created": "2017-03-21T17:07:11",
  "date_created_gmt": "2017-03-21T20:07:11",
  "amount": "10.00",
  "reason": "",
  "meta_data": [],
  "line_items": [],
  "_links": {
    "self": [
      {
        "href": "https://example.com/wp-json/wc/v2/orders/723/refunds/726"
      }
    ],
    "collection": [
      {
        "href": "https://example.com/wp-json/wc/v2/orders/723/refunds"
      }
    ],
    "up": [
      {
        "href": "https://example.com/wp-json/wc/v2/orders/723"
      }
    ]
  }
}
</TabItem> </Tabs>

Available parameters

ParameterTypeDescription
forcebooleanRequired to be true, as resource does not support trashing.