Skip to content

Commit 9900649

Browse files
committed
fix(api): normalize payment currency codes
1 parent 3be52e0 commit 9900649

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

apps/api/src/services/paymentService.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff 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+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
});

0 commit comments

Comments
 (0)