{
  "info": {
    "_postman_id": "d7d8515b-f6b0-4d95-aaf3-2eab8f52ce31",
    "name": "Conjugador Subscription Tracker",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
    "description": "Requests to test Telegram tracker notifications for subscription activation and renewal."
  },
  "item": [
    {
      "name": "Auth",
      "item": [
        {
          "name": "Login",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "const json = pm.response.json();",
                  "if (json.token) {",
                  "  pm.collectionVariables.set('token', json.token);",
                  "}",
                  "if (json.user_id) {",
                  "  pm.collectionVariables.set('user_id', String(json.user_id));",
                  "}"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Accept",
                "value": "application/json"
              },
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"email\": \"{{email}}\",\n  \"password\": \"{{password}}\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{base_url}}/login",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "login"
              ]
            },
            "description": "Authenticates a user and stores the returned Sanctum token in the collection variable `token`."
          },
          "response": []
        }
      ]
    },
    {
      "name": "iOS",
      "item": [
        {
          "name": "Validate Receipt (dev)",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Accept",
                "value": "application/json"
              },
              {
                "key": "Content-Type",
                "value": "application/json"
              },
              {
                "key": "Authorization",
                "value": "Bearer {{token}}"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"receipt\": \"{{ios_receipt_ref}}\",\n  \"product\": \"{{ios_product}}\",\n  \"dev\": \"true\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{base_url}}/validate-receipt",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "validate-receipt"
              ]
            },
            "description": "Uses the iOS dev shortcut in the backend to create a purchase record and trigger the Telegram `subscription_started` notification."
          },
          "response": []
        },
        {
          "name": "Apple Webhook DID_RENEW",
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "const encodeJson = (value) => CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(JSON.stringify(value)));",
                  "const makeJwt = (payload) => `${encodeJson({ alg: 'none', typ: 'JWT' })}.${encodeJson(payload)}.signature`;",
                  "const innerPayload = {",
                  "  originalTransactionId: pm.collectionVariables.get('ios_receipt_ref'),",
                  "  productId: pm.collectionVariables.get('ios_product')",
                  "};",
                  "const outerPayload = {",
                  "  notificationType: 'DID_RENEW',",
                  "  data: {",
                  "    signedTransactionInfo: makeJwt(innerPayload)",
                  "  }",
                  "};",
                  "pm.collectionVariables.set('apple_signed_payload', makeJwt(outerPayload));"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Accept",
                "value": "application/json"
              },
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"signedPayload\": \"{{apple_signed_payload}}\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{base_url}}/apple-subscription-webhook",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "apple-subscription-webhook"
              ]
            },
            "description": "Builds a synthetic Apple webhook payload that matches the current backend decoder and should trigger the Telegram `subscription_renewed` notification."
          },
          "response": []
        }
      ]
    },
    {
      "name": "Android",
      "item": [
        {
          "name": "Android Webhook Renewed (optional)",
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "const payload = {",
                  "  subscriptionNotification: {",
                  "    notificationType: 2,",
                  "    purchaseToken: pm.collectionVariables.get('android_purchase_token'),",
                  "    subscriptionId: pm.collectionVariables.get('android_product')",
                  "  }",
                  "};",
                  "const encoded = CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(JSON.stringify(payload)));",
                  "pm.collectionVariables.set('android_pubsub_data', encoded);"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Accept",
                "value": "application/json"
              },
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"message\": {\n    \"data\": \"{{android_pubsub_data}}\"\n  }\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{base_url}}/android-subscription-webhook",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "android-subscription-webhook"
              ]
            },
            "description": "Optional. Requires `android_purchase_token` to already exist in the purchases table."
          },
          "response": []
        }
      ]
    }
  ],
  "variable": [
    {
      "key": "base_url",
      "value": "https://your-domain.com/api"
    },
    {
      "key": "email",
      "value": ""
    },
    {
      "key": "password",
      "value": ""
    },
    {
      "key": "token",
      "value": ""
    },
    {
      "key": "user_id",
      "value": ""
    },
    {
      "key": "ios_receipt_ref",
      "value": "postman-ios-renew-001"
    },
    {
      "key": "ios_product",
      "value": "prov2"
    },
    {
      "key": "apple_signed_payload",
      "value": ""
    },
    {
      "key": "android_purchase_token",
      "value": ""
    },
    {
      "key": "android_product",
      "value": "prov2"
    },
    {
      "key": "android_pubsub_data",
      "value": ""
    }
  ]
}
