mirror of
https://github.com/profullstack/logicsrc.git
synced 2026-12-03 18:24:53 +00:00
fix(coinpay): settle paid Hire Us checkouts from the signed webhook (#252)
The CoinPay webhook only logged. It now verifies X-CoinPay-Signature (t=,v1= over t.rawBody), reads the nested payload (data.payment_id, not the top-level event id), and records a confirmed/forwarded Hire Us payment once in hire_us_payments (payment_id primary key), mapped to the buyer via metadata.account_id/email. Unknown or pending payments are a 200 no-op. Hire Us checkout now sends property, account_id (CoinPay session) and email in metadata. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
7171c2cdeb
commit
54ec1a4925
7 changed files with 292 additions and 16 deletions
|
|
@ -1,6 +1,12 @@
|
|||
import type { NextRequest } from "next/server";
|
||||
import { json } from "@/lib/http";
|
||||
import { choosePaymentRail, fetchMerchantEligibility, parseJson } from "@/lib/coinpay";
|
||||
import {
|
||||
COINPAY_SESSION_COOKIE,
|
||||
choosePaymentRail,
|
||||
fetchMerchantEligibility,
|
||||
parseJson,
|
||||
verifySession
|
||||
} from "@/lib/coinpay";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
|
|
@ -37,7 +43,19 @@ export async function POST(request: NextRequest) {
|
|||
|
||||
try {
|
||||
const body = (await request.json().catch(() => ({}))) as Record<string, unknown>;
|
||||
const buyerEmail = typeof body.email === "string" ? body.email.trim().slice(0, 160) : "";
|
||||
// A signed-in CoinPay session (OAuth cookie) identifies the account; the
|
||||
// webhook maps the settled payment back to it via metadata.account_id.
|
||||
const sessionCookie = request.cookies.get(COINPAY_SESSION_COOKIE)?.value;
|
||||
let session: Record<string, unknown> | null = null;
|
||||
try {
|
||||
session = sessionCookie ? verifySession(sessionCookie) : null;
|
||||
} catch {
|
||||
session = null;
|
||||
}
|
||||
const accountId = typeof session?.sub === "string" ? session.sub : "";
|
||||
const sessionEmail = typeof session?.email === "string" ? session.email : "";
|
||||
const bodyEmail = typeof body.email === "string" ? body.email.trim().slice(0, 160) : "";
|
||||
const buyerEmail = bodyEmail || sessionEmail;
|
||||
const hours = body.hours === undefined ? MINIMUM_HOURS : parseHours(body.hours);
|
||||
|
||||
if (hours === null) {
|
||||
|
|
@ -82,7 +100,9 @@ export async function POST(request: NextRequest) {
|
|||
hours,
|
||||
rate_usd_per_hour: RATE_USD_PER_HOUR,
|
||||
source: "logicsrc.com/hire-us",
|
||||
...(buyerEmail ? { buyer_email: buyerEmail } : {})
|
||||
property: "logicsrc.com",
|
||||
...(accountId ? { account_id: accountId } : {}),
|
||||
...(buyerEmail ? { email: buyerEmail, buyer_email: buyerEmail } : {})
|
||||
}
|
||||
})
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue