Accept ZEC
A buyer pays an invoice with a shielded Zcash wallet. Your system creates the invoice, shows the payment request and waits for the result.
Show the payment request
Section titled “Show the payment request”The response of POST /v1/invoices contains a zip321_uri. ZIP-321 is the Zcash standard for payment request URIs. The URI holds the address, the amount and a memo that links the payment to the invoice.
-
Create the invoice on your server.
-
Send the
id,addressandzip321_urito your checkout page. -
Encode the
zip321_urias a QR code. -
Show the QR code and the
addressas text. -
Show the amount and the time left before
expires_at.
Do not put your API key in the checkout page. Create the invoice on your server only.
Follow the status
Section titled “Follow the status”You have two options to find the status of an invoice. Use the WebSocket for a live checkout page. Use polling for a simple backend check. The webhook is the best source for fulfilling an order.
Open GET /v1/invoices/{id}/ws as a WebSocket. No key is necessary. The invoice ID is the access token.
The server sends a message when you connect and on each status change.
{"status": "detected"}If a swap exists, the message also has a swap_status field with the 1Click status. The server closes the connection when the status is paid, underpaid or expired.
const ws = new WebSocket(`wss://lunaz.alwaysbedream.dev/api/v1/invoices/${id}/ws`);ws.onmessage = (e) => { const { status } = JSON.parse(e.data); if (status === "paid") showConfirmation();};Use wss:// when your page uses HTTPS.
Call GET /v1/invoices/{id} every few seconds. Stop when the status is paid, underpaid or expired.
curl https://lunaz.alwaysbedream.dev/api/v1/invoices/8f14e45f-ceea-4672-9b2d-5c1d0a7e3b11Fulfil the order
Section titled “Fulfil the order”Wait for the invoice.paid webhook, or for the status paid. See Webhooks.
Handle partial payments
Section titled “Handle partial payments”A buyer can pay the difference before the invoice expires, because payments to one address add up. If the invoice expires with a payment that is too small, the status is underpaid and Lunaz sends invoice.underpaid. You refund the buyer yourself.