{
  "info": {
    "name": "RfoofPay API",
    "description": "Supplier portal backend — MyFatoorah proxy. All endpoints are under /api/v1/. Login via Auth > JWT Create to auto-populate the {{access_token}} and {{refresh_token}} environment variables.",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "auth": {
    "type": "bearer",
    "bearer": [
      { "key": "token", "value": "{{access_token}}", "type": "string" }
    ]
  },
  "event": [
    {
      "listen": "prerequest",
      "script": { "type": "text/javascript", "exec": [""] }
    }
  ],
  "variable": [],
  "item": [
    {
      "name": "Health",
      "item": [
        {
          "name": "Health Check",
          "request": {
            "auth": { "type": "noauth" },
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{base_url}}/api/v1/health/",
              "host": ["{{base_url}}"],
              "path": ["api", "v1", "health", ""]
            }
          }
        }
      ]
    },
    {
      "name": "Auth",
      "item": [
        {
          "name": "JWT Create (Login)",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "var json = {};",
                  "try { json = pm.response.json(); } catch (e) {}",
                  "var data = json.data || json;",
                  "var access = data.access_token || data.access;",
                  "var refresh = data.refresh_token || data.refresh;",
                  "if (access) {",
                  "    pm.environment.set('access_token', access);",
                  "    console.log('access_token saved');",
                  "}",
                  "if (refresh) {",
                  "    pm.environment.set('refresh_token', refresh);",
                  "    console.log('refresh_token saved');",
                  "}",
                  "pm.test('login succeeded', function () {",
                  "    pm.expect(pm.response.code).to.be.oneOf([200, 201]);",
                  "});",
                  "pm.test('access token captured', function () {",
                  "    pm.expect(access, 'access token in response').to.be.a('string').and.not.empty;",
                  "});"
                ]
              }
            }
          ],
          "request": {
            "auth": { "type": "noauth" },
            "method": "POST",
            "header": [
              { "key": "Content-Type", "value": "application/json" }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n    \"email\": \"{{email}}\",\n    \"password\": \"{{password}}\"\n}"
            },
            "url": {
              "raw": "{{base_url}}/api/v1/auth/jwt/create/",
              "host": ["{{base_url}}"],
              "path": ["api", "v1", "auth", "jwt", "create", ""]
            }
          }
        },
        {
          "name": "JWT Refresh",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "var json = {};",
                  "try { json = pm.response.json(); } catch (e) {}",
                  "var data = json.data || json;",
                  "var access = data.access_token || data.access;",
                  "if (access) {",
                  "    pm.environment.set('access_token', access);",
                  "    console.log('access_token refreshed');",
                  "}"
                ]
              }
            }
          ],
          "request": {
            "auth": { "type": "noauth" },
            "method": "POST",
            "header": [
              { "key": "Content-Type", "value": "application/json" }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n    \"refresh\": \"{{refresh_token}}\"\n}"
            },
            "url": {
              "raw": "{{base_url}}/api/v1/auth/jwt/refresh/",
              "host": ["{{base_url}}"],
              "path": ["api", "v1", "auth", "jwt", "refresh", ""]
            }
          }
        },
        {
          "name": "JWT Verify",
          "request": {
            "auth": { "type": "noauth" },
            "method": "POST",
            "header": [
              { "key": "Content-Type", "value": "application/json" }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n    \"token\": \"{{access_token}}\"\n}"
            },
            "url": {
              "raw": "{{base_url}}/api/v1/auth/jwt/verify/",
              "host": ["{{base_url}}"],
              "path": ["api", "v1", "auth", "jwt", "verify", ""]
            }
          }
        }
      ]
    },
    {
      "name": "Users",
      "item": [
        {
          "name": "List Users (admin)",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{base_url}}/api/v1/auth/users/",
              "host": ["{{base_url}}"],
              "path": ["api", "v1", "auth", "users", ""]
            }
          }
        },
        {
          "name": "Create User (admin)",
          "request": {
            "method": "POST",
            "header": [
              { "key": "Content-Type", "value": "application/json" }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n    \"email\": \"newuser@example.com\",\n    \"password\": \"Sup3rStr0ng!\",\n    \"full_name\": \"New User\",\n    \"phone\": \"+971501234567\"\n}"
            },
            "url": {
              "raw": "{{base_url}}/api/v1/auth/users/",
              "host": ["{{base_url}}"],
              "path": ["api", "v1", "auth", "users", ""]
            }
          }
        },
        {
          "name": "Get Me",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{base_url}}/api/v1/auth/users/me/",
              "host": ["{{base_url}}"],
              "path": ["api", "v1", "auth", "users", "me", ""]
            }
          }
        },
        {
          "name": "Update Me",
          "request": {
            "method": "PATCH",
            "header": [
              { "key": "Content-Type", "value": "application/json" }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n    \"full_name\": \"Updated Name\",\n    \"language\": \"ar\"\n}"
            },
            "url": {
              "raw": "{{base_url}}/api/v1/auth/users/me/",
              "host": ["{{base_url}}"],
              "path": ["api", "v1", "auth", "users", "me", ""]
            }
          }
        },
        {
          "name": "Get User by ID (admin)",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{base_url}}/api/v1/auth/users/{{user_id}}/",
              "host": ["{{base_url}}"],
              "path": ["api", "v1", "auth", "users", "{{user_id}}", ""]
            }
          }
        },
        {
          "name": "Update User by ID (admin)",
          "request": {
            "method": "PATCH",
            "header": [
              { "key": "Content-Type", "value": "application/json" }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n    \"full_name\": \"Changed Name\"\n}"
            },
            "url": {
              "raw": "{{base_url}}/api/v1/auth/users/{{user_id}}/",
              "host": ["{{base_url}}"],
              "path": ["api", "v1", "auth", "users", "{{user_id}}", ""]
            }
          }
        },
        {
          "name": "Delete User by ID (admin)",
          "request": {
            "method": "DELETE",
            "header": [],
            "url": {
              "raw": "{{base_url}}/api/v1/auth/users/{{user_id}}/",
              "host": ["{{base_url}}"],
              "path": ["api", "v1", "auth", "users", "{{user_id}}", ""]
            }
          }
        },
        {
          "name": "Set Password",
          "request": {
            "method": "POST",
            "header": [
              { "key": "Content-Type", "value": "application/json" }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n    \"current_password\": \"{{password}}\",\n    \"new_password\": \"N3wStr0ngP@ss!\"\n}"
            },
            "url": {
              "raw": "{{base_url}}/api/v1/auth/users/set_password/",
              "host": ["{{base_url}}"],
              "path": ["api", "v1", "auth", "users", "set_password", ""]
            }
          }
        },
        {
          "name": "Reset Password (request email)",
          "request": {
            "auth": { "type": "noauth" },
            "method": "POST",
            "header": [
              { "key": "Content-Type", "value": "application/json" }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n    \"email\": \"{{email}}\"\n}"
            },
            "url": {
              "raw": "{{base_url}}/api/v1/auth/users/reset_password/",
              "host": ["{{base_url}}"],
              "path": ["api", "v1", "auth", "users", "reset_password", ""]
            }
          }
        },
        {
          "name": "Reset Password Confirm",
          "request": {
            "auth": { "type": "noauth" },
            "method": "POST",
            "header": [
              { "key": "Content-Type", "value": "application/json" }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n    \"uid\": \"<uid-from-email>\",\n    \"token\": \"<token-from-email>\",\n    \"new_password\": \"N3wStr0ngP@ss!\"\n}"
            },
            "url": {
              "raw": "{{base_url}}/api/v1/auth/users/reset_password_confirm/",
              "host": ["{{base_url}}"],
              "path": ["api", "v1", "auth", "users", "reset_password_confirm", ""]
            }
          }
        }
      ]
    },
    {
      "name": "Suppliers - Me",
      "item": [
        {
          "name": "My Profile",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{base_url}}/api/v1/suppliers/me/",
              "host": ["{{base_url}}"],
              "path": ["api", "v1", "suppliers", "me", ""]
            }
          }
        },
        {
          "name": "Dashboard",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{base_url}}/api/v1/suppliers/me/dashboard/",
              "host": ["{{base_url}}"],
              "path": ["api", "v1", "suppliers", "me", "dashboard", ""]
            }
          }
        },
        {
          "name": "Deposits",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{base_url}}/api/v1/suppliers/me/deposits/?search=&start=0&length=20",
              "host": ["{{base_url}}"],
              "path": ["api", "v1", "suppliers", "me", "deposits", ""],
              "query": [
                { "key": "search", "value": "" },
                { "key": "start", "value": "0" },
                { "key": "length", "value": "20" },
                { "key": "sort_column", "value": "", "disabled": true },
                { "key": "sort_direction", "value": "", "disabled": true }
              ]
            }
          }
        },
        {
          "name": "Deposit Invoices",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{base_url}}/api/v1/suppliers/me/deposits/invoices/?deposit_reference={{deposit_reference}}",
              "host": ["{{base_url}}"],
              "path": ["api", "v1", "suppliers", "me", "deposits", "invoices", ""],
              "query": [
                { "key": "deposit_reference", "value": "{{deposit_reference}}" }
              ]
            }
          }
        },
        {
          "name": "Refund Status",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{base_url}}/api/v1/suppliers/me/refunds/?key={{invoice_id}}&key_type=InvoiceId",
              "host": ["{{base_url}}"],
              "path": ["api", "v1", "suppliers", "me", "refunds", ""],
              "query": [
                { "key": "key", "value": "{{invoice_id}}" },
                { "key": "key_type", "value": "InvoiceId", "description": "InvoiceId | RefundReference | RefundId" }
              ]
            }
          }
        },
        {
          "name": "List Documents",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{base_url}}/api/v1/suppliers/me/documents/",
              "host": ["{{base_url}}"],
              "path": ["api", "v1", "suppliers", "me", "documents", ""]
            }
          }
        },
        {
          "name": "Upload Document",
          "request": {
            "method": "POST",
            "header": [],
            "body": {
              "mode": "formdata",
              "formdata": [
                { "key": "file", "type": "file", "src": [] },
                { "key": "file_type", "value": "CivilId", "type": "text", "description": "See suppliers/constants.py FILE_TYPE_CHOICES" },
                { "key": "expire_date", "value": "2027-01-01", "type": "text", "description": "Optional YYYY-MM-DD" }
              ]
            },
            "url": {
              "raw": "{{base_url}}/api/v1/suppliers/me/documents/",
              "host": ["{{base_url}}"],
              "path": ["api", "v1", "suppliers", "me", "documents", ""]
            }
          }
        },
        {
          "name": "Transactions",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{base_url}}/api/v1/suppliers/me/transactions/?page=1&page_size=20",
              "host": ["{{base_url}}"],
              "path": ["api", "v1", "suppliers", "me", "transactions", ""],
              "query": [
                { "key": "page", "value": "1" },
                { "key": "page_size", "value": "20" },
                { "key": "status", "value": "Paid", "disabled": true }
              ]
            }
          }
        },
        {
          "name": "Create Payment Link",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "var json = {};",
                  "try { json = pm.response.json(); } catch (e) {}",
                  "var result = (json.data && json.data.result) || json.result || {};",
                  "var invoiceId = result.InvoiceId || result.InvoiceID;",
                  "if (invoiceId) {",
                  "    pm.environment.set('invoice_id', String(invoiceId));",
                  "    console.log('invoice_id saved: ' + invoiceId);",
                  "}"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              { "key": "Content-Type", "value": "application/json" }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n    \"customer_name\": \"John Doe\",\n    \"invoice_value\": 150.00,\n    \"notification_option\": \"EML\",\n    \"customer_email\": \"john@example.com\",\n    \"customer_mobile\": \"501234567\",\n    \"mobile_country_code\": \"971\",\n    \"display_currency_iso\": \"AED\",\n    \"language\": \"en\",\n    \"customer_reference\": \"ORD-001\",\n    \"invoice_items\": [\n        { \"item_name\": \"Item A\", \"quantity\": 1, \"unit_price\": 150.00 }\n    ]\n}"
            },
            "url": {
              "raw": "{{base_url}}/api/v1/suppliers/me/payments/",
              "host": ["{{base_url}}"],
              "path": ["api", "v1", "suppliers", "me", "payments", ""]
            }
          }
        },
        {
          "name": "Payment Status",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{base_url}}/api/v1/suppliers/me/payments/{{invoice_id}}/",
              "host": ["{{base_url}}"],
              "path": ["api", "v1", "suppliers", "me", "payments", "{{invoice_id}}", ""]
            }
          }
        },
        {
          "name": "Payment Methods",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{base_url}}/api/v1/suppliers/me/payment-methods/?amount=100&currency=AED",
              "host": ["{{base_url}}"],
              "path": ["api", "v1", "suppliers", "me", "payment-methods", ""],
              "query": [
                { "key": "amount", "value": "100" },
                { "key": "currency", "value": "AED" }
              ]
            }
          }
        }
      ]
    },
    {
      "name": "Suppliers - Admin",
      "item": [
        {
          "name": "Link Supplier",
          "request": {
            "method": "POST",
            "header": [
              { "key": "Content-Type", "value": "application/json" }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n    \"user_id\": {{user_id}},\n    \"supplier_code\": {{supplier_code}}\n}"
            },
            "url": {
              "raw": "{{base_url}}/api/v1/suppliers/admin/link/",
              "host": ["{{base_url}}"],
              "path": ["api", "v1", "suppliers", "admin", "link", ""]
            }
          }
        }
      ]
    },
    {
      "name": "Webhooks",
      "item": [
        {
          "name": "Payment Webhook (MyFatoorah)",
          "request": {
            "auth": { "type": "noauth" },
            "method": "POST",
            "header": [
              { "key": "Content-Type", "value": "application/json" },
              { "key": "MyFatoorah-Signature", "value": "<computed-hmac-sha256-base64>", "description": "Required if MYFATOORAH_WEBHOOK_SECRET is set" }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n    \"Event\": { \"Code\": 1, \"Message\": \"PAYMENT_STATUS_CHANGED\" },\n    \"Data\": {\n        \"Invoice\": { \"Id\": 123456, \"Status\": \"Paid\", \"Reference\": \"REF-001\", \"ExternalIdentifier\": \"\" },\n        \"Transaction\": { \"Status\": \"Success\", \"PaymentId\": \"0000001\" },\n        \"Customer\": { \"Name\": \"John Doe\" },\n        \"Amount\": { \"ValueInDisplayCurrency\": 150.00, \"DisplayCurrency\": \"AED\" },\n        \"Suppliers\": [ { \"SupplierCode\": {{supplier_code}} } ]\n    }\n}"
            },
            "url": {
              "raw": "{{base_url}}/api/v1/suppliers/webhooks/payment/",
              "host": ["{{base_url}}"],
              "path": ["api", "v1", "suppliers", "webhooks", "payment", ""]
            }
          }
        }
      ]
    }
  ]
}
