Orders and payments
Take an order, get it paid through a payment link, and let Ghala deliver the receipt.
Take an order
curl https://v3.ghala.io/v1/commerce/shop/orders \
-H "Authorization: Bearer $GHALA_KEY" \
-H "Content-Type: application/json" \
-d '{"items": [{"product_id": "PRODUCT_ID", "quantity": 2}], "customer_name": "Asha", "customer_phone": "0712345678"}'/v1/commerce/shop/ordersCreate orderorders:write
- Ghala prices every order: each line is the variant's or product's price times the quantity. A price you send is refused.
- An order totals at least 500, and a line holds at most 10,000.
- Tracked stock is taken when the order is placed, so the last unit sells once. Cancelling an order returns its stock.
Statuses
| Field | Moves |
|---|---|
status | PENDING to CONFIRMED or CANCELLED; CONFIRMED to FULFILLED or CANCELLED |
payment_status | UNPAID to PENDING or PAID; PENDING to PAID or UNPAID; PAID to REFUNDED |
Change them with PATCH /v1/commerce/shop/orders/{order}. A paid order is refunded before it is cancelled, and marking a pending order paid confirms it. Any other move is 409 invalid_transition.
Get paid
Buyers pay into your own Snippe account with a payment link. Ghala never holds the money. An owner or admin connects the Snippe account in the dashboard; no key can.
curl https://v3.ghala.io/v1/commerce/shop/orders/$ORDER_ID/pay \
-H "Authorization: Bearer $GHALA_KEY" \
-H "Content-Type: application/json" \
-d '{"method": "LINK"}'/v1/commerce/shop/orders/{order}/payPay orderpayments:write
The answer carries pay_url, the link for the order's total. Send it to the buyer.
- Asking again within 30 minutes answers the same link. After that a new link replaces it.
- The order is
PENDINGwhile a link is open, andPAIDonce Snippe reports the full amount. - A payment's
statusisCREATED,COMPLETED,FAILED,EXPIREDorVOIDED. - Charging needs
payments:write. A test key cannot use any payment route.
Delivery and receipts
Once an order is PAID, Ghala sends the buyer, over WhatsApp, each digital item and then a receipt. An order whose items are all digital and all delivered becomes FULFILLED. These sends are charged like any message.
/v1/commerce/shop/orders/{order}/redeliverRedeliver orderorders:write
POST/v1/commerce/shop/orders/{order}/receiptReissue order receiptorders:write
Events
Your webhook endpoints can receive order.created, order.paid, order.cancelled, order.fulfilled, payment.completed and payment.failed.
When it fails
| Status | code | When |
|---|---|---|
409 | invalid_transition | a status move that is not allowed |
409 | payments_not_connected | no Snippe account is connected |
409 | payment_in_progress | the link is still being made; try again in a moment |
409 | order_not_paid | files or a receipt before the order is paid |
409 | shop_has_no_number | the shop has no WhatsApp number to send from |
422 | stock_insufficient | not enough stock for the order |
Every Commerce endpoint is listed at the end of Shop and catalogue.