# Generate New Payment

This is a variant of [POST /generate-sale — Generate Payment](/payments-migrated/hosted-payment-page/post-generate-sale); the request and responses below are the ones documented for IL Direct Debit.

- Sandbox: `POST https://sandbox.payme.io/api/generate-sale`
- Production: `POST https://live.payme.io/api/generate-sale`

## Credentials

- Request body field `seller_payme_id` (required): The MPL the authorization will be given for

## Overview

The Israeli Direct Debit alternative payment method works in a two-phase setup:
1. Setting up the bank authorization 
2. Completing the payment using the bank authorization <- **You are here**

### Generate a new payment using Israeli Direct Debit

In order to setup a new payment using the Israeli Direct Debit alternative payment method, you will need to use our `generate-sale` endpoint, using a few specific parameters.
1. `sale_type = sale`
2. `sale_payment_method = il-direct-debit`
3. include a `buyer-key` parameter as a part of your `generate-sale` request in order to initiate the payment flow

### Callbacks
Status | Description
---- | ----
Success | In case the payment was successful, you won't get any callback. Please note that the payment process can take up to 8 days.
Failure | In case that payment failed, you will get a callback indicates on failure.

### Testing

Information for testing can be found here - [Israeli Direct Debit Testing Information](/payments-migrated/introduction/test-cards-and-payment-methods#israeli-direct-debit-testing-information).

## Parameters

This endpoint takes no path, query or header parameters.

## Request body

Content type: `application/json`

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `seller_payme_id` | string | yes | The MPL the authorization will be given for |
| `sale_price` | string | yes | Must be included, won't be charged as a part of the authorization setup |
| `currency` | string | yes | Sale currency. [3-letter ISO 4217 name](https://en.wikipedia.org/wiki/ISO_4217). |
| `product_name` | string | yes | Use a generic value here (will not affect the authorization setup process) |
| `language` | string | no | The language the page will be presented in |
| `sale_type` | string | yes | The sale type. For authorization setup, use `token` by default |
| `sale_payment_method` | string | yes | The sale payment method. Must be `il-direct-debit` for the authorization setup process |
| `sale_return_url` | string | no | The URL the user will be redirected to after completing the authorization setup process |

### Request example

```json
{
  "seller_payme_id": "MPL16370-57351SJQ-0DTLUQXA-NJ916MXU",
  "sale_price": "1000",
  "currency": "ILS",
  "product_name": "Shirt",
  "language": "en",
  "sale_type": "token",
  "sale_payment_method": "il-direct-debit",
  "sale_return_url": "https://sport5.co.il"
}
```

## Code samples

### curl

```bash
curl -X POST 'https://sandbox.payme.io/api/generate-sale' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "seller_payme_id": "MPL16370-57351SJQ-0DTLUQXA-NJ916MXU",
  "sale_price": "1000",
  "currency": "ILS",
  "product_name": "Shirt",
  "language": "en",
  "sale_type": "token",
  "sale_payment_method": "il-direct-debit",
  "sale_return_url": "https://sport5.co.il"
}'
```

### Node.js

```javascript
const response = await fetch("https://sandbox.payme.io/api/generate-sale", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "seller_payme_id": "MPL16370-57351SJQ-0DTLUQXA-NJ916MXU",
    "sale_price": "1000",
    "currency": "ILS",
    "product_name": "Shirt",
    "language": "en",
    "sale_type": "token",
    "sale_payment_method": "il-direct-debit",
    "sale_return_url": "https://sport5.co.il"
  }),
});

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

### Python

```python
import requests

response = requests.post(
    "https://sandbox.payme.io/api/generate-sale",
    json={
        "seller_payme_id": "MPL16370-57351SJQ-0DTLUQXA-NJ916MXU",
        "sale_price": "1000",
        "currency": "ILS",
        "product_name": "Shirt",
        "language": "en",
        "sale_type": "token",
        "sale_payment_method": "il-direct-debit",
        "sale_return_url": "https://sport5.co.il",
    },
)

print(response.text)
```

### PHP

```php
<?php

$body = <<<'BODY'
{
  "seller_payme_id": "MPL16370-57351SJQ-0DTLUQXA-NJ916MXU",
  "sale_price": "1000",
  "currency": "ILS",
  "product_name": "Shirt",
  "language": "en",
  "sale_type": "token",
  "sale_payment_method": "il-direct-debit",
  "sale_return_url": "https://sport5.co.il"
}
BODY;

$ch = curl_init('https://sandbox.payme.io/api/generate-sale');
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` | string | Status of the request (0 - success, 1 - error) |
| `sale_url` | string | The URL of the IFRAME secured payment form to display to the buyer |
| `payme_sale_id` | string | Our unique sale ID |
| `payme_sale_code` | integer | Our unique sale code (for display purposes only) |
| `price` | integer | Sale final price. For example, if the price is 50.75 (max 2 decimal points) the value that needs to be sent is 5075 |
| `transaction_id` | string | Transaction ID |
| `currency` | string |  |
| `sale_payment_method` | string | The sale payment method. Must be il-direct-debit for the authorization setup process |

```json
{
  "status_code": 0,
  "sale_url": "https://sandbox.payme.io/sale/generate/SALETEST-XXXXXXXX-XXXXXXXX-XXXXXXXX",
  "payme_sale_id": "SALE1687-957072WX-0MEX63QM-GMHDMGNU",
  "payme_sale_code": 1234567,
  "price": 1000,
  "transaction_id": "12345",
  "currency": "ILS",
  "sale_payment_method": "il-direct-debit"
}
```
