-
Notifications
You must be signed in to change notification settings - Fork 4
Feat/auto create products #85
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
base: main
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -55,30 +55,63 @@ export async function handleOnboarding( | |
|
|
||
| let liveSecret: string; | ||
| let testSecret: string; | ||
| let liveProductId: string; | ||
| let testProductId: string; | ||
| try { | ||
| const liveWebhook = await liveClient.webhooks.create({ | ||
| url: `${appUrl}/webhooks/payment/createdCheckout?mode=production`, | ||
| description: "Scrawn live payment webhook", | ||
| filter_types: ["payment.succeeded", "payment.failed"], | ||
| }); | ||
| const [liveWebhook, testWebhook, liveProduct, testProduct] = | ||
| await Promise.all([ | ||
| liveClient.webhooks.create({ | ||
| url: `${appUrl}/webhooks/payment/createdCheckout?mode=production`, | ||
| description: "Scrawn live payment webhook", | ||
| filter_types: ["payment.succeeded", "payment.failed"], | ||
| }), | ||
| testClient.webhooks.create({ | ||
| url: `${appUrl}/webhooks/payment/createdCheckout?mode=test`, | ||
| description: "Scrawn test payment webhook", | ||
| filter_types: ["payment.succeeded", "payment.failed"], | ||
| }), | ||
| liveClient.products.create({ | ||
| name: "Scrawn Billing", | ||
| price: { | ||
| type: "one_time_price", | ||
| currency: validated.currency, | ||
| price: 0, | ||
| pay_what_you_want: true, | ||
| purchasing_power_parity: false, | ||
| discount: 0, | ||
| }, | ||
| tax_category: "saas", | ||
| }), | ||
| testClient.products.create({ | ||
| name: "Scrawn Billing", | ||
| price: { | ||
| type: "one_time_price", | ||
| currency: validated.currency, | ||
| price: 0, | ||
| pay_what_you_want: true, | ||
| purchasing_power_parity: false, | ||
| discount: 0, | ||
| }, | ||
| tax_category: "saas", | ||
| }), | ||
| ]); | ||
|
|
||
| liveSecret = (await liveClient.webhooks.retrieveSecret(liveWebhook.id)) | ||
| .secret; | ||
|
|
||
| const testWebhook = await testClient.webhooks.create({ | ||
| url: `${appUrl}/webhooks/payment/createdCheckout?mode=test`, | ||
| description: "Scrawn test payment webhook", | ||
| filter_types: ["payment.succeeded", "payment.failed"], | ||
| }); | ||
| testSecret = (await testClient.webhooks.retrieveSecret(testWebhook.id)) | ||
| .secret; | ||
| liveProductId = liveProduct.product_id; | ||
| testProductId = testProduct.product_id; | ||
|
Comment on lines
99
to
+104
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.
If Consider using separate try/catch scopes for the |
||
| } catch (error) { | ||
| const errMsg = error instanceof Error ? error.message : String(error); | ||
| Sentry.captureException(error, { | ||
| extra: { context: "dodo webhook registration during onboarding" }, | ||
| extra: { | ||
| context: "dodo webhook/product registration during onboarding", | ||
| }, | ||
| }); | ||
| builder.setError(400, { | ||
| type: "DodoApiError", | ||
| message: `Failed to register webhook with Dodo: ${errMsg}`, | ||
| message: `Failed to configure Dodo resources: ${errMsg}`, | ||
| }); | ||
| reply.code(400); | ||
| return {}; | ||
|
|
@@ -87,8 +120,8 @@ export async function handleOnboarding( | |
| await upsertMetadata({ | ||
| dodo_live_api_key: encrypt(validated.dodoLiveApiKey), | ||
| dodo_test_api_key: encrypt(validated.dodoTestApiKey), | ||
| dodo_live_product_id: validated.dodoLiveProductId, | ||
| dodo_test_product_id: validated.dodoTestProductId, | ||
| dodo_live_product_id: liveProductId, | ||
| dodo_test_product_id: testProductId, | ||
| dodo_live_webhook_secret: encrypt(liveSecret), | ||
| dodo_test_webhook_secret: encrypt(testSecret), | ||
| currency: validated.currency, | ||
|
|
||
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.
The
scrawndotdev/documentationrepo's dashboard-setup.mdx still walks users through manually creating Dodo products and pasting their Product IDs into the onboarding form. With this PR, product creation is automatic and thedodoLiveProductId/dodoTestProductIdfields have been removed from the schema. Any user following the current documentation will look for input fields that no longer exist, making the setup guide actively misleading.