# Delayed Market Fee

- Sandbox: `PATCH https://sandbox.payme.io/api/sales/{guid}/external-market-fee`
- Production: `PATCH https://live.payme.io/api/sales/{guid}/external-market-fee`

## Credentials

- Header `PayMe-Partner-Key` (optional): The partner secret key.
- Header `PayMe-Merchant-Key` (optional): The MPL of the seller.

## Overview

This endpoint allows you to create a new charge (fee) that is connected to a sale and is limited by the transaction amount. 

### Limitations

1. You must include at least one of the following - `market_fee_percentage` or `market_fee_fixed`
2. The sale must be generated by the MPL
3. `market_fee_percentage` - can be from 0.0 to 60.0
4. `market_fee_fixed` - limited to the amount settled to the wallet and cannot be higher than that.

## Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `PayMe-Partner-Key` | header | string | no | The partner secret key. |
| `PayMe-Merchant-Key` | header | string | no | The MPL of the seller. |
| `guid` | path | string | yes |  |

## Request body

Content type: `application/json`

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `market_fee_percentage` | number | no | The percentage that will be charged. Limited to be between 0 to 60. |
| `market_fee_fixed` | integer | no | The fixed market fee - limited to the amount settled to the wallet. |

### Request example

```json
{
  "market_fee_percentage": 10.2,
  "market_fee_fixed": 15000
}
```

## Code samples

### curl

```bash
curl -X PATCH 'https://sandbox.payme.io/api/sales/<guid>/external-market-fee' \
  -H 'Content-Type: application/json' \
  -H 'PayMe-Partner-Key: <PayMe-Partner-Key>' \
  -H 'PayMe-Merchant-Key: <PayMe-Merchant-Key>' \
  --data-raw '{
  "market_fee_percentage": 10.2,
  "market_fee_fixed": 15000
}'
```

### Node.js

```javascript
const response = await fetch("https://sandbox.payme.io/api/sales/<guid>/external-market-fee", {
  method: "PATCH",
  headers: {
    "Content-Type": "application/json",
    "PayMe-Partner-Key": "<PayMe-Partner-Key>",
    "PayMe-Merchant-Key": "<PayMe-Merchant-Key>",
  },
  body: JSON.stringify({
    "market_fee_percentage": 10.2,
    "market_fee_fixed": 15000
  }),
});

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

### Python

```python
import requests

response = requests.patch(
    "https://sandbox.payme.io/api/sales/<guid>/external-market-fee",
    headers={
        "PayMe-Partner-Key": "<PayMe-Partner-Key>",
        "PayMe-Merchant-Key": "<PayMe-Merchant-Key>",
    },
    json={
        "market_fee_percentage": 10.2,
        "market_fee_fixed": 15000,
    },
)

print(response.text)
```

### PHP

```php
<?php

$body = <<<'BODY'
{
  "market_fee_percentage": 10.2,
  "market_fee_fixed": 15000
}
BODY;

$ch = curl_init('https://sandbox.payme.io/api/sales/<guid>/external-market-fee');
curl_setopt_array($ch, [
    CURLOPT_CUSTOMREQUEST => 'PATCH',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        'Content-Type: application/json',
        'PayMe-Partner-Key: <PayMe-Partner-Key>',
        'PayMe-Merchant-Key: <PayMe-Merchant-Key>',
    ],
    CURLOPT_POSTFIELDS => $body,
]);

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

echo $response;
```

## Responses

### 200 — OK (success)

| Field | Type | Description |
| --- | --- | --- |
| `status_code` | integer | 0 - Sucess 1 - Failure |
| `payme_status` | string | The status of the action. |
| `payme_sale_id` | string | The sale the fee was associated with. |

```json
{
  "status_code": 0,
  "payme_status": "success",
  "payme_sale_id": "SALEGUID-SALEGUID-SALEGUID-SALEGUID"
}
```
