Skip to content

Commit

Permalink
add checks for no lemon squeezy customer portal url (#270)
Browse files Browse the repository at this point in the history
  • Loading branch information
vincanger committed Sep 16, 2024
1 parent 7c73d21 commit 3fa35b1
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
8 changes: 3 additions & 5 deletions template/app/src/payment/lemonSqueezy/paymentProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions template/app/src/payment/operations.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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) {
throw new HttpError(401);
}
Expand Down
2 changes: 1 addition & 1 deletion template/app/src/payment/paymentProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string | undefined>;
fetchCustomerPortalUrl: (args: FetchCustomerPortalUrlArgs) => Promise<string | null>;
webhook: PaymentsWebhook;
webhookMiddlewareConfigFn: MiddlewareConfigFn;
}
Expand Down
2 changes: 2 additions & 0 deletions template/app/src/user/AccountPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ function CustomerPortalButton() {

if (customerPortalUrl) {
window.open(customerPortalUrl, '_blank');
} else {
console.error('Customer portal URL is not available');
}
};

Expand Down

0 comments on commit 3fa35b1

Please sign in to comment.