# Withdraw Balance

- Sandbox: `POST https://sandbox.payme.io/api/withdraw-balance`
- Production: `POST https://live.payme.io/api/withdraw-balance`

## Credentials

- Request body field `payme_client_key` (required): Your private key provided by us for authentication
- Request body field `seller_payme_id` (required): Our unique seller ID

## Overview

This endpoint is used to generate a new request to withdraw balance.

#### Notes
*  Until we obtain and verify the 3 mandatory documents (`Social Id, Bank, Corporate Certificate`), funds will not be available for withdrawal to the Seller's bank account.
* **Partial-withdrawal** - In order to create a partial-withdrawal, you will need to add another parameter to your request which states which transactions you are willing to get the balance for to your bank account.

Parameter|Description
---|---
`transaction_ids`| The transaction GUIDs that will be included as a part of your withdrawal request. 

### Withdrawal Callback Notification Types
Notification	|Description
--|--
withdrawal-complete	|A withdrawal was completed successfully

Attribute|	Description
--|--
status_code	|`0` Status of the request (0 - success, 1 - error)
notify_type	|`withdrawal-complete`
seller_payme_id|	`XXXXXXXX-XXXXXXXX-XXXXXXXX-XXXXXXXX`
tran_payme_code|	`123456` Our unique Withdrawal code
tran_created	|`2016-01-01 15:15:15`
tran_type	|`40` Financial Transaction type Bank Withdrawal
tran_currency	|`USD`
tran_total	|`10000`
tran_description|	`משיכה לבנק

## Parameters

This endpoint takes no path, query or header parameters.

## Request body

Content type: `application/json`

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `payme_client_key` | string | yes | Your private key provided by us for authentication |
| `seller_payme_id` | string | yes | Our unique seller ID |
| `withdrawal_currency` | string | yes | Sale currency. [3-letter ISO 4217 name](https://en.wikipedia.org/wiki/ISO_4217). |
| `language` | string | no | Changes the error message language to English. Default value is Hebrew (he) |
| `transaction_ids` | array | no | The transaction IDs that will be used for the partial withdrawal request. Transaction guids can be fetched using our `get-transcations` API endpoint. Example: TRANDEMO-XXXXXXXX-XXXXXXXX-XXXXXXXX |

### Request example

```json
{
  "payme_client_key": "string",
  "seller_payme_id": "string",
  "withdrawal_currency": "string",
  "language": "string"
}
```

## Code samples

### curl

```bash
curl -X POST 'https://sandbox.payme.io/api/withdraw-balance' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "payme_client_key": "string",
  "seller_payme_id": "string",
  "withdrawal_currency": "string",
  "language": "string"
}'
```

### Node.js

```javascript
const response = await fetch("https://sandbox.payme.io/api/withdraw-balance", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "payme_client_key": "string",
    "seller_payme_id": "string",
    "withdrawal_currency": "string",
    "language": "string"
  }),
});

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

### Python

```python
import requests

response = requests.post(
    "https://sandbox.payme.io/api/withdraw-balance",
    json={
        "payme_client_key": "string",
        "seller_payme_id": "string",
        "withdrawal_currency": "string",
        "language": "string",
    },
)

print(response.text)
```

### PHP

```php
<?php

$body = <<<'BODY'
{
  "payme_client_key": "string",
  "seller_payme_id": "string",
  "withdrawal_currency": "string",
  "language": "string"
}
BODY;

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

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

echo $response;
```

## Responses

### 200 — OK (success)

| Field | Type | Description |
| --- | --- | --- |
| `status_code` | number | Status of the request (0 - success, 1 - error) |

```json
{
  "status_code": 0
}
```

### 500 — Internal Server Error (error)

| Field | Type | Description |
| --- | --- | --- |
| `status_code` | number |  |
| `status_error_details` | string |  |
| `status_additional_info` | string |  |
| `status_error_code` | number |  |

```json
{
  "status_code": 0,
  "status_error_details": "string",
  "status_additional_info": null,
  "status_error_code": 0
}
```
