Integration Guide
Go from zero to accepting payments in 5 steps. This guide walks you through the complete integration — backend, frontend, and payment confirmation.
How It Works
A Glin integration has four parts: your backend creates a remittance (payment request), the SDK collects and tokenizes payment data on the frontend, your backend confirms the payment with your secret API key, and your backend receives a webhook when the payment completes.
Security model: Your public key can only collect data and tokenize cards. Actual charges require your API key (Bearer token) from your backend. This is the same pattern used by Stripe and MercadoPago.
Prerequisites
Before you start, make sure you have:
- Glin merchant account -- start with the staging environment for testing.
- API key (Bearer token) -- used by your backend to create remittances and manage webhooks. Find it in your merchant dashboard under Integration Keys.
- Public key -- used by the Checkout SDK on the frontend. Found in the same dashboard page. Not needed if you use the Redirect approach.
| Environment | Base URL | Purpose |
|---|---|---|
| Staging | pay.staging.glin.com.br | Development and testing (sandbox payments) |
| Production | pay.glin.com.br | Live payments (real money) |
Never expose your API key in client-side code. It should only be used on your backend. The public key is safe to use in the browser.
Step 1: Create a Remittance
A remittance is Glin's payment request. Your backend creates one for each order, specifying the amount and currency. Glin returns a remittanceId and a checkoutUrl.
/merchant-api/remittances/Request Body
| Name | Type | Required | Description |
|---|---|---|---|
clientReferenceId | string | Your internal order ID (1-64 characters). Use this to correlate the remittance with your system. | |
amount | number | Payment amount (minimum 0.01). The currency determines how this is interpreted. | |
currency | string | ISO 4217 currency code. Must match your merchant contract (e.g. "USD", "EUR", "GBP", "JPY", "CAD"). | |
expiresAt | string (ISO 8601) | — | When the checkout link expires. Must be at least 15 minutes from now. |
successUrl | string (URL) | — | Where to redirect the customer after a successful payment. Must be HTTPS. |
cancelUrl | string (URL) | — | Where to redirect the customer if they cancel. Must be HTTPS. |
Example (cURL)
curl --request POST \
--url https://pay.staging.glin.com.br/merchant-api/remittances/ \
--header 'Authorization: Bearer YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data '{
"clientReferenceId": "order-12345",
"type": "target_amount_fixed",
"amount": 500.00,
"currency": "USD",
"expiresAt": "2026-03-01T19:00:00Z",
"successUrl": "https://your-site.com/order/success?id=12345",
"cancelUrl": "https://your-site.com/order/cancel?id=12345"
}'Response
{
"id": "550e8400-e29b-41d4-a716-446655440000",
"status": "created",
"clientReferenceId": "order-12345",
"type": "target_amount_fixed",
"amount": 500.00,
"currency": "USD",
"payoutAmount": 500.00,
"payoutCurrency": "USD",
"expiresAt": "2026-03-01T19:00:00Z",
"successUrl": "https://your-site.com/order/success?id=12345",
"cancelUrl": "https://your-site.com/order/cancel?id=12345",
"checkoutUrl": "https://pay.staging.glin.com.br/remittances/550e8400-e29b-41d4-a716-446655440000",
"shortUrl": "https://staging.glin.com.br/pay/K7M2QXPTRW"
}Backend Implementation
Your backend needs two endpoints: one to create remittances and one to confirm payments. Pick your language:
const express = require('express');
const app = express();
app.use(express.json());
const GLIN_API_KEY = process.env.GLIN_API_KEY;
const GLIN_BASE_URL = 'https://pay.staging.glin.com.br';
// Create a remittance for the order
app.post('/api/create-checkout', async (req, res) => {
const { orderId, amount, currency } = req.body;
const response = await fetch(GLIN_BASE_URL + '/merchant-api/remittances/', {
method: 'POST',
headers: {
'Authorization': 'Bearer ' + GLIN_API_KEY,
'Content-Type': 'application/json',
},
body: JSON.stringify({
clientReferenceId: orderId,
amount,
currency,
expiresAt: new Date(Date.now() + 30 * 60 * 1000).toISOString(),
successUrl: 'https://your-site.com/order/success?id=' + orderId,
cancelUrl: 'https://your-site.com/order/cancel?id=' + orderId,
}),
});
const remittance = await response.json();
res.json({ remittanceId: remittance.id, checkoutUrl: remittance.checkoutUrl });
});
// Confirm payment (called by the SDK's onPaymentReady callback)
app.post('/api/confirm-payment', async (req, res) => {
const { remittanceId, paymentData } = req.body;
const response = await fetch(
GLIN_BASE_URL + '/merchant-api/remittances/' + remittanceId + '/pay',
{
method: 'POST',
headers: {
'Authorization': 'Bearer ' + GLIN_API_KEY,
'Content-Type': 'application/json',
},
body: JSON.stringify(paymentData),
}
);
const result = await response.json();
res.json(result);
}); Use clientReferenceId to tie each remittance to your internal order ID. This makes it easy to match webhook events to your orders later.
Step 2: Present Checkout to the Customer
Now that you have a remittance, show the payment form to your customer. Choose the approach that fits your needs:
| Approach | Frontend Work | Customization | Best For |
|---|---|---|---|
| Redirect | None | None | Fastest launch, no frontend changes |
| Plug & Play SDK | Mount one <div> | Theme colors | Most merchants |
| Customizable SDK | Mount + config | Full control (layout, fields, styles) | Design-sensitive brands |
| Headless SDK | Build your own UI | Total control (own design system) | SPAs, custom design systems |
Option A: Redirect (zero frontend code)
Just redirect the customer to the checkoutUrl from Step 1. Glin handles the entire checkout experience and redirects the customer back to your successUrl when done.
// After creating the remittance on your backend:
const { checkoutUrl } = await fetch('/api/create-checkout', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ orderId: 'order-12345', amount: 500, currency: 'USD' }),
}).then(res => res.json());
// Redirect the customer to Glin's hosted checkout
window.location.href = checkoutUrl;With Redirect, the customer leaves your site and returns after payment. If you want the checkout form embedded in your page, use Option B instead.
Option B: Embedded SDK
Embed the checkout form directly in your page. The SDK collects customer data and tokenizes the card, then sends the payment data to your backend via the onPaymentReady callback. Your backend confirms the payment using your API key, and returns the result to the SDK, which handles PIX QR display, 3D Secure authentication, and status polling.
<!DOCTYPE html>
<html>
<head>
<title>Checkout</title>
<script src="https://sdk.glin.com.br/v1/glin-checkout.js"></script>
</head>
<body>
<div id="checkout"></div>
<script>
fetch('/api/create-checkout', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ orderId: 'order-12345', amount: 500, currency: 'USD' }),
})
.then(res => res.json())
.then(({ remittanceId }) => {
GlinCheckout.mount('#checkout', {
publicKey: 'YOUR_PUBLIC_KEY',
remittanceId: remittanceId,
onPaymentReady: async ({ remittanceId, paymentData }) => {
const res = await fetch('/api/confirm-payment', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ remittanceId, paymentData }),
});
return res.json();
},
onSuccess: (data) => {
console.log('Payment succeeded:', data.orderId);
window.location.href = '/order/success?id=order-12345';
},
onError: (error) => {
console.error('Payment failed:', error.message);
},
});
});
</script>
</body>
</html> The SDK automatically detects the environment from your public key prefix: pk_stag_* routes to staging, pk_prod_* routes to production. No manual URL configuration needed.
Want to customize colors, layout, or field visibility? See the Customizable SDK page for theming and advanced configuration. Need full UI control? See the Headless SDK page.
Framework Examples
Here's how to mount the SDK in popular frontend frameworks. Each example assumes your backend already exposes /api/confirm-payment from Step 1.
import { useEffect, useRef } from 'react';
export default function CheckoutPage({ remittanceId }) {
const containerRef = useRef(null);
useEffect(() => {
const script = document.createElement('script');
script.src = 'https://sdk.glin.com.br/v1/glin-checkout.js';
script.onload = () => {
GlinCheckout.mount(containerRef.current, {
publicKey: process.env.NEXT_PUBLIC_GLIN_PUBLIC_KEY,
remittanceId,
onPaymentReady: async ({ remittanceId, paymentData }) => {
const res = await fetch('/api/confirm-payment', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ remittanceId, paymentData }),
});
return res.json();
},
onSuccess: (data) => {
window.location.href = `/order/success?id=${data.orderId}`;
},
onError: (error) => {
console.error('Payment failed:', error.message);
},
});
};
document.head.appendChild(script);
return () => { script.remove(); };
}, [remittanceId]);
return <div ref={containerRef} />;
}Payment states managed by the SDK: after submission, the SDK automatically handles pending validation (polling with visual indicator), 3DS authentication (popup when required by issuer), rejection with retry (form restored with inline error), and PIX QR code (QR display with copy-paste and auto-polling). No additional frontend implementation is needed for these scenarios.
Optimization: Pre-Register Customer
When the customer submits payment, Glin runs a compliance check (KYC) before processing the charge. This typically takes 5-15 seconds. To eliminate this wait, you can pre-register the customer as soon as you have their CPF, name, email, and phone -- while they're still filling out address and card details.
Call POST /checkout-api/customer/register with your public key. The compliance check runs in the background. When the payment request arrives, if the customer is already approved, the charge proceeds immediately.
// Call this as soon as you have CPF, name, email, and phone
async function preRegisterCustomer(publicKey, taxId, name, email, phone) {
const response = await fetch(GLIN_BASE_URL + '/checkout-api/customer/register', {
method: 'POST',
headers: {
'X-Public-Key': publicKey,
'Content-Type': 'application/json',
},
body: JSON.stringify({ taxId, name, email, phone }),
});
const { customerId, status } = await response.json();
return customerId;
}
// Then mount the SDK with the customerId:
GlinCheckout.mount('#checkout', {
publicKey: 'YOUR_PUBLIC_KEY',
remittanceId: remittanceId,
data: {
customerId: preRegisteredCustomerId, // Skips compliance wait
customer: { taxId }, // Required for card tokenization
},
onPaymentReady: async ({ remittanceId, paymentData }) => {
const res = await fetch('/api/confirm-payment', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ remittanceId, paymentData }),
});
return res.json();
},
}); This is optional. If you don't pre-register, the compliance check runs automatically when your backend calls the /pay endpoint -- it just adds a few seconds to the payment time.
Returning customers: The /pay response includes a customerId. Store it in your system and pass it via data.customerId on future SDK mounts to skip customer registration and compliance checks. For card payments, also pass the customer's CPF via data.customer.taxId so the SDK can tokenize the card.
Step 3: Handle Payment Result
When a customer pays, Glin sends a webhook to your backend. This is the reliable way to confirm payment — don't rely solely on the frontend onSuccess callback or the redirect to successUrl.
Register a Webhook
curl --request POST \
--url https://pay.staging.glin.com.br/merchant-api/webhooks/ \
--header 'Authorization: Bearer YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data '{
"url": "https://your-site.com/webhooks/glin",
"eventTypes": [
"remittance_paid",
"remittance_delivered",
"remittance_expired"
]
}'Webhook Payload
Each webhook event includes a unique top-level event id, the event type, and a remittance snapshot in object. Use the top-level id, not object.id, to make processing idempotent across retries.
{
"id": "9b5599d4-6800-4b5f-9e7d-67dff2d12a2f",
"type": "remittance_paid",
"happenedAt": "2026-02-25T14:30:00Z",
"notifiedAt": "2026-02-25T14:30:01Z",
"object": {
"type": "target_amount_fixed",
"id": "550e8400-e29b-41d4-a716-446655440000",
"status": "paid",
"clientReferenceId": "order-12345",
"amount": 500.0,
"currency": "USD",
"payoutAmount": 500.0,
"payoutCurrency": "USD",
"exchangeRate": 5.12,
"payment": {
"method": "card",
"installments": 6
}
}
}Handle Events
app.post('/webhooks/glin', express.text({ type: 'application/json' }), async (req, res) => {
const rawBody = req.body;
const event = JSON.parse(rawBody);
// TODO: Verify JWS signature in production
// See: /developers/api/webhooks#jws-signature-verification
switch (event.type) {
case 'remittance_paid':
await fulfillOrder(event.object.clientReferenceId);
break;
case 'remittance_delivered':
await markOrderDelivered(event.object.clientReferenceId);
break;
case 'remittance_expired':
await cancelOrder(event.object.clientReferenceId);
break;
}
res.sendStatus(200);
}); In production, always verify the x-jws-signature header to ensure webhook events are really from Glin. See the JWS Signature Verification section for implementation details.
Key Events
| Event | What Happened | Your Action |
|---|---|---|
remittance_paid | Customer payment confirmed | Fulfill the order |
remittance_delivered | Funds delivered to your account | Mark order as settled |
remittance_expired | Payment window expired | Cancel or re-create the order |
You can also poll for status with GET /merchant-api/remittances/{id} as a fallback. The status progresses: created → paid → delivered.
Check Status (Optional)
/merchant-api/remittances/{id}curl --request GET \
--url https://pay.staging.glin.com.br/merchant-api/remittances/550e8400-e29b-41d4-a716-446655440000 \
--header 'Authorization: Bearer YOUR_API_KEY'Step 4: Test Your Integration
Use the staging environment with test credentials to verify your integration before going live.
Test Card Numbers
| Brand | Number | CVV | Expiration |
|---|---|---|---|
| Visa | 4509 9535 6623 3704 | 123 | Any future date |
| Mastercard | 5031 4332 1540 6351 | 123 | Any future date |
Simulate Payment Results
The cardholder name controls the payment outcome in staging:
| Cardholder Name | Result | Description |
|---|---|---|
| APRO | Approved | Payment is approved. |
| OTHE | Rejected | Payment is rejected (general error). |
| CONT | Pending | Payment stays in pending status. |
| CALL | Call to authorize | Payment requires phone authorization. |
Use any valid CPF format for the customer tax ID in staging (e.g. 123.456.789-09). For PIX, payments are auto-confirmed in the staging environment.
Testing Checklist
- Successful card payment -- use cardholder name
APROand verify your webhook receivesremittance_paid - Rejected card payment -- use cardholder name
OTHEand verify error handling - PIX payment -- select PIX, verify QR code displays, confirm payment completes
- Expired remittance -- create a remittance with a short
expiresAtand verify expiration handling - Webhook delivery -- verify your endpoint returns
200and processes the event correctly
Use ngrok to expose your local webhook endpoint for testing. For a complete testing reference, see the Testing Guide.
Step 5: Go Live
When your integration works in staging, switch to production:
- Switch base URLs from
pay.staging.glin.com.brtopay.glin.com.brin your backend - Replace API credentials -- use your production API key and public key from the merchant dashboard
- Use your production public key (
pk_prod_*) — the SDK auto-routes to the production API - Update your webhook URL if your production endpoint differs from staging
- Verify JWS signatures -- make sure your webhook handler verifies the
x-jws-signatureheader - Make a test payment with a real card to confirm the full flow works end-to-end
Never mix staging and production keys. Staging API keys do not work against the production API and vice versa.
Next Steps
Dive deeper into specific topics: