Phase 5 Xendit: Stages 1-7 (XENDIT_ENABLED=false; Stage 8 pending creds)
Backend - payment_sessions → payment_requests rename across DB schema + 29 files - payment.service.js becomes product-agnostic owner: EventEmitter + Xendit wrapper + requestPayment / confirmPayment public API; legacy aliases retained for existing chat callers - Webhook handler at POST /api/shared/payment/webhooks/xendit, with constant-time token verification (8 vitest cases) - Server-driven pairing: payment.service emits payment_request.confirmed → pairing subscriber starts the blast. Legacy POST /chat/request still works during the cutover. - Reconciliation sweeper extended (re-emits events for confirmed rows with no chat session) - SIGTERM drain + startup reconciliation pass in server.js Customer app - waiting_payment_screen opens xendit_invoice_url via LaunchMode.inAppBrowserView - searching / no-bestie / targeted-waiting / pairing-notifier updated to consume the new payment_request_id contract - pending_payments_provider + bestie-unavailable dialog migrated Dev / testing - XENDIT_ENABLED=false is the safe default; .env.example documents the four new vars - backend/.dev/xendit-fake-webhook.sh exercises the handler without ngrok - 90/92 backend tests pass (two pre-existing session-timer flakes, unrelated); client_app analyzer clean - requirement/phase5-xendit-plan.md is the canonical reference Stage 8 (live E2E) blocked on Xendit test-mode keys. The dashboard's single-webhook-URL constraint will be worked around via a self-poll script next session. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -149,6 +149,22 @@ export const getMitraHeartbeatCadenceSeconds = () => {
|
||||
return Number.isFinite(parsed) && parsed >= 5 ? parsed : 30
|
||||
}
|
||||
|
||||
// --- Phase 5: Xendit integration ---
|
||||
//
|
||||
// Env-driven (per backend/CLAUDE.md Config-Source Convention). All five values
|
||||
// read from process.env at call time so test setups can inject via vi.stubEnv.
|
||||
// When `enabled` is true, payment.service.js mints a real Xendit invoice on
|
||||
// requestPayment(); when false, invoice creation is skipped and the dev/Maestro
|
||||
// stub /internal/_test/force-confirm-payment plays the role of the webhook.
|
||||
// See requirement/phase5-xendit-plan.md D6/D9.
|
||||
export const getXenditConfig = () => ({
|
||||
enabled: process.env.XENDIT_ENABLED === 'true',
|
||||
secretKey: process.env.XENDIT_SECRET_KEY ?? '',
|
||||
webhookToken: process.env.XENDIT_WEBHOOK_TOKEN ?? '',
|
||||
successRedirectUrl: process.env.XENDIT_SUCCESS_REDIRECT_URL ?? '',
|
||||
failureRedirectUrl: process.env.XENDIT_FAILURE_REDIRECT_URL ?? '',
|
||||
})
|
||||
|
||||
export const getMitraPingConfig = async () => {
|
||||
const [requireRow] = await sql`SELECT value FROM app_config WHERE key = 'require_mitra_ping'`
|
||||
const [staleRow] = await sql`SELECT value FROM app_config WHERE key = 'mitra_stale_after_seconds'`
|
||||
@@ -291,18 +307,18 @@ export const setCcLoginLockoutConfig = async ({ max_attempts, lockout_minutes })
|
||||
|
||||
// --- Paid Pairing Flow + Returning-Chat + Extension Flip ---
|
||||
|
||||
export const getPaymentSessionTimeoutMinutes = async () => {
|
||||
const [row] = await sql`SELECT value FROM app_config WHERE key = 'payment_session_timeout_minutes'`
|
||||
return { payment_session_timeout_minutes: row?.value?.value ?? 20 }
|
||||
export const getPaymentRequestTimeoutMinutes = async () => {
|
||||
const [row] = await sql`SELECT value FROM app_config WHERE key = 'payment_request_timeout_minutes'`
|
||||
return { payment_request_timeout_minutes: row?.value?.value ?? 20 }
|
||||
}
|
||||
|
||||
export const setPaymentSessionTimeoutMinutes = async (value) => {
|
||||
export const setPaymentRequestTimeoutMinutes = async (value) => {
|
||||
await sql`
|
||||
INSERT INTO app_config (key, value, updated_at)
|
||||
VALUES ('payment_session_timeout_minutes', ${sql.json({ value })}, NOW())
|
||||
VALUES ('payment_request_timeout_minutes', ${sql.json({ value })}, NOW())
|
||||
ON CONFLICT (key) DO UPDATE SET value = EXCLUDED.value, updated_at = NOW()
|
||||
`
|
||||
return { payment_session_timeout_minutes: value }
|
||||
return { payment_request_timeout_minutes: value }
|
||||
}
|
||||
|
||||
export const getReturningChatConfirmationTimeoutSeconds = async () => {
|
||||
|
||||
Reference in New Issue
Block a user