Criar Preço de Assinatura
curl --request POST \
--url https://garu.com.br/api/subscription-prices \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"productId": "<string>",
"name": "<string>",
"amount": 123,
"billingInterval": "<string>",
"trialDays": 123,
"isActive": true
}
'import requests
url = "https://garu.com.br/api/subscription-prices"
payload = {
"productId": "<string>",
"name": "<string>",
"amount": 123,
"billingInterval": "<string>",
"trialDays": 123,
"isActive": True
}
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({
productId: '<string>',
name: '<string>',
amount: 123,
billingInterval: '<string>',
trialDays: 123,
isActive: true
})
};
fetch('https://garu.com.br/api/subscription-prices', 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://garu.com.br/api/subscription-prices",
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([
'productId' => '<string>',
'name' => '<string>',
'amount' => 123,
'billingInterval' => '<string>',
'trialDays' => 123,
'isActive' => true
]),
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://garu.com.br/api/subscription-prices"
payload := strings.NewReader("{\n \"productId\": \"<string>\",\n \"name\": \"<string>\",\n \"amount\": 123,\n \"billingInterval\": \"<string>\",\n \"trialDays\": 123,\n \"isActive\": true\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://garu.com.br/api/subscription-prices")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"productId\": \"<string>\",\n \"name\": \"<string>\",\n \"amount\": 123,\n \"billingInterval\": \"<string>\",\n \"trialDays\": 123,\n \"isActive\": true\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://garu.com.br/api/subscription-prices")
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 \"productId\": \"<string>\",\n \"name\": \"<string>\",\n \"amount\": 123,\n \"billingInterval\": \"<string>\",\n \"trialDays\": 123,\n \"isActive\": true\n}"
response = http.request(request)
puts response.read_body{
"id": 123,
"uuid": "<string>",
"productId": "<string>",
"name": "<string>",
"amount": 123,
"billingInterval": "<string>",
"trialDays": 123,
"isActive": true
}Preços de Assinatura
Criar Preço de Assinatura
Crie planos de preço para produtos de assinatura
POST
/
api
/
subscription-prices
Criar Preço de Assinatura
curl --request POST \
--url https://garu.com.br/api/subscription-prices \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"productId": "<string>",
"name": "<string>",
"amount": 123,
"billingInterval": "<string>",
"trialDays": 123,
"isActive": true
}
'import requests
url = "https://garu.com.br/api/subscription-prices"
payload = {
"productId": "<string>",
"name": "<string>",
"amount": 123,
"billingInterval": "<string>",
"trialDays": 123,
"isActive": True
}
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({
productId: '<string>',
name: '<string>',
amount: 123,
billingInterval: '<string>',
trialDays: 123,
isActive: true
})
};
fetch('https://garu.com.br/api/subscription-prices', 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://garu.com.br/api/subscription-prices",
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([
'productId' => '<string>',
'name' => '<string>',
'amount' => 123,
'billingInterval' => '<string>',
'trialDays' => 123,
'isActive' => true
]),
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://garu.com.br/api/subscription-prices"
payload := strings.NewReader("{\n \"productId\": \"<string>\",\n \"name\": \"<string>\",\n \"amount\": 123,\n \"billingInterval\": \"<string>\",\n \"trialDays\": 123,\n \"isActive\": true\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://garu.com.br/api/subscription-prices")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"productId\": \"<string>\",\n \"name\": \"<string>\",\n \"amount\": 123,\n \"billingInterval\": \"<string>\",\n \"trialDays\": 123,\n \"isActive\": true\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://garu.com.br/api/subscription-prices")
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 \"productId\": \"<string>\",\n \"name\": \"<string>\",\n \"amount\": 123,\n \"billingInterval\": \"<string>\",\n \"trialDays\": 123,\n \"isActive\": true\n}"
response = http.request(request)
puts response.read_body{
"id": 123,
"uuid": "<string>",
"productId": "<string>",
"name": "<string>",
"amount": 123,
"billingInterval": "<string>",
"trialDays": 123,
"isActive": true
}Visão Geral
Crie um preço de assinatura para definir quanto e com que frequência os clientes serão cobrados. Um produto pode ter múltiplos preços (ex: mensal, anual).Parâmetros
Campos Obrigatórios
string
required
UUID do produto pai (ex:
prod_abc123xyz). O produto deve ser do tipo subscription.string
required
Nome do plano exibido ao cliente (ex: “Plano Mensal”).
number
required
Valor em Reais (ex: 49.90).
string
required
Intervalo de cobrança:
daily, weekly, monthly, annually.Campos Opcionais
integer
default:"0"
Dias de teste gratuito antes da primeira cobrança.
boolean
default:"true"
Se o plano está disponível para novos assinantes.
A moeda padrão é
BRL (Real Brasileiro). Não é necessário enviar o campo currency na requisição.Exemplo de Requisição
curl -X POST https://garu.com.br/api/subscription-prices \
-H "Authorization: Bearer sk_test_sua_chave" \
-H "Content-Type: application/json" \
-d '{
"productId": "prod_abc123xyz",
"name": "Plano Mensal",
"amount": 49.90,
"billingInterval": "monthly",
"trialDays": 7
}'
const response = await fetch('https://garu.com.br/api/subscription-prices', {
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.GARU_API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
productId: 'prod_abc123xyz',
name: 'Plano Mensal',
amount: 49.90,
billingInterval: 'monthly',
trialDays: 7
})
});
const preco = await response.json();
console.log(`Checkout: https://garu.com.br/pay/prod_abc123xyz?priceId=${preco.uuid}`);
import requests
import os
response = requests.post(
'https://garu.com.br/api/subscription-prices',
headers={
'Authorization': f'Bearer {os.environ["GARU_API_KEY"]}',
'Content-Type': 'application/json'
},
json={
'productId': 'prod_abc123xyz',
'name': 'Plano Mensal',
'amount': 49.90,
'billingInterval': 'monthly',
'trialDays': 7
}
)
preco = response.json()
print(f"Preço criado: {preco['uuid']}")
Resposta de Sucesso
number
ID interno do preço.
string
Identificador único usado no link de checkout.
string
UUID do produto pai.
string
Nome do plano.
number
Valor em Reais.
string
Intervalo de cobrança.
number
Dias de teste gratuito.
boolean
Se o plano está ativo.
Exemplo de Resposta (201 Created)
{
"id": "price_def456uvw",
"productId": "prod_abc123xyz",
"sellerId": 1,
"name": "Plano Mensal",
"amount": 49.90,
"currency": "BRL",
"billingInterval": "monthly",
"trialDays": 7,
"isActive": true,
"createdAt": "2024-01-15T10:35:00.000Z",
"updatedAt": "2024-01-15T10:35:00.000Z"
}
Intervalos de Cobrança
| Intervalo | Valor | Descrição |
|---|---|---|
| Diário | daily | Cobrança a cada dia |
| Semanal | weekly | Cobrança a cada 7 dias |
| Mensal | monthly | Cobrança no mesmo dia todo mês |
| Anual | annually | Cobrança uma vez por ano |
Link de Pagamento
Após criar o preço de assinatura, você pode gerar o link de pagamento combinando o UUID do produto com o ID do preço.Formato do Link
https://garu.com.br/pay/{product_uuid}?priceId={price_id}
| Parâmetro | Origem | Descrição |
|---|---|---|
product_uuid | Resposta de POST /api/v1/products | UUID do produto (campo uuid) |
price_id | Resposta de POST /api/subscription-prices | ID do preço (campo id) |
Exemplo
Considerando:- Produto criado com
uuid:c69c63d2-4207-4613-ad69-28e7e902544b - Preço criado com
id:price_gNgQVRrG5goab0Ql
https://garu.com.br/pay/c69c63d2-4207-4613-ad69-28e7e902544b?priceId=price_gNgQVRrG5goab0Ql
Exemplo Completo em Código
// 1. Criar produto de assinatura
const produto = await fetch('https://garu.com.br/api/v1/products', {
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.GARU_API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
name: 'Plano Premium',
isSubscription: true
})
}).then(r => r.json());
// 2. Criar preço de assinatura
const preco = await fetch('https://garu.com.br/api/subscription-prices', {
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.GARU_API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
productId: produto.uuid,
name: 'Mensal',
amount: 49.90,
billingInterval: 'monthly'
})
}).then(r => r.json());
// 3. Gerar link de pagamento
const linkPagamento = `https://garu.com.br/pay/${produto.uuid}?priceId=${preco.id}`;
console.log(linkPagamento);
// https://garu.com.br/pay/c69c63d2-4207-4613-ad69-28e7e902544b?priceId=price_gNgQVRrG5goab0Ql
Salve o
uuid do produto e o id do preço no seu banco de dados para poder gerar links de pagamento a qualquer momento.Múltiplos Planos
Crie diferentes planos para o mesmo produto:// Plano Básico - Mensal
await criarPreco({
productId: 'prod_abc123xyz',
name: 'Básico Mensal',
amount: 29.90,
billingInterval: 'monthly'
});
// Plano Pro - Mensal
await criarPreco({
productId: 'prod_abc123xyz',
name: 'Pro Mensal',
amount: 49.90,
billingInterval: 'monthly',
trialDays: 7
});
// Plano Pro - Anual (com desconto de 20%)
await criarPreco({
productId: 'prod_abc123xyz',
name: 'Pro Anual',
amount: 479.00, // 12 meses com 20% de desconto
billingInterval: 'annually',
trialDays: 14
});
Próximos Passos
Listar Preços
Consulte todos os preços cadastrados
Listar Assinaturas
Consulte as assinaturas ativas
Was this page helpful?