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:
@@ -36,7 +36,7 @@ const { createPaymentSession, confirmPaymentSession } = await import('../../src/
|
||||
const {
|
||||
WsMessage,
|
||||
PairingFailureCause,
|
||||
PaymentSessionStatus,
|
||||
PaymentRequestStatus,
|
||||
SessionStatus,
|
||||
} = await import('../../src/constants.js')
|
||||
const { db, resetDb, resetAppConfig } = await import('../helpers/db.js')
|
||||
@@ -72,7 +72,7 @@ describe('pairing.service', () => {
|
||||
|
||||
// Act: customer fires the general blast — only one mitra is online.
|
||||
const session = await createPairingRequest(customer.id, {
|
||||
paymentSessionId: pay.id,
|
||||
paymentRequestId: pay.id,
|
||||
})
|
||||
expect(session.status).toBe(SessionStatus.PENDING_ACCEPTANCE)
|
||||
|
||||
@@ -83,15 +83,15 @@ describe('pairing.service', () => {
|
||||
// Assert: pairing_failures audit row carries ALL_MITRAS_REJECTED.
|
||||
const sql = db()
|
||||
const failures = await sql`
|
||||
SELECT cause_tag FROM pairing_failures WHERE payment_session_id = ${pay.id}
|
||||
SELECT cause_tag FROM pairing_failures WHERE payment_request_id = ${pay.id}
|
||||
`
|
||||
expect(failures).toHaveLength(1)
|
||||
expect(failures[0].cause_tag).toBe(PairingFailureCause.ALL_MITRAS_REJECTED)
|
||||
|
||||
// Payment session stays CONFIRMED — the customer can re-blast on the same
|
||||
// payment via the S7 Timeout "coba cari lagi" CTA.
|
||||
const [paySession] = await sql`SELECT status FROM payment_sessions WHERE id = ${pay.id}`
|
||||
expect(paySession.status).toBe(PaymentSessionStatus.CONFIRMED)
|
||||
const [payRequest] = await sql`SELECT status FROM payment_requests WHERE id = ${pay.id}`
|
||||
expect(payRequest.status).toBe(PaymentRequestStatus.CONFIRMED)
|
||||
|
||||
// Customer was notified with PAIRING_FAILED carrying is_terminal=false so
|
||||
// the client renders the retryable variant of the S7 timeout screen.
|
||||
@@ -112,7 +112,7 @@ describe('pairing.service', () => {
|
||||
})
|
||||
await confirmPaymentSession(pay.id, customer.id)
|
||||
const session = await createPairingRequest(customer.id, {
|
||||
paymentSessionId: pay.id,
|
||||
paymentRequestId: pay.id,
|
||||
})
|
||||
|
||||
// Act: customer cancels.
|
||||
@@ -131,7 +131,7 @@ describe('pairing.service', () => {
|
||||
// Payment session is still terminated (CUSTOMER_CANCELLED) — the failure row exists
|
||||
// for ops accounting, just no real-time push to the customer who initiated the cancel.
|
||||
const sql = db()
|
||||
const failures = await sql`SELECT cause_tag FROM pairing_failures WHERE payment_session_id = ${pay.id}`
|
||||
const failures = await sql`SELECT cause_tag FROM pairing_failures WHERE payment_request_id = ${pay.id}`
|
||||
expect(failures).toHaveLength(1)
|
||||
expect(failures[0].cause_tag).toBe(PairingFailureCause.CUSTOMER_CANCELLED)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user