Criar nova transação
curl --request POST \
--url https://api.payments.bob.company/api/v1/transactions/ \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"customer": {
"address": {
"city": "<string>",
"neighborhood": "<string>",
"state": "<string>",
"street": "<string>",
"streetNumber": "<string>",
"zipCode": "<string>",
"complement": "<string>",
"country": "BR"
},
"document": "<string>",
"email": "[email protected]",
"name": "<string>",
"phone": "<string>"
},
"originDomain": "<string>",
"payment": {
"amountCents": 25000000,
"product": "<string>",
"expirationDays": 15,
"quantity": 1
},
"customerIp": "127.0.0.1",
"paymentMethod": "pix"
}
'import requests
url = "https://api.payments.bob.company/api/v1/transactions/"
payload = {
"customer": {
"address": {
"city": "<string>",
"neighborhood": "<string>",
"state": "<string>",
"street": "<string>",
"streetNumber": "<string>",
"zipCode": "<string>",
"complement": "<string>",
"country": "BR"
},
"document": "<string>",
"email": "[email protected]",
"name": "<string>",
"phone": "<string>"
},
"originDomain": "<string>",
"payment": {
"amountCents": 25000000,
"product": "<string>",
"expirationDays": 15,
"quantity": 1
},
"customerIp": "127.0.0.1",
"paymentMethod": "pix"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
customer: {
address: {
city: '<string>',
neighborhood: '<string>',
state: '<string>',
street: '<string>',
streetNumber: '<string>',
zipCode: '<string>',
complement: '<string>',
country: 'BR'
},
document: '<string>',
email: '[email protected]',
name: '<string>',
phone: '<string>'
},
originDomain: '<string>',
payment: {amountCents: 25000000, product: '<string>', expirationDays: 15, quantity: 1},
customerIp: '127.0.0.1',
paymentMethod: 'pix'
})
};
fetch('https://api.payments.bob.company/api/v1/transactions/', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.payments.bob.company/api/v1/transactions/",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'customer' => [
'address' => [
'city' => '<string>',
'neighborhood' => '<string>',
'state' => '<string>',
'street' => '<string>',
'streetNumber' => '<string>',
'zipCode' => '<string>',
'complement' => '<string>',
'country' => 'BR'
],
'document' => '<string>',
'email' => '[email protected]',
'name' => '<string>',
'phone' => '<string>'
],
'originDomain' => '<string>',
'payment' => [
'amountCents' => 25000000,
'product' => '<string>',
'expirationDays' => 15,
'quantity' => 1
],
'customerIp' => '127.0.0.1',
'paymentMethod' => 'pix'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.payments.bob.company/api/v1/transactions/"
payload := strings.NewReader("{\n \"customer\": {\n \"address\": {\n \"city\": \"<string>\",\n \"neighborhood\": \"<string>\",\n \"state\": \"<string>\",\n \"street\": \"<string>\",\n \"streetNumber\": \"<string>\",\n \"zipCode\": \"<string>\",\n \"complement\": \"<string>\",\n \"country\": \"BR\"\n },\n \"document\": \"<string>\",\n \"email\": \"[email protected]\",\n \"name\": \"<string>\",\n \"phone\": \"<string>\"\n },\n \"originDomain\": \"<string>\",\n \"payment\": {\n \"amountCents\": 25000000,\n \"product\": \"<string>\",\n \"expirationDays\": 15,\n \"quantity\": 1\n },\n \"customerIp\": \"127.0.0.1\",\n \"paymentMethod\": \"pix\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.payments.bob.company/api/v1/transactions/")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"customer\": {\n \"address\": {\n \"city\": \"<string>\",\n \"neighborhood\": \"<string>\",\n \"state\": \"<string>\",\n \"street\": \"<string>\",\n \"streetNumber\": \"<string>\",\n \"zipCode\": \"<string>\",\n \"complement\": \"<string>\",\n \"country\": \"BR\"\n },\n \"document\": \"<string>\",\n \"email\": \"[email protected]\",\n \"name\": \"<string>\",\n \"phone\": \"<string>\"\n },\n \"originDomain\": \"<string>\",\n \"payment\": {\n \"amountCents\": 25000000,\n \"product\": \"<string>\",\n \"expirationDays\": 15,\n \"quantity\": 1\n },\n \"customerIp\": \"127.0.0.1\",\n \"paymentMethod\": \"pix\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.payments.bob.company/api/v1/transactions/")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"customer\": {\n \"address\": {\n \"city\": \"<string>\",\n \"neighborhood\": \"<string>\",\n \"state\": \"<string>\",\n \"street\": \"<string>\",\n \"streetNumber\": \"<string>\",\n \"zipCode\": \"<string>\",\n \"complement\": \"<string>\",\n \"country\": \"BR\"\n },\n \"document\": \"<string>\",\n \"email\": \"[email protected]\",\n \"name\": \"<string>\",\n \"phone\": \"<string>\"\n },\n \"originDomain\": \"<string>\",\n \"payment\": {\n \"amountCents\": 25000000,\n \"product\": \"<string>\",\n \"expirationDays\": 15,\n \"quantity\": 1\n },\n \"customerIp\": \"127.0.0.1\",\n \"paymentMethod\": \"pix\"\n}"
response = http.request(request)
puts response.read_body{
"data": {
"externalId": "<string>",
"id": "<string>",
"status": "<string>",
"expirationDate": "<string>",
"pixCode": "<string>"
},
"success": true,
"billingWarning": "<string>",
"message": "<string>"
}{
"data": {
"externalId": "<string>",
"id": "<string>",
"status": "<string>",
"expirationDate": "<string>",
"pixCode": "<string>"
},
"success": true,
"billingWarning": "<string>",
"message": "<string>"
}{
"detail": "<string>",
"instance": "<string>",
"status": 499,
"title": "<string>",
"type": "<string>",
"details": {},
"errorCode": "<string>"
}{
"detail": "<string>",
"instance": "<string>",
"status": 499,
"title": "<string>",
"type": "<string>",
"details": {},
"errorCode": "<string>"
}{
"detail": "<string>",
"instance": "<string>",
"status": 499,
"title": "<string>",
"type": "<string>",
"details": {},
"errorCode": "<string>"
}{
"detail": "<string>",
"instance": "<string>",
"status": 499,
"title": "<string>",
"type": "<string>",
"details": {},
"errorCode": "<string>"
}{
"detail": "<string>",
"instance": "<string>",
"status": 499,
"title": "<string>",
"type": "<string>",
"details": {},
"errorCode": "<string>"
}{
"detail": "<string>",
"instance": "<string>",
"status": 499,
"title": "<string>",
"type": "<string>",
"details": {},
"errorCode": "<string>"
}Criar uma nova cobrança
Cria uma nova transação PIX.
POST
/
api
/
v1
/
transactions
/
Criar nova transação
curl --request POST \
--url https://api.payments.bob.company/api/v1/transactions/ \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"customer": {
"address": {
"city": "<string>",
"neighborhood": "<string>",
"state": "<string>",
"street": "<string>",
"streetNumber": "<string>",
"zipCode": "<string>",
"complement": "<string>",
"country": "BR"
},
"document": "<string>",
"email": "[email protected]",
"name": "<string>",
"phone": "<string>"
},
"originDomain": "<string>",
"payment": {
"amountCents": 25000000,
"product": "<string>",
"expirationDays": 15,
"quantity": 1
},
"customerIp": "127.0.0.1",
"paymentMethod": "pix"
}
'import requests
url = "https://api.payments.bob.company/api/v1/transactions/"
payload = {
"customer": {
"address": {
"city": "<string>",
"neighborhood": "<string>",
"state": "<string>",
"street": "<string>",
"streetNumber": "<string>",
"zipCode": "<string>",
"complement": "<string>",
"country": "BR"
},
"document": "<string>",
"email": "[email protected]",
"name": "<string>",
"phone": "<string>"
},
"originDomain": "<string>",
"payment": {
"amountCents": 25000000,
"product": "<string>",
"expirationDays": 15,
"quantity": 1
},
"customerIp": "127.0.0.1",
"paymentMethod": "pix"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
customer: {
address: {
city: '<string>',
neighborhood: '<string>',
state: '<string>',
street: '<string>',
streetNumber: '<string>',
zipCode: '<string>',
complement: '<string>',
country: 'BR'
},
document: '<string>',
email: '[email protected]',
name: '<string>',
phone: '<string>'
},
originDomain: '<string>',
payment: {amountCents: 25000000, product: '<string>', expirationDays: 15, quantity: 1},
customerIp: '127.0.0.1',
paymentMethod: 'pix'
})
};
fetch('https://api.payments.bob.company/api/v1/transactions/', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.payments.bob.company/api/v1/transactions/",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'customer' => [
'address' => [
'city' => '<string>',
'neighborhood' => '<string>',
'state' => '<string>',
'street' => '<string>',
'streetNumber' => '<string>',
'zipCode' => '<string>',
'complement' => '<string>',
'country' => 'BR'
],
'document' => '<string>',
'email' => '[email protected]',
'name' => '<string>',
'phone' => '<string>'
],
'originDomain' => '<string>',
'payment' => [
'amountCents' => 25000000,
'product' => '<string>',
'expirationDays' => 15,
'quantity' => 1
],
'customerIp' => '127.0.0.1',
'paymentMethod' => 'pix'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.payments.bob.company/api/v1/transactions/"
payload := strings.NewReader("{\n \"customer\": {\n \"address\": {\n \"city\": \"<string>\",\n \"neighborhood\": \"<string>\",\n \"state\": \"<string>\",\n \"street\": \"<string>\",\n \"streetNumber\": \"<string>\",\n \"zipCode\": \"<string>\",\n \"complement\": \"<string>\",\n \"country\": \"BR\"\n },\n \"document\": \"<string>\",\n \"email\": \"[email protected]\",\n \"name\": \"<string>\",\n \"phone\": \"<string>\"\n },\n \"originDomain\": \"<string>\",\n \"payment\": {\n \"amountCents\": 25000000,\n \"product\": \"<string>\",\n \"expirationDays\": 15,\n \"quantity\": 1\n },\n \"customerIp\": \"127.0.0.1\",\n \"paymentMethod\": \"pix\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.payments.bob.company/api/v1/transactions/")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"customer\": {\n \"address\": {\n \"city\": \"<string>\",\n \"neighborhood\": \"<string>\",\n \"state\": \"<string>\",\n \"street\": \"<string>\",\n \"streetNumber\": \"<string>\",\n \"zipCode\": \"<string>\",\n \"complement\": \"<string>\",\n \"country\": \"BR\"\n },\n \"document\": \"<string>\",\n \"email\": \"[email protected]\",\n \"name\": \"<string>\",\n \"phone\": \"<string>\"\n },\n \"originDomain\": \"<string>\",\n \"payment\": {\n \"amountCents\": 25000000,\n \"product\": \"<string>\",\n \"expirationDays\": 15,\n \"quantity\": 1\n },\n \"customerIp\": \"127.0.0.1\",\n \"paymentMethod\": \"pix\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.payments.bob.company/api/v1/transactions/")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"customer\": {\n \"address\": {\n \"city\": \"<string>\",\n \"neighborhood\": \"<string>\",\n \"state\": \"<string>\",\n \"street\": \"<string>\",\n \"streetNumber\": \"<string>\",\n \"zipCode\": \"<string>\",\n \"complement\": \"<string>\",\n \"country\": \"BR\"\n },\n \"document\": \"<string>\",\n \"email\": \"[email protected]\",\n \"name\": \"<string>\",\n \"phone\": \"<string>\"\n },\n \"originDomain\": \"<string>\",\n \"payment\": {\n \"amountCents\": 25000000,\n \"product\": \"<string>\",\n \"expirationDays\": 15,\n \"quantity\": 1\n },\n \"customerIp\": \"127.0.0.1\",\n \"paymentMethod\": \"pix\"\n}"
response = http.request(request)
puts response.read_body{
"data": {
"externalId": "<string>",
"id": "<string>",
"status": "<string>",
"expirationDate": "<string>",
"pixCode": "<string>"
},
"success": true,
"billingWarning": "<string>",
"message": "<string>"
}{
"data": {
"externalId": "<string>",
"id": "<string>",
"status": "<string>",
"expirationDate": "<string>",
"pixCode": "<string>"
},
"success": true,
"billingWarning": "<string>",
"message": "<string>"
}{
"detail": "<string>",
"instance": "<string>",
"status": 499,
"title": "<string>",
"type": "<string>",
"details": {},
"errorCode": "<string>"
}{
"detail": "<string>",
"instance": "<string>",
"status": 499,
"title": "<string>",
"type": "<string>",
"details": {},
"errorCode": "<string>"
}{
"detail": "<string>",
"instance": "<string>",
"status": 499,
"title": "<string>",
"type": "<string>",
"details": {},
"errorCode": "<string>"
}{
"detail": "<string>",
"instance": "<string>",
"status": 499,
"title": "<string>",
"type": "<string>",
"details": {},
"errorCode": "<string>"
}{
"detail": "<string>",
"instance": "<string>",
"status": 499,
"title": "<string>",
"type": "<string>",
"details": {},
"errorCode": "<string>"
}{
"detail": "<string>",
"instance": "<string>",
"status": 499,
"title": "<string>",
"type": "<string>",
"details": {},
"errorCode": "<string>"
}Idempotência
Timeouts e falhas de rede deixam a dúvida: a cobrança foi criada ou não? Envie um identificador único por pedido no headerIdempotency-Key.
| Cenário | O que acontece |
|---|---|
| Primeira requisição com a chave | Processada normalmente. A resposta 2xx fica guardada por 1 hora. |
| Repetição com a mesma chave e o mesmo body | A API replaya a resposta original, com x-idempotent-replayed: true. Nenhuma cobrança nova é criada. |
| Repetição enquanto a original ainda processa | 409 Conflict. Aguarde cerca de 1s e repita com a mesma chave. |
| Mesma chave com body diferente | 422. Cada requisição distinta precisa de uma chave nova. |
| Requisição que terminou em erro (4xx/5xx) | A chave é liberada. Repetir re-executa a criação. |
O escopo da chave é o seu projeto. Use até 256 caracteres. Um UUID ou o ID do pedido são boas escolhas. Ao repetir após timeout, use a mesma chave da tentativa original.
HTTP 202
202 não é erro. O PIX foi gerado, mas a persistência ainda está em reconciliação:
data.idpode virnull. Usedata.externalIdcomo referência.- O
pixCodeé válido e pagável. Entregue ao comprador normalmente. - A transação aparece na listagem em alguns minutos.
Erros
Toda resposta 4xx/5xx segue o RFC 7807:{
"type": "ERR_INTEGRATION_006",
"title": "Método não disponível",
"status": 422,
"detail": "O método de pagamento informado não está habilitado no projeto.",
"instance": "/api/v1/transactions"
}
status + type. As mensagens podem mudar; os códigos não.
| Status | O que fazer |
|---|---|
400 | Não repita sem corrigir. Veja details.issues. |
401 | Confira o header Authorization: Bearer sk_.... |
403 | Cheque o tipo da chave e o modo do projeto. |
404 | ID errado ou de outro projeto. |
409 | Aguarde ~1s e repita com a mesma Idempotency-Key. |
422 | Corrija a causa de negócio antes de repetir. |
429 | Aguarde o header Retry-After. |
500 / 503 | Repita com backoff e a mesma Idempotency-Key. |
transaction.paid. Veja como validar o webhook.Authorizations
Body
application/json
Was this page helpful?
