@@ -40,10 +40,10 @@ type Done = (p: Plan | null) => boolean;
4040
4141const readFromTheServer = ( p : Plan | null ) : p is Plan => ! ! p && ! p . mock ;
4242const NO_PLAN = "Could not read your plan, so no checkout opened. Finish on the page." ;
43+ const NO_PRICE = "Could not read the price, so no checkout opened. Finish on the page." ;
4344
4445async function payOrShowTheNewPrice (
4546 kind : "plans" | "credits" ,
46- offer : Offer ,
4747 done : Done ,
4848 shown : string ,
4949 stop : AbortSignal ,
@@ -53,8 +53,10 @@ async function payOrShowTheNewPrice(
5353 if ( stop . aborted ) return undefined ;
5454 if ( ! readFromTheServer ( now ) ) return void console . log ( NO_PLAN ) ;
5555 if ( done ( now ) ) return undefined ;
56+ const offer = await readOffer ( ) ;
5657 const missing = needed ? needed - now . credits : undefined ;
57- const line = priceLine ( kind , offer , missing , needed ) ?? shown ;
58+ const line = priceLine ( kind , offer , missing , needed ) ;
59+ if ( ! line ) return void console . log ( NO_PRICE ) ;
5860 if ( line !== shown ) {
5961 console . log ( line ) ;
6062 return line ;
@@ -66,7 +68,6 @@ async function payOrShowTheNewPrice(
6668
6769async function checkoutOnEnterAtTheCurrentPrice (
6870 kind : "plans" | "credits" ,
69- offer : Offer ,
7071 done : Done ,
7172 shown : string ,
7273 stop : AbortSignal ,
@@ -76,7 +77,7 @@ async function checkoutOnEnterAtTheCurrentPrice(
7677 try {
7778 for ( let price : string | undefined = shown ; price ; ) {
7879 await rl . question ( "Press Enter to pay, or finish on the page " , { signal : stop } ) ;
79- price = await payOrShowTheNewPrice ( kind , offer , done , price , stop , needed ) ;
80+ price = await payOrShowTheNewPrice ( kind , done , price , stop , needed ) ;
8081 }
8182 } catch ( error ) {
8283 if ( ! stop . aborted ) throw error ;
@@ -97,13 +98,12 @@ async function offerCheckoutOrPrintTheLink(
9798 const offer = await readOffer ( ) ;
9899 const missing = needed ? needed - before . credits : undefined ;
99100 const line = priceLine ( kind , offer , missing , needed ) ;
100- if ( ! line )
101- return void console . log ( "Could not read the price, so no checkout opened. Finish on the page." ) ;
101+ if ( ! line ) return void console . log ( NO_PRICE ) ;
102102 console . log ( line ) ;
103103 try {
104104 if ( isUnattended ( ) )
105105 console . log ( `Checkout link: ${ c . accent ( await createCheckout ( kind , offer , missing ) ) } ` ) ;
106- else await checkoutOnEnterAtTheCurrentPrice ( kind , offer , done , line , stop , needed ) ;
106+ else await checkoutOnEnterAtTheCurrentPrice ( kind , done , line , stop , needed ) ;
107107 } catch ( error ) {
108108 console . error ( c . error ( error instanceof Error ? error . message : String ( error ) ) ) ;
109109 }
0 commit comments