Contents
On this page
Refund as Store Credit - Plugixa PDF Vouchers for WooCommerce
POST /plugixa-pdf-vouchers/v1/orders/{id}/store-credit
Pay a refund onto a voucher instead of back to the card or bank, like the Refund as store credit box on an order. The order gets a real WooCommerce refund with no payment gateway call, and the voucher gets the value in the same step; if the voucher cannot be credited, the refund is removed again. See Store credit and wallet.
Needs a user who can edit WooCommerce orders (edit_shop_orders) and holds plugixa_pdfv_create, signed in with an Application Password.
Note. Pro only: on the free plugin this route answers
404rest_no_route.
Request
POST https://your-store.example/wp-json/plugixa-pdf-vouchers/v1/orders/611/store-credit
Path parameters
| Name | Type | Description |
|---|---|---|
id |
integer |
The order’s id |
Request body
Content type: application/json
| Field | Type | Required | Description |
|---|---|---|---|
amount |
number |
Yes | More than 0, at most what is left to refund on the order. |
voucher_id |
integer |
No | One of the customer’s own gift cards (active or used up) to credit. 0 (default) makes a new gift card, emailed to the customer. |
reason |
string |
No | Added after Refunded as store credit. in the refund reason. Up to 190 characters. |
{
"amount": 20,
"voucher_id": 0,
"reason": "Damaged candle"
}
Responses
200 OK.
{
"success": true,
"data": {
"voucher_id": 97,
"code": "PX-****-H4TZ",
"balance": 20
}
}
| Field | Type | Meaning |
|---|---|---|
data.voucher_id |
integer |
The voucher credited |
data.code |
string |
Its code, masked |
data.balance |
number |
Its balance after the credit |
Errors
| Status | Code | When |
|---|---|---|
401 / 403 |
plugixa_pdfv_forbidden |
The caller lacks the capability. |
404 |
plugixa_pdfv_not_found |
Order not found. |
422 |
plugixa_pdfv_amount |
Not more than 0, or more than is left: At most (amount) can still be refunded on this order. |
422 |
plugixa_pdfv_email |
This order has no customer email, so store credit cannot be sent. |
422 |
plugixa_pdfv_target |
voucher_id is not one of the customer’s gift cards: That voucher cannot take store credit for this customer. |
Plus the errors every endpoint can return.
Examples
curl -s -X POST "https://your-store.example/wp-json/plugixa-pdf-vouchers/v1/orders/611/store-credit" \
-u "$WP_USER:$WP_APP_PASSWORD" \
-H "Content-Type: application/json" \
-d '{"amount":20,"voucher_id":0,"reason":"Damaged candle"}'
<?php
$ch = curl_init('https://your-store.example/wp-json/plugixa-pdf-vouchers/v1/orders/611/store-credit');
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_USERPWD => getenv('WP_USER') . ':' . getenv('WP_APP_PASSWORD'),
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
CURLOPT_POSTFIELDS => json_encode([
'amount' => 20,
'voucher_id' => 0,
'reason' => 'Damaged candle',
]),
]);
$response = json_decode(curl_exec($ch), true);
curl_close($ch);
const response = await fetch('https://your-store.example/wp-json/plugixa-pdf-vouchers/v1/orders/611/store-credit', {
method: 'POST',
headers: {
'Authorization': `Basic ${btoa(`${process.env.WP_USER}:${process.env.WP_APP_PASSWORD}`)}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({ amount: 20, voucher_id: 0, reason: 'Damaged candle' }),
});
const { data } = await response.json();
Quick Links
Share