{
  "info": {
    "name": "Paystation API /v1",
    "description": "Gerada do OpenAPI da API /v1. Escolha o ambiente (homologação ou produção) e preencha as chaves no local value.",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "event": [
    {
      "listen": "prerequest",
      "script": {
        "type": "text/javascript",
        "exec": [
          "const readOnly = pm.request.method === 'GET' || [\"/v1/reusable-payment/search\"].some(path => pm.request.url.getPath().endsWith(path))",
          "const token = pm.variables.replaceIn(pm.request.auth?.parameters().get('token') ?? '')",
          "const toHomolog = pm.variables.replaceIn('{{base_url}}').includes('paystation-homolog.quero.space')",
          "const testOnly = toHomolog && /^(sk|pk)_test_/.test(token)",
          "if (!readOnly && !testOnly && pm.environment.get('allow_writes') !== 'true') {",
          "  console.warn('Escrita fora da homologação bloqueada: defina allow_writes como true no ambiente para enviar.')",
          "  pm.variables.set('blocked', 'true')",
          "  pm.execution.skipRequest()",
          "}"
        ]
      }
    }
  ],
  "item": [
    {
      "name": "me",
      "item": [
        {
          "name": "Describe the key used on the request",
          "event": [],
          "request": {
            "method": "GET",
            "auth": {
              "type": "bearer",
              "bearer": [
                {
                  "key": "token",
                  "value": "{{secret_key}}",
                  "type": "string"
                }
              ]
            },
            "header": [],
            "url": {
              "raw": "{{base_url}}/v1/me",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "v1",
                "me"
              ]
            }
          }
        }
      ]
    },
    {
      "name": "offers",
      "item": [
        {
          "name": "List your published offers, newest first",
          "event": [],
          "request": {
            "method": "GET",
            "auth": {
              "type": "bearer",
              "bearer": [
                {
                  "key": "token",
                  "value": "{{secret_key}}",
                  "type": "string"
                }
              ]
            },
            "header": [],
            "url": {
              "raw": "{{base_url}}/v1/offers",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "v1",
                "offers"
              ],
              "query": [
                {
                  "key": "limit",
                  "value": "",
                  "description": "1 to 100; defaults to 20.",
                  "disabled": true
                },
                {
                  "key": "starting_after",
                  "value": "",
                  "description": "The last `id` of the previous page.",
                  "disabled": true
                }
              ]
            }
          }
        },
        {
          "name": "Create an offer",
          "event": [],
          "request": {
            "method": "POST",
            "auth": {
              "type": "bearer",
              "bearer": [
                {
                  "key": "token",
                  "value": "{{secret_key}}",
                  "type": "string"
                }
              ]
            },
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{base_url}}/v1/offers",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "v1",
                "offers"
              ]
            },
            "body": {
              "mode": "raw",
              "raw": "{\n  \"offer_id\": \"string\",\n  \"title\": \"string\",\n  \"description\": \"string\",\n  \"price\": 0,\n  \"payment_methods\": [\n    \"card\"\n  ],\n  \"installments\": 0,\n  \"offer_type\": \"default\",\n  \"subscription\": {\n    \"cycles\": 0,\n    \"amount\": 0\n  }\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            }
          }
        },
        {
          "name": "Retrieve one of your offers: published with a public key, any status with a secret key",
          "event": [],
          "request": {
            "method": "GET",
            "auth": {
              "type": "bearer",
              "bearer": [
                {
                  "key": "token",
                  "value": "{{secret_key}}",
                  "type": "string"
                }
              ]
            },
            "header": [],
            "url": {
              "raw": "{{base_url}}/v1/offers/:id",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "v1",
                "offers",
                ":id"
              ],
              "variable": [
                {
                  "key": "id",
                  "value": "{{offer_id}}"
                }
              ]
            }
          }
        },
        {
          "name": "Update one of your offers; only the fields sent change",
          "event": [],
          "request": {
            "method": "POST",
            "auth": {
              "type": "bearer",
              "bearer": [
                {
                  "key": "token",
                  "value": "{{secret_key}}",
                  "type": "string"
                }
              ]
            },
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{base_url}}/v1/offers/:id",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "v1",
                "offers",
                ":id"
              ],
              "variable": [
                {
                  "key": "id",
                  "value": "{{offer_id}}"
                }
              ]
            },
            "body": {
              "mode": "raw",
              "raw": "{\n  \"offer_id\": \"string\",\n  \"offer_type\": \"default\",\n  \"title\": \"string\",\n  \"description\": \"string\",\n  \"price\": 0,\n  \"payment_methods\": [\n    \"card\"\n  ],\n  \"installments\": 0,\n  \"status\": \"published\",\n  \"subscription\": {\n    \"cycles\": 0,\n    \"amount\": 0\n  }\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            }
          }
        },
        {
          "name": "Replace the order bumps of one of your offers",
          "event": [],
          "request": {
            "method": "POST",
            "auth": {
              "type": "bearer",
              "bearer": [
                {
                  "key": "token",
                  "value": "{{secret_key}}",
                  "type": "string"
                }
              ]
            },
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{base_url}}/v1/offers/:id/order_bumps",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "v1",
                "offers",
                ":id",
                "order_bumps"
              ],
              "variable": [
                {
                  "key": "id",
                  "value": "{{offer_id}}"
                }
              ]
            },
            "body": {
              "mode": "raw",
              "raw": "{\n  \"order_bumps\": [\n    {\n      \"offer_id\": \"9f1c2b1e-7a4d-4c3b-9a55-2f7e0b6d1a11\",\n      \"price\": 0\n    }\n  ]\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            }
          }
        },
        {
          "name": "Quote an offer: payment methods, instalments and totals",
          "event": [],
          "request": {
            "method": "GET",
            "auth": {
              "type": "bearer",
              "bearer": [
                {
                  "key": "token",
                  "value": "{{secret_key}}",
                  "type": "string"
                }
              ]
            },
            "header": [],
            "url": {
              "raw": "{{base_url}}/v1/offers/:id/checkout",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "v1",
                "offers",
                ":id",
                "checkout"
              ],
              "query": [
                {
                  "key": "coupon",
                  "value": "",
                  "disabled": true
                },
                {
                  "key": "order_bump_ids",
                  "value": "",
                  "description": "Comma-separated order bump ids.",
                  "disabled": true
                }
              ],
              "variable": [
                {
                  "key": "id",
                  "value": "{{offer_id}}"
                }
              ]
            }
          }
        }
      ]
    },
    {
      "name": "acquirers",
      "item": [
        {
          "name": "List the acquirers to tokenize with, in failover order",
          "event": [],
          "request": {
            "method": "GET",
            "auth": {
              "type": "bearer",
              "bearer": [
                {
                  "key": "token",
                  "value": "{{secret_key}}",
                  "type": "string"
                }
              ]
            },
            "header": [],
            "url": {
              "raw": "{{base_url}}/v1/acquirers/priorities",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "v1",
                "acquirers",
                "priorities"
              ],
              "query": [
                {
                  "key": "payment_method",
                  "value": "card",
                  "description": "Defaults to `card`.",
                  "disabled": true
                },
                {
                  "key": "installments",
                  "value": "",
                  "description": "Positive integer.",
                  "disabled": true
                },
                {
                  "key": "acquirer_name",
                  "value": "",
                  "disabled": true
                },
                {
                  "key": "has_split",
                  "value": "",
                  "description": "`true` lists only acquirers that support split; any other value lists all. Ignored when `offer_id` is sent.",
                  "disabled": true
                },
                {
                  "key": "offer_id",
                  "value": "{{offer_id}}",
                  "description": "One of your offers; decides `has_split` from it, and on a subscription offer leaves out the card acquirers a subscription cannot renew on.",
                  "disabled": true
                }
              ]
            }
          }
        }
      ]
    },
    {
      "name": "checkout_sessions",
      "item": [
        {
          "name": "Open a Stark Bank tokenization session",
          "event": [],
          "request": {
            "method": "GET",
            "auth": {
              "type": "bearer",
              "bearer": [
                {
                  "key": "token",
                  "value": "{{secret_key}}",
                  "type": "string"
                }
              ]
            },
            "header": [
              {
                "key": "cf-turnstile-token",
                "value": "{{turnstile_token}}",
                "description": "Cloudflare Turnstile token solved in the browser."
              }
            ],
            "url": {
              "raw": "{{base_url}}/v1/checkout_sessions?acquirer_name=stark_bank&visitor_id=",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "v1",
                "checkout_sessions"
              ],
              "query": [
                {
                  "key": "acquirer_name",
                  "value": "stark_bank"
                },
                {
                  "key": "visitor_id",
                  "value": ""
                },
                {
                  "key": "expires_in",
                  "value": "",
                  "description": "Session lifetime in seconds. Anything that is not a positive integer is ignored and 3600 is used, with no error.",
                  "disabled": true
                },
                {
                  "key": "expire_in",
                  "value": "",
                  "description": "Alias of `expires_in`, read only when `expires_in` is absent or empty.",
                  "disabled": true
                }
              ]
            }
          }
        }
      ]
    },
    {
      "name": "webhook_destinations",
      "item": [
        {
          "name": "List where this account is notified",
          "event": [],
          "request": {
            "method": "GET",
            "auth": {
              "type": "bearer",
              "bearer": [
                {
                  "key": "token",
                  "value": "{{secret_key}}",
                  "type": "string"
                }
              ]
            },
            "header": [],
            "url": {
              "raw": "{{base_url}}/v1/webhook_destinations",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "v1",
                "webhook_destinations"
              ]
            }
          }
        },
        {
          "name": "Register a webhook destination",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "if (pm.response.code === 200 || pm.response.code === 201) pm.environment.set('destination_id', pm.response.json().id)"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "auth": {
              "type": "bearer",
              "bearer": [
                {
                  "key": "token",
                  "value": "{{secret_key}}",
                  "type": "string"
                }
              ]
            },
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{base_url}}/v1/webhook_destinations",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "v1",
                "webhook_destinations"
              ]
            },
            "body": {
              "mode": "raw",
              "raw": "{\n  \"url\": \"{{webhook_url}}\",\n  \"events\": [\n    \"subscription_cycle\",\n    \"subscription\"\n  ]\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            }
          }
        },
        {
          "name": "Replace the events of a webhook destination",
          "event": [],
          "request": {
            "method": "POST",
            "auth": {
              "type": "bearer",
              "bearer": [
                {
                  "key": "token",
                  "value": "{{secret_key}}",
                  "type": "string"
                }
              ]
            },
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{base_url}}/v1/webhook_destinations/:id",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "v1",
                "webhook_destinations",
                ":id"
              ],
              "variable": [
                {
                  "key": "id",
                  "value": "{{destination_id}}"
                }
              ]
            },
            "body": {
              "mode": "raw",
              "raw": "{\n  \"events\": [\n    \"subscription_cycle\",\n    \"subscription\"\n  ]\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            }
          }
        },
        {
          "name": "Remove a webhook destination",
          "event": [],
          "request": {
            "method": "DELETE",
            "auth": {
              "type": "bearer",
              "bearer": [
                {
                  "key": "token",
                  "value": "{{secret_key}}",
                  "type": "string"
                }
              ]
            },
            "header": [],
            "url": {
              "raw": "{{base_url}}/v1/webhook_destinations/:id",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "v1",
                "webhook_destinations",
                ":id"
              ],
              "variable": [
                {
                  "key": "id",
                  "value": "{{destination_id}}"
                }
              ]
            }
          }
        }
      ]
    },
    {
      "name": "charges",
      "item": [
        {
          "name": "Create a charge",
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "if (pm.variables.get('blocked') !== 'true') {",
                  "  const key = pm.environment.get('idempotency_key') || pm.variables.replaceIn('{{$guid}}')",
                  "  pm.variables.set('attempt_key', key)",
                  "  pm.environment.set('last_attempt_key', key)",
                  "  pm.environment.set('charge_id', '')",
                  "  pm.environment.set('subscription_id', '')",
                  "  const turnstile = pm.environment.get('turnstile_token')",
                  "  if (turnstile) {",
                  "    pm.request.headers.remove('cf-turnstile-token')",
                  "    pm.request.headers.add({ key: 'cf-turnstile-token', value: turnstile })",
                  "  }",
                  "}"
                ]
              }
            },
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "if (pm.response.code === 201) {",
                  "  const charge = pm.response.json()",
                  "  pm.environment.set('charge_id', charge.id)",
                  "  pm.environment.set('subscription_id', charge.subscription ?? '')",
                  "}"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "auth": {
              "type": "bearer",
              "bearer": [
                {
                  "key": "token",
                  "value": "{{secret_key}}",
                  "type": "string"
                }
              ]
            },
            "header": [
              {
                "key": "idempotency-key",
                "value": "{{attempt_key}}",
                "description": "UUID v4, one per purchase attempt. The key is bound to the purchase: every body field but `payment.cards` must match the first request under it (`idempotency_key_reuse` otherwise). While the key holds nothing, a request under it charges the cards it carries, so their tokens must be valid when sent (a Pagar.me token is single use and lives 60s). Once the key holds an answer or a charge, that answers every request under it, whatever cards it carries: a kept answer is replayed for 24h from when it was stored (then `idempotency_key_expired`), a charge in progress is answered as it is now. Each response below says whether the key keeps it."
              },
              {
                "key": "cf-turnstile-token",
                "value": "{{turnstile_token}}",
                "description": "Required for card payments with a public key, and on any key when the account enables Turnstile.",
                "disabled": true
              },
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{base_url}}/v1/charges",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "v1",
                "charges"
              ]
            },
            "body": {
              "mode": "raw",
              "raw": "{\n  \"offer_id\": \"{{offer_id}}\",\n  \"customer\": {\n    \"name\": \"Maria Souza\",\n    \"email\": \"maria@example.com\",\n    \"document\": \"52998224725\",\n    \"document_type\": \"cpf\",\n    \"phone\": \"+5511988888888\",\n    \"address\": {\n      \"street\": \"Rua das Flores\",\n      \"number\": \"100\",\n      \"neighborhood\": \"Centro\",\n      \"zip_code\": \"01000000\",\n      \"city\": \"São Paulo\",\n      \"state\": \"SP\"\n    }\n  },\n  \"payment\": {\n    \"method\": \"pix\"\n  },\n  \"metadata\": {\n    \"attempt_id\": \"{{attempt_key}}\",\n    \"order_id\": \"postman\"\n  }\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            }
          }
        },
        {
          "name": "List your charges, newest first",
          "event": [],
          "request": {
            "method": "GET",
            "auth": {
              "type": "bearer",
              "bearer": [
                {
                  "key": "token",
                  "value": "{{secret_key}}",
                  "type": "string"
                }
              ]
            },
            "header": [],
            "url": {
              "raw": "{{base_url}}/v1/charges",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "v1",
                "charges"
              ],
              "query": [
                {
                  "key": "limit",
                  "value": "",
                  "description": "1 to 100; defaults to 20.",
                  "disabled": true
                },
                {
                  "key": "starting_after",
                  "value": "",
                  "description": "The last `id` of the previous page.",
                  "disabled": true
                },
                {
                  "key": "status",
                  "value": "processing",
                  "disabled": true
                },
                {
                  "key": "created_gte",
                  "value": "",
                  "disabled": true
                },
                {
                  "key": "created_lte",
                  "value": "",
                  "disabled": true
                },
                {
                  "key": "offer",
                  "value": "{{offer_id}}",
                  "disabled": true
                },
                {
                  "key": "metadata[attempt_id]",
                  "value": "{{last_attempt_key}}",
                  "disabled": true
                }
              ]
            }
          }
        },
        {
          "name": "Retrieve a charge",
          "event": [],
          "request": {
            "method": "GET",
            "auth": {
              "type": "bearer",
              "bearer": [
                {
                  "key": "token",
                  "value": "{{secret_key}}",
                  "type": "string"
                }
              ]
            },
            "header": [],
            "url": {
              "raw": "{{base_url}}/v1/charges/:id",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "v1",
                "charges",
                ":id"
              ],
              "variable": [
                {
                  "key": "id",
                  "value": "{{charge_id}}"
                }
              ]
            }
          }
        },
        {
          "name": "Refund a charge in full; a charge already refunding or refunded is answered as it is",
          "event": [],
          "request": {
            "method": "POST",
            "auth": {
              "type": "bearer",
              "bearer": [
                {
                  "key": "token",
                  "value": "{{secret_key}}",
                  "type": "string"
                }
              ]
            },
            "header": [],
            "url": {
              "raw": "{{base_url}}/v1/charges/:id/refund",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "v1",
                "charges",
                ":id",
                "refund"
              ],
              "variable": [
                {
                  "key": "id",
                  "value": "{{charge_id}}"
                }
              ]
            }
          }
        }
      ]
    },
    {
      "name": "subscriptions",
      "item": [
        {
          "name": "Retrieve a subscription",
          "event": [],
          "request": {
            "method": "GET",
            "auth": {
              "type": "bearer",
              "bearer": [
                {
                  "key": "token",
                  "value": "{{secret_key}}",
                  "type": "string"
                }
              ]
            },
            "header": [],
            "url": {
              "raw": "{{base_url}}/v1/subscriptions/:id",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "v1",
                "subscriptions",
                ":id"
              ],
              "variable": [
                {
                  "key": "id",
                  "value": "{{subscription_id}}"
                }
              ]
            }
          }
        },
        {
          "name": "Cancel a subscription without a fee; a canceled one is answered as it is",
          "event": [],
          "request": {
            "method": "POST",
            "auth": {
              "type": "bearer",
              "bearer": [
                {
                  "key": "token",
                  "value": "{{secret_key}}",
                  "type": "string"
                }
              ]
            },
            "header": [],
            "url": {
              "raw": "{{base_url}}/v1/subscriptions/:id/cancel",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "v1",
                "subscriptions",
                ":id",
                "cancel"
              ],
              "variable": [
                {
                  "key": "id",
                  "value": "{{subscription_id}}"
                }
              ]
            }
          }
        }
      ]
    },
    {
      "name": "reusable-payment",
      "item": [
        {
          "name": "Find a pending pix or boleto the buyer can resume",
          "event": [],
          "request": {
            "method": "POST",
            "auth": {
              "type": "bearer",
              "bearer": [
                {
                  "key": "token",
                  "value": "{{secret_key}}",
                  "type": "string"
                }
              ]
            },
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{base_url}}/v1/reusable-payment/search",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "v1",
                "reusable-payment",
                "search"
              ]
            },
            "body": {
              "mode": "raw",
              "raw": "{\n  \"document\": \"52998224725\",\n  \"offer_id\": \"{{offer_id}}\",\n  \"method\": \"pix\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            }
          }
        }
      ]
    },
    {
      "name": "upsell",
      "item": [
        {
          "name": "Check whether an upsell can be offered after a purchase",
          "event": [],
          "request": {
            "method": "GET",
            "auth": {
              "type": "bearer",
              "bearer": [
                {
                  "key": "token",
                  "value": "{{secret_key}}",
                  "type": "string"
                }
              ]
            },
            "header": [],
            "url": {
              "raw": "{{base_url}}/v1/upsell?offer_id={{offer_id}}&transaction_id={{charge_id}}",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "v1",
                "upsell"
              ],
              "query": [
                {
                  "key": "offer_id",
                  "value": "{{offer_id}}"
                },
                {
                  "key": "transaction_id",
                  "value": "{{charge_id}}"
                }
              ]
            }
          }
        }
      ]
    }
  ]
}
