{
	"info": {
		"_postman_id": "eb088672-af11-54a6-85d9-29262bfaa76a",
		"name": "EZPIN Access API v2",
		"description": "Partner (vendor) API for EZPIN digital gift cards — **v2**.\n\n## Getting started\n1. Set `base_url`, `client_id` and `secret_key` in the collection variables (or in an environment).\n2. Send any request. An access token is fetched automatically before the first request and again shortly before it expires. You can also run **Authentication → Get access token** manually.\n\n## Authentication\n`POST /vendors/v2/auth/token/` returns `access` (a JWT) and `expire` (lifetime in seconds). Every other request sends it as `Authorization: Bearer <access>`.\n\nIf IP whitelisting is enabled for your account, requests from other IP addresses are rejected. Sandbox accounts only see sandbox products.\n\n## Errors\nErrors are returned as `{\"detail\": \"<message>\", \"code\": <error code>}`. Field validation errors use the standard `{\"<field>\": [\"<message>\"]}` format.\n\n## Rate limits\n- Get access token: 1 request per second.\n- Create order: 1 request per second.\n- Other requests: 100 requests per minute.\n",
		"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
	},
	"item": [
		{
			"name": "Authentication",
			"description": "Get the bearer token used by all other requests.",
			"item": [
				{
					"name": "Get access token",
					"request": {
						"method": "POST",
						"header": [
							{
								"key": "Content-Type",
								"value": "application/json"
							}
						],
						"url": {
							"raw": "{{base_url}}/vendors/v2/auth/token/",
							"host": [
								"{{base_url}}"
							],
							"path": [
								"vendors",
								"v2",
								"auth",
								"token",
								""
							]
						},
						"description": "Returns `access` (JWT) and `expire` (seconds). The token is saved to `access_token` automatically.",
						"body": {
							"mode": "raw",
							"raw": "{\n    \"client_id\": \"{{client_id}}\",\n    \"secret_key\": \"{{secret_key}}\"\n}",
							"options": {
								"raw": {
									"language": "json"
								}
							}
						},
						"auth": {
							"type": "noauth"
						}
					},
					"response": [],
					"event": [
						{
							"listen": "test",
							"script": {
								"type": "text/javascript",
								"exec": [
									"pm.test('Status code is 200', () => pm.response.to.have.status(200));",
									"",
									"const data = pm.response.json();",
									"if (data.access) {",
									"    pm.collectionVariables.set('access_token', data.access);",
									"    pm.collectionVariables.set('token_expires_at', Date.now() + data.expire * 1000);",
									"}"
								]
							}
						}
					]
				}
			]
		},
		{
			"name": "Account",
			"description": "",
			"item": [
				{
					"name": "Get balance",
					"request": {
						"method": "GET",
						"header": [],
						"url": {
							"raw": "{{base_url}}/vendors/v2/balance/",
							"host": [
								"{{base_url}}"
							],
							"path": [
								"vendors",
								"v2",
								"balance",
								""
							]
						},
						"description": "Returns your wallet balances: a list of `{currency, balance}`."
					},
					"response": []
				},
				{
					"name": "List exchange rates",
					"request": {
						"method": "GET",
						"header": [],
						"url": {
							"raw": "{{base_url}}/vendors/v2/exchange_rates/",
							"host": [
								"{{base_url}}"
							],
							"path": [
								"vendors",
								"v2",
								"exchange_rates",
								""
							]
						},
						"description": "Active exchange rates: `{count, results}`, each with `from_currency`, `to_currency`, `rate`."
					},
					"response": []
				}
			]
		},
		{
			"name": "Catalog",
			"description": "Products you can order. Use a product's `sku` and a price within its range when creating an order.",
			"item": [
				{
					"name": "List catalogs",
					"request": {
						"method": "GET",
						"header": [],
						"url": {
							"raw": "{{base_url}}/vendors/v2/catalogs/",
							"host": [
								"{{base_url}}"
							],
							"path": [
								"vendors",
								"v2",
								"catalogs",
								""
							]
						},
						"description": "All products available to you, both price ranges and fixed prices: `{count, results}` (not paginated).\n\nEach result: `sku`, `upc`, `upc_string`, `title`, `min_price`, `max_price`, `pre_order`, `activation_fee`, `showing_price`, `percentage_of_buying_price`, `currency`, `categories`, `regions`, `image`, `description`, `reward_type`, `reward_type_text`.\n\nCached for 1 hour."
					},
					"response": []
				},
				{
					"name": "Check catalog availability",
					"request": {
						"method": "GET",
						"header": [],
						"url": {
							"raw": "{{base_url}}/vendors/v2/catalogs/{{sku}}/availability/?item_count=1&price={{price}}",
							"host": [
								"{{base_url}}"
							],
							"path": [
								"vendors",
								"v2",
								"catalogs",
								"{{sku}}",
								"availability",
								""
							],
							"query": [
								{
									"key": "item_count",
									"value": "1",
									"description": "Required. Number of cards."
								},
								{
									"key": "price",
									"value": "{{price}}",
									"description": "Required. Card price."
								}
							]
						},
						"description": "Checks whether `item_count` cards of a product are available at `price`.\n\nResponse: `availability` (bool), `detail`, `delivery_type`, `delivery_type_text`.\n\n`delivery_type`: `1` available now, `2` or `3` can be pre-ordered, `0` out of stock.\n\nValidation errors are returned with HTTP 200 in the usual `{\"detail\", \"code\"}` format, so check for `availability` in the response."
					},
					"response": []
				}
			]
		},
		{
			"name": "Orders",
			"description": "`status`: `-2` created, `-1` rejected, `0` pending, `1` accepted (cards are ready).",
			"item": [
				{
					"name": "Create order",
					"request": {
						"method": "POST",
						"header": [
							{
								"key": "Content-Type",
								"value": "application/json"
							}
						],
						"url": {
							"raw": "{{base_url}}/vendors/v2/orders/",
							"host": [
								"{{base_url}}"
							],
							"path": [
								"vendors",
								"v2",
								"orders",
								""
							]
						},
						"description": "Places a digital card order. Saves `reference_code` for the requests below.\n\n- `sku` (int, required)\n- `quantity` (int, required)\n- `price` (decimal, required): within the product's price range\n- `pre_order` (bool, required): allow the order to wait for stock\n- `reference_code` (UUID, required): your own unique ID for the order. A new one is generated for each request.\n- `terminal_id` (string, optional): place the order as one of your terminals\n- `terminal_pin` (string, optional): PIN of the terminal placing the order. Required when your account requires a PIN; a wrong PIN returns HTTP 406.\n- `delivery_type` (int, optional): `0` none, `1` email, `2` SMS, `3` WhatsApp\n- `destination` (string): required when `delivery_type` is 1–3. An email address, or a phone number in international format (digits, optional leading `+`).\n\nResponse: `order_id`, `delivery_type`, `destination`, `status`, `status_text`, `created_time`, `terminal_id`, `reference_code`, `product` (`sku`, `title`), `face_value`, `count`, `total_face_value`, `total_fees`, `total_discounts`, `total_customer_cost`, `is_completed`, `share_link`, `exchange`.",
						"body": {
							"mode": "raw",
							"raw": "{\n    \"sku\": {{sku}},\n    \"quantity\": 1,\n    \"price\": {{price}},\n    \"pre_order\": false,\n    \"reference_code\": \"{{reference_code}}\",\n    \"terminal_id\": \"{{terminal_id}}\",\n    \"terminal_pin\": \"{{terminal_pin}}\",\n    \"delivery_type\": 0,\n    \"destination\": \"\"\n}",
							"options": {
								"raw": {
									"language": "json"
								}
							}
						}
					},
					"response": [],
					"event": [
						{
							"listen": "prerequest",
							"script": {
								"type": "text/javascript",
								"exec": [
									"// Every order needs a new UUID. It is saved so the \"by reference\" requests can use it.",
									"pm.collectionVariables.set('reference_code', pm.variables.replaceIn('{{$guid}}'));"
								]
							}
						},
						{
							"listen": "test",
							"script": {
								"type": "text/javascript",
								"exec": [
									"pm.test('Status code is 200', () => pm.response.to.have.status(200));"
								]
							}
						}
					]
				},
				{
					"name": "List orders",
					"request": {
						"method": "GET",
						"header": [],
						"url": {
							"raw": "{{base_url}}/vendors/v2/orders/?start_date={{start_date}}&end_date={{end_date}}&limit=10&offset=0",
							"host": [
								"{{base_url}}"
							],
							"path": [
								"vendors",
								"v2",
								"orders",
								""
							],
							"query": [
								{
									"key": "start_date",
									"value": "{{start_date}}",
									"description": "Required. `YYYY-MM-DD` or `YYYY-MM-DD HH:MM:SS`. Orders created at or after this time."
								},
								{
									"key": "end_date",
									"value": "{{end_date}}",
									"description": "Required. `YYYY-MM-DD` or `YYYY-MM-DD HH:MM:SS`. Orders created at or before this time. A plain date means midnight at the start of that day."
								},
								{
									"key": "limit",
									"value": "10",
									"description": "Page size (default 10)."
								},
								{
									"key": "offset",
									"value": "0",
									"description": "Number of items to skip."
								}
							]
						},
						"description": "Orders created between `start_date` and `end_date` (both required). Paginated: `count`, `next`, `previous`, `results`."
					},
					"response": [],
					"event": [
						{
							"listen": "prerequest",
							"script": {
								"type": "text/javascript",
								"exec": [
									"// Defaults to the last 7 days when start_date / end_date are not set.",
									"// Dates are compared to the order's created time, so a plain date means midnight at the start of that day.",
									"const day = (offset) => new Date(Date.now() + offset * 864e5).toISOString().slice(0, 10);",
									"if (!pm.variables.get('start_date')) pm.variables.set('start_date', day(-7));",
									"if (!pm.variables.get('end_date')) pm.variables.set('end_date', day(1));"
								]
							}
						}
					]
				},
				{
					"name": "Get order",
					"request": {
						"method": "GET",
						"header": [],
						"url": {
							"raw": "{{base_url}}/vendors/v2/orders/{{reference_code}}/",
							"host": [
								"{{base_url}}"
							],
							"path": [
								"vendors",
								"v2",
								"orders",
								"{{reference_code}}",
								""
							]
						},
						"description": "A single order by its `reference_code`. Same fields as the create response, without `reference_code`."
					},
					"response": []
				},
				{
					"name": "Get order cards",
					"request": {
						"method": "GET",
						"header": [],
						"url": {
							"raw": "{{base_url}}/vendors/v2/orders/{{reference_code}}/cards/",
							"host": [
								"{{base_url}}"
							],
							"path": [
								"vendors",
								"v2",
								"orders",
								"{{reference_code}}",
								"cards",
								""
							]
						},
						"description": "The cards of an accepted order: `{results}` (not paginated).\n\nEach card: `card_number`, `pin_code`, `claim_url`, `expire_date`, `reward_type`, `reward_type_text`, `barcode`, `barcode_standard`.\n\nReturns HTTP 400 while the order is still being processed, or if it was rejected."
					},
					"response": []
				}
			]
		},
		{
			"name": "Retailer Products",
			"description": "Products identified by an EAN `product_code` that encodes both the product and its price.",
			"item": [
				{
					"name": "List retailer products",
					"request": {
						"method": "GET",
						"header": [],
						"url": {
							"raw": "{{base_url}}/vendors/v2/retailer_products/",
							"host": [
								"{{base_url}}"
							],
							"path": [
								"vendors",
								"v2",
								"retailer_products",
								""
							]
						},
						"description": "`{count, results}` (not paginated). Each result: `product_code`, `price`, `buying_price`, `product` (`sku`, `title`, `currency`, `categories`, `upc`, `image`, `pre_order`, `description`, `regions`, `reward_type`, `reward_type_text`).\n\nCached for 1 hour."
					},
					"response": []
				},
				{
					"name": "Check retailer product availability",
					"request": {
						"method": "GET",
						"header": [],
						"url": {
							"raw": "{{base_url}}/vendors/v2/retailer_product_availability/?item_count=1&product_code={{product_code}}",
							"host": [
								"{{base_url}}"
							],
							"path": [
								"vendors",
								"v2",
								"retailer_product_availability",
								""
							],
							"query": [
								{
									"key": "item_count",
									"value": "1",
									"description": "Required. Number of cards."
								},
								{
									"key": "product_code",
									"value": "{{product_code}}",
									"description": "Required. EAN product code from **List retailer products**."
								}
							]
						},
						"description": "Checks whether `item_count` cards of a retailer product are available.\n\nResponse: `availability` (bool), `detail`, `delivery_type`, `delivery_type_text`.\n\n`delivery_type`: `1` available now, `2` or `3` can be pre-ordered, `0` out of stock.\n\nValidation errors are returned with HTTP 200 in the usual `{\"detail\", \"code\"}` format, so check for `availability` in the response."
					},
					"response": []
				},
				{
					"name": "Create retailer order",
					"request": {
						"method": "POST",
						"header": [
							{
								"key": "Content-Type",
								"value": "application/json"
							}
						],
						"url": {
							"raw": "{{base_url}}/vendors/v2/retailer_order/",
							"host": [
								"{{base_url}}"
							],
							"path": [
								"vendors",
								"v2",
								"retailer_order",
								""
							]
						},
						"description": "Places an order by `product_code`. The price comes from the product code. Saves `reference_code`, so **Orders → Get order** and **Get order cards** work for it too.\n\n- `product_code` (string, required): EAN from **List retailer products**\n- `quantity` (int, required)\n- `pre_order` (bool, required)\n- `reference_code` (UUID, required): a new one is generated for each request\n- `terminal_id` (string, optional): place the order as one of your terminals\n- `terminal_pin` (string, optional): PIN of the terminal placing the order. Required when your account requires a PIN; a wrong PIN returns HTTP 406.\n- `delivery_type` (int, optional): `0` none, `1` email, `2` SMS, `3` WhatsApp\n- `destination` (string): required when `delivery_type` is 1–3. An email address, or a phone number in international format (digits, optional leading `+`).\n\nResponse: `order_id`, `delivery_type`, `destination`, `status`, `status_text`, `created_time`, `terminal_id`, `reference_code`, `product` (`sku`, `title`), `face_value`, `count`, `total_face_value`, `total_fees`, `total_discounts`, `total_customer_cost`, `is_completed`, `share_link`, `exchange`.",
						"body": {
							"mode": "raw",
							"raw": "{\n    \"product_code\": \"{{product_code}}\",\n    \"quantity\": 1,\n    \"pre_order\": false,\n    \"reference_code\": \"{{reference_code}}\",\n    \"terminal_id\": \"{{terminal_id}}\",\n    \"terminal_pin\": \"{{terminal_pin}}\",\n    \"delivery_type\": 0,\n    \"destination\": \"\"\n}",
							"options": {
								"raw": {
									"language": "json"
								}
							}
						}
					},
					"response": [],
					"event": [
						{
							"listen": "prerequest",
							"script": {
								"type": "text/javascript",
								"exec": [
									"// Every order needs a new UUID. It is saved so the \"by reference\" requests can use it.",
									"pm.collectionVariables.set('reference_code', pm.variables.replaceIn('{{$guid}}'));"
								]
							}
						},
						{
							"listen": "test",
							"script": {
								"type": "text/javascript",
								"exec": [
									"pm.test('Status code is 200', () => pm.response.to.have.status(200));"
								]
							}
						}
					]
				}
			]
		},
		{
			"name": "Notifications",
			"description": "When an order's status changes, EZPIN sends a `POST` request with a JSON body to your `endpoint`:\n\n```json\n{\n    \"type_code\": 0,\n    \"type_text\": \"digital\",\n    \"order_id\": 12345,\n    \"status\": 1,\n    \"confidential_key\": \"<your confidential key>\"\n}\n```\n\n`confidential_key` is included only when it is set; use it to verify that the request came from EZPIN.",
			"item": [
				{
					"name": "Get notification config",
					"request": {
						"method": "GET",
						"header": [],
						"url": {
							"raw": "{{base_url}}/vendors/v2/notification_config/",
							"host": [
								"{{base_url}}"
							],
							"path": [
								"vendors",
								"v2",
								"notification_config",
								""
							]
						},
						"description": "Returns the current `endpoint` and `confidential_key`."
					},
					"response": []
				},
				{
					"name": "Set notification config",
					"request": {
						"method": "POST",
						"header": [
							{
								"key": "Content-Type",
								"value": "application/json"
							}
						],
						"url": {
							"raw": "{{base_url}}/vendors/v2/notification_config/",
							"host": [
								"{{base_url}}"
							],
							"path": [
								"vendors",
								"v2",
								"notification_config",
								""
							]
						},
						"description": "Sets the webhook URL for order status notifications.\n\n- `endpoint` (URL, optional): where notifications are sent.\n- `confidential_key` (string, max 255, optional): sent back in each notification so you can verify it.\n\nResponse: `{\"detail\": \"API setting added successfully.\", \"code\": 801}`",
						"body": {
							"mode": "raw",
							"raw": "{\n    \"endpoint\": \"https://example.com/ezpin/webhook/\",\n    \"confidential_key\": \"replace-with-a-secret-key\"\n}",
							"options": {
								"raw": {
									"language": "json"
								}
							}
						}
					},
					"response": []
				}
			]
		}
	],
	"auth": {
		"type": "bearer",
		"bearer": [
			{
				"key": "token",
				"value": "{{access_token}}",
				"type": "string"
			}
		]
	},
	"event": [
		{
			"listen": "prerequest",
			"script": {
				"type": "text/javascript",
				"exec": [
					"// Fetches a new access token when there is none or it is about to expire,",
					"// so every request can be sent directly after client_id and secret_key are set.",
					"const isTokenRequest = pm.request.url.getPath().includes('/auth/token');",
					"const token = pm.collectionVariables.get('access_token');",
					"const expiresAt = Number(pm.collectionVariables.get('token_expires_at') || 0);",
					"",
					"if (!isTokenRequest && (!token || Date.now() > expiresAt - 60 * 1000)) {",
					"    pm.sendRequest({",
					"        url: pm.variables.replaceIn('{{base_url}}/vendors/v2/auth/token/'),",
					"        method: 'POST',",
					"        header: {'Content-Type': 'application/json'},",
					"        body: {",
					"            mode: 'raw',",
					"            raw: JSON.stringify({",
					"                client_id: pm.variables.get('client_id'),",
					"                secret_key: pm.variables.get('secret_key')",
					"            })",
					"        }",
					"    }, (err, res) => {",
					"        if (err || res.code !== 200 || !res.json().access) {",
					"            console.error('Could not get an access token:', err || res.text());",
					"            return;",
					"        }",
					"        const data = res.json();",
					"        pm.collectionVariables.set('access_token', data.access);",
					"        pm.collectionVariables.set('token_expires_at', Date.now() + data.expire * 1000);",
					"    });",
					"}"
				]
			}
		}
	],
	"variable": [
		{
			"key": "base_url",
			"value": "https://api.ezpaypin.com",
			"type": "string",
			"description": "API host, without a trailing slash."
		},
		{
			"key": "client_id",
			"value": "",
			"type": "string",
			"description": "Your API client ID."
		},
		{
			"key": "secret_key",
			"value": "",
			"type": "string",
			"description": "Your API secret key."
		},
		{
			"key": "access_token",
			"value": "",
			"type": "string",
			"description": "Set automatically. Do not define it in an environment, or it will hide the refreshed token."
		},
		{
			"key": "token_expires_at",
			"value": "",
			"type": "string",
			"description": "Set automatically (epoch milliseconds)."
		},
		{
			"key": "start_date",
			"value": "",
			"type": "string",
			"description": "Optional. Defaults to 7 days ago in the order list request."
		},
		{
			"key": "end_date",
			"value": "",
			"type": "string",
			"description": "Optional. Defaults to tomorrow in the order list request."
		},
		{
			"key": "sku",
			"value": "1",
			"type": "string",
			"description": "Product SKU from the catalog."
		},
		{
			"key": "price",
			"value": "10",
			"type": "string",
			"description": "Card price, within the product's price range."
		},
		{
			"key": "product_code",
			"value": "",
			"type": "string",
			"description": "EAN product code from List retailer products."
		},
		{
			"key": "terminal_id",
			"value": "",
			"type": "string",
			"description": "Optional terminal ID to place orders as."
		},
		{
			"key": "terminal_pin",
			"value": "",
			"type": "string",
			"description": "Optional terminal PIN."
		},
		{
			"key": "reference_code",
			"value": "",
			"type": "string",
			"description": "Set automatically by Create order and Create retailer order."
		}
	]
}
