add checks for no lemon squeezy customer portal url (#270)

This commit is contained in:
vincanger
2024-09-16 12:02:48 +02:00
committed by GitHub
parent 7c73d21bda
commit 3fa35b1d9c
4 changed files with 7 additions and 8 deletions

View File

@@ -29,11 +29,9 @@ export const lemonSqueezyPaymentProcessor: PaymentProcessor = {
lemonSqueezyCustomerPortalUrl: true, lemonSqueezyCustomerPortalUrl: true,
}, },
}); });
if (!user.lemonSqueezyCustomerPortalUrl) { // Note that Lemon Squeezy assigns a unique URL to each user after the first successful payment.
console.log(`User with ID ${args.userId} does not have a LemonSqueezy customer portal URL`); // This is handled in the Lemon Squeezy webhook.
} else { return user.lemonSqueezyCustomerPortalUrl;
return user.lemonSqueezyCustomerPortalUrl;
}
}, },
webhook: lemonSqueezyWebhook, webhook: lemonSqueezyWebhook,
webhookMiddlewareConfigFn: lemonSqueezyMiddlewareConfigFn, webhookMiddlewareConfigFn: lemonSqueezyMiddlewareConfigFn,

View File

@@ -1,5 +1,4 @@
import type { GenerateCheckoutSession, GetCustomerPortalUrl } from 'wasp/server/operations'; import type { GenerateCheckoutSession, GetCustomerPortalUrl } from 'wasp/server/operations';
import type { FetchCustomerPortalUrlArgs } from './paymentProcessor';
import { PaymentPlanId, paymentPlans } from '../payment/plans'; import { PaymentPlanId, paymentPlans } from '../payment/plans';
import { paymentProcessor } from './paymentProcessor'; import { paymentProcessor } from './paymentProcessor';
import { HttpError } from 'wasp/server'; import { HttpError } from 'wasp/server';
@@ -39,7 +38,7 @@ export const generateCheckoutSession: GenerateCheckoutSession<PaymentPlanId, Che
}; };
}; };
export const getCustomerPortalUrl: GetCustomerPortalUrl<void, string | undefined> = async (_args, context) => { export const getCustomerPortalUrl: GetCustomerPortalUrl<void, string | null> = async (_args, context) => {
if (!context.user) { if (!context.user) {
throw new HttpError(401); throw new HttpError(401);
} }

View File

@@ -19,7 +19,7 @@ export interface FetchCustomerPortalUrlArgs {
export interface PaymentProcessor { export interface PaymentProcessor {
id: 'stripe' | 'lemonsqueezy'; id: 'stripe' | 'lemonsqueezy';
createCheckoutSession: (args: CreateCheckoutSessionArgs) => Promise<{ session: { id: string; url: string }; }>; createCheckoutSession: (args: CreateCheckoutSessionArgs) => Promise<{ session: { id: string; url: string }; }>;
fetchCustomerPortalUrl: (args: FetchCustomerPortalUrlArgs) => Promise<string | undefined>; fetchCustomerPortalUrl: (args: FetchCustomerPortalUrlArgs) => Promise<string | null>;
webhook: PaymentsWebhook; webhook: PaymentsWebhook;
webhookMiddlewareConfigFn: MiddlewareConfigFn; webhookMiddlewareConfigFn: MiddlewareConfigFn;
} }

View File

@@ -124,6 +124,8 @@ function CustomerPortalButton() {
if (customerPortalUrl) { if (customerPortalUrl) {
window.open(customerPortalUrl, '_blank'); window.open(customerPortalUrl, '_blank');
} else {
console.error('Customer portal URL is not available');
} }
}; };