# PaalPOS receipts

Send a WhatsApp receipt when a sale completes.

> **In a nutshell:** Each shop is a business. When a sale completes and the customer gave a number, send an approved receipt template with the sale ID as reference. A URL button can link to the full receipt.

## Setup per shop

1. `POST /businesses` with `external_id` = the shop ID.
2. The shop owner connects WhatsApp through a [connect link](/docs/connect-whatsapp).
3. The owner creates a `UTILITY` template in WhatsApp Manager, for example:

```text
Thank you for shopping at {{1}}. Total: GHS {{2}}. Receipt no. {{3}}.
[Button: View receipt → https://pos.example.com/r/{{1}}]
```

## On each sale

```php
Http::withToken(config('services.paalchat.token'))->acceptJson()
    ->post("https://whatsapp.paaltech.org/api/v1/businesses/{$shop->id}/messages", [
        'to' => $sale->customer_phone,
        'type' => 'template',
        'reference' => 'receipt-'.$sale->id,
        'template' => [
            'name' => 'sale_receipt',
            'language' => 'en_US',
            'components' => [
                ['type' => 'body', 'parameters' => [
                    ['type' => 'text', 'text' => $shop->name],
                    ['type' => 'text', 'text' => number_format($sale->total, 2)],
                    ['type' => 'text', 'text' => $sale->number],
                ]],
                ['type' => 'button', 'sub_type' => 'url', 'index' => '0', 'parameters' => [
                    ['type' => 'text', 'text' => $sale->public_token],
                ]],
            ],
        ],
    ]);
```

```javascript
await fetch(`${BASE}/businesses/${shop.id}/messages`, { method: 'POST', headers: HEADERS, body: JSON.stringify({
  to: sale.customerPhone, type: 'template', reference: `receipt-${sale.id}`,
  template: { name: 'sale_receipt', language: 'en_US', components: [
    { type: 'body', parameters: [{ type: 'text', text: shop.name }, { type: 'text', text: sale.total.toFixed(2) }, { type: 'text', text: sale.number }] },
    { type: 'button', sub_type: 'url', index: '0', parameters: [{ type: 'text', text: sale.publicToken }] },
  ] },
}) });
```

> [!TIP]
> Send receipts from a queue so a slow network never delays the till. The
> `receipt-{sale id}` reference means a retried job never sends a second receipt.
