mirror of
https://github.com/rowboatlabs/rowboat.git
synced 2026-05-16 18:25:17 +02:00
Refactor billing information structure and API integration
This commit is contained in:
parent
27e8fe0f22
commit
3674eb77ad
4 changed files with 16 additions and 20 deletions
|
|
@ -3,7 +3,6 @@ import { useState, useEffect, useCallback } from 'react'
|
|||
interface BillingInfo {
|
||||
subscriptionPlan: string
|
||||
subscriptionStatus: string
|
||||
trialUsed: boolean
|
||||
sanctionedCredits: number
|
||||
availableCredits: number
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,38 +1,39 @@
|
|||
import { getAccessToken } from '../models/gateway.js';
|
||||
import { ROWBOAT_BILLING_BASE_URL } from '../config/env.js';
|
||||
import { API_URL } from '../config/env.js';
|
||||
|
||||
export interface BillingInfo {
|
||||
subscriptionPlan: string | null;
|
||||
subscriptionStatus: string | null;
|
||||
trialUsed: boolean;
|
||||
sanctionedCredits: number;
|
||||
availableCredits: number;
|
||||
}
|
||||
|
||||
export async function getBillingInfo(): Promise<BillingInfo> {
|
||||
const accessToken = await getAccessToken();
|
||||
const response = await fetch(`${ROWBOAT_BILLING_BASE_URL}/me`, {
|
||||
const response = await fetch(`${API_URL}/v1/me`, {
|
||||
headers: { Authorization: `Bearer ${accessToken}` },
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error(`Billing API failed: ${response.status}`);
|
||||
}
|
||||
const body = await response.json() as {
|
||||
customer: {
|
||||
subscriptionPlan: string | null;
|
||||
subscriptionStatus: string | null;
|
||||
trialUsed: boolean;
|
||||
user: {
|
||||
id: string;
|
||||
email: string;
|
||||
};
|
||||
usage: {
|
||||
sanctionedCredits: number;
|
||||
availableCredits: number;
|
||||
billing: {
|
||||
plan: string | null;
|
||||
status: string | null;
|
||||
usage: {
|
||||
sanctionedCredits: number;
|
||||
availableCredits: number;
|
||||
};
|
||||
};
|
||||
};
|
||||
return {
|
||||
subscriptionPlan: body.customer.subscriptionPlan,
|
||||
subscriptionStatus: body.customer.subscriptionStatus,
|
||||
trialUsed: body.customer.trialUsed,
|
||||
sanctionedCredits: body.usage.sanctionedCredits,
|
||||
availableCredits: body.usage.availableCredits,
|
||||
subscriptionPlan: body.billing.plan,
|
||||
subscriptionStatus: body.billing.status,
|
||||
sanctionedCredits: body.billing.usage.sanctionedCredits,
|
||||
availableCredits: body.billing.usage.availableCredits,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,3 @@ export const API_URL =
|
|||
|
||||
export const SUPABASE_PROJECT_URL =
|
||||
process.env.SUPABASE_PROJECT_URL || 'http://127.0.0.1:54321';
|
||||
|
||||
export const ROWBOAT_BILLING_BASE_URL =
|
||||
process.env.ROWBOAT_BILLING_BASE_URL || 'https://billing.staging.x.rowboatlabs.com';
|
||||
|
|
|
|||
|
|
@ -522,7 +522,6 @@ const ipcSchemas = {
|
|||
res: z.object({
|
||||
subscriptionPlan: z.string().nullable(),
|
||||
subscriptionStatus: z.string().nullable(),
|
||||
trialUsed: z.boolean(),
|
||||
sanctionedCredits: z.number(),
|
||||
availableCredits: z.number(),
|
||||
}),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue