martmull
2024-08-23 16:01:40 +02:00
committed by GitHub
parent ee6180a76f
commit f9af25b57e
8 changed files with 64 additions and 25 deletions

View File

@ -43,7 +43,7 @@ export class BillingResolver {
@Args() { returnUrlPath }: BillingSessionInput,
) {
return {
url: await this.billingPortalWorkspaceService.computeBillingPortalSessionURL(
url: await this.billingPortalWorkspaceService.computeBillingPortalSessionURLOrThrow(
user.defaultWorkspaceId,
returnUrlPath,
),

View File

@ -65,18 +65,22 @@ export class BillingPortalWorkspaceService {
return session.url;
}
async computeBillingPortalSessionURL(
async computeBillingPortalSessionURLOrThrow(
workspaceId: string,
returnUrlPath?: string,
) {
const currentSubscriptionItem =
const currentSubscription =
await this.billingSubscriptionService.getCurrentBillingSubscriptionOrThrow(
{
workspaceId,
},
);
const stripeCustomerId = currentSubscriptionItem.stripeCustomerId;
if (!currentSubscription) {
throw new Error('Error: missing subscription');
}
const stripeCustomerId = currentSubscription.stripeCustomerId;
if (!stripeCustomerId) {
throw new Error('Error: missing stripeCustomerId');