From 490d12b24d2e151be24d7828dda7c3a1c9a38efd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl-Gerhard=20Lindesva=CC=88rd?= Date: Mon, 24 Mar 2025 11:22:20 +0100 Subject: [PATCH] fix(dashboard): correct prices --- .../organization/organization/billing.tsx | 2 +- packages/payments/scripts/create-products.ts | 22 +++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/apps/dashboard/src/app/(app)/[organizationSlug]/[projectId]/settings/organization/organization/billing.tsx b/apps/dashboard/src/app/(app)/[organizationSlug]/[projectId]/settings/organization/organization/billing.tsx index 2aa9e34b..ad24846c 100644 --- a/apps/dashboard/src/app/(app)/[organizationSlug]/[projectId]/settings/organization/organization/billing.tsx +++ b/apps/dashboard/src/app/(app)/[organizationSlug]/[projectId]/settings/organization/organization/billing.tsx @@ -129,7 +129,7 @@ export default function Billing({ organization }: Props) { style: 'currency', currency: price.priceCurrency, minimumFractionDigits: 0, - maximumFractionDigits: 0, + maximumFractionDigits: 1, }).format(price.priceAmount / 100)} {' / '} {recurringInterval === 'year' ? 'year' : 'month'} diff --git a/packages/payments/scripts/create-products.ts b/packages/payments/scripts/create-products.ts index 6407cf26..d49feb9b 100644 --- a/packages/payments/scripts/create-products.ts +++ b/packages/payments/scripts/create-products.ts @@ -69,6 +69,7 @@ async function main() { const isDry = process.argv.includes('--dry'); const products = await getProducts(); + const createProducts = []; for (const price of PRICING) { if (price.price === 0) { const exists = products.find( @@ -126,12 +127,14 @@ async function main() { const monthlyProductExists = products.find( (p) => p.metadata?.eventsLimit === price.events && - p.recurringInterval === 'month', + p.recurringInterval === 'month' && + p.name === productCreate.name, ); const yearlyProductExists = products.find( (p) => p.metadata?.eventsLimit === price.events && - p.recurringInterval === 'year', + p.recurringInterval === 'year' && + p.name === `${productCreate.name} (yearly)`, ); if (monthlyProductExists) { @@ -148,6 +151,7 @@ async function main() { console.log(' - Prices:', monthlyProduct.prices); console.log(' - Recurring Interval:', monthlyProduct.recurringInterval); console.log(' - Events Limit:', monthlyProduct.metadata?.eventsLimit); + createProducts.push(monthlyProduct); } if (yearlyProductExists) { @@ -165,6 +169,7 @@ async function main() { ) { productCreate.prices[0]!.priceAmount = price.price * 100 * 10; } + // console.log('CREATE YEARLY', productCreate); const yearlyProduct = await polar.products.create(productCreate); console.log('Yearly product created:'); console.log(' - ID:', yearlyProduct.id); @@ -172,10 +177,23 @@ async function main() { console.log(' - Prices:', yearlyProduct.prices); console.log(' - Recurring Interval:', yearlyProduct.recurringInterval); console.log(' - Events Limit:', yearlyProduct.metadata?.eventsLimit); + createProducts.push(yearlyProduct); } } console.log('---'); } + + if (createProducts.length > 0) { + console.log('Create below products:'); + for (const product of createProducts) { + console.log('Product created:'); + console.log(' - ID:', product.id); + console.log(' - Name:', product.name); + console.log(' - Prices:', product.prices); + console.log(' - Recurring Interval:', product.recurringInterval); + console.log(' - Events Limit:', product.metadata?.eventsLimit); + } + } } main();