# Create New Contract

- Sandbox: `POST https://sandbox.payme.io/api/payment-contracts`
- Production: `POST https://live.payme.io/api/payment-contracts`

## Credentials

- Header `PayMe-Merchant-Key` (optional): MPL

This endpoint enables to create a new contract.
There is an option to send payment (payment.type = 1), and to send a payment request (payment.type = 2)

## Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `PayMe-Merchant-Key` | header | string | no | MPL |

## Request body

Content type: `application/json`

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `description` | string | yes | Describes the reason of the payment |
| `amount` | number | yes | The amount of the payment. The provided amount should be with pennies. For example, 1000 = 10.00 |
| `currency` | string | yes | The currency that will be used for the payment |
| `remote_id` | string | no | A unique Key that could be used as an identifier |
| `callback_url` | string | no | The URL to receive callbacks for every change in status |
| `recipient` | object | yes | The recipient's details |
| `recipient.language` | string | no | The language of the notifications that will be sent to the recipient. |
| `recipient.business_code` | number | no | Business number of the recipient |
| `recipient.email` | string | no | Recipient's phone number |
| `recipient.phone` | string | no | The phone number of the recipie |
| `recipient.payme_id` | string | no | Optional. MPL can be used in order to attach the payment contract directly to  a specific use in the syste m. If that parameter is provided in the payload, there is no need to send in the recipients array the following - business_code phone email |
| `payment` | object | yes | The payment details |
| `payment.type` | number | yes | Type of action 1 - Send Payment 2 - Payment Request |
| `payment.method` | string | yes | Supported payment methods values - 1. funds-transfer 2. credit-card 3. il-direct-debit |
| `payment.buyer_key` | string | no | Required in case the payment method isn't funds transfer |
| `payment.due_date` | string | yes | The date when the payment will take place Has to be a future date |
| `payment.recurring` | object | no | That object should be sent if the payment is recurring |
| `payment.recurring.iterations` | number | no | Number of payments |
| `payment.recurring.frequency_type` | number | no | The frequency of the payment |

### Request example

```json
{
  "description": "December payment",
  "amount": 500000,
  "currency": "ILS",
  "remote_id": "RAN123",
  "supply_date": "2021-12-08 00:00:00",
  "callback_url": "http://www.example.com/callback",
  "recipient": {
    "language": "en",
    "business_code": 51234567,
    "email": "yarden.cohen@paymeservice.com",
    "phone": "+972546545945"
  },
  "payment": {
    "type": "1",
    "method": "funds-transfer",
    "guarantee_type": 1,
    "due_date": "2021-11-22 20:00:00",
    "recurring": {
      "frequency_type": 4,
      "iterations": 36
    },
    "cash_discount_rate": 3.5
  },
  "services": [
    {
      "name": "invoice",
      "settings": {
        "active": false
      }
    }
  ]
}
```

## Code samples

### curl

```bash
curl -X POST 'https://sandbox.payme.io/api/payment-contracts' \
  -H 'Content-Type: application/json' \
  -H 'PayMe-Merchant-Key: <PayMe-Merchant-Key>' \
  --data-raw '{
  "description": "December payment",
  "amount": 500000,
  "currency": "ILS",
  "remote_id": "RAN123",
  "supply_date": "2021-12-08 00:00:00",
  "callback_url": "http://www.example.com/callback",
  "recipient": {
    "language": "en",
    "business_code": 51234567,
    "email": "yarden.cohen@paymeservice.com",
    "phone": "+972546545945"
  },
  "payment": {
    "type": "1",
    "method": "funds-transfer",
    "guarantee_type": 1,
    "due_date": "2021-11-22 20:00:00",
    "recurring": {
      "frequency_type": 4,
      "iterations": 36
    },
    "cash_discount_rate": 3.5
  },
  "services": [
    {
      "name": "invoice",
      "settings": {
        "active": false
      }
    }
  ]
}'
```

### Node.js

```javascript
const response = await fetch("https://sandbox.payme.io/api/payment-contracts", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "PayMe-Merchant-Key": "<PayMe-Merchant-Key>",
  },
  body: JSON.stringify({
    "description": "December payment",
    "amount": 500000,
    "currency": "ILS",
    "remote_id": "RAN123",
    "supply_date": "2021-12-08 00:00:00",
    "callback_url": "http://www.example.com/callback",
    "recipient": {
      "language": "en",
      "business_code": 51234567,
      "email": "yarden.cohen@paymeservice.com",
      "phone": "+972546545945"
    },
    "payment": {
      "type": "1",
      "method": "funds-transfer",
      "guarantee_type": 1,
      "due_date": "2021-11-22 20:00:00",
      "recurring": {
        "frequency_type": 4,
        "iterations": 36
      },
      "cash_discount_rate": 3.5
    },
    "services": [
      {
        "name": "invoice",
        "settings": {
          "active": false
        }
      }
    ]
  }),
});

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

### Python

```python
import requests

