{
  "info": {
    "_postman_id": "unit-quickstart-v1",
    "name": "Quickstart",
    "description": "Postman collection for the Quickstart guide — Peter Parker sandbox flow: create an account, fund $1,000, create a virtual debit card, spend $500 at Amazon.\n\nSet your sandbox API token in the collection TOKEN variable (Variables tab). All requests inherit Bearer auth from the collection.\n\nIdempotency keys are regenerated automatically before each create request.",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "auth": {
    "type": "bearer",
    "bearer": [
      {
        "key": "token",
        "value": "{{TOKEN}}",
        "type": "string"
      }
    ]
  },
  "variable": [
    {
      "key": "BASE_URL",
      "value": "https://api.s.unit.sh",
      "type": "default"
    },
    {
      "key": "TOKEN",
      "value": "",
      "type": "default",
      "description": "Your sandbox API token from app.s.unit.sh → Developer → API Tokens"
    },
    {
      "key": "CUSTOMER_ID",
      "value": "",
      "type": "default"
    },
    {
      "key": "ACCOUNT_ID",
      "value": "",
      "type": "default"
    },
    {
      "key": "CARD_ID",
      "value": "",
      "type": "default"
    },
    {
      "key": "CARD_LAST4",
      "value": "",
      "type": "default",
      "description": "Set automatically from Step 4 — required for the Amazon purchase in Step 5"
    },
    {
      "key": "IDEMPOTENCY_KEY",
      "value": "",
      "type": "default",
      "description": "Regenerated before each request that needs an idempotency key"
    },
    {
      "key": "FUND_AMOUNT",
      "value": "100000",
      "type": "default",
      "description": "Sandbox fund amount in cents ($1,000.00) — Step 3"
    },
    {
      "key": "PURCHASE_AMOUNT",
      "value": "50000",
      "type": "default",
      "description": "Card purchase amount in cents ($500.00) — Step 5"
    }
  ],
  "event": [
    {
      "listen": "prerequest",
      "script": {
        "type": "text/javascript",
        "exec": [
          "pm.collectionVariables.set('IDEMPOTENCY_KEY', pm.variables.replaceIn('{{$guid}}'));"
        ]
      }
    }
  ],
  "item": [
    {
      "name": "1. Create an Application (Peter Parker)",
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "var json = pm.response.json();",
              "var appId = json.data.id;",
              "var status = json.data.attributes.status;",
              "function setCustomerFromResponse(responseJson) {",
              "  var customer = responseJson.data.relationships && responseJson.data.relationships.customer;",
              "  if (customer && customer.data && customer.data.id) {",
              "    pm.collectionVariables.set('CUSTOMER_ID', customer.data.id);",
              "    console.log('CUSTOMER_ID:', customer.data.id);",
              "    return true;",
              "  }",
              "  return false;",
              "}",
              "if (status === 'Approved') {",
              "  setCustomerFromResponse(json);",
              "  pm.test('Application approved', function () { pm.expect(status).to.equal('Approved'); });",
              "} else if (status === 'PendingReview' || status === 'AwaitingDocuments') {",
              "  pm.sendRequest({",
              "    url: pm.collectionVariables.get('BASE_URL') + '/sandbox/applications/' + appId + '/approve',",
              "    method: 'POST',",
              "    header: {",
              "      'Content-Type': 'application/vnd.api+json',",
              "      'Authorization': 'Bearer ' + pm.collectionVariables.get('TOKEN')",
              "    },",
              "    body: { mode: 'raw', raw: JSON.stringify({ data: { type: 'applicationApprove', attributes: { reason: 'sandbox' } } }) }",
              "  }, function (err, res) {",
              "    pm.test('Sandbox approve succeeded', function () {",
              "      pm.expect(err).to.be.null;",
              "      pm.expect(res.code).to.equal(200);",
              "    });",
              "    if (!err && res.code === 200) { setCustomerFromResponse(res.json()); }",
              "  });",
              "} else {",
              "  pm.test('Application approved (status: ' + status + ')', function () {",
              "    pm.expect.fail('Application was ' + status + '. Use Peter Parker SSN 721074426 only once per sandbox org, or contact support.');",
              "  });",
              "}",
              "console.log('Application status:', status);"
            ]
          }
        }
      ],
      "request": {
        "method": "POST",
        "header": [
          { "key": "Content-Type", "value": "application/vnd.api+json" }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"data\": {\n    \"type\": \"individualApplication\",\n    \"attributes\": {\n      \"ssn\": \"721074426\",\n      \"fullName\": {\n        \"first\": \"Peter\",\n        \"last\": \"Parker\"\n      },\n      \"dateOfBirth\": \"2001-08-10\",\n      \"address\": {\n        \"street\": \"20 Ingram St\",\n        \"city\": \"Forest Hills\",\n        \"state\": \"NY\",\n        \"postalCode\": \"11375\",\n        \"country\": \"US\"\n      },\n      \"email\": \"peter@oscorp.com\",\n      \"phone\": {\n        \"countryCode\": \"1\",\n        \"number\": \"5555555555\"\n      },\n      \"ip\": \"127.0.0.2\",\n      \"occupation\": \"ArchitectOrEngineer\",\n      \"annualIncome\": \"Between50kAnd100k\",\n      \"sourceOfIncome\": \"EmploymentOrPayrollIncome\",\n      \"tags\": {\n        \"userId\": \"{{IDEMPOTENCY_KEY}}\"\n      },\n      \"idempotencyKey\": \"{{IDEMPOTENCY_KEY}}\"\n    }\n  }\n}",
          "options": { "raw": { "language": "json" } }
        },
        "url": {
          "raw": "{{BASE_URL}}/applications",
          "host": ["{{BASE_URL}}"],
          "path": ["applications"]
        },
        "description": "To identify a customer, create an Application with Peter Parker's details. Once approved, a Customer is created. CUSTOMER_ID is set from relationships.customer. If PendingReview or AwaitingDocuments, the test script calls sandbox approve."
      }
    },
    {
      "name": "2. Create a Deposit Account",
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "var json = pm.response.json();",
              "pm.collectionVariables.set('ACCOUNT_ID', json.data.id);",
              "console.log('ACCOUNT_ID:', json.data.id);"
            ]
          }
        }
      ],
      "request": {
        "method": "POST",
        "header": [
          { "key": "Content-Type", "value": "application/vnd.api+json" }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"data\": {\n    \"type\": \"depositAccount\",\n    \"attributes\": {\n      \"depositProduct\": \"checking\",\n      \"tags\": {\n        \"purpose\": \"checking\"\n      },\n      \"idempotencyKey\": \"{{IDEMPOTENCY_KEY}}\"\n    },\n    \"relationships\": {\n      \"customer\": {\n        \"data\": {\n          \"type\": \"individualCustomer\",\n          \"id\": \"{{CUSTOMER_ID}}\"\n        }\n      }\n    }\n  }\n}",
          "options": { "raw": { "language": "json" } }
        },
        "url": {
          "raw": "{{BASE_URL}}/accounts",
          "host": ["{{BASE_URL}}"],
          "path": ["accounts"]
        },
        "description": "Create a deposit account for Peter Parker. Uses CUSTOMER_ID from Step 1. After running, ACCOUNT_ID is set automatically."
      }
    },
    {
      "name": "3. Fund the Account",
      "request": {
        "method": "POST",
        "header": [
          { "key": "Content-Type", "value": "application/vnd.api+json" }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"data\": {\n    \"type\": \"achPayment\",\n    \"attributes\": {\n      \"amount\": {{FUND_AMOUNT}},\n      \"direction\": \"Credit\",\n      \"description\": \"Payment from Sandbox\"\n    },\n    \"relationships\": {\n      \"account\": {\n        \"data\": {\n          \"type\": \"depositAccount\",\n          \"id\": \"{{ACCOUNT_ID}}\"\n        }\n      }\n    }\n  }\n}",
          "options": { "raw": { "language": "json" } }
        },
        "url": {
          "raw": "{{BASE_URL}}/sandbox/payments",
          "host": ["{{BASE_URL}}"],
          "path": ["sandbox", "payments"]
        },
        "description": "Simulate an incoming ACH credit of $1,000.00 to fund Peter's account."
      }
    },
    {
      "name": "4. Create a Virtual Debit Card",
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "var json = pm.response.json();",
              "pm.collectionVariables.set('CARD_ID', json.data.id);",
              "pm.collectionVariables.set('CARD_LAST4', json.data.attributes.last4Digits);",
              "console.log('CARD_ID:', json.data.id);",
              "console.log('CARD_LAST4:', json.data.attributes.last4Digits);"
            ]
          }
        }
      ],
      "request": {
        "method": "POST",
        "header": [
          { "key": "Content-Type", "value": "application/vnd.api+json" }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"data\": {\n    \"type\": \"individualVirtualDebitCard\",\n    \"attributes\": {\n      \"idempotencyKey\": \"{{IDEMPOTENCY_KEY}}\",\n      \"limits\": {\n        \"dailyWithdrawal\": 50000,\n        \"dailyPurchase\": 50000,\n        \"monthlyWithdrawal\": 500000,\n        \"monthlyPurchase\": 700000\n      }\n    },\n    \"relationships\": {\n      \"account\": {\n        \"data\": {\n          \"type\": \"depositAccount\",\n          \"id\": \"{{ACCOUNT_ID}}\"\n        }\n      }\n    }\n  }\n}",
          "options": { "raw": { "language": "json" } }
        },
        "url": {
          "raw": "{{BASE_URL}}/cards",
          "host": ["{{BASE_URL}}"],
          "path": ["cards"]
        },
        "description": "Create a virtual debit card on the account from Step 2. Virtual cards are Active immediately. After running, CARD_ID and CARD_LAST4 are set automatically."
      }
    },
    {
      "name": "5. Make a Card Purchase at Amazon",
      "request": {
        "method": "POST",
        "header": [
          { "key": "Content-Type", "value": "application/vnd.api+json" }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"data\": {\n    \"type\": \"purchaseTransaction\",\n    \"attributes\": {\n      \"amount\": {{PURCHASE_AMOUNT}},\n      \"direction\": \"Debit\",\n      \"merchantName\": \"Amazon\",\n      \"merchantType\": 1000,\n      \"last4Digits\": \"{{CARD_LAST4}}\"\n    },\n    \"relationships\": {\n      \"account\": {\n        \"data\": {\n          \"type\": \"depositAccount\",\n          \"id\": \"{{ACCOUNT_ID}}\"\n        }\n      }\n    }\n  }\n}",
          "options": { "raw": { "language": "json" } }
        },
        "url": {
          "raw": "{{BASE_URL}}/sandbox/purchases",
          "host": ["{{BASE_URL}}"],
          "path": ["sandbox", "purchases"]
        },
        "description": "Simulate a $500.00 card purchase at Amazon. last4Digits must match the card from Step 4 (CARD_LAST4)."
      }
    }
  ]
}
