cURL
curl --request GET \ --url https://garu.com.br/api/subscriptions/{id} \ --header 'Authorization: Bearer <token>'
{ "id": 123, "uuid": "<string>", "status": "<string>", "currentPeriodStart": "<string>", "currentPeriodEnd": "<string>", "trialEndsAt": {}, "cancelAt": {}, "cancelAtPeriodEnd": true, "nextPaymentAt": "<string>", "lastPaymentAt": "<string>", "failedPaymentCount": 123, "subscriptionPrice": {}, "customer": {}, "paymentMethod": {} }
Consulte os detalhes completos de uma assinatura específica
curl -X GET https://garu.com.br/api/subscriptions/100 \ -H "Authorization: Bearer sk_test_sua_chave"
pending
active
pending_cancellation
canceled
failed
{ "id": 100, "uuid": "sub_xyz789", "customerId": 50, "subscriptionPriceId": 456, "sellerId": 1, "status": "active", "currentPeriodStart": "2024-02-15T00:00:00.000Z", "currentPeriodEnd": "2024-03-15T00:00:00.000Z", "trialEndsAt": null, "cancelAt": null, "cancelledAt": null, "cancelAtPeriodEnd": false, "paymentMethodId": 789, "lastPaymentAt": "2024-02-15T10:00:00.000Z", "nextPaymentAt": "2024-03-15T10:00:00.000Z", "failedPaymentCount": 0, "createdAt": "2024-01-15T10:30:00.000Z", "updatedAt": "2024-02-15T10:00:00.000Z", "subscriptionPrice": { "id": 456, "uuid": "price_def456uvw", "name": "Plano Mensal", "unitAmount": 49.90, "billingInterval": "monthly", "product": { "id": 123, "name": "Premium Membership" } }, "customer": { "id": 50, "name": "João Silva", "email": "joao@example.com" }, "paymentMethod": { "id": 789, "cardLast4": "4242", "cardBrand": "visa" } }
async function verificarStatusAssinatura(subscriptionId) { const response = await fetch( `https://garu.com.br/api/subscriptions/${subscriptionId}`, { headers: { 'Authorization': `Bearer ${process.env.GARU_API_KEY}` } } ); const subscription = await response.json(); // Verificar se está ativa const isActive = subscription.status === 'active'; // Verificar se está em período de teste const inTrial = subscription.trialEndsAt && new Date(subscription.trialEndsAt) > new Date(); // Verificar se tem cancelamento agendado const willCancel = subscription.cancelAtPeriodEnd || subscription.status === 'pending_cancellation'; return { isActive, inTrial, willCancel, nextPayment: subscription.nextPaymentAt, plan: subscription.subscriptionPrice.name, customer: subscription.customer }; } // Uso const status = await verificarStatusAssinatura(100); if (status.isActive) { console.log(`Assinatura ativa: ${status.plan}`); console.log(`Próxima cobrança: ${status.nextPayment}`); }
Was this page helpful?