File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3,7 +3,13 @@ export async function createPaymentIntent(payload) {
33 return {
44 paymentId : `pay_${ Date . now ( ) } ` ,
55 amount : payload . amount ,
6- currency : payload . currency ?? "usd" ,
6+ currency : normalizeCurrency ( payload . currency ) ,
77 provider : "stripe"
88 } ;
99}
10+
11+ function normalizeCurrency ( currency ) {
12+ return typeof currency === "string" && currency . length > 0
13+ ? currency . toUpperCase ( )
14+ : "USD" ;
15+ }
Original file line number Diff line number Diff line change 1+ import test from "node:test" ;
2+ import assert from "node:assert/strict" ;
3+ import { createPaymentIntent } from "../services/paymentService.js" ;
4+
5+ test ( "createPaymentIntent defaults to uppercase USD" , async ( ) => {
6+ const intent = await createPaymentIntent ( { amount : 2500 } ) ;
7+
8+ assert . equal ( intent . currency , "USD" ) ;
9+ } ) ;
10+
11+ test ( "createPaymentIntent normalizes lowercase currency codes" , async ( ) => {
12+ const intent = await createPaymentIntent ( { amount : 2500 , currency : "eur" } ) ;
13+
14+ assert . equal ( intent . currency , "EUR" ) ;
15+ } ) ;
You can’t perform that action at this time.
0 commit comments