Criar transação
curl --request POST \
--url https://api.sandbox.z2pay.com/v1/transactions \
--header 'Content-Type: application/json' \
--header 'x-api-key: <api-key>' \
--data '
{
"referenceCode": "<string>",
"items": [
{
"description": "<string>",
"quantity": 2,
"amount": 2,
"code": "<string>"
}
],
"payments": [
{
"amount": 2,
"installments": 1,
"additionalInfo": {},
"creditCard": {
"id": "<string>",
"token": "<string>",
"statementDescriptor": "<string>",
"authentication": {
"gatewayConfigId": "<string>",
"externalId": "<string>",
"transStatus": "<string>"
},
"billingAddress": {
"street": "<string>",
"number": "<string>",
"complement": "<string>",
"neighborhood": "<string>",
"city": "<string>",
"state": "<string>",
"country": "<string>",
"postalCode": "<string>"
}
},
"boleto": {
"expirationDate": "2023-11-07T05:31:56Z",
"instructions": "<string>"
},
"pix": {
"expirationDate": "2023-11-07T05:31:56Z",
"authorizationId": "<string>"
},
"splitId": "<string>",
"split": [
{
"recipientId": "<string>",
"value": 1.01,
"type": "sale",
"processingFee": true,
"liable": true
}
]
}
],
"customerId": "<string>",
"currency": "BRL",
"ip": "<string>",
"additionalInfo": {}
}
'const options = {
method: 'POST',
headers: {'x-api-key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
referenceCode: '<string>',
items: [{description: '<string>', quantity: 2, amount: 2, code: '<string>'}],
payments: [
{
amount: 2,
installments: 1,
additionalInfo: {},
creditCard: {
id: '<string>',
token: '<string>',
statementDescriptor: '<string>',
authentication: {gatewayConfigId: '<string>', externalId: '<string>', transStatus: '<string>'},
billingAddress: {
street: '<string>',
number: '<string>',
complement: '<string>',
neighborhood: '<string>',
city: '<string>',
state: '<string>',
country: '<string>',
postalCode: '<string>'
}
},
boleto: {expirationDate: '2023-11-07T05:31:56Z', instructions: '<string>'},
pix: {expirationDate: '2023-11-07T05:31:56Z', authorizationId: '<string>'},
splitId: '<string>',
split: [
{
recipientId: '<string>',
value: 1.01,
type: 'sale',
processingFee: true,
liable: true
}
]
}
],
customerId: '<string>',
currency: 'BRL',
ip: '<string>',
additionalInfo: {}
})
};
fetch('https://api.sandbox.z2pay.com/v1/transactions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));import requests
url = "https://api.sandbox.z2pay.com/v1/transactions"
payload = {
"referenceCode": "<string>",
"items": [
{
"description": "<string>",
"quantity": 2,
"amount": 2,
"code": "<string>"
}
],
"payments": [
{
"amount": 2,
"installments": 1,
"additionalInfo": {},
"creditCard": {
"id": "<string>",
"token": "<string>",
"statementDescriptor": "<string>",
"authentication": {
"gatewayConfigId": "<string>",
"externalId": "<string>",
"transStatus": "<string>"
},
"billingAddress": {
"street": "<string>",
"number": "<string>",
"complement": "<string>",
"neighborhood": "<string>",
"city": "<string>",
"state": "<string>",
"country": "<string>",
"postalCode": "<string>"
}
},
"boleto": {
"expirationDate": "2023-11-07T05:31:56Z",
"instructions": "<string>"
},
"pix": {
"expirationDate": "2023-11-07T05:31:56Z",
"authorizationId": "<string>"
},
"splitId": "<string>",
"split": [
{
"recipientId": "<string>",
"value": 1.01,
"type": "sale",
"processingFee": True,
"liable": True
}
]
}
],
"customerId": "<string>",
"currency": "BRL",
"ip": "<string>",
"additionalInfo": {}
}
headers = {
"x-api-key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text){
"id": "txn_tyjpijlt9r6tig31605cvkbru",
"customerId": "cust_f7vm6b4j4cckf8gli2b2472ix",
"amount": 19990,
"currency": "BRL",
"paidAmount": 0,
"refundedAmount": 0,
"status": "waiting_payment",
"parentTransactionId": null,
"referenceCode": "ORDER-2025-00123",
"ip": "189.45.12.34",
"additionalInfo": {
"source": "checkout-web"
},
"customerName": "Maria Silva",
"customerEmail": "maria.silva@example.com",
"customerDocument": "12345678909",
"customerDocumentType": "cpf",
"customerPhone": "+5511987654321",
"createdAt": "2025-06-29T13:45:30.000Z",
"updatedAt": "2025-06-29T13:45:30.000Z",
"paidAt": null,
"expiresAt": "2026-06-25T12:00:00.000Z",
"canceledAt": null,
"refundedAt": null,
"chargedbackAt": null,
"protestedAt": null,
"items": [
{
"id": "item_s4206yea51f6fsiugybgb51sr",
"transactionId": "txn_tyjpijlt9r6tig31605cvkbru",
"code": "PLANO-PRO",
"description": "Plano Pro (mensal)",
"unitValue": 19990,
"quantity": 1,
"amount": 19990,
"createdAt": "2026-06-24T12:00:00.000Z",
"updatedAt": "2026-06-24T12:00:00.000Z"
}
],
"payments": [
{
"id": "pay_kd6z67zbp52rgtg2idms96fhm",
"transactionId": "txn_tyjpijlt9r6tig31605cvkbru",
"replacedByPaymentId": null,
"amount": 19990,
"currency": "BRL",
"installments": 1,
"paymentMethod": "pix",
"cardId": null,
"status": "waiting_payment",
"additionalInfo": null,
"statementDescriptor": null,
"billingAddress": null,
"boletoUrl": null,
"boletoDigitableLine": null,
"boletoBarcode": null,
"pixUrl": "https://pix.z2pay.com/qr/pay_kd6z67zbp52rgtg2idms96fhm/qr.png",
"pixCopyPaste": "00020126580014br.gov.bcb.pix0136a1b2c3d4-e5f6-7890-abcd-ef1234567890520400005303986540519.905802BR5913LOJA EXEMPLO6009SAO PAULO62070503***6304A1B2",
"splitConfigId": null,
"originalAmount": null,
"interestAmount": null,
"retryable": null,
"declineCode": null,
"errorMessage": null,
"createdAt": "2026-06-24T12:00:00.000Z",
"updatedAt": "2026-06-24T12:05:00.000Z",
"paidAt": null,
"expiresAt": "2026-06-25T12:00:00.000Z",
"canceledAt": null,
"refundedAt": null,
"chargedbackAt": null,
"protestedAt": null,
"card": null,
"splits": []
}
],
"customer": {
"id": "cust_f7vm6b4j4cckf8gli2b2472ix",
"name": "Maria Silva",
"email": "maria.silva@example.com",
"type": "individual",
"document": "12345678909",
"documentType": "cpf",
"phone": "+5511999998888",
"address": {
"street": "Av. Paulista",
"number": "1000",
"complement": "Conj. 101",
"neighborhood": "Bela Vista",
"city": "São Paulo",
"state": "SP",
"postalCode": "01310100",
"country": "BR"
},
"createdAt": "2026-06-24T12:00:00.000Z",
"updatedAt": "2026-06-24T12:00:00.000Z"
},
"customerAddress": {
"street": "Av. Paulista",
"number": "1000",
"complement": "Conj. 101",
"neighborhood": "Bela Vista",
"city": "São Paulo",
"state": "SP",
"postalCode": "01310100",
"country": "BR"
}
}{
"error": {
"code": "VALIDATION_ERROR",
"message": "Validation failed",
"issues": [
{
"path": "status",
"message": "Status inválido. Valores aceitos: pending, waiting_payment, paid, refused, canceled, refunded"
},
{
"path": "startDate",
"message": "Data deve ser ISO 8601 com timezone (ex.: 2026-06-24T00:00:00Z)"
}
]
}
}{
"error": {
"code": "UNAUTHORIZED",
"message": "Invalid API key"
}
}{
"error": "A request with this idempotency key is already being processed"
}{
"error": "Idempotency key already used with a different request body"
}Transações
Criar transação
Cria uma transação com seus itens e pagamentos, cobrando na mesma requisição ou deixando a cobrança para depois.
POST
/
transactions
Criar transação
curl --request POST \
--url https://api.sandbox.z2pay.com/v1/transactions \
--header 'Content-Type: application/json' \
--header 'x-api-key: <api-key>' \
--data '
{
"referenceCode": "<string>",
"items": [
{
"description": "<string>",
"quantity": 2,
"amount": 2,
"code": "<string>"
}
],
"payments": [
{
"amount": 2,
"installments": 1,
"additionalInfo": {},
"creditCard": {
"id": "<string>",
"token": "<string>",
"statementDescriptor": "<string>",
"authentication": {
"gatewayConfigId": "<string>",
"externalId": "<string>",
"transStatus": "<string>"
},
"billingAddress": {
"street": "<string>",
"number": "<string>",
"complement": "<string>",
"neighborhood": "<string>",
"city": "<string>",
"state": "<string>",
"country": "<string>",
"postalCode": "<string>"
}
},
"boleto": {
"expirationDate": "2023-11-07T05:31:56Z",
"instructions": "<string>"
},
"pix": {
"expirationDate": "2023-11-07T05:31:56Z",
"authorizationId": "<string>"
},
"splitId": "<string>",
"split": [
{
"recipientId": "<string>",
"value": 1.01,
"type": "sale",
"processingFee": true,
"liable": true
}
]
}
],
"customerId": "<string>",
"currency": "BRL",
"ip": "<string>",
"additionalInfo": {}
}
'const options = {
method: 'POST',
headers: {'x-api-key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
referenceCode: '<string>',
items: [{description: '<string>', quantity: 2, amount: 2, code: '<string>'}],
payments: [
{
amount: 2,
installments: 1,
additionalInfo: {},
creditCard: {
id: '<string>',
token: '<string>',
statementDescriptor: '<string>',
authentication: {gatewayConfigId: '<string>', externalId: '<string>', transStatus: '<string>'},
billingAddress: {
street: '<string>',
number: '<string>',
complement: '<string>',
neighborhood: '<string>',
city: '<string>',
state: '<string>',
country: '<string>',
postalCode: '<string>'
}
},
boleto: {expirationDate: '2023-11-07T05:31:56Z', instructions: '<string>'},
pix: {expirationDate: '2023-11-07T05:31:56Z', authorizationId: '<string>'},
splitId: '<string>',
split: [
{
recipientId: '<string>',
value: 1.01,
type: 'sale',
processingFee: true,
liable: true
}
]
}
],
customerId: '<string>',
currency: 'BRL',
ip: '<string>',
additionalInfo: {}
})
};
fetch('https://api.sandbox.z2pay.com/v1/transactions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));import requests
url = "https://api.sandbox.z2pay.com/v1/transactions"
payload = {
"referenceCode": "<string>",
"items": [
{
"description": "<string>",
"quantity": 2,
"amount": 2,
"code": "<string>"
}
],
"payments": [
{
"amount": 2,
"installments": 1,
"additionalInfo": {},
"creditCard": {
"id": "<string>",
"token": "<string>",
"statementDescriptor": "<string>",
"authentication": {
"gatewayConfigId": "<string>",
"externalId": "<string>",
"transStatus": "<string>"
},
"billingAddress": {
"street": "<string>",
"number": "<string>",
"complement": "<string>",
"neighborhood": "<string>",
"city": "<string>",
"state": "<string>",
"country": "<string>",
"postalCode": "<string>"
}
},
"boleto": {
"expirationDate": "2023-11-07T05:31:56Z",
"instructions": "<string>"
},
"pix": {
"expirationDate": "2023-11-07T05:31:56Z",
"authorizationId": "<string>"
},
"splitId": "<string>",
"split": [
{
"recipientId": "<string>",
"value": 1.01,
"type": "sale",
"processingFee": True,
"liable": True
}
]
}
],
"customerId": "<string>",
"currency": "BRL",
"ip": "<string>",
"additionalInfo": {}
}
headers = {
"x-api-key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text){
"id": "txn_tyjpijlt9r6tig31605cvkbru",
"customerId": "cust_f7vm6b4j4cckf8gli2b2472ix",
"amount": 19990,
"currency": "BRL",
"paidAmount": 0,
"refundedAmount": 0,
"status": "waiting_payment",
"parentTransactionId": null,
"referenceCode": "ORDER-2025-00123",
"ip": "189.45.12.34",
"additionalInfo": {
"source": "checkout-web"
},
"customerName": "Maria Silva",
"customerEmail": "maria.silva@example.com",
"customerDocument": "12345678909",
"customerDocumentType": "cpf",
"customerPhone": "+5511987654321",
"createdAt": "2025-06-29T13:45:30.000Z",
"updatedAt": "2025-06-29T13:45:30.000Z",
"paidAt": null,
"expiresAt": "2026-06-25T12:00:00.000Z",
"canceledAt": null,
"refundedAt": null,
"chargedbackAt": null,
"protestedAt": null,
"items": [
{
"id": "item_s4206yea51f6fsiugybgb51sr",
"transactionId": "txn_tyjpijlt9r6tig31605cvkbru",
"code": "PLANO-PRO",
"description": "Plano Pro (mensal)",
"unitValue": 19990,
"quantity": 1,
"amount": 19990,
"createdAt": "2026-06-24T12:00:00.000Z",
"updatedAt": "2026-06-24T12:00:00.000Z"
}
],
"payments": [
{
"id": "pay_kd6z67zbp52rgtg2idms96fhm",
"transactionId": "txn_tyjpijlt9r6tig31605cvkbru",
"replacedByPaymentId": null,
"amount": 19990,
"currency": "BRL",
"installments": 1,
"paymentMethod": "pix",
"cardId": null,
"status": "waiting_payment",
"additionalInfo": null,
"statementDescriptor": null,
"billingAddress": null,
"boletoUrl": null,
"boletoDigitableLine": null,
"boletoBarcode": null,
"pixUrl": "https://pix.z2pay.com/qr/pay_kd6z67zbp52rgtg2idms96fhm/qr.png",
"pixCopyPaste": "00020126580014br.gov.bcb.pix0136a1b2c3d4-e5f6-7890-abcd-ef1234567890520400005303986540519.905802BR5913LOJA EXEMPLO6009SAO PAULO62070503***6304A1B2",
"splitConfigId": null,
"originalAmount": null,
"interestAmount": null,
"retryable": null,
"declineCode": null,
"errorMessage": null,
"createdAt": "2026-06-24T12:00:00.000Z",
"updatedAt": "2026-06-24T12:05:00.000Z",
"paidAt": null,
"expiresAt": "2026-06-25T12:00:00.000Z",
"canceledAt": null,
"refundedAt": null,
"chargedbackAt": null,
"protestedAt": null,
"card": null,
"splits": []
}
],
"customer": {
"id": "cust_f7vm6b4j4cckf8gli2b2472ix",
"name": "Maria Silva",
"email": "maria.silva@example.com",
"type": "individual",
"document": "12345678909",
"documentType": "cpf",
"phone": "+5511999998888",
"address": {
"street": "Av. Paulista",
"number": "1000",
"complement": "Conj. 101",
"neighborhood": "Bela Vista",
"city": "São Paulo",
"state": "SP",
"postalCode": "01310100",
"country": "BR"
},
"createdAt": "2026-06-24T12:00:00.000Z",
"updatedAt": "2026-06-24T12:00:00.000Z"
},
"customerAddress": {
"street": "Av. Paulista",
"number": "1000",
"complement": "Conj. 101",
"neighborhood": "Bela Vista",
"city": "São Paulo",
"state": "SP",
"postalCode": "01310100",
"country": "BR"
}
}{
"error": {
"code": "VALIDATION_ERROR",
"message": "Validation failed",
"issues": [
{
"path": "status",
"message": "Status inválido. Valores aceitos: pending, waiting_payment, paid, refused, canceled, refunded"
},
{
"path": "startDate",
"message": "Data deve ser ISO 8601 com timezone (ex.: 2026-06-24T00:00:00Z)"
}
]
}
}{
"error": {
"code": "UNAUTHORIZED",
"message": "Invalid API key"
}
}{
"error": "A request with this idempotency key is already being processed"
}{
"error": "Idempotency key already used with a different request body"
}POST /transactions
Faz parte do recurso Transações — o conceito, o ciclo de vida e a
tabela de status estão lá.
Cria uma transação. São obrigatórios o cliente, o seu código de referência
(referenceCode), pelo menos um item e pelo menos um pagamento. O que decide se a cobrança
acontece agora ou depois não é a presença do payments, e sim a dos dados do meio de pagamento
dentro dele:
- Com
creditCard,pixouboleto→ o pagamento é cobrado imediatamente no gateway. Para cartão, os dados vão emcreditCard; para Pix e boleto, os objetospix/boletosão opcionais e servem só para customizar a expiração. No Pix, o QR Code (pixUrl/pixCopyPaste) já vem preenchido na resposta síncrona doPOST. - Sem nenhum deles → o pagamento nasce registrado e não cobrado, e a transação fica em
pending. Você cobra quando quiser, emPOST /transactions/:id/payments/process. É o caminho para ter o número do pedido antes de o comprador digitar o cartão.
payments não aceita lista vazia. A transação precisa nascer com pelo menos um pagamento,
ainda que sem os dados de cobrança. Não existe rota para acrescentar um pagamento a uma transação
já criada — sem nenhum, ela ficaria em pending para sempre, e a única saída seria criar outra.
Enviar [] ou omitir o campo resulta em 400.Endpoint idempotente. Envie o header
Idempotency-Key (TTL de 7 dias) para garantir que reenvios
da mesma requisição não criem transações duplicadas. Veja Convenções.Regras de negócio importantes
customer e customerId são mutuamente exclusivos. Envie um dos dois (obrigatório):
customerId para reusar um cliente já cadastrado, ou customer inline para criar/identificar o
cliente no ato. Enviar os dois, ou nenhum, resulta em 400.A soma dos pagamentos deve bater com a soma dos itens. Quando
payments é enviado, a soma de
payment.amount precisa ser exatamente igual ao total dos itens
(Σ item.amount × item.quantity). Caso contrário, 400. Todos os valores são inteiros em
centavos.Expiração de Pix e boleto tem default. Sem
pix.expirationDate, o QR Code vale 30
minutos; sem boleto.expirationDate, o boleto vence em 3 dias. Os dois objetos existem
só para mudar isso — o pagamento é processado com ou sem eles.O token do cartão muda de nome entre as APIs. O Tokenizer devolve o campo
como
tokenId; aqui ele entra como creditCard.token, e no Checkout como card.tokenId. É o
mesmo valor — só o nome do campo acompanha o contexto.statementDescriptor é normalizado antes de ir para a fatura. A criação aceita até 100
caracteres, mas o texto persistido e enviado à adquirente passa por três etapas: os acentos são
removidos (é → e), tudo que não for letra, número ou espaço cai fora, e o resultado é
cortado em 13 caracteres. "Café & Cia" chega ao portador como "Cafe Cia".A limpeza não é preciosismo: a adquirente recusa a cobrança inteira se o descritor trouxer
caractere especial. Por isso o campo é saneado em vez de rejeitado — e por isso a resposta já o
devolve na forma final. Use um texto curto, sem acento e reconhecível na fatura.O endereço da compra volta para o cadastro do cliente. Além de virar o
customerAddress
congelado na transação, o customer.address informado aqui atualiza o cadastro — campo a
campo: valor preenchido substitui, valor vazio não apaga o que já estava lá. Um checkout que
pede só o CEP não zera rua, cidade e estado de quem já tinha endereço.A atualização é best-effort: se falhar, a venda segue normalmente, porque a transação já guarda o
seu próprio snapshot.Exemplo: criar transação com Pix
curl -X POST https://api.sandbox.z2pay.com/v1/transactions \
-H "x-api-key: SUA_CHAVE_DE_SANDBOX" \
-H "Idempotency-Key: pedido-2026-0001" \
-H "Content-Type: application/json" \
-d '{
"referenceCode": "pedido-2026-0001",
"customer": {
"name": "Maria Souza",
"email": "maria@example.com",
"type": "individual",
"document": "12345678909",
"documentType": "cpf",
"phone": "+5511999998888"
},
"items": [
{ "description": "Plano Pro (mensal)", "quantity": 1, "amount": 9990 }
],
"payments": [
{ "paymentMethod": "pix", "amount": 9990 }
]
}'
O item custa
9990 centavos (R$ 99,90) e o pagamento soma 9990 — as somas batem, então a
requisição é válida.{
"id": "txn_ebgsvfsb4151nmbgvj4sek6ol",
"referenceCode": "pedido-2026-0001",
"status": "waiting_payment",
"amount": 9990,
"currency": "BRL",
"customerId": "cust_lhsmn6ugmjotm5qvnunrr2hz1",
"payments": [
{
"id": "pay_kd6z67zbp52rgtg2idms96fhm",
"paymentMethod": "pix",
"status": "waiting_payment",
"amount": 9990,
"pixUrl": "https://pix.z2pay.com/qr/pay_kd6z67zbp52rgtg2idms96fhm/qr.png",
"pixCopyPaste": "00020126580014br.gov.bcb.pix0136f1d2...6304A1B2",
"expiresAt": "2026-06-24T12:30:00.000Z"
}
],
"items": [
{
"id": "item_s4206yea51f6fsiugybgb51sr",
"description": "Plano Pro (mensal)",
"quantity": 1,
"unitValue": 9990,
"amount": 9990
}
],
"createdAt": "2026-06-24T12:00:00.000Z"
}
Resposta
201 Created. O exemplo de JSON é ilustrativo — confira os campos reais na resposta do seu ambiente.O pagamento já volta com
pixUrl (URL da imagem do QR Code) e pixCopyPaste (BR Code
copia-e-cola, EMV iniciando em 00020126...) preenchidos na própria resposta síncrona do create —
é esse o dado que você exibe ao comprador. O status waiting_payment significa que o QR Code foi
emitido e aguarda o pagador; expiresAt reflete a expiração default de 30 minutos.Na resposta, cada item traz
unitValue (o valor unitário que você enviou em items[].amount)
e amount (o total da linha = unitValue × quantity). Com quantity: 1 os dois coincidem;
no exemplo de cartão abaixo, com quantity: 2, o amount é o dobro do unitValue.Exemplo: criar e cobrar cartão com cartão tokenizado
curl -X POST https://api.sandbox.z2pay.com/v1/transactions \
-H "x-api-key: SUA_CHAVE_DE_SANDBOX" \
-H "Idempotency-Key: pedido-2026-0002" \
-H "Content-Type: application/json" \
-d '{
"referenceCode": "pedido-2026-0002",
"customerId": "cust_lhsmn6ugmjotm5qvnunrr2hz1",
"items": [
{ "description": "Camiseta", "quantity": 2, "amount": 5000 }
],
"payments": [
{
"paymentMethod": "credit_card",
"amount": 10000,
"installments": 1,
"creditCard": {
"token": "tok_exemplo_sandbox",
"statementDescriptor": "MINHALOJA"
}
}
]
}'
Um item com valor unitário de
5000 centavos (R$ 50,00) e quantity: 2 → total de 10000
centavos (R$ 100,00); o pagamento soma 10000. As somas batem. O cartão é
enviado como token (gerado pelo Tokenizer) — nunca envie dados crus
do cartão para a API.Body
application/json
Response
Transação criada