Add subscription product admin - #21
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| </div> | ||
| <div className="grid gap-4 sm:grid-cols-3"> | ||
| <div className="grid gap-2"> | ||
| <FieldLabel htmlFor={`${idPrefix}-price`}>Price (USD)</FieldLabel> |
There was a problem hiding this comment.
🟠 High subscriptions/subscription-admin-client.tsx:90
Editing an existing non-USD product labels its price as USD, so an administrator can enter the wrong amount for products such as EUR subscriptions. The label is hard-coded even though product.currency contains the Stripe currency preserved by updates; render that currency instead.
| <FieldLabel htmlFor={`${idPrefix}-price`}>Price (USD)</FieldLabel> | |
| <FieldLabel htmlFor={`${idPrefix}-price`}>Price ({product?.currency?.toUpperCase() ?? 'USD'})</FieldLabel> |
🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
In file @apps/builder-egghead/src/app/admin/subscriptions/subscription-admin-client.tsx around line 90:
Editing an existing non-USD product labels its price as USD, so an administrator can enter the wrong amount for products such as EUR subscriptions. The label is hard-coded even though `product.currency` contains the Stripe currency preserved by updates; render that currency instead.
| } | ||
| throw error | ||
| } | ||
| if (!updatedProduct?.price) { |
There was a problem hiding this comment.
🟠 High lib/subscription-products.ts:363
An unsuccessful update after line 332 leaves a previously inactive product active in both the local database and Stripe. The rollback only catches errors from courseBuilderAdapter.updateProduct, so failures from the missing-price check, getProductCommerceRecords, the price update, or final setSubscriptionProductActive skip restoration; wrap the entire post-activation workflow in one rollback path.
🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
In file @apps/builder-egghead/src/lib/subscription-products.ts around line 363:
An unsuccessful update after line 332 leaves a previously inactive product active in both the local database and Stripe. The rollback only catches errors from `courseBuilderAdapter.updateProduct`, so failures from the missing-`price` check, `getProductCommerceRecords`, the price update, or final `setSubscriptionProductActive` skip restoration; wrap the entire post-activation workflow in one rollback path.
| const paymentsAdapter = stripeProvider.options.paymentsAdapter | ||
| const status = input.active ? 1 : 0 | ||
|
|
||
| await paymentsAdapter.updatePrice(input.records.merchantPrice.identifier, { |
There was a problem hiding this comment.
🟠 High lib/subscription-products.ts:124
prepareProductForAdapterUpdate can leave an inactive product partially activated when any later setSubscriptionProductActive write fails: updatePrice may succeed before updateProduct or a database update throws, leaving Stripe and local statuses inconsistent. Because this call runs before updateSubscriptionProduct's try block, the caller cannot restore the previous state; add compensation for partial Stripe/database writes and include the preparation step in the failure-handling path.
🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
In file @apps/builder-egghead/src/lib/subscription-products.ts around line 124:
`prepareProductForAdapterUpdate` can leave an inactive product partially activated when any later `setSubscriptionProductActive` write fails: `updatePrice` may succeed before `updateProduct` or a database update throws, leaving Stripe and local statuses inconsistent. Because this call runs before `updateSubscriptionProduct`'s `try` block, the caller cannot restore the previous state; add compensation for partial Stripe/database writes and include the preparation step in the failure-handling path.
Summary
Stack
Verification
pnpm checkNote
Add subscription product admin at
/admin/subscriptionswith Stripe synccreateSubscriptionProductActionandupdateSubscriptionProductActionparse form data via Zod schema, call the workflows in subscription-products.ts, and return structured success/error states.getSubscriptionProductAdminDataassembles the admin list with sync status, interval, price, currency, and write capability per product.createDatabase()factory in index.ts: picks a shared mysql2 pool for local Docker and Planetscale serverless otherwise.closeBuilderDatabaseadded for graceful shutdown.assertBuilderCommerceWritesAllowedandassertStripeTestMode.DATABASE_URL;updateSubscriptionProductrolls back active state on adapter failure.📊 Macroscope summarized 95722f1. 11 files reviewed, 4 issues evaluated, 0 issues filtered, 3 comments posted
🗂️ Filtered Issues