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 {
|
interface BillingInfo {
|
||||||
subscriptionPlan: string
|
subscriptionPlan: string
|
||||||
subscriptionStatus: string
|
subscriptionStatus: string
|
||||||
trialUsed: boolean
|
|
||||||
sanctionedCredits: number
|
sanctionedCredits: number
|
||||||
availableCredits: number
|
availableCredits: number
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,38 +1,39 @@
|
||||||
import { getAccessToken } from '../models/gateway.js';
|
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 {
|
export interface BillingInfo {
|
||||||
subscriptionPlan: string | null;
|
subscriptionPlan: string | null;
|
||||||
subscriptionStatus: string | null;
|
subscriptionStatus: string | null;
|
||||||
trialUsed: boolean;
|
|
||||||
sanctionedCredits: number;
|
sanctionedCredits: number;
|
||||||
availableCredits: number;
|
availableCredits: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getBillingInfo(): Promise<BillingInfo> {
|
export async function getBillingInfo(): Promise<BillingInfo> {
|
||||||
const accessToken = await getAccessToken();
|
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}` },
|
headers: { Authorization: `Bearer ${accessToken}` },
|
||||||
});
|
});
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error(`Billing API failed: ${response.status}`);
|
throw new Error(`Billing API failed: ${response.status}`);
|
||||||
}
|
}
|
||||||
const body = await response.json() as {
|
const body = await response.json() as {
|
||||||
customer: {
|
user: {
|
||||||
subscriptionPlan: string | null;
|
id: string;
|
||||||
subscriptionStatus: string | null;
|
email: string;
|
||||||
trialUsed: boolean;
|
|
||||||
};
|
};
|
||||||
usage: {
|
billing: {
|
||||||
sanctionedCredits: number;
|
plan: string | null;
|
||||||
availableCredits: number;
|
status: string | null;
|
||||||
|
usage: {
|
||||||
|
sanctionedCredits: number;
|
||||||
|
availableCredits: number;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
return {
|
return {
|
||||||
subscriptionPlan: body.customer.subscriptionPlan,
|
subscriptionPlan: body.billing.plan,
|
||||||
subscriptionStatus: body.customer.subscriptionStatus,
|
subscriptionStatus: body.billing.status,
|
||||||
trialUsed: body.customer.trialUsed,
|
sanctionedCredits: body.billing.usage.sanctionedCredits,
|
||||||
sanctionedCredits: body.usage.sanctionedCredits,
|
availableCredits: body.billing.usage.availableCredits,
|
||||||
availableCredits: body.usage.availableCredits,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,3 @@ export const API_URL =
|
||||||
|
|
||||||
export const SUPABASE_PROJECT_URL =
|
export const SUPABASE_PROJECT_URL =
|
||||||
process.env.SUPABASE_PROJECT_URL || 'http://127.0.0.1:54321';
|
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({
|
res: z.object({
|
||||||
subscriptionPlan: z.string().nullable(),
|
subscriptionPlan: z.string().nullable(),
|
||||||
subscriptionStatus: z.string().nullable(),
|
subscriptionStatus: z.string().nullable(),
|
||||||
trialUsed: z.boolean(),
|
|
||||||
sanctionedCredits: z.number(),
|
sanctionedCredits: z.number(),
|
||||||
availableCredits: z.number(),
|
availableCredits: z.number(),
|
||||||
}),
|
}),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue