Eventos da Assinatura
curl --request GET \
--url https://garu.com.br/api/subscriptions/{id}/events \
--header 'Authorization: Bearer <token>'import requests
url = "https://garu.com.br/api/subscriptions/{id}/events"
headers = {"Authorization": "Bearer <token>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {Authorization: 'Bearer <token>'}};
fetch('https://garu.com.br/api/subscriptions/{id}/events', 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/subscriptions/{id}/events",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://garu.com.br/api/subscriptions/{id}/events"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://garu.com.br/api/subscriptions/{id}/events")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://garu.com.br/api/subscriptions/{id}/events")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_body{
"id": 123,
"subscriptionId": 123,
"eventType": "<string>",
"eventData": {},
"createdAt": "<string>"
}Assinaturas
Eventos da Assinatura
Consulte o histórico de eventos e billing history de uma assinatura
GET
/
api
/
subscriptions
/
{id}
/
events
Eventos da Assinatura
curl --request GET \
--url https://garu.com.br/api/subscriptions/{id}/events \
--header 'Authorization: Bearer <token>'import requests
url = "https://garu.com.br/api/subscriptions/{id}/events"
headers = {"Authorization": "Bearer <token>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {Authorization: 'Bearer <token>'}};
fetch('https://garu.com.br/api/subscriptions/{id}/events', 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/subscriptions/{id}/events",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://garu.com.br/api/subscriptions/{id}/events"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://garu.com.br/api/subscriptions/{id}/events")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://garu.com.br/api/subscriptions/{id}/events")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_body{
"id": 123,
"subscriptionId": 123,
"eventType": "<string>",
"eventData": {},
"createdAt": "<string>"
}Visão Geral
Consulte o histórico completo de eventos de uma assinatura, incluindo pagamentos, mudanças de status, períodos de teste e cancelamentos.Exemplo de Requisição
curl -X GET https://garu.com.br/api/subscriptions/100/events \
-H "Authorization: Bearer sk_test_sua_chave"
const response = await fetch(
'https://garu.com.br/api/subscriptions/100/events',
{
headers: {
'Authorization': `Bearer ${process.env.GARU_API_KEY}`
}
}
);
const events = await response.json();
events.forEach(event => {
console.log(`${event.createdAt}: ${event.eventType}`);
});
import requests
import os
url = "https://garu.com.br/api/subscriptions/100/events"
headers = {
"Authorization": f"Bearer {os.environ['GARU_API_KEY']}"
}
response = requests.get(url, headers=headers)
events = response.json()
for event in events:
print(f"{event['createdAt']}: {event['eventType']}")
Resposta de Sucesso (200 OK)
[
{
"id": 789,
"subscriptionId": 100,
"eventType": "payment_success",
"eventData": {
"amount": 4990,
"transactionId": "tx_abc123",
"paidAt": "2024-02-15T10:00:00.000Z"
},
"createdAt": "2024-02-15T10:00:00.000Z"
},
{
"id": 788,
"subscriptionId": 100,
"eventType": "subscription.activated",
"eventData": {},
"createdAt": "2024-01-15T10:30:00.000Z"
},
{
"id": 787,
"subscriptionId": 100,
"eventType": "subscription.created",
"eventData": {
"priceId": 456,
"trialDays": 7
},
"createdAt": "2024-01-08T10:30:00.000Z"
}
]
Tipos de Evento
| Tipo | Descrição |
|---|---|
subscription.created | Assinatura criada |
subscription.activated | Assinatura ativada após primeiro pagamento |
trial_started | Período de teste iniciado |
trial_ended | Período de teste encerrado |
payment_success | Pagamento recorrente bem-sucedido |
payment_failed | Tentativa de pagamento falhou |
subscription.paused | Assinatura pausada |
subscription.resumed | Assinatura retomada após pausa |
subscription.canceled | Assinatura cancelada |
subscription.expired | Assinatura expirou |
Campos do Evento
number
ID único do evento.
number
ID da assinatura relacionada.
string
Tipo do evento (veja tabela acima).
object
Dados adicionais específicos do evento.
string
Data e hora do evento (ISO 8601).
Exemplo: Construindo um Billing History
async function getBillingHistory(subscriptionId) {
const response = await fetch(
`https://garu.com.br/api/subscriptions/${subscriptionId}/events`,
{
headers: {
'Authorization': `Bearer ${process.env.GARU_API_KEY}`
}
}
);
const events = await response.json();
// Filtrar apenas eventos de pagamento
const payments = events.filter(e =>
e.eventType === 'payment_success' || e.eventType === 'payment_failed'
);
return payments.map(payment => ({
date: payment.createdAt,
status: payment.eventType === 'payment_success' ? 'Pago' : 'Falhou',
amount: payment.eventData.amount,
transactionId: payment.eventData.transactionId
}));
}
// Uso
const history = await getBillingHistory(100);
console.log('Histórico de Pagamentos:');
history.forEach(p => {
console.log(`${p.date}: R$ ${p.amount.toFixed(2)} - ${p.status}`);
});
Próximos Passos
Detalhes da Assinatura
Consulte os detalhes completos da assinatura
Webhooks
Receba eventos em tempo real
Was this page helpful?