# Create payment

POST `https://app.iteras.dk/api/customers/createpayment/`

The API key must allow "Change subscriber data".

Creates a payment on a customer.

## Parameters

- `id` (string, required): ID of the customer.
- `invoice_number` (string): The specific invoice the payment should be allocated to. If you do not have an invoice number, you may need to specify the business entity if there are more than one.
- `business_entity` (string): External ID of the business entity inside Iteras to connect the payment to, if you do not specify an invoice and if you have more than one business entity.
- `amount` (integer, required): Integer amount, e.g. `1050` for €10.50.
- `currency` (string, required): Three-letter ISO currency code, e.g. `EUR`, `DKK`, `SEK`, `NOK`. The currency must match the invoice/business entity.
- `method` (string, Defaults to `manual`): Payment method. Either `manual` (for manually registered), `internal` (internal transfer of funds) or `external` (for refunds registered on behalf of another system).
- `date` (date): The date the payment was received in the bank account, as `YYYY-MM-DD`. The default is today.
- `data` (object): Keys and values of custom payment fields, if any are set up inside Iteras, e.g. `{"examplefield": "value"}`.
- `note` (string): Internal note attached to the payment.
- `exclude_from_webhooks` (bool, Defaults to `false`): Set to `true` to keep every event the request causes from being sent to webhooks, invoice and payment events included, e.g. `"exclude_from_webhooks": true`. The events are still added to the history.

## Examples

Create a payment connected to a business entity:

```http
POST /api/customers/createpayment/ HTTP/1.1
Content-Type: application/json
```

```json
{
  "id": "12345",
  "business_entity": "DKbranch",
  "amount": 1050,
  "currency": "DKK",
  "note": "Balance from old system"
}
```

Create a payment allocated to a specific invoice:

```http
POST /api/customers/createpayment/ HTTP/1.1
Content-Type: application/json
```

```json
{
  "id": "12345",
  "invoice_number": 1007,
  "amount": 1050,
  "currency": "DKK"
}
```

## Return value

On success the endpoint returns the ID of the new payment:

```json
{ "payment_id": "982137" }
```

## Errors

Invalid requests due to programming error, e.g. invalid JSON, returns 400. This also covers specifying both `business_entity` and `invoice_number`.

A well-formed operation where a supplied value is invalid is not executed and returns an HTTP 422 error. The response is a JSON object with the errors keyed by the field they concern, e.g. a currency that doesn't match the business entity:

```json
{
  "currency": ["Invalid currency: EUR"]
}
```

This also covers needing to specify `business_entity` when there are several:

```json
{
  "business_entity": ["Must specify \"business_entity\"."]
}
```

Errors that are not specific to a field are returned with the empty string as key, e.g. an unknown business entity or invoice:

```json
{
  "": ["Business entity does not exist."]
}
```