Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve logic for no lemon squeezy customer portal url #270

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed this to null since that's what prisma returns if the user hasn't had a customer portal url assigned to it yet by Lemon Squeezy

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