-
Notifications
You must be signed in to change notification settings - Fork 501
Rename offer to product, offer group to product catalog #914
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
Changes from all commits
c151039
e162ec4
8d167d8
5fe50f9
ccc90ea
c4b860a
b2da2f0
4790eb3
e72849e
6548cd4
687be84
c9a0726
f81279e
5c7f3d9
3e3b2a8
5bf4ede
4be51b4
e6e20ec
4884446
39f9b6d
73bea8c
eb95114
c50e96c
3d095e6
680c971
7e88c9f
9199a61
fb7ca6a
74e4a98
090a661
7e191fd
e3227bc
0cd66a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| -- AlterTable | ||
| ALTER TABLE "OneTimePurchase" | ||
| RENAME COLUMN "offer" TO "product"; | ||
|
|
||
| -- AlterTable | ||
| ALTER TABLE "OneTimePurchase" | ||
| RENAME COLUMN "offerId" TO "productId"; | ||
|
|
||
| -- AlterTable | ||
| ALTER TABLE "Subscription" | ||
| RENAME COLUMN "offer" TO "product"; | ||
|
|
||
| -- AlterTable | ||
| ALTER TABLE "Subscription" | ||
| RENAME COLUMN "offerId" TO "productId"; |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -53,7 +53,7 @@ async function processStripeWebhookEvent(event: Stripe.Event): Promise<void> { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw new StackAssertionError("Tenancy not found", { event }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const prisma = await getPrismaClientForTenancy(tenancy); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const offer = JSON.parse(metadata.offer || "{}"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const product = JSON.parse(metadata.product || "{}"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Stripe webhook handlers will fail to process existing payment intents and subscriptions that still have the old metadata field names ( View Details📝 Patch Detailsdiff --git a/apps/backend/src/app/api/latest/integrations/stripe/webhooks/route.tsx b/apps/backend/src/app/api/latest/integrations/stripe/webhooks/route.tsx
index 1fba69c1..69a51330 100644
--- a/apps/backend/src/app/api/latest/integrations/stripe/webhooks/route.tsx
+++ b/apps/backend/src/app/api/latest/integrations/stripe/webhooks/route.tsx
@@ -53,7 +53,7 @@ async function processStripeWebhookEvent(event: Stripe.Event): Promise<void> {
throw new StackAssertionError("Tenancy not found", { event });
}
const prisma = await getPrismaClientForTenancy(tenancy);
- const product = JSON.parse(metadata.product || "{}");
+ const product = JSON.parse(metadata.product || metadata.offer || "{}");
const qty = Math.max(1, Number(metadata.purchaseQuantity || 1));
const stripePaymentIntentId = event.data.object.id;
if (!metadata.customerId || !metadata.customerType) {
@@ -73,7 +73,7 @@ async function processStripeWebhookEvent(event: Stripe.Event): Promise<void> {
tenancyId: tenancy.id,
customerId: metadata.customerId,
customerType: typedToUppercase(metadata.customerType),
- productId: metadata.productId || null,
+ productId: metadata.productId || metadata.offerId || null,
priceId: metadata.priceId || null,
stripePaymentIntentId,
product,
@@ -81,7 +81,7 @@ async function processStripeWebhookEvent(event: Stripe.Event): Promise<void> {
creationSource: "PURCHASE_PAGE",
},
update: {
- productId: metadata.productId || null,
+ productId: metadata.productId || metadata.offerId || null,
priceId: metadata.priceId || null,
product,
quantity: qty,
diff --git a/apps/backend/src/lib/stripe.tsx b/apps/backend/src/lib/stripe.tsx
index 3ab57d28..49a01d6d 100644
--- a/apps/backend/src/lib/stripe.tsx
+++ b/apps/backend/src/lib/stripe.tsx
@@ -89,7 +89,7 @@ export async function syncStripeSubscriptions(stripe: Stripe, stripeAccountId: s
},
update: {
status: subscription.status,
- product: JSON.parse(subscription.metadata.product),
+ product: JSON.parse(subscription.metadata.product || subscription.metadata.offer || "{}"),
quantity: item.quantity ?? 1,
currentPeriodEnd: new Date(item.current_period_end * 1000),
currentPeriodStart: new Date(item.current_period_start * 1000),
@@ -100,9 +100,9 @@ export async function syncStripeSubscriptions(stripe: Stripe, stripeAccountId: s
tenancyId: tenancy.id,
customerId,
customerType,
- productId: subscription.metadata.productId,
+ productId: subscription.metadata.productId || subscription.metadata.offerId,
priceId: priceId ?? null,
- product: JSON.parse(subscription.metadata.product),
+ product: JSON.parse(subscription.metadata.product || subscription.metadata.offer || "{}"),
quantity: item.quantity ?? 1,
stripeSubscriptionId: subscription.id,
status: subscription.status,
AnalysisStripe webhook handlers fail for existing payment intents and subscriptions with old metadata field namesWhat fails: Webhook processing crashes for existing Stripe objects that use How to reproduce:
Result:
Expected: Webhook handlers should fall back to old field names ( Files affected:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const qty = Math.max(1, Number(metadata.purchaseQuantity || 1)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const stripePaymentIntentId = event.data.object.id; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+56
to
58
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guard JSON.parse and fix NaN quantity bug. JSON.parse can throw on bad metadata; Math.max(1, Number(...)) returns NaN if the value is non‑numeric, causing Prisma write failures. Apply: - const product = JSON.parse(metadata.product || "{}");
- const qty = Math.max(1, Number(metadata.purchaseQuantity || 1));
+ const product = (() => {
+ try {
+ return metadata.product ? JSON.parse(metadata.product) : null;
+ } catch {
+ return null;
+ }
+ })();
+ const qty = (() => {
+ const n = Number(metadata.purchaseQuantity);
+ return Number.isFinite(n) && n >= 1 ? Math.floor(n) : 1;
+ })();📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!metadata.customerId || !metadata.customerType) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -73,17 +73,17 @@ async function processStripeWebhookEvent(event: Stripe.Event): Promise<void> { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| tenancyId: tenancy.id, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| customerId: metadata.customerId, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| customerType: typedToUppercase(metadata.customerType), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| offerId: metadata.offerId || null, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| productId: metadata.productId || null, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| priceId: metadata.priceId || null, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| stripePaymentIntentId, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| offer, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| product, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| quantity: qty, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| creationSource: "PURCHASE_PAGE", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| update: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| offerId: metadata.offerId || null, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| productId: metadata.productId || null, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| priceId: metadata.priceId || null, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| offer, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| product, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| quantity: qty, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+76
to
87
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick Nullish-coalesce IDs; keep product nullable. Use ?? to avoid treating valid falsy strings as null; align with priceId style. Ensure product can be null. Apply: - productId: metadata.productId || null,
+ productId: metadata.productId ?? null,
...
- product,
+ product,
...
- productId: metadata.productId || null,
+ productId: metadata.productId ?? null,
...
- product,
+ product,Also consider updating adjacent priceId occurrences to use ?? for consistency. 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Unintended Changes Impact Data Integrity Verification
This commit introduces several changes to the
verify-data-integrity.tsscript, which appear unrelated to an 'offer-to-product' rename. These include adding a--recent-firstflag, reducingmaxUsersPerProjectfrom 10000 to 100, and aneslint-disablecomment. ThemaxUsersPerProjectreduction significantly alters the script's behavior, potentially processing fewer users and missing data integrity issues.