# Create a payment link

`POST /businesses/{bid}/payment-requests`

Requires the `documents` scope.

A link the payer opens to pay by card on the business's own terminal. Give `lines` (or `amount` and `description`) for a payment that pays for nothing issued yet; to ask for what an invoice still owes, use `POST /documents/{id}/payment-request`. Once paid, the receipt is issued by itself and `payment_request.paid` is sent.

## Path parameters

| Name | Type | | Description |
|---|---|---|---|
| `bid` | string | **required** | Business id, from `POST /businesses`. |

## Headers

| Name | Type | | Description |
|---|---|---|---|
| `Idempotency-Key` | string |  | Your own stable id for this call. A retry returns the same row with `deduped: true` instead of creating a duplicate. Interchangeable with `externalRef` in the body. |

## Body

| Field | Type | | Description |
|---|---|---|---|
| `amount` | integer |  | VAT included. With `documentId`, defaults to what is still owed and may not exceed it. Integer agorot (₪1 = 100). |
| `description` | string |  | What the payment is for. Required without `documentId` or `lines`. |
| `lines` | array of object |  |  |
| `party` | object |  |  |
| `party.partyId` | string |  |  |
| `party.name` | string |  |  |
| `party.phone` | string |  |  |
| `party.email` | string |  | The receipt is mailed here. |
| `party.taxId` | string |  |  |
| `maxInstallments` | integer |  | Up to the terminal's own maximum. |
| `expiresAt` | string |  |  |
| `externalRef` | string |  | Idempotency, like the `Idempotency-Key` header. |

## Response

`201`: `{ "ok": true, … }`

| Field | Type | | Description |
|---|---|---|---|
| `ok` | boolean | **required** |  |
| `paymentRequest` | PaymentRequest | **required** | A request for a payment and its public link. When the card company confirms the payment, BillOS issues the receipt itself: a קבלה (400) for an invoice it pays, a חשבונית מס/קבלה (320) for a proforma or for its own lines (a 400 for an עוסק פטור), and the invoice it paid is closed. |
| `deduped` | boolean |  |  |

Errors: `400`, `401`, `403`, `404`, `429`. Every failure answers `{ "error", "reason", "hint", "param", "doc_url", "retryable", "request_id" }`: branch on `reason`, and read `hint` for what to change (https://docs.billos.co.il/errors.md).

## Examples

### cURL

```bash
curl -X POST "$BASE/businesses/$BID/payment-requests" \
  -H "X-Api-Key: $KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "lines": [
      {
        "description": "איפור כלה",
        "quantity": 1
      }
    ],
    "party": {
      "name": "דנה לוי",
      "phone": "0521111111",
      "email": "dana@example.com",
      "taxId": "123456782"
    },
    "externalRef": "order-8812"
  }'
```
### Node

```node
const res = await fetch(`${BASE}/businesses/${BID}/payment-requests`, {
  method: 'POST',
  headers: {
    'X-Api-Key': KEY,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    "lines": [
      {
        "description": "איפור כלה",
        "quantity": 1
      }
    ],
    "party": {
      "name": "דנה לוי",
      "phone": "0521111111",
      "email": "dana@example.com",
      "taxId": "123456782"
    },
    "externalRef": "order-8812"
  }),
})
const data = await res.json()
if (!data.ok) throw new Error(data.reason)
```
### Python

```python
import requests
res = requests.post(
    f"{BASE}/businesses/{BID}/payment-requests",
    headers={"X-Api-Key": KEY},
    json={
      "lines": [
        {
          "description": "איפור כלה",
          "quantity": 1
        }
      ],
      "party": {
        "name": "דנה לוי",
        "phone": "0521111111",
        "email": "dana@example.com",
        "taxId": "123456782"
      },
      "externalRef": "order-8812"
    },
)
data = res.json()
```
### PHP

```php
$ch = curl_init("$BASE/businesses/$BID/payment-requests");
curl_setopt_array($ch, [
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_HTTPHEADER => ["X-Api-Key: $KEY", 'Content-Type: application/json'],
  CURLOPT_POSTFIELDS => json_encode([
    'lines' => [
      [
        'description' => 'איפור כלה',
        'quantity' => 1,
      ],
    ],
    'party' => [
      'name' => 'דנה לוי',
      'phone' => '0521111111',
      'email' => 'dana@example.com',
      'taxId' => '123456782',
    ],
    'externalRef' => 'order-8812',
  ]),
]);
$data = json_decode(curl_exec($ch), true);
```
### C#

```csharp
using System.Text;
using System.Text.Json;

using var http = new HttpClient();
using var req = new HttpRequestMessage(HttpMethod.Post, $"{BASE}/businesses/{BID}/payment-requests");
req.Headers.Add("X-Api-Key", KEY);
req.Content = new StringContent("""
    {
      "lines": [
        {
          "description": "איפור כלה",
          "quantity": 1
        }
      ],
      "party": {
        "name": "דנה לוי",
        "phone": "0521111111",
        "email": "dana@example.com",
        "taxId": "123456782"
      },
      "externalRef": "order-8812"
    }
    """, Encoding.UTF8, "application/json");
using var res = await http.SendAsync(req);
var data = JsonDocument.Parse(await res.Content.ReadAsStringAsync()).RootElement;
```