Criar um checkout
curl --request POST \
--url https://api.valorapayments.com.br/v1/checkouts \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"product_cart": [
{
"product_id": "prod_Ab12Cd34Ef56Gh78",
"quantity": 1
}
],
"customer": {
"name": "Ana Souza",
"email": "ana@example.com"
},
"allowed_payment_method_types": [
"pix",
"card"
],
"success_url": "https://sualoja.com/pedido/1001/obrigado",
"cancel_url": "https://sualoja.com/carrinho",
"external_reference": "pedido-1001"
}
'const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
product_cart: [{product_id: 'prod_Ab12Cd34Ef56Gh78', quantity: 1}],
customer: {name: 'Ana Souza', email: 'ana@example.com'},
allowed_payment_method_types: ['pix', 'card'],
success_url: 'https://sualoja.com/pedido/1001/obrigado',
cancel_url: 'https://sualoja.com/carrinho',
external_reference: 'pedido-1001'
})
};
fetch('https://api.valorapayments.com.br/v1/checkouts', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));import requests
url = "https://api.valorapayments.com.br/v1/checkouts"
payload = {
"product_cart": [
{
"product_id": "prod_Ab12Cd34Ef56Gh78",
"quantity": 1
}
],
"customer": {
"name": "Ana Souza",
"email": "ana@example.com"
},
"allowed_payment_method_types": ["pix", "card"],
"success_url": "https://sualoja.com/pedido/1001/obrigado",
"cancel_url": "https://sualoja.com/carrinho",
"external_reference": "pedido-1001"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.valorapayments.com.br/v1/checkouts",
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([
'product_cart' => [
[
'product_id' => 'prod_Ab12Cd34Ef56Gh78',
'quantity' => 1
]
],
'customer' => [
'name' => 'Ana Souza',
'email' => 'ana@example.com'
],
'allowed_payment_method_types' => [
'pix',
'card'
],
'success_url' => 'https://sualoja.com/pedido/1001/obrigado',
'cancel_url' => 'https://sualoja.com/carrinho',
'external_reference' => 'pedido-1001'
]),
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;
}{
"id": "cs_Xk2v9QeR7tLmN3bA",
"object": "checkout_session",
"status": "open",
"livemode": true,
"checkout_url": "https://pay.valorapayments.com.br/s/cs_Xk2v9QeR7tLmN3bA",
"product_cart": [
{
"product_id": "<string>",
"name": "<string>",
"quantity": 123,
"unit_amount": 123
}
],
"amount": {
"subtotal": 123,
"total": 123,
"currency": "BRL"
},
"allowed_payment_method_types": [
"pix"
],
"customer_id": "<string>",
"payment_id": "<string>",
"method": "pix",
"success_url": "<string>",
"cancel_url": "<string>",
"external_reference": "<string>",
"metadata": {
"order_id": "1001"
},
"expires_at": "2023-11-07T05:31:56Z",
"completed_at": "2023-11-07T05:31:56Z",
"created_at": "2023-11-07T05:31:56Z"
}{
"error": {
"type": "invalid_api_key",
"message": "Chave de API inválida ou revogada."
}
}{
"error": {
"type": "missing_scope",
"message": "A chave não tem o escopo necessário."
}
}{
"error": {
"type": "product_not_found",
"message": "Produto não encontrado."
}
}{
"error": {
"type": "product_inactive",
"message": "O produto não está ativo."
}
}{
"error": {
"type": "invalid_request",
"message": "Corpo inválido.",
"details": {
"amount": [
"Valor inválido."
]
}
}
}{
"error": {
"type": "rate_limited",
"message": "Muitas requisições. Tente novamente em instantes."
}
}{
"error": {
"type": "service_unavailable",
"message": "Serviço temporariamente indisponível."
}
}Checkouts
Criar um checkout
Cria uma compra e devolve o checkout_url, o link que você manda ao cliente. O cliente escolhe Pix, cartão ou boleto na página da Valora. O preço vem do produto e fica travado na criação.
Escopo: checkouts:write.
POST
/
v1
/
checkouts
Criar um checkout
curl --request POST \
--url https://api.valorapayments.com.br/v1/checkouts \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"product_cart": [
{
"product_id": "prod_Ab12Cd34Ef56Gh78",
"quantity": 1
}
],
"customer": {
"name": "Ana Souza",
"email": "ana@example.com"
},
"allowed_payment_method_types": [
"pix",
"card"
],
"success_url": "https://sualoja.com/pedido/1001/obrigado",
"cancel_url": "https://sualoja.com/carrinho",
"external_reference": "pedido-1001"
}
'const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
product_cart: [{product_id: 'prod_Ab12Cd34Ef56Gh78', quantity: 1}],
customer: {name: 'Ana Souza', email: 'ana@example.com'},
allowed_payment_method_types: ['pix', 'card'],
success_url: 'https://sualoja.com/pedido/1001/obrigado',
cancel_url: 'https://sualoja.com/carrinho',
external_reference: 'pedido-1001'
})
};
fetch('https://api.valorapayments.com.br/v1/checkouts', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));import requests
url = "https://api.valorapayments.com.br/v1/checkouts"
payload = {
"product_cart": [
{
"product_id": "prod_Ab12Cd34Ef56Gh78",
"quantity": 1
}
],
"customer": {
"name": "Ana Souza",
"email": "ana@example.com"
},
"allowed_payment_method_types": ["pix", "card"],
"success_url": "https://sualoja.com/pedido/1001/obrigado",
"cancel_url": "https://sualoja.com/carrinho",
"external_reference": "pedido-1001"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.valorapayments.com.br/v1/checkouts",
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([
'product_cart' => [
[
'product_id' => 'prod_Ab12Cd34Ef56Gh78',
'quantity' => 1
]
],
'customer' => [
'name' => 'Ana Souza',
'email' => 'ana@example.com'
],
'allowed_payment_method_types' => [
'pix',
'card'
],
'success_url' => 'https://sualoja.com/pedido/1001/obrigado',
'cancel_url' => 'https://sualoja.com/carrinho',
'external_reference' => 'pedido-1001'
]),
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;
}{
"id": "cs_Xk2v9QeR7tLmN3bA",
"object": "checkout_session",
"status": "open",
"livemode": true,
"checkout_url": "https://pay.valorapayments.com.br/s/cs_Xk2v9QeR7tLmN3bA",
"product_cart": [
{
"product_id": "<string>",
"name": "<string>",
"quantity": 123,
"unit_amount": 123
}
],
"amount": {
"subtotal": 123,
"total": 123,
"currency": "BRL"
},
"allowed_payment_method_types": [
"pix"
],
"customer_id": "<string>",
"payment_id": "<string>",
"method": "pix",
"success_url": "<string>",
"cancel_url": "<string>",
"external_reference": "<string>",
"metadata": {
"order_id": "1001"
},
"expires_at": "2023-11-07T05:31:56Z",
"completed_at": "2023-11-07T05:31:56Z",
"created_at": "2023-11-07T05:31:56Z"
}{
"error": {
"type": "invalid_api_key",
"message": "Chave de API inválida ou revogada."
}
}{
"error": {
"type": "missing_scope",
"message": "A chave não tem o escopo necessário."
}
}{
"error": {
"type": "product_not_found",
"message": "Produto não encontrado."
}
}{
"error": {
"type": "product_inactive",
"message": "O produto não está ativo."
}
}{
"error": {
"type": "invalid_request",
"message": "Corpo inválido.",
"details": {
"amount": [
"Valor inválido."
]
}
}
}{
"error": {
"type": "rate_limited",
"message": "Muitas requisições. Tente novamente em instantes."
}
}{
"error": {
"type": "service_unavailable",
"message": "Serviço temporariamente indisponível."
}
}Autorizações
Corpo
application/json
Resposta
Compra criada.