mirror of
https://github.com/wasp-lang/open-saas.git
synced 2025-06-22 14:51:30 +02:00
PR comments
This commit is contained in:
parent
a537d00809
commit
85ff1af4e0
@ -43,7 +43,7 @@ export const lemonSqueezyWebhook: PaymentsWebhook = async (request, response, co
|
||||
return response.status(200).json({ received: true });
|
||||
} catch (err) {
|
||||
if (err instanceof UnhandledWebhookEventError) {
|
||||
return response.status(200).json({ received: true });
|
||||
return response.status(422).json({ error: err.message });
|
||||
}
|
||||
|
||||
console.error('Webhook error:', err);
|
||||
|
@ -34,6 +34,9 @@ export type SubscriptionData = z.infer<typeof subscriptionDataSchema>;
|
||||
|
||||
export type OrderData = z.infer<typeof orderDataSchema>;
|
||||
|
||||
/**
|
||||
* This schema is based on LemonSqueezyResponse type
|
||||
*/
|
||||
const genericEventSchema = z.object({
|
||||
meta: z.object({
|
||||
event_name: z.string(),
|
||||
@ -44,8 +47,11 @@ const genericEventSchema = z.object({
|
||||
data: z.unknown(),
|
||||
});
|
||||
|
||||
// This is a subtype of Order type from "@lemonsqueezy/lemonsqueezy.js"
|
||||
// specifically Order['data']
|
||||
/**
|
||||
* This schema is based on
|
||||
* @type import('@lemonsqueezy/lemonsqueezy.js').Order
|
||||
* specifically Order['data'].
|
||||
*/
|
||||
const orderDataSchema = z.object({
|
||||
attributes: z.object({
|
||||
customer_id: z.number(),
|
||||
@ -57,8 +63,11 @@ const orderDataSchema = z.object({
|
||||
}),
|
||||
});
|
||||
|
||||
// This is a subtype of Subscription type from "@lemonsqueezy/lemonsqueezy.js"
|
||||
// specifically Subscription['data']
|
||||
/**
|
||||
* This schema is based on
|
||||
* @type import('@lemonsqueezy/lemonsqueezy.js').Subscription
|
||||
* specifically Subscription['data'].
|
||||
*/
|
||||
const subscriptionDataSchema = z.object({
|
||||
attributes: z.object({
|
||||
customer_id: z.number(),
|
||||
|
@ -51,7 +51,7 @@ export const stripeWebhook: PaymentsWebhook = async (request, response, context)
|
||||
return response.json({ received: true }); // Stripe expects a 200 response to acknowledge receipt of the webhook
|
||||
} catch (err) {
|
||||
if (err instanceof UnhandledWebhookEventError) {
|
||||
return response.status(200).json({ received: true });
|
||||
return response.status(422).json({ error: err.message });
|
||||
}
|
||||
|
||||
console.error('Webhook error:', err);
|
||||
@ -211,6 +211,9 @@ const subscriptionItemsSchema = z.object({
|
||||
});
|
||||
|
||||
function extractPriceId(items: SubscsriptionItems): string {
|
||||
if (items.data.length === 0) {
|
||||
throw new HttpError(400, 'No items in stripe event object');
|
||||
}
|
||||
if (items.data.length > 1) {
|
||||
throw new HttpError(400, 'More than one item in stripe event object');
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user