feat(hire-us): CoinPay hosted checkout sessions for Hire Us (#254)
Some checks failed
CI / build (push) Has been cancelled
Deploy to dev2 / deploy (push) Has been cancelled
test / test (push) Has been cancelled

POST /api/hire-us/coinpay-checkout now opens a CoinPay checkout session
instead of a single-chain USDC_POL /api/payments/create. The buyer picks
any coin the business has a wallet for, or PayPal. Each session sends
customer_email (required), account_id (CoinPay OAuth sub when signed in,
else the buyer email for guests), property logicsrc.com and the Hire Us
metadata. The cs_ id is recorded in the new hire_us_checkouts table.

The webhook records session payments from the session fields
(checkout_session_id, account_id, customer_email, property), stores the
session id on hire_us_payments, marks the checkout paid, and stays
idempotent on payment_id across confirmed, forwarded and replays.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Anthony Ettinger 2026-10-21 06:22:17 -07:00 • committed by GitHub
parent 5192684de9
commit 580817b06f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 341 additions and 215 deletions

View file

@ -42,12 +42,34 @@ function realShaped(status = "confirmed", type = "payment.confirmed") {
function memoryStore() {
const rows = new Map<string, HireUsPaymentRow>();
const paidSessions: [string, string][] = [];
return {
rows,
paidSessions,
async insertIfAbsent(row: HireUsPaymentRow) {
if (rows.has(row.payment_id)) return false;
rows.set(row.payment_id, row);
return true;
},
async markCheckoutPaid(sessionId: string, paymentId: string) {
paidSessions.push([sessionId, paymentId]);
}
};
}
const SID = "cs_Ju1h16BXSobdRs7XWg9MUIj0";
// A hosted checkout session payment: CoinPay adds the session fields to data.
function sessionShaped(status = "confirmed", type = "payment.confirmed") {
const base = realShaped(status, type);
return {
...base,
data: {
...base.data,
checkout_session_id: SID,
customer_email: "guest@example.com",
account_id: "guest@example.com",
property: "logicsrc.com",
metadata: { ...base.data.metadata, account_id: "guest@example.com", email: "guest@example.com" }
}
};
}
@ -89,4 +111,32 @@ describe("CoinPay webhook (logicsrc Hire Us)", () => {
expect(await settleHireUsWebhook(foreign, store)).toMatchObject({ settled: false, reason: "unknown payment" });
expect(store.rows.size).toBe(0);
});
it("settles a checkout-session payment from the session fields, once", async () => {
const store = memoryStore();
const first = await settleHireUsWebhook(sessionShaped(), store);
expect(first).toMatchObject({
settled: true,
duplicate: false,
payment_id: PAYMENT_ID,
checkout_session_id: SID,
account_id: "guest@example.com",
email: "guest@example.com"
});
expect(store.rows.get(PAYMENT_ID)).toMatchObject({ checkout_session_id: SID, property: "logicsrc.com", hours: 10 });
expect(store.paidSessions).toEqual([[SID, PAYMENT_ID]]);
const forwarded = await settleHireUsWebhook(sessionShaped("forwarded", "payment.forwarded"), store);
const replay = await settleHireUsWebhook(sessionShaped(), store);
expect(forwarded).toMatchObject({ settled: true, duplicate: true });
expect(replay).toMatchObject({ settled: true, duplicate: true });
expect(store.rows.size).toBe(1);
});
it("does not record a pending session payment", async () => {
const store = memoryStore();
expect(await settleHireUsWebhook(sessionShaped("pending", "payment.pending"), store)).toMatchObject({ settled: false });
expect(store.rows.size).toBe(0);
expect(store.paidSessions).toEqual([]);
});
});