Load the SDK
window.Pagou.
| Environment | Use |
|---|---|
production | Default. Uses production collection endpoints. |
sandbox | Use for test public keys and sandbox transactions. |
local | Internal development only. |
Initialize Elements
| Option | Required | Description |
|---|---|---|
publicKey | Yes before submit | Company public key. Use pk_test_* in sandbox and pk_live_* in production. |
locale | No | Locale forwarded to the hosted card field. Defaults to pt-BR. |
origin | No | Checkout origin stored on the Element session. Defaults to window.location.origin. |
Create and mount the card field
elements.create("card") creates one hosted card field. If a card field already exists on the same elements instance, the SDK unmounts it before creating the new one.
Card options:
| Option | Description |
|---|---|
theme | default, night, or flat. |
locale | Overrides the Elements locale for this card field. |
style | Style object forwarded to the hosted field. |
mountTimeoutMs | Mount timeout in milliseconds. Defaults to 8000. |
telemetry | Sends best-effort mount failure telemetry when supported. Defaults to true. |
Card events
| Event | Payload | Use |
|---|---|---|
ready | {} | Hosted iframe loaded and completed the SDK handshake. |
change | { valid, brand, errors } | Enable submit only when valid is true. |
error | { code, message } | Show initialization, mount, or card field errors. |
Submit a payment
elements.submit(...) is the main SDK action. It creates an Element session, tokenizes the hosted card field, calls your createTransaction callback, and continues 3DS when the transaction response includes next_action.
createTransaction receives:
token to your backend as the payment credential. Treat brand, last4, exp_month, and exp_year as display or bookkeeping metadata.
Submit result
status values include:
| Status | Meaning |
|---|---|
| Transaction status | If there is no next_action, the SDK returns the transaction status from your backend response. |
completed | Fallback when the backend response has no status. |
requires_action | A next_action exists and automatic 3DS modal handling is disabled for the Element session. |
succeeded | 3DS challenge completed successfully. |
failed | 3DS challenge or payment failed. |
canceled | Buyer closed the 3DS modal. |
timed_out | 3DS challenge did not finish within the SDK timeout. |
error | Tokenization, session creation, callback, or SDK flow failed. |
3D Secure
When your backend returns a transaction withnext_action, the SDK can open the challenge modal automatically.
Token mode
Pass amode to submit to declare the caller’s intent and select the resulting token type:
mode | Token | When to use |
|---|---|---|
payment (default) | single-use pgct_ | One-off charge |
upsell | reusable pgpm_ | Initial purchase + one-click upsell |
subscription | single-use pgct_ | Card capture to start a subscription |
Cleanup
Unmount a card field when leaving the checkout screen:Production rules
- Use
pk_test_*only withPagou.setEnvironment("sandbox"). - Use
pk_live_*with the default production environment. - Never send raw card data to your backend.
- Never log
pgct_*,pgpm_*,client_secret, or card data. - Disable duplicate submits while
elements.submit(...)is running. - Return your transaction payload from the backend without removing
id,status, ornext_action. - Treat browser status as provisional until webhook or reconciliation confirms the final payment state.

