From 24703c0a1fa78983d35a93d54ab53b9bcf27a253 Mon Sep 17 00:00:00 2001 From: Emil Widlund Date: Sat, 2 Nov 2024 01:11:15 +0100 Subject: [PATCH] fix pricing --- package.json | 2 +- src/cli.tsx | 1 + src/prompts/product.ts | 34 +++++++++++++++++++++++++--------- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 09f223f..34daa64 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "checkout-link", - "version": "0.1.2", + "version": "0.1.3", "license": "Apache-2.0", "bin": "bin/cli.js", "type": "module", diff --git a/src/cli.tsx b/src/cli.tsx index 0689fc2..15d4ec8 100644 --- a/src/cli.tsx +++ b/src/cli.tsx @@ -40,6 +40,7 @@ const [filePath] = cli.input; (async () => { const product = await productPrompt(); + console.log(product); const server = await serverPrompt(); await authenticationMessage(); diff --git a/src/prompts/product.ts b/src/prompts/product.ts index 9c71cae..c2249f7 100644 --- a/src/prompts/product.ts +++ b/src/prompts/product.ts @@ -17,19 +17,19 @@ export const productPrompt = async () => { const priceTypeResponse = await prompts({ type: "select", - name: "priceType", + name: "type", message: "Product Type", choices: [ - { title: "One-Time Purchase", value: "one-time" }, + { title: "One-Time Purchase", value: "one_time" }, { title: "Subscription", value: "recurring" }, ], }); - if (priceTypeResponse.priceType === "one-time") { + if (priceTypeResponse.type === "one_time") { const priceResponse = await prompts([ { type: "select", - name: "priceAmountType", + name: "amountType", message: "Price Type", choices: [ { title: "Free", value: "free" }, @@ -46,7 +46,15 @@ export const productPrompt = async () => { return { ...productResponse, - prices: [priceResponse], + prices: [ + { + ...priceResponse, + ...priceTypeResponse, + ...(typeof priceResponse.priceAmount === "number" + ? { priceAmount: priceResponse.priceAmount * 100 } + : {}), + }, + ], }; } @@ -56,13 +64,13 @@ export const productPrompt = async () => { name: "recurringInterval", message: "Recurring Interval", choices: [ - { title: "Monthly", value: "monthly" }, - { title: "Yearly", value: "yearly" }, + { title: "Monthly", value: "month" }, + { title: "Yearly", value: "year" }, ], }, { type: "select", - name: "priceAmountType", + name: "amountType", message: "Price Type", choices: [ { title: "Free", value: "free" }, @@ -79,6 +87,14 @@ export const productPrompt = async () => { return { ...productResponse, - prices: [priceResponse], + prices: [ + { + ...priceResponse, + ...priceTypeResponse, + ...(typeof priceResponse.priceAmount === "number" + ? { priceAmount: priceResponse.priceAmount * 100 } + : {}), + }, + ], }; };