# Refund POS Sale

- Sandbox: `PUT https://sandbox.payme.io/api/sales`
- Production: `PUT https://live.payme.io/api/sales`

## Credentials

No credentials are documented for this endpoint.

In order to refund a sale paid via a POS device, you can use PUT function which will trigger a manual refund request sent back to the device.

### You will need to chain the sale GUID unique identifier to the endpoint URL in the following form:
`https://<env>.payme.io/api/sales/{sale_guid}` 

#### Example:

`https://<env>.payme.io/api/sales/SALEGUID-TEST123-TEST123-TEST123` 

The request will trigger a refund that will be sent to the designated device per the device ID mentioned in the request (see request example below)

## Parameters

This endpoint takes no path, query or header parameters.

## Request body

Content type: `application/json`

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `seller_payme_id` | string | no | PayMe's unqiue seller ID |
| `product_name` | string | no | Product's description |
| `currency` | string | no | Sale currency. [3-letter ISO 4217 name](https://en.wikipedia.org/wiki/ISO_4217). |
| `transaction_id` | string | no | The external transaction ID. |
| `sale_callback_url` | string | no | The callback url for the specific sale. |
| `payment` | object | no | The payment object. |
| `payment.method` | string | no | The payment method. |
| `payment.pos_id` | string | no | The POS ID - the device that will be used to process the refund request. |
| `payment.action` | string | no | The action - must be `refund` in order to complete this action. |
| `payment.amount` | string | no | The sale amount in Agorot |
| `language` | string | no | The language of the customer's interface. |

### Request example

```json
{
  "seller_payme_id": "string",
  "product_name": "string",
  "sale_price": 0,
  "currency": "USD",
  "transaction_id": "string",
  "sale_callback_url": "string",
  "payment": {
    "method": "pos",
    "pos_id": "002",
    "action": "refund"
  },
  "customer": {
    "name": "string",
    "email": "string",
    "phone": "string",
    "zip_code": "string",
    "social_id": "string"
  },
  "language": "he"
}
```

## Code samples

### curl

```bash
curl -X PUT 'https://sandbox.payme.io/api/sales' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "seller_payme_id": "string",
  "product_name": "string",
  "sale_price": 0,
  "currency": "USD",
  "transaction_id": "string",
  "sale_callback_url": "string",
  "payment": {
    "method": "pos",
    "pos_id": "002",
    "action": "refund"
  },
  "customer": {
    "name": "string",
    "email": "string",
    "phone": "string",
    "zip_code": "string",
    "social_id": "string"
  },
  "language": "he"
}'
```

### Node.js

```javascript
const response = await fetch("https://sandbox.payme.io/api/sales", {
  method: "PUT",
  headers: {
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "seller_payme_id": "string",
    "product_name": "string",
    "sale_price": 0,
    "currency": "USD",
    "transaction_id": "string",
    "sale_callback_url": "string",
    "payment": {
      "method": "pos",
      "pos_id": "002",
      "action": "refund"
    },
    "customer": {
      "name": "string",
      "email": "string",
      "phone": "string",
      "zip_code": "string",
      "social_id": "string"
    },
    "language": "he"
  }),
});

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

### Python

```python
import requests

response = requests.put(
    "https://sandbox.payme.io/api/sales",
    json={
        "seller_payme_id": "string",
        "product_name": "string",
        "sale_price": 0,
        "currency": "USD",
        "transaction_id": "string",
        "sale_callback_url": "string",
        "payment": {
            "method": "pos",
            "pos_id": "002",
            "action": "refund",
        },
        "customer": {
            "name": "string",
            "email": "string",
            "phone": "string",
            "zip_code": "string",
            "social_id": "string",
        },
        "language": "he",
    },
)

print(response.text)
```

### PHP

```php
<?php

$body = <<<'BODY'
{
  "seller_payme_id": "string",
  "product_name": "string",
  "sale_price": 0,
  "currency": "USD",
  "transaction_id": "string",
  "sale_callback_url": "string",
  "payment": {
    "method": "pos",
    "pos_id": "002",
    "action": "refund"
  },
  "customer": {
    "name": "string",
    "email": "string",
    "phone": "string",
    "zip_code": "string",
    "social_id": "string"
  },
  "language": "he"
}
BODY;

$ch = curl_init('https://sandbox.payme.io/api/sales');
curl_setopt_array($ch, [
    CURLOPT_CUSTOMREQUEST => 'PUT',
    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 | PayMe's payment status (success/failure) |
| `payme_status` | string | Sale status |
| `payme_sale_id` | string | PayMe's unique Sale ID |
| `payme_sale_code` | integer | PayMe's unique Sale code |
| `sale_created` | string | The date the sale was created (timestamp) |
| `payme_sale_status` | string | PayMe's sale status |
| `sale_status` | string | Sale status |
| `currency` | string | Sale currency. [3-letter ISO 4217 name](https://en.wikipedia.org/wiki/ISO_4217). |
| `transaction_id` | string | Transaction ID |
| `is_token_sale` | boolean | Was the card tokenized or not |
| `price` | integer | Payment price |
| `payme_signature` | string | PayMe's signature for the payment |
| `sale_description` | string | Sale description |
| `payme_transaction_id` | string | PayMe transaction ID |
| `payme_transaction_total` | string | Transaction total amount |
| `payme_transaction_card_brand` | string | The card brand |
| `payme_transaction_auth_number` | string | Transaction authorization number |
| `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 | Card mask |
| `buyer_card_exp` | string | Buyer's card expiration date |
| `buyer_card_is_foreign` | boolean | Is the card foreign or domestic? (For IL Sellers only) |
| `buyer_social_id` | string | Buyer's social ID number |
| `installments` | integer | Number of installments used for the payment |
| `sale_paid_date` | string | Sale paid date |

```json
{
  "status_code": 0,
  "payme_status": "success",
  "status_error_code": 0,
  "payme_sale_id": "SALE1688-XXXXXXXX-XXXXXXXX-XXXXXXXX",
  "payme_sale_code": 12346578,
  "sale_created": "2023-06-29 13:33:54",
  "payme_sale_status": "authorized",
  "sale_status": "authorized",
  "currency": "ILS",
  "transaction_id": "string",
  "is_token_sale": false,
  "price": 100,
  "payme_signature": "db1c276**********c5b39",
  "sale_description": "bbb",
  "sale_deferred_months": null,
  "payme_transaction_id": "TRAN1688-034834SZ-OYNALKNE-DWOXFEUZ",
  "payme_transaction_total": "100",
  "payme_transaction_card_brand": "Mastercard",
  "payme_transaction_auth_number": "12345678",
  "payme_transaction_voucher": null,
  "payme_transaction_emv_uid": "2306**********102613",
  "payme_transaction_acquirer": "PayMe",
  "payme_transaction_auth_source": "CreditCompany",
  "payme_transaction_card_issuer": "Isracard",
  "payme_transaction_credit_type": "RegularCredit",
  "buyer_name": "First Name",
  "buyer_email": "test@example.com",
  "buyer_phone": "+15417543010",
  "buyer_card_mask": "532610******5846",
  "buyer_card_exp": "0426",
  "buyer_card_is_foreign": false,
  "buyer_social_id": "123456782",
  "installments": 1,
  "transaction_first_payment": "100",
  "transaction_periodical_payment": 0,
  "transaction_arn": "2306**********2613",
  "sale_paid_date": "2023-06-29 13:33:54",
  "sale_release_date": null,
  "sale_3ds": false,
  "redirect_url": null
}
```
