WooCommerce REST API 文档

title: "订单 - 退款 #" post_status: publish comment_status: open taxonomy: category: - woocommerce-rest-api post_tag: - V3 - Includes - Source


订单 - 退款

本节列出了所有可用于创建、编辑或操作订单退款的 API 端点。

订单退款属性

属性 类型 描述
id integer 订单备注 ID 只读
created_at string 订单退款创建时的 UTC 日期时间 只读
amount string 退款金额 必需
reason string 退款原因
line_items array 要退款的订单商品列表。参见 商品属性

为订单创建退款

此 API 可帮助您为订单创建新的退款。

HTTP 请求

POST
/wc-api/v3/orders/<id>/refunds
curl -X POST https://example.com/wc-api/v3/orders/645/refunds \
    -u consumer_key:consumer_secret \
    -H "Content-Type: application/json" \
    -d '{
  "order_refund": {
    "amount": 10
  }
}'
var data = {
  order_refund: {
    amount: 10
  }
};

WooCommerce.post('orders/645/refunds', data, function(err, data, res) {
  console.log(res);
});
<?php
$data = [
    'order_refund' => [
        'amount' => 10
    ]
];

print_r($woocommerce->post('orders/645/refunds', $data));
?>
data = {
    "order_refund": {
        "amount": 10
    }
}

print(wcapi.post("orders/645/refunds", data).json())
data = {
  order_refund: {
    amount: 10
  }
}

woocommerce.post("orders/645/refunds", data).parsed_response

JSON 响应示例:

{
  "order_refund": {
    "id": 649,
    "created_at": "2015-01-26T19:29:32Z",
    "amount": "10.00",
    "reason": "",
    "line_items": []
  }
}

查看订单退款

此 API 允许您检索并查看订单中的特定退款。

HTTP 请求

GET
/wc-api/v3/orders/<id>/refunds/<refund_id>
curl https://example.com/wc-api/v3/orders/645/refunds/649 \
    -u consumer_key:consumer_secret
WooCommerce.get('orders/645/refunds/649', function(err, data, res) {
  console.log(res);
});
<?php print_r($woocommerce->get('orders/645/refunds/649')); ?>
print(wcapi.get("orders/645/refunds/649").json())
woocommerce.get("orders/645/refunds/649").parsed_response

JSON 响应示例:

{
  "order_refund": {
    "id": 649,
    "created_at": "2015-01-26T19:29:32Z",
    "amount": "10.00",
    "reason": "",
    "line_items": []
  }
}

查看订单退款列表

此 API 可帮助您查看订单的所有退款记录。

HTTP 请求

GET
/wc-api/v3/orders/<id>/refunds
curl https://example.com/wc-api/v3/orders/645/refunds \
    -u consumer_key:consumer_secret
WooCommerce.get('orders/645/refunds', function(err, data, res) {
  console.log(res);
});
<?php print_r($woocommerce->get('orders/645/refunds')); ?>
print(wcapi.get("orders/645/refunds").json())
woocommerce.get("orders/645/refunds").parsed_response

JSON 响应示例:

{
  "order_refunds": [
    {
      "id": 649,
      "created_at": "2015-01-26T19:29:32Z",
      "amount": "10.00",
      "reason": "",
      "line_items": []
    },
    {
      "id": 647,
      "created_at": "2015-01-26T19:19:06Z",
      "amount": "21.99",
      "reason": "",
      "line_items": [
        {
          "id": 514,
          "subtotal": "-21.99",
          "subtotal_tax": "0.00",
          "total": "-21.99",
          "total_tax": "0.00",
          "price": "-21.99",
          "quantity": 1,
          "tax_class": "reduced-rate",
          "name": "Premium Quality",
          "product_id": 546,
          "sku": "",
          "meta": []
        },
        {
          "id": 515,
          "subtotal": "0.00",
          "subtotal_tax": "0.00",
          "total": "0.00",
          "total_tax": "0.00",
          "price": "0.00",
          "quantity": 0,
          "tax_class": null,
          "name": "Ship Your Idea",
          "product_id": 613,
          "sku": "",
          "meta": []
        }
      ]
    }
  ]
}

更新订单退款

此 API 允许您修改订单退款。

HTTP 请求

PUT
/wc-api/v3/orders/<id>/refunds/<refund_id>
curl -X PUT https://example.com/wc-api/v3/orders/645/refunds/649 \
    -u consumer_key:consumer_secret \
    -H "Content-Type: application/json" \
    -d '{
  "order_refund": {
    "reason": "Because was it necessary!"
  }
}'
var data = {
  order_refund: {
    reason: 'Because was it necessary!'
  }
};

WooCommerce.put('orders/645/refunds/649', data, function(err, data, res) {
  console.log(res);
});
<?php
$data = [
    'order_refund' => [
        'reason' => 'Because was it necessary!'
    ]
];

print_r($woocommerce->put('orders/645/refunds/649', $data));
?>
data = {
    "order_refund": {
        "reason": "Because was it necessary!"
    }
}

print(wcapi.put("orders/645/refunds/649", data).json())
data = {
  order_refund: {
    reason: "Because was it necessary!"
  }
}

woocommerce.put("orders/645/refunds/649", data).parsed_response

JSON 响应示例:

{
  "order_refund": {
    "id": 649,
    "created_at": "2015-01-26T19:29:32Z",
    "amount": "10.00",
    "reason": "Because was it necessary!",
    "line_items": []
  }
}

Delete an Order Refund

This API helps you delete an order refund.

HTTP Request

DELETE
/wc-api/v3/orders/<id>/refunds/<refund_id>
curl -X DELETE https://example.com/wc-api/v3/orders/645/refunds/649 \
    -u consumer_key:consumer_secret
WooCommerce.delete('orders/645/refunds/649', function(err, data, res) {
  console.log(res);
});
<?php print_r($woocommerce->delete('orders/645/refunds/649')); ?>
print(wcapi.delete("orders/645/refunds/649").json())
woocommerce.delete("orders/645/refunds/649").parsed_response

JSON response example:

{
  "message": "Permanently deleted refund"
}