PayZu OnboardingTutoriais

Abrir uma conta PJ

  1. Troque o ID token Google da sua conta de serviço em POST /oauth/token, sem header Authorization. O token retornado vai em Bearer nas outras rotas.

  2. type COMPANY com o CNPJ em taxId. callbackUrl recebe os callbacks desta proposta no lugar da URL de callback do tenant.

  3. A resposta traz o link da jornada em journeyUrl. Entregue ao cliente pelo seu canal; se ele se perder, gere outro com actions/issue-link.

  4. X-Callback-Signature traz sha256= e o HMAC-SHA256 de <X-Callback-Timestamp>.<corpo cru> com o segredo do tenant. O timestamp vem em segundos: recuse os antigos.

  5. proposal.decided traz APPROVED ou REPROVED em data.status, e proposal.waiting_data avisa que a PayZu pediu dados ao cliente. O mesmo evento pode chegar de novo: decida pelo id.

open-business-account.js
import crypto from 'node:crypto'import http from 'node:http' const API = 'https://api.sandbox.payzu.dev'const headers = { 'content-type': 'application/json' }const post = (path, body) =>  fetch(`${API}${path}`, { method: 'POST', headers, body: JSON.stringify(body) }).then((r) => r.json()) const { access_token } = await post('/oauth/token', {  grant_type: 'urn:ietf:params:oauth:grant-type:token-exchange',  subject_token: process.env.GOOGLE_ID_TOKEN,  subject_token_type: 'urn:ietf:params:oauth:token-type:id_token',  audience: 'payzu'})headers.authorization = `Bearer ${access_token}` const proposal = await post('/v1/proposals', {  clientCode: 'crm-9001',  type: 'COMPANY',  taxId: '11.222.333/0001-81',  contact: 'financeiro@empresa.com.br',  callbackUrl: 'https://api.exemplo.com.br/webhooks/abertura-de-conta'}) console.log(proposal.id, proposal.journeyUrl) http.createServer(async (req, res) => {  const chunks = []  for await (const chunk of req) chunks.push(chunk)  const raw = Buffer.concat(chunks).toString()  const timestamp = req.headers['x-callback-timestamp'] ?? ''  const expected = crypto.createHmac('sha256', process.env.PAYZU_CALLBACK_SECRET).update(`${timestamp}.${raw}`).digest()  const given = /^sha256=([0-9a-f]{64})$/.exec(req.headers['x-callback-signature'] ?? '')  const fresh = Math.abs(Date.now() / 1000 - Number(timestamp)) <= 300  if (!fresh || !given || !crypto.timingSafeEqual(expected, Buffer.from(given[1], 'hex'))) return res.writeHead(401).end()  const { id, event, proposal: summary, data } = JSON.parse(raw)  console.log(id, event, summary.status, data.status)  res.writeHead(200).end()}).listen(3000)
Resposta · 200 Proposta já existente
{  "id": "cmf0p8x1a0001qk08prop0001",  "clientCode": "crm-8812",  "type": "PERSON",  "taxId": "12345678909",  "contact": "5573991699000",  "status": "CREATED",  "delivery": "LINK",  "expiresAt": "2026-09-24T12:00:00.000Z",  "submittedAt": null,  "decidedAt": null,  "version": 0,  "createdAt": "2026-09-17T12:00:00.000Z",  "updatedAt": "2026-09-17T12:00:00.000Z",  "journeyUrl": null,  "embedUrl": null}

Referência: Criar uma proposta de abertura de conta