Store credit
The append-only credit ledger, its transactions, and the credit notes an adjustment writes.
One append-only ledger, with the balance summed and never stored. See Store credit, gift cards and credit notes.
List store-credit accounts
/api/v1/kahunacart/credit/accounts
Every store-credit account with its balance, which is summed from the account's transactions on every read and stored in no column anywhere. One account per customer, plus an anonymous account per order that issued a gift card — a guest can buy a card, and a guest has no customer record to hang one on. Pass customer_id to narrow to one person.
Parameters
| Name | Type | Description |
|---|---|---|
| customer_id optional | integer | Only this customer's account; omit for every account in the store |
| sort optional | string |
A column to sort the whole list by before it is paged; leave out for the usual order
One of:
customer, balance, movements, status |
| dir optional | string |
One of:
asc, descDefault:
asc |
| q optional | string | Words to search for in the customer's email and name, and the number of the order a guest's account was opened on; every word has to be there, in any order. Applied before the sort and the page, and total counts what it found |
| page optional | integer |
At least 1.
Default:
1 |
Get a store-credit account
/api/v1/kahunacart/credit/accounts/{id}
One account with its balance, the customer it belongs to, and how many movements it carries.
Parameters
| Name | Type | Description |
|---|---|---|
| id required | integer | Store-credit account id |
Read a store-credit statement
/api/v1/kahunacart/credit/accounts/{id}/transactions
One account's movements, newest first, each with the provenance the ledger required of it — what produced the row (gift_card, refund, order or adjustment), which one, the order it belongs to, and a source snapshot of what the producing rule saw. This is how you answer "why is this balance what it is?". Positive amounts credit the account and negative amounts debit it.
Parameters
| Name | Type | Description |
|---|---|---|
| id required | integer | Store-credit account id |
| sort optional | string |
A column to sort the whole list by before it is paged; leave out for the usual order
One of:
date, movement, provenance, amount |
| dir optional | string |
One of:
asc, descDefault:
asc |
| q optional | string | Words to search for in the movement, where it came from, the note and the order number; every word has to be there, in any order. Applied before the sort and the page, and total counts what it found |
| page optional | integer |
At least 1.
Default:
1 |
Adjust a store-credit balance
/api/v1/kahunacart/credit/accounts/{id}/adjust
Add credit to an account or take some back, by hand. The amount is signed — positive credits, negative debits — and a note is required, because this is the only movement in the whole ledger a person makes rather than a rule, and it is the one row nobody will be able to explain later without one. A debit larger than the balance is refused before anything is written. Send amount as a decimal string or amount_minor in minor units.
Parameters
| Name | Type | Description |
|---|---|---|
| id required | integer | Store-credit account id |
| amount optional | string | Signed decimal in the store currency, e.g. "10.00" or "-5.00" |
| amount_minor optional | integer | The same amount in minor units; use this or amount, not both |
| note required | string | Why this adjustment was made. Required, and stored with the row forever |
Refund an order to store credit
/api/v1/kahunacart/credit/refunds
Give a refund back as store credit instead of to the card that paid for the order. The same refund in every other way — it counts against the same refundable balance, restocks the same lines, fires the same events, earns the same credit note and sends the same email. A split refund needs no special call: refund part of the order through refund_order for the card's share and the rest through this one. Omit items to refund whatever is left of the order.
Parameters
| Name | Type | Description |
|---|---|---|
| order_id required | integer | The order being refunded |
| amount optional | string | Decimal override in the order's own currency; omit to credit what the lines come to. The credit lands in the customer's account in that currency |
| amount_minor optional | integer | The same override in minor units |
| items optional | array of object | Lines to credit; omit to credit the whole remaining balance. Keys: `item_id`, `quantity` |
| shipping_minor optional | integer | The postage portion, in minor units |
| restock optional | boolean |
Put the credited units back on the shelf
Default:
false |
| reason optional | string | Recorded on the refund and printed on the credit note |
| notify optional | boolean |
Email the customer about the refund
Default:
true |
| return_id optional | integer | The received return this credit is for. Checked as refund_order checks it (404 when not on the order, 409 when not received, 422 with nothing named), and the refund is linked to it so the return closes once its refunds cover what it owes |
List an order's credit notes
/api/v1/kahunacart/orders/{id}/credit-notes
The numbered documents an order's refunds have earned, oldest first. A credit note is issued automatically whenever a refund is confirmed, is numbered from its own gapless sequence, and states the tax being credited. The PDF is not available through this interface — it is a document to print rather than a payload to read.
Parameters
| Name | Type | Description |
|---|---|---|
| id required | integer | Order id |
Get a credit note PDF
/api/v1/kahunacart/orders/{id}/credit-notes/{cnid}.pdf
One credit note for one order as a PDF, at the numbers and tax figures the ledger recorded. list_credit_notes answers the same facts as JSON.
Amounts cross the wire both ways: send amount as a decimal string or amount_minor in minor units, and reads return both. A debit that would take a balance below zero is refused before anything is written.