Add self-serve billing: tiers, credits, BTCPay and Zaprite

This commit is contained in:
Keysat
2026-06-13 13:36:05 -05:00
parent 84d56c94c9
commit 0aa648706e
17 changed files with 3781 additions and 116 deletions
+52
View File
@@ -0,0 +1,52 @@
// Zaprite (card rail) pure-logic tests: the paid-status gate that decides
// whether a webhook should grant a tier, and the order-id extraction that
// tolerates Zaprite's loosely-documented webhook payload shapes.
import { test, describe } from "node:test";
import assert from "node:assert/strict";
import { isOrderPaid, orderIdFromWebhook } from "../zaprite-client.js";
describe("zaprite isOrderPaid", () => {
test("paid statuses grant; everything else does not", () => {
for (const status of ["PAID", "COMPLETE", "OVERPAID"]) {
assert.equal(isOrderPaid({ status }), true, `${status} should be paid`);
}
for (const status of ["PENDING", "PROCESSING", "UNDERPAID", "", "WAT"]) {
assert.equal(isOrderPaid({ status }), false, `${status} should NOT be paid`);
}
});
test("case-insensitive + null-safe", () => {
assert.equal(isOrderPaid({ status: "paid" }), true);
assert.equal(isOrderPaid({ status: "complete" }), true);
assert.equal(isOrderPaid(null), false);
assert.equal(isOrderPaid({}), false);
assert.equal(isOrderPaid(undefined), false);
});
});
describe("zaprite orderIdFromWebhook", () => {
test("extracts id from the common payload shapes", () => {
assert.equal(orderIdFromWebhook({ id: "o1" }), "o1");
assert.equal(orderIdFromWebhook({ orderId: "o2" }), "o2");
assert.equal(orderIdFromWebhook({ order: { id: "o3" } }), "o3");
assert.equal(orderIdFromWebhook({ data: { id: "o4" } }), "o4");
assert.equal(orderIdFromWebhook({ data: { orderId: "o5" } }), "o5");
assert.equal(orderIdFromWebhook({ data: { order: { id: "o6" } } }), "o6");
});
test("prefers explicit orderId over a nested id", () => {
assert.equal(
orderIdFromWebhook({ orderId: "explicit", order: { id: "nested" } }),
"explicit",
);
});
test("returns null when no id is present", () => {
assert.equal(orderIdFromWebhook({}), null);
assert.equal(orderIdFromWebhook(null), null);
assert.equal(orderIdFromWebhook("nope"), null);
assert.equal(orderIdFromWebhook({ foo: "bar" }), null);
});
});