# Create income document

- Sandbox: `POST https://sandbox.payme.io/api/seller/api/documents/income`
- Production: `POST https://live.payme.io/api/seller/api/documents/income`

## Credentials

- Header `Authorization: Bearer <token>`

Create a new income document (invoice, receipt, deal, etc.) using the new invoicing service.

## Parameters

This endpoint takes no path, query or header parameters.

## Request body

Content type: `application/json`

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `type` | string | yes | Document type |
| `client` | object | yes |  |
| `client.name` | string | yes | Client/customer name |
| `client.email` | string | no | Client email address |
| `client.phone` | string | no | Client phone number |
| `client.socialId` | string | no | Client's social/business ID number (ת.ז. / ח.פ.) |
| `currency` | string | yes | Document currency (currently only ILS supported) |
| `docValueDate` | string | yes | Document value date |
| `dueDate` | string | no | Payment due date (required for invoice, deal, offer) |
| `title` | string | no | Document title (optional) |
| `docLang` | string | yes | Document language |
| `items` | array | yes | Document line items |
| `items[].name` | string | yes | Item name/description |
| `items[].quantity` | number | yes | Item quantity |
| `items[].itemNetPrice` | number | yes | Item net price (before VAT) |
| `items[].itemTotalPrice` | number | no | Item total price (calculated) |
| `items[].itemSumNetTotalPrice` | number | no | Item sum net total price (quantity * itemNetPrice) |
| `items[].itemCurrency` | string | yes | Item currency |
| `items[].isNoItemVat` | boolean | no | VAT exempt flag (true = no VAT for this item) |
| `bankDetails` | object | no | Bank account details for payment |
| `bankDetails.bankName` | string | no | Bank name |
| `bankDetails.branchNumber` | string | no | Branch number |
| `bankDetails.accountNumber` | string | no | Account number |
| `bankDetails.accountName` | string | no | Account holder name |
| `bankDetails.IBAN` | string | no | IBAN number |
| `subTotal` | number | no | Subtotal before discount |
| `discount` | number | no | Discount amount |
| `totalWithoutVatAmount` | number | no | Total amount without VAT |
| `vatAmount` | number | no | VAT amount |
| `totalAmount` | number | yes | Total amount including VAT |
| `totalPaid` | number | no | Total amount paid (required for receipts) |
| `originTaxDeduction` | number | no | Tax deduction at source (ניכוי מס במקור) |
| `comment` | string | no | Document comments/notes |
| `paymentCash` | object | no | Cash payment details |
| `paymentCash.date` | string | yes | Payment date |
| `paymentCash.amount` | number | yes | Payment amount |
| `paymentCreditCard` | object | no | Credit card payment details |
| `paymentCreditCard.date` | string | yes | Payment date |
| `paymentCreditCard.amount` | number | yes | Payment amount |
| `paymentCreditCard.last4Digits` | string | no | Last 4 digits of card |
| `paymentBankTransfer` | object | no | Bank transfer payment details |
| `paymentBankTransfer.date` | string | yes | Payment date |
| `paymentBankTransfer.amount` | number | yes | Payment amount |
| `paymentBankTransfer.bankNumber` | integer | no | Bank code |
| `paymentBankTransfer.branchNumber` | integer | no | Branch number |
| `paymentBankTransfer.accountNumber` | integer | no | Account number |
| `paymentCheque` | object | no | Cheque payment details |
| `paymentCheque.date` | string | yes | Cheque date |
| `paymentCheque.receivedDate` | string | yes | Date cheque was received |
| `paymentCheque.amount` | number | yes | Payment amount |
| `paymentCheque.chequeNumber` | string | yes | Cheque number |
| `paymentCheque.bankNumber` | integer | no | Bank code |
| `paymentCheque.branchNumber` | integer | no | Branch number |
| `paymentCheque.accountNumber` | integer | no | Account number |
| `paymentEWallet` | object | no | E-wallet payment details (PayPal, Bit, etc.) |
| `paymentEWallet.date` | string | yes | Payment date |
| `paymentEWallet.amount` | number | yes | Payment amount |
| `paymentEWallet.walletType` | string | yes | E-wallet type |
| `payment` | object | no | Payment link settings (for invoice/deal) |
| `payment.isEnabled` | boolean | no | Enable payment link |
| `payment.clientEmail` | string | no | Email to send payment link to |
| `payment.clientPhone` | string | no | Phone to send payment link to |
| `callbacks` | object | no | Callback URLs for async notifications |
| `callbacks.success` | array | no | URLs to call on success |
| `callbacks.error` | array | no | URLs to call on error |

### Request example

```json
{
  "type": "invoice",
  "client": {
    "name": "John Doe",
    "email": "john@example.com",
    "phone": "0501234567",
    "socialId": "123456789"
  },
  "currency": "ILS",
  "docValueDate": "2024-01-15",
  "dueDate": "2024-02-15",
  "docLang": "he",
  "items": [
    {
      "name": "Consulting Service",
      "quantity": 1,
      "itemNetPrice": 1000,
      "itemCurrency": "ILS",
      "isNoItemVat": false
    }
  ],
  "subTotal": 1000,
  "totalWithoutVatAmount": 1000,
  "vatAmount": 170,
  "totalAmount": 1170,
  "comment": "Thank you for your business"
}
```

## Code samples

### curl

```bash
curl -X POST 'https://sandbox.payme.io/api/seller/api/documents/income' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer <YOUR_TOKEN>' \
  --data-raw '{
  "type": "invoice",
  "client": {
    "name": "John Doe",
    "email": "john@example.com",
    "phone": "0501234567",
    "socialId": "123456789"
  },
  "currency": "ILS",
  "docValueDate": "2024-01-15",
  "dueDate": "2024-02-15",
  "docLang": "he",
  "items": [
    {
      "name": "Consulting Service",
      "quantity": 1,
      "itemNetPrice": 1000,
      "itemCurrency": "ILS",
      "isNoItemVat": false
    }
  ],
  "subTotal": 1000,
  "totalWithoutVatAmount": 1000,
  "vatAmount": 170,
  "totalAmount": 1170,
  "comment": "Thank you for your business"
}'
```

### Node.js

```javascript
const response = await fetch("https://sandbox.payme.io/api/seller/api/documents/income", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Authorization": "Bearer <YOUR_TOKEN>",
  },
  body: JSON.stringify({
    "type": "invoice",
    "client": {
      "name": "John Doe",
      "email": "john@example.com",
      "phone": "0501234567",
      "socialId": "123456789"
    },
    "currency": "ILS",
    "docValueDate": "2024-01-15",
    "dueDate": "2024-02-15",
    "docLang": "he",
    "items": [
      {
        "name": "Consulting Service",
        "quantity": 1,
        "itemNetPrice": 1000,
        "itemCurrency": "ILS",
        "isNoItemVat": false
      }
    ],
    "subTotal": 1000,
    "totalWithoutVatAmount": 1000,
    "vatAmount": 170,
    "totalAmount": 1170,
    "comment": "Thank you for your business"
  }),
});

console.log(await response.text());
```

### Python

```python
import requests

response = requests.post(
    "https://sandbox.payme.io/api/seller/api/documents/income",
    headers={
        "Authorization": "Bearer <YOUR_TOKEN>",
    },
    json={
        "type": "invoice",
        "client": {
            "name": "John Doe",
            "email": "john@example.com",
            "phone": "0501234567",
            "socialId": "123456789",
        },
        "currency": "ILS",
        "docValueDate": "2024-01-15",
        "dueDate": "2024-02-15",
        "docLang": "he",
        "items": [
            {
                "name": "Consulting Service",
                "quantity": 1,
                "itemNetPrice": 1000,
                "itemCurrency": "ILS",
                "isNoItemVat": False,
            },
        ],
        "subTotal": 1000,
        "totalWithoutVatAmount": 1000,
        "vatAmount": 170,
        "totalAmount": 1170,
        "comment": "Thank you for your business",
    },
)

print(response.text)
```

### PHP

```php
<?php

$body = <<<'BODY'
{
  "type": "invoice",
  "client": {
    "name": "John Doe",
    "email": "john@example.com",
    "phone": "0501234567",
    "socialId": "123456789"
  },
  "currency": "ILS",
  "docValueDate": "2024-01-15",
  "dueDate": "2024-02-15",
  "docLang": "he",
  "items": [
    {
      "name": "Consulting Service",
      "quantity": 1,
      "itemNetPrice": 1000,
      "itemCurrency": "ILS",
      "isNoItemVat": false
    }
  ],
  "subTotal": 1000,
  "totalWithoutVatAmount": 1000,
  "vatAmount": 170,
  "totalAmount": 1170,
  "comment": "Thank you for your business"
}
BODY;

$ch = curl_init('https://sandbox.payme.io/api/seller/api/documents/income');
curl_setopt_array($ch, [
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        'Content-Type: application/json',
        'Authorization: Bearer <YOUR_TOKEN>',
    ],
    CURLOPT_POSTFIELDS => $body,
]);

$response = curl_exec($ch);
curl_close($ch);

echo $response;
```

## Responses

### 201 — Document created successfully (success)

| Field | Type | Description |
| --- | --- | --- |
| `id` | string | Created document ID |
| `url` | string | URL to download/view the document |
| `docRegulationNumber` | string | Tax authority regulation number (מספר אסמכתא) |

### 400 — Bad Request (error)

| Field | Type | Description |
| --- | --- | --- |
| `statusCode` | integer | HTTP status code |
| `message` | string | Error message(s) |
| `error` | string | Error type |

```json
{
  "statusCode": 400,
  "message": [
    "Validation failed"
  ],
  "error": "Bad Request"
}
```

### 401 — Unauthorized (error)

| Field | Type | Description |
| --- | --- | --- |
| `statusCode` | integer | HTTP status code |
| `message` | string | Error message(s) |
| `error` | string | Error type |

```json
{
  "statusCode": 401,
  "message": "Unauthorized",
  "error": "Unauthorized"
}
```
