Commerce

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"}'
POST/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

FieldMoves
statusPENDING to CONFIRMED or CANCELLED; CONFIRMED to FULFILLED or CANCELLED
payment_statusUNPAID 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"}'
POST/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 PENDING while a link is open, and PAID once Snippe reports the full amount.
  • A payment's status is CREATED, COMPLETED, FAILED, EXPIRED or VOIDED.
  • 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.

POST/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

StatuscodeWhen
409invalid_transitiona status move that is not allowed
409payments_not_connectedno Snippe account is connected
409payment_in_progressthe link is still being made; try again in a moment
409order_not_paidfiles or a receipt before the order is paid
409shop_has_no_numberthe shop has no WhatsApp number to send from
422stock_insufficientnot enough stock for the order

Every Commerce endpoint is listed at the end of Shop and catalogue.

On this page