From 3fa35b1d9c9069f161c3e5e4eb041b1ca98c6e98 Mon Sep 17 00:00:00 2001 From: vincanger <70215737+vincanger@users.noreply.github.com> Date: Mon, 16 Sep 2024 12:02:48 +0200 Subject: [PATCH] add checks for no lemon squeezy customer portal url (#270) --- template/app/src/payment/lemonSqueezy/paymentProcessor.ts | 8 +++----- template/app/src/payment/operations.ts | 3 +-- template/app/src/payment/paymentProcessor.ts | 2 +- template/app/src/user/AccountPage.tsx | 2 ++ 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/template/app/src/payment/lemonSqueezy/paymentProcessor.ts b/template/app/src/payment/lemonSqueezy/paymentProcessor.ts index 9e481f18..2d4ac646 100644 --- a/template/app/src/payment/lemonSqueezy/paymentProcessor.ts +++ b/template/app/src/payment/lemonSqueezy/paymentProcessor.ts @@ -29,11 +29,9 @@ export const lemonSqueezyPaymentProcessor: PaymentProcessor = { lemonSqueezyCustomerPortalUrl: true, }, }); - if (!user.lemonSqueezyCustomerPortalUrl) { - console.log(`User with ID ${args.userId} does not have a LemonSqueezy customer portal URL`); - } else { - return user.lemonSqueezyCustomerPortalUrl; - } + // Note that Lemon Squeezy assigns a unique URL to each user after the first successful payment. + // This is handled in the Lemon Squeezy webhook. + return user.lemonSqueezyCustomerPortalUrl; }, webhook: lemonSqueezyWebhook, webhookMiddlewareConfigFn: lemonSqueezyMiddlewareConfigFn, diff --git a/template/app/src/payment/operations.ts b/template/app/src/payment/operations.ts index fb543554..86b833ca 100644 --- a/template/app/src/payment/operations.ts +++ b/template/app/src/payment/operations.ts @@ -1,5 +1,4 @@ import type { GenerateCheckoutSession, GetCustomerPortalUrl } from 'wasp/server/operations'; -import type { FetchCustomerPortalUrlArgs } from './paymentProcessor'; import { PaymentPlanId, paymentPlans } from '../payment/plans'; import { paymentProcessor } from './paymentProcessor'; import { HttpError } from 'wasp/server'; @@ -39,7 +38,7 @@ export const generateCheckoutSession: GenerateCheckoutSession = async (_args, context) => { +export const getCustomerPortalUrl: GetCustomerPortalUrl = async (_args, context) => { if (!context.user) { throw new HttpError(401); } diff --git a/template/app/src/payment/paymentProcessor.ts b/template/app/src/payment/paymentProcessor.ts index d4a1a12f..9049e721 100644 --- a/template/app/src/payment/paymentProcessor.ts +++ b/template/app/src/payment/paymentProcessor.ts @@ -19,7 +19,7 @@ export interface FetchCustomerPortalUrlArgs { export interface PaymentProcessor { id: 'stripe' | 'lemonsqueezy'; createCheckoutSession: (args: CreateCheckoutSessionArgs) => Promise<{ session: { id: string; url: string }; }>; - fetchCustomerPortalUrl: (args: FetchCustomerPortalUrlArgs) => Promise; + fetchCustomerPortalUrl: (args: FetchCustomerPortalUrlArgs) => Promise; webhook: PaymentsWebhook; webhookMiddlewareConfigFn: MiddlewareConfigFn; } diff --git a/template/app/src/user/AccountPage.tsx b/template/app/src/user/AccountPage.tsx index 0777ea2f..85e9d75c 100644 --- a/template/app/src/user/AccountPage.tsx +++ b/template/app/src/user/AccountPage.tsx @@ -124,6 +124,8 @@ function CustomerPortalButton() { if (customerPortalUrl) { window.open(customerPortalUrl, '_blank'); + } else { + console.error('Customer portal URL is not available'); } };