mirror of
https://github.com/wasp-lang/open-saas.git
synced 2025-10-10 23:24:27 +02:00
add checks for no lemon squeezy customer portal url (#270)
This commit is contained in:
@@ -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,
|
||||||
|
@@ -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);
|
||||||
}
|
}
|
||||||
|
@@ -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;
|
||||||
}
|
}
|
||||||
|
@@ -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');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user