# Initialize 3DSecure Request

- Sandbox: `POST https://sandbox.payme.io/api/sales/payme_sale_id/3ds`
- Production: `POST https://live.payme.io/api/sales/payme_sale_id/3ds`

## Credentials

- Header `PayMe-Public-Key` (optional): Merchant's public key.

This end-point is used for our MPI / 3D secure as-a-service funtionality. 

If you wish to process transactions with a different gateway but wish to use PayMe's MPI capability - this end-point can be used to get 3DS values required for processing a 3DS sale.

Please follow the instructions that can be found [Hosted Fields JSAPI Guide](/guides-and-use-cases-migrated/integrations/hosted-fields-jsapi-guide#3ds-integration-using-js-api).

In order to the 3DS service, you'll need to implement our library in your checkout page and collect the user data, then send it to us as a part of the `sales/{payme_sale_id}/3ds` request.

The parameter that needs to be sent is the string you receive from the library after initiating the data collection action:
Paramter|Example|Comments
---|---|---
`meta_data_jwt` | `eyJ0eXAiOiJKV1QiLCJh.......dyfwpbA` | The JWT string received from the library.

## Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `PayMe-Public-Key` | header | string | no | Merchant's public key. |

## Request body

Content type: `application/json`

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `payment` | object | no |  |
| `payment.method` | string | yes | Payment method for 3DSecure. 3DSecure is a Credit Card module, thus is the only available method |
| `payment.card_number` | string | yes | The card number to make authenticated payment uppon. |
| `payment.card_expiry` | string | yes | Card Expiry date. Format: mmyy |
| `customer` | object | yes |  |
| `customer.name` | string | yes | Card holder name. |
| `customer.email` | string | yes | Card holder email. |
| `customer.phone` | string | yes | Card holder mobile phone number. |
| `customer.zip_code` | string | yes | Card holder address zip code. |
| `customer.social_id` | string | yes | Card holder social id / national id. |
| `meta_data_jwt` | string | yes | The user data collected from the browser. Must be encrypted by PayMe's service. |

### Request example

```json
{
  "payment": {
    "method": "credit-card",
    "card_number": "4111111111111111",
    "card_expiry": "1221"
  },
  "customer": {
    "name": "developer test",
    "email": "test@paymeservice.com",
    "phone": "+972501234567",
    "zip_code": "857393485",
    "social_id": "123456782"
  }
}
```

## Code samples

### curl

```bash
curl -X POST 'https://sandbox.payme.io/api/sales/payme_sale_id/3ds' \
  -H 'Content-Type: application/json' \
  -H 'PayMe-Public-Key: <PayMe-Public-Key>' \
  --data-raw '{
  "payment": {
    "method": "credit-card",
    "card_number": "4111111111111111",
    "card_expiry": "1221"
  },
  "customer": {
    "name": "developer test",
    "email": "test@paymeservice.com",
    "phone": "+972501234567",
    "zip_code": "857393485",
    "social_id": "123456782"
  }
}'
```

### Node.js

```javascript
const response = await fetch("https://sandbox.payme.io/api/sales/payme_sale_id/3ds", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "PayMe-Public-Key": "<PayMe-Public-Key>",
  },
  body: JSON.stringify({
    "payment": {
      "method": "credit-card",
      "card_number": "4111111111111111",
      "card_expiry": "1221"
    },
    "customer": {
      "name": "developer test",
      "email": "test@paymeservice.com",
      "phone": "+972501234567",
      "zip_code": "857393485",
      "social_id": "123456782"
    }
  }),
});

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

### Python

```python
import requests

response = requests.post(
    "https://sandbox.payme.io/api/sales/payme_sale_id/3ds",
    headers={
        "PayMe-Public-Key": "<PayMe-Public-Key>",
    },
    json={
        "payment": {
            "method": "credit-card",
            "card_number": "4111111111111111",
            "card_expiry": "1221",
        },
        "customer": {
            "name": "developer test",
            "email": "test@paymeservice.com",
            "phone": "+972501234567",
            "zip_code": "857393485",
            "social_id": "123456782",
        },
    },
)

print(response.text)
```

### PHP

```php
<?php

$body = <<<'BODY'
{
  "payment": {
    "method": "credit-card",
    "card_number": "4111111111111111",
    "card_expiry": "1221"
  },
  "customer": {
    "name": "developer test",
    "email": "test@paymeservice.com",
    "phone": "+972501234567",
    "zip_code": "857393485",
    "social_id": "123456782"
  }
}
BODY;

$ch = curl_init('https://sandbox.payme.io/api/sales/payme_sale_id/3ds');
curl_setopt_array($ch, [
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        'Content-Type: application/json',
        'PayMe-Public-Key: <PayMe-Public-Key>',
    ],
    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-redirect, 1 - error) |
| `status_message` | string | A message you may show to the buyer |
| `redirect_url` | string | The URL we should redirect (GET method) to the user. |

```json
{
  "status_code": 5,
  "status_message": "Generating validation page, please wait",
  "redirect_url": "https://preprod.paymeservice.com/3ds/redirect/SALE1587-486438YT-JLHBOZLR-AJJTULHT?pa=eJxdU9tu4jAQfUfqP1h5T%252Bw4V5BxRZeulpWC2C5V1b55nVmIlAt1kgL79WuTBpL6yXPmjOfMxez%252BVOToA1SdVeXcch1iIShllWblbm49b7%252FbsXXP7yZsu1cAy98gWwV8ghBLoK7FDlCWzi047Lw0FmEsXZumgW%252F7f1PPFj5MbRrQOAyI60EElgnUoZvFE7x3d219Juc6t0MZ7s3enYCSe1E2PaAhId8fVmvuB0Hkewx%252Fmjd%252FAWq15EEU0CgMwsilrn63A68kxEpRAF%252BgBuoG9UkYvqADlqzaslFn7kUhw70x8Lcq5%252FumOdQzjI%252FHo5PVSkihUnuXV39E7siqYNiQ%252Bnrw14LYpjVAPUp7ylKe%252FHvI19uf%252BVuR%252BG8vr%252Bf1cuUn9PGYbH%252FNGTaMQUAqGuCUUEIC4iE3mnnTGdVlX%252FABTxSmBv74%252FIRcQhxCdP86aEA6GEWLDtYsQxpCw%252Fa0Sul9OfNpFOv%252B9NaAAadDVYKO0mKu96FwqCVfwgfaqCptZYPWegJat4FvtGv3vjaLffsxKk%252FKRo%252FZd8fHLMnFMRaW6VlS1%252B2UZbfBMty%252FqhP2y2omd1l5PmF49B3uJv8Blq7hOg%253D%253D&url=https%253A%252F%252Fwww.3dsecurempi.com%252FTDS%252FAUT%253FAction%253DAuthenticate&track=BUYER158-7473169I-GRHJVHIH-VBT25PLM%7CTRAN1588-5275735M-BYGTDXRQ-ZPZT4XRE&pay=0"
}
```

### 500 — Internal Server Error (error)

| Field | Type | Description |
| --- | --- | --- |
| `status_code` | number |  |
| `status_error_details` | string | Error message to the client |
| `status_additional_info` | string | Additional error information ` |
| `status_error_code` | number | Our unique error code |

```json
{
  "status_code": 1,
  "status_error_details": "Invalid credit card expiry",
  "status_additional_info": "1221f",
  "status_error_code": 356
}
```
