# Capture Buyer Token

- Sandbox: `POST https://sandbox.payme.io/api/capture-buyer-token`
- Production: `POST https://live.payme.io/api/capture-buyer-token`

## Credentials

- Request body field `seller_payme_id` (required): Our unique seller ID

## Overview

This endpoint can be used only if you are PCI compliant and are able to handle raw credit card infromation. 

This end-point is used to create a new token, by sending a request with the full credit card data and getting a response with the token. This token can be used later on to perform sales and other payment actions.

## 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 | Our unique seller ID |
| `buyer_name` | string | no | Buyer's full name |
| `buyer_social_id` | string | no | Buyer's social ID number |
| `buyer_email` | string | no | Buyer's email address |
| `buyer_phone` | string | no | Buyer's phone number |
| `buyer_zip_code` | string | no | Buyer's address zip code |
| `credit_card_number` | integer | yes | Card number |
| `credit_card_exp` | string | yes | Buyer's card exp (MMYY) |
| `credit_card_cvv` | integer | yes |  |
| `buyer_perform_validation` | boolean | no | Flag for performing an online validation of the card with the Issuer. |

### Request example

```json
{
  "seller_payme_id": "MPLDEMO-MPLDEMO-MPLDEMO-1234567",
  "buyer_name": "Idan testing",
  "buyer_social_id": "123456789",
  "buyer_email": "TestTest@paymeservice.com",
  "buyer_phone": "05222222",
  "buyer_zip_code": "1q2w3exx",
  "credit_card_number": 4111111111111111,
  "credit_card_exp": "0322",
  "credit_card_cvv": 123
}
```

## Code samples

### curl

```bash
curl -X POST 'https://sandbox.payme.io/api/capture-buyer-token' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "seller_payme_id": "MPLDEMO-MPLDEMO-MPLDEMO-1234567",
  "buyer_name": "Idan testing",
  "buyer_social_id": "123456789",
  "buyer_email": "TestTest@paymeservice.com",
  "buyer_phone": "05222222",
  "buyer_zip_code": "1q2w3exx",
  "credit_card_number": 4111111111111111,
  "credit_card_exp": "0322",
  "credit_card_cvv": 123
}'
```

### Node.js

```javascript
const response = await fetch("https://sandbox.payme.io/api/capture-buyer-token", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "seller_payme_id": "MPLDEMO-MPLDEMO-MPLDEMO-1234567",
    "buyer_name": "Idan testing",
    "buyer_social_id": "123456789",
    "buyer_email": "TestTest@paymeservice.com",
    "buyer_phone": "05222222",
    "buyer_zip_code": "1q2w3exx",
    "credit_card_number": 4111111111111111,
    "credit_card_exp": "0322",
    "credit_card_cvv": 123
  }),
});

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

### Python

```python
import requests

response = requests.post(
    "https://sandbox.payme.io/api/capture-buyer-token",
    json={
        "seller_payme_id": "MPLDEMO-MPLDEMO-MPLDEMO-1234567",
        "buyer_name": "Idan testing",
        "buyer_social_id": "123456789",
        "buyer_email": "TestTest@paymeservice.com",
        "buyer_phone": "05222222",
        "buyer_zip_code": "1q2w3exx",
        "credit_card_number": 4111111111111111,
        "credit_card_exp": "0322",
        "credit_card_cvv": 123,
    },
)

print(response.text)
```

### PHP

```php
<?php

$body = <<<'BODY'
{
  "seller_payme_id": "MPLDEMO-MPLDEMO-MPLDEMO-1234567",
  "buyer_name": "Idan testing",
  "buyer_social_id": "123456789",
  "buyer_email": "TestTest@paymeservice.com",
  "buyer_phone": "05222222",
  "buyer_zip_code": "1q2w3exx",
  "credit_card_number": 4111111111111111,
  "credit_card_exp": "0322",
  "credit_card_cvv": 123
}
BODY;

$ch = curl_init('https://sandbox.payme.io/api/capture-buyer-token');
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` | integer | Action status code (0 - Success, 1 - Failure) |
| `buyer_key` | string | Buyer's unique token |
| `buyer_name` | string | Buyer's full name |
| `buyer_email` | string | Buyer's email address |
| `buyer_phone` | string | Buyer's phone number |
| `buyer_card_mask` | string | Buyer's card mask |
| `buyer_card_exp` | string | Buyer's card exp (MMYY) |
| `buyer_social_id` | string | Buyer's social ID number |
| `buyer_is_permanent` | boolean | Is the token temporary or permanant |
| `buyer_status` | integer | The status's buyer |

```json
{
  "status_code": 0,
  "buyer_key": "BUYER168-6667348Q-V8Z99RXJ-CQ60HNGY",
  "buyer_name": "Ran Tester",
  "buyer_email": "TestTest@paymeservice.com",
  "buyer_phone": "05222222",
  "buyer_card_mask": "532610******5846",
  "buyer_card_exp": "0426",
  "buyer_social_id": "123456789",
  "buyer_is_permanent": false,
  "buyer_status": null
}
```

### 356 (error)

| Field | Type | Description |
| --- | --- | --- |
| `status_code` | integer |  |
| `status_error_details` | string |  |
| `status_additional_info` | boolean |  |
| `status_error_code` | integer |  |
| `session` | string |  |

```json
{
  "status_code": 1,
  "status_error_details": "תוקף כרטיס אשראי לא תקין",
  "status_additional_info": false,
  "status_error_code": 356,
  "session": "khANe7Jl"
}
```

### 500 — Internal Server Error (error)

| Field | Type | Description |
| --- | --- | --- |
| `status_code` | integer |  |
| `status_error_details` | string |  |
| `status_additional_info` | string |  |
| `status_error_code` | integer |  |
| `session` | string |  |

```json
{
  "status_code": 1,
  "status_error_details": "Required parameter is missing",
  "status_additional_info": "credit_card_cvv",
  "status_error_code": 1,
  "session": "0PFThooQ"
}
```