response = requests.post(
    "https://sandbox.payme.io/api/payment-contracts",
    headers={
        "PayMe-Merchant-Key": "<PayMe-Merchant-Key>",
    },
    json={
        "description": "December payment",
        "amount": 500000,
        "currency": "ILS",
        "remote_id": "RAN123",
        "supply_date": "2021-12-08 00:00:00",
        "callback_url": "http://www.example.com/callback",
        "recipient": {
            "language": "en",
            "business_code": 51234567,
            "email": "yarden.cohen@paymeservice.com",
            "phone": "+972546545945",
        },
        "payment": {
            "type": "1",
            "method": "funds-transfer",
            "guarantee_type": 1,
            "due_date": "2021-11-22 20:00:00",
            "recurring": {
                "frequency_type": 4,
                "iterations": 36,
            },
            "cash_discount_rate": 3.5,
        },
        "services": [
            {
                "name": "invoice",
                "settings": {
                    "active": False,
                },
            },
        ],
    },
)

print(response.text)
```

### PHP

```php
<?php

$body = <<<'BODY'
{
  "description": "December payment",
  "amount": 500000,
  "currency": "ILS",
  "remote_id": "RAN123",
  "supply_date": "2021-12-08 00:00:00",
  "callback_url": "http://www.example.com/callback",
  "recipient": {
    "language": "en",
    "business_code": 51234567,
    "email": "yarden.cohen@paymeservice.com",
    "phone": "+972546545945"
  },
  "payment": {
    "type": "1",
    "method": "funds-transfer",
    "guarantee_type": 1,
    "due_date": "2021-11-22 20:00:00",
    "recurring": {
      "frequency_type": 4,
      "iterations": 36
    },
    "cash_discount_rate": 3.5
  },
  "services": [
    {
      "name": "invoice",
      "settings": {
        "active": false
      }
    }
  ]
}
BODY;

$ch = curl_init('https://sandbox.payme.io/api/payment-contracts');
curl_setopt_array($ch, [
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        'Content-Type: application/json',
        'PayMe-Merchant-Key: <PayMe-Merchant-Key>',
    ],
    CURLOPT_POSTFIELDS => $body,
]);

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

echo $response;
```

## Responses

### 201 — Contract Created Successfully (success)

| Field | Type | Description |
| --- | --- | --- |
| `data` | object |  |
| `data.id` | number | The ID of the payment |
| `data.guid` | string | The payment GUID after being created successfully |
| `data.description` | string |  |
| `data.seller_payme_id` | string |  |
| `data.remote_id` | string |  |
| `data.created_date` | string |  |
| `data.confirmed_by_recipient_date` | string |  |
| `data.confirmed_by_initiator_date` | string |  |
| `data.resolution_date` | string |  |
| `data.status` | number |  |
| `data.amount` | number |  |
| `data.currency` | string |  |
| `data.payme_signature` | string |  |
| `data.error_code` | string |  |
| `data.error_note` | string |  |
| `data.error_text` | string |  |
| `data.recipient` | object |  |
| `data.recipient.language` | string |  |
| `data.recipient.business_code` | number |  |
| `data.recipient.email` | string |  |
| `data.recipient.phone` | string |  |
| `data.payment` | object |  |
| `data.payment.type` | string |  |
| `data.payment.method` | string |  |
| `data.payment.guarantee_type` | number |  |
| `data.payment.due_date` | string |  |
| `data.payment.recurring` | object |  |
| `data.payment.recurring.frequency_type` | number |  |
| `data.payment.recurring.iterations` | number |  |
| `status_code` | number |  |

```json
{
  "data": {
    "id": 63,
    "guid": "CONT1635-760813TL-0HKBYTFM-PWEBJAAV",
    "description": "December payment",
    "seller_payme_id": "MPL16348-26868UCA-EWLWXDZN-GF0TSYWF",
    "remote_id": "RAN123",
    "created_date": "2021-11-01 12:00:13",
    "confirmed_by_recipient_date": null,
    "confirmed_by_initiator_date": null,
    "resolution_date": null,
    "status": 1,
    "amount": 500000,
    "currency": "ILS",
    "payme_signature": "5dbf1885ce1d4e082757a2cd6086edd1",
    "error_code": null,
    "error_note": null,
    "error_text": null,
    "recipient": {
      "language": "en",
      "business_code": 51234567,
      "email": "yarden.cohen@paymeservice.com",
      "phone": "+972546545945"
    },
    "payment": {
      "type": "1",
      "method": "funds-transfer",
      "guarantee_type": 1,
      "due_date": "2021-11-22 20:00:00",
      "recurring": {
        "frequency_type": 4,
        "iterations": 36
      }
    }
  },
  "status_code": 0
}
```

### 400 — Missing Required Information (error)

| Field | Type | Description |
| --- | --- | --- |
| `status_code` | number |  |
| `status_error_details` | string |  |
| `status_additional_info` | object |  |
| `status_additional_info.payment.method` | array |  |
| `status_error_code` | number |  |

```json
{
  "status_code": 1,
  "status_error_details": "The given data was invalid.",
  "status_additional_info": {
    "payment.method": [
      "The payment.method field is required."
    ]
  },
  "status_error_code": 20
}
```
