{
	"info": {
		"_postman_id": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
		"name": "World Ledgers Communication API",
		"description": "SMS endpoints for the World Ledgers Communication API.\n\n## Sandbox test credentials\n\n| Variable | Value |\n|----------|-------|\n| `base_url` | `http://localhost/api/v1/communication` (change to your app URL) |\n| `api_key` | `wl_test_communication_sms_sandbox` |\n\nRun `php artisan db:seed --class=CommunicationApiSandboxSeeder` to create the sandbox firm with 10,000 test credits.\n\n**No real SMS is sent** with sandbox keys (`wl_test_…`). Statuses and responses are simulated immediately.\n\n### Test phone numbers\n\n| Number | Simulated outcome |\n|--------|-------------------|\n| `254712345678` | Delivered — `Success (sandbox)` |\n| `254700000099` | Failed — `Simulated delivery failure (sandbox)` |\n| `254700000088` | Failed — `SMS credit not enough` |\n\nAuth: send `X-API-Key: {{api_key}}` or `Authorization: Bearer {{api_key}}`.",
		"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
	},
	"auth": {
		"type": "apikey",
		"apikey": [
			{
				"key": "value",
				"value": "{{api_key}}",
				"type": "string"
			},
			{
				"key": "key",
				"value": "X-API-Key",
				"type": "string"
			}
		]
	},
	"item": [
		{
			"name": "SMS",
			"item": [
				{
					"name": "SMS credits balance",
					"request": {
						"method": "GET",
						"header": [],
						"url": "{{base_url}}/sms-credits/balance",
						"description": "Returns current SMS credit balance. Sandbox firms include `\"sandbox\": true`."
					},
					"response": []
				},
				{
					"name": "Send SMS (success)",
					"event": [
						{
							"listen": "prerequest",
							"script": {
								"type": "text/javascript",
								"exec": [
									"pm.environment.set('reference', 'postman-success-' + Date.now());"
								]
							}
						},
						{
							"listen": "test",
							"script": {
								"type": "text/javascript",
								"exec": [
									"const json = pm.response.json();",
									"pm.test('Status 202', () => pm.response.to.have.status(202));",
									"pm.test('Sandbox mode', () => pm.expect(json.data.sandbox).to.eql(true));",
									"if (json.data && json.data.messages && json.data.messages[0]) {",
									"  pm.environment.set('message_id', String(json.data.messages[0].message_id || json.data.messages[0].id));",
									"  pm.test('Delivered', () => pm.expect(json.data.messages[0].status).to.eql('delivered'));",
									"}"
								]
							}
						}
					],
					"request": {
						"method": "POST",
						"header": [
							{
								"key": "Content-Type",
								"value": "application/json"
							}
						],
						"body": {
							"mode": "raw",
							"raw": "{\n  \"message\": \"Hello {first_name}, your sandbox balance is {account_balance}.\",\n  \"recipients\": [\"254712345678\"],\n  \"reference\": \"{{reference}}\",\n  \"variables\": {\n    \"first_name\": \"Jane\",\n    \"account_balance\": \"1,250.00\"\n  }\n}"
						},
						"url": "{{base_url}}/sms",
						"description": "Schedules one SMS and immediately simulates delivery in sandbox mode."
					},
					"response": []
				},
				{
					"name": "Send SMS (simulate failure)",
					"event": [
						{
							"listen": "prerequest",
							"script": {
								"type": "text/javascript",
								"exec": [
									"pm.environment.set('reference', 'postman-fail-' + Date.now());"
								]
							}
						},
						{
							"listen": "test",
							"script": {
								"type": "text/javascript",
								"exec": [
									"const json = pm.response.json();",
									"pm.test('Status 202', () => pm.response.to.have.status(202));",
									"if (json.data && json.data.messages && json.data.messages[0]) {",
									"  pm.environment.set('message_id', String(json.data.messages[0].message_id || json.data.messages[0].id));",
									"  pm.test('Failed', () => pm.expect(json.data.messages[0].status).to.eql('failed'));",
									"  pm.test('Failure response', () => pm.expect(json.data.messages[0].response).to.include('Simulated delivery failure'));",
									"}"
								]
							}
						}
					],
					"request": {
						"method": "POST",
						"header": [
							{
								"key": "Content-Type",
								"value": "application/json"
							}
						],
						"body": {
							"mode": "raw",
							"raw": "{\n  \"message\": \"This sandbox SMS will fail delivery.\",\n  \"recipients\": [\"254700000099\"],\n  \"reference\": \"{{reference}}\"\n}"
						},
						"url": "{{base_url}}/sms",
						"description": "Uses test number `254700000099` to simulate a provider delivery failure."
					},
					"response": []
				},
				{
					"name": "Send SMS (insufficient credits)",
					"event": [
						{
							"listen": "test",
							"script": {
								"type": "text/javascript",
								"exec": [
									"const json = pm.response.json();",
									"pm.test('Status 202', () => pm.response.to.have.status(202));",
									"if (json.data && json.data.messages && json.data.messages[0]) {",
									"  pm.test('Failed', () => pm.expect(json.data.messages[0].status).to.eql('failed'));",
									"  pm.test('Credit error', () => pm.expect(json.data.messages[0].response).to.eql('SMS credit not enough'));",
									"}"
								]
							}
						}
					],
					"request": {
						"method": "POST",
						"header": [
							{
								"key": "Content-Type",
								"value": "application/json"
							}
						],
						"body": {
							"mode": "raw",
							"raw": "{\n  \"message\": \"Sandbox insufficient-credits scenario.\",\n  \"recipients\": [\"254700000088\"],\n  \"reference\": \"postman-low-credits-{{$timestamp}}\"\n}"
						},
						"url": "{{base_url}}/sms",
						"description": "Uses test number `254700000088` to simulate insufficient SMS credits without deducting balance."
					},
					"response": []
				},
				{
					"name": "SMS status by ID",
					"request": {
						"method": "GET",
						"header": [],
						"url": "{{base_url}}/sms/{{message_id}}",
						"description": "Poll delivery status. Run **Send SMS** first — it saves `message_id` to the environment."
					},
					"response": []
				},
				{
					"name": "SMS status by reference",
					"request": {
						"method": "GET",
						"header": [],
						"url": "{{base_url}}/sms/by-reference/{{reference}}",
						"description": "Look up the first SMS row for the `reference` set by the send requests."
					},
					"response": []
				}
			]
		}
	],
	"variable": [
		{
			"key": "base_url",
			"value": "http://localhost/api/v1/communication"
		},
		{
			"key": "api_key",
			"value": "wl_test_communication_sms_sandbox"
		}
	]
}
