From 3201ca2f9331b522726bf1e6902f770ad1218a06 Mon Sep 17 00:00:00 2001 From: epeks Date: Thu, 5 Nov 2026 15:54:57 +0000 Subject: [PATCH 1/6] Validate recipients and improve transfers, receipts, and status updates --- apps/api/next.config.ts | 7 +- apps/api/package.json | 2 + .../v1/payments/[paymentId]/receipt/route.ts | 33 +++++ apps/api/src/shared/infrastructure/http.ts | 2 + .../v1/modules/deposits/providers/paystack.ts | 22 ++++ .../modules/payments/jobs/process-payment.ts | 54 +++++--- .../src/v1/modules/payments/routes/handler.ts | 16 ++- .../payments/services/create-payment.ts | 15 ++- .../v1/modules/payments/services/receipt.ts | 108 +++++++++++++++ .../v1/modules/users/routes/beneficiaries.ts | 12 ++ .../v1/modules/wallets/routes/capabilities.ts | 8 +- .../v1/modules/withdrawals/routes/handler.ts | 26 +++- apps/mobile/package.json | 1 + .../components/sign-up-form/SignUpForm.tsx | 2 +- .../screens/BeneficiariesScreen.tsx | 4 +- .../features/bills/screens/BillsScreen.tsx | 8 +- .../transactions/components/ReceiptMenu.tsx | 108 +++++++++++++++ .../screens/TransactionScreen.tsx | 26 ++-- .../wallet/screens/WithdrawalScreen.tsx | 6 +- apps/mobile/src/lib/forms.ts | 7 +- .../src/components/ui/form-field/index.tsx | 13 ++ .../components/sign-up-form/SignUpForm.tsx | 2 +- .../beneficiaries/BeneficiariesPage.tsx | 14 +- apps/web/src/features/bills/BillsPage.tsx | 18 ++- .../src/features/transactions/ReceiptMenu.tsx | 92 +++++++++++++ .../transactions/TransactionDetails.tsx | 23 ++-- .../src/features/wallet/WithdrawalPage.tsx | 31 ++++- packages/api-client/src/index.ts | 17 ++- packages/contracts/package.json | 1 + packages/contracts/src/index.ts | 34 +++-- pnpm-lock.yaml | 113 ++++++++++------ pnpm-workspace.yaml | 1 + tests/browser/account-lifecycle.spec.ts | 2 +- tests/browser/connection.spec.ts | 2 +- tests/browser/quickpay.spec.ts | 59 ++++++++- tests/browser/reliability.spec.ts | 2 +- tests/configuration.test.ts | 8 +- tests/financial.test.ts | 4 +- tests/mobile-core.test.ts | 2 +- tests/payment-reconciliation.test.ts | 124 ++++++++++++++++++ tests/receipt.test.ts | 69 ++++++++++ 41 files changed, 965 insertions(+), 133 deletions(-) create mode 100644 apps/api/src/app/api/v1/payments/[paymentId]/receipt/route.ts create mode 100644 apps/api/src/v1/modules/payments/services/receipt.ts create mode 100644 apps/mobile/src/features/transactions/components/ReceiptMenu.tsx create mode 100644 apps/web/src/features/transactions/ReceiptMenu.tsx create mode 100644 tests/payment-reconciliation.test.ts create mode 100644 tests/receipt.test.ts diff --git a/apps/api/next.config.ts b/apps/api/next.config.ts index ca00df0..7cd792c 100644 --- a/apps/api/next.config.ts +++ b/apps/api/next.config.ts @@ -2,5 +2,10 @@ import type { NextConfig } from "next"; export default { distDir: process.env.NEXT_BUILD_DIR || ".next", transpilePackages: ["@quickpay/contracts", "@quickpay/database"], - serverExternalPackages: ["pg"], + serverExternalPackages: ["pg", "sharp"], + outputFileTracingIncludes: { + "/api/v1/payments/*/receipt": [ + "../../assets/brand/quick-pay-brand-pack-v1/website/header-light@2x.png", + ], + }, } satisfies NextConfig; diff --git a/apps/api/package.json b/apps/api/package.json index a9e58fa..e25b574 100644 --- a/apps/api/package.json +++ b/apps/api/package.json @@ -13,9 +13,11 @@ "better-auth": "1.7.16", "drizzle-orm": "0.45.4", "next": "16.4.5", + "pdf-lib": "^1.17.1", "pg": "8.23.1", "react": "19.3.1", "react-dom": "19.3.1", + "sharp": "^0.35.5", "zod": "4.6.7" }, "devDependencies": { diff --git a/apps/api/src/app/api/v1/payments/[paymentId]/receipt/route.ts b/apps/api/src/app/api/v1/payments/[paymentId]/receipt/route.ts new file mode 100644 index 0000000..2d3cd04 --- /dev/null +++ b/apps/api/src/app/api/v1/payments/[paymentId]/receipt/route.ts @@ -0,0 +1,33 @@ +import { endpoint } from "@quickpay/server/shared/infrastructure/http"; +import { identity } from "@quickpay/server/shared/auth"; +import { assert } from "@quickpay/server/shared/errors"; +import { + ownPayment, + publicTransaction, +} from "@quickpay/server/v1/modules/payments/repositories/payment.repository"; +import { renderReceipt } from "@quickpay/server/v1/modules/payments/services/receipt"; +export const GET = endpoint(async (req, ctx) => { + const session = await identity(req); + const { paymentId } = await ctx.params; + const format = new URL(req.url).searchParams.get("format") || "pdf"; + assert( + format === "pdf" || format === "png", + "INVALID_FORMAT", + "Choose PDF or PNG.", + ); + const payment = publicTransaction( + await ownPayment(paymentId, session.user.id), + ); + const bytes = await renderReceipt( + { ...payment, createdAt: payment.createdAt.toISOString() }, + format, + ); + return new Response(new Uint8Array(bytes).buffer, { + headers: { + "Content-Type": format === "pdf" ? "application/pdf" : "image/png", + "Content-Disposition": `attachment; filename="QuickPay-receipt-${payment.id}.${format}"`, + "Cache-Control": "private, no-store", + "X-Content-Type-Options": "nosniff", + }, + }); +}); diff --git a/apps/api/src/shared/infrastructure/http.ts b/apps/api/src/shared/infrastructure/http.ts index 7dbf8e0..147a093 100644 --- a/apps/api/src/shared/infrastructure/http.ts +++ b/apps/api/src/shared/infrastructure/http.ts @@ -101,6 +101,8 @@ export function endpoint( correlationId, event: "request_failed", type: e instanceof Error ? e.name : "unknown", + path: new URL(req.url).pathname, + ...(known ? { code: e.code } : {}), ...(configuration ? { fields: e.fields } : {}), }), ); diff --git a/apps/api/src/v1/modules/deposits/providers/paystack.ts b/apps/api/src/v1/modules/deposits/providers/paystack.ts index b730894..56fd7c9 100644 --- a/apps/api/src/v1/modules/deposits/providers/paystack.ts +++ b/apps/api/src/v1/modules/deposits/providers/paystack.ts @@ -5,6 +5,13 @@ import { assert } from "../../../../shared/errors"; export function paystackConfigured() { return env().PAYMENT_MODE !== "disabled" && !!env().PAYSTACK_SECRET_KEY; } +export function withdrawalsConfigured() { + return ( + paystackConfigured() && + (env().PAYMENT_MODE === "sandbox" || + env().PAYSTACK_TRANSFERS_ENABLED === "true") + ); +} export async function paystack( path: string, schema: T, @@ -25,6 +32,21 @@ export async function paystack( body: payload ? JSON.stringify(payload) : undefined, signal: AbortSignal.timeout(20000), }); + if ( + !r.ok && + r.status >= 400 && + r.status < 500 && + ![408, 409, 425, 429].includes(r.status) + ) { + assert( + false, + "PROVIDER_REJECTED", + path.startsWith("bank/resolve") + ? "The bank could not verify this account. Check the account number and bank." + : "The payment provider could not accept this request. Please contact support if it continues.", + 422, + ); + } assert( r.ok, "PAYMENT_PENDING", diff --git a/apps/api/src/v1/modules/payments/jobs/process-payment.ts b/apps/api/src/v1/modules/payments/jobs/process-payment.ts index 29b541f..5645e07 100644 --- a/apps/api/src/v1/modules/payments/jobs/process-payment.ts +++ b/apps/api/src/v1/modules/payments/jobs/process-payment.ts @@ -8,10 +8,10 @@ import { import { vtpass } from "../../billers/providers/vtpass"; import { unseal } from "../../../../shared/infrastructure/security"; import { env } from "../../../../shared/infrastructure/env"; -import { assert } from "../../../../shared/errors"; +import { assert, DomainError } from "../../../../shared/errors"; import { settlePayment } from "../services/settle-payment"; import type { PaymentRow } from "../repositories/payment.repository"; -import { parseNaira } from "@quickpay/contracts"; +import { phone, parseNaira } from "@quickpay/contracts"; export async function verifyPayment(p: PaymentRow) { if (p.kind === "deposit") { const data = await paystack( @@ -75,8 +75,17 @@ export async function verifyPayment(p: PaymentRow) { ); const destination = content.transactions.unique_element || content.transactions.phone; + const storedPhone = ["airtime", "data"].includes(String(p.details.category)) + ? phone.safeParse(p.details.beneficiary) + : null; + const providerPhone = storedPhone?.success + ? phone.safeParse(destination) + : null; assert( - destination === p.details.beneficiary, + destination === p.details.beneficiary || + (storedPhone?.success && + providerPhone?.success && + storedPhone.data === providerPhone.data), "DESTINATION_MISMATCH", "This payment needs a further check.", 409, @@ -172,21 +181,34 @@ export async function processPayment(id: string) { ], ); if (!claimed.rowCount) return; - await paystack( - "transfer", - z.object({ - reference: z.string(), - status: z.string(), - transfer_code: z.string(), - }), - { - source: "balance", + try { + await paystack( + "transfer", + z.object({ + reference: z.string(), + status: z.string(), + transfer_code: z.string(), + }), + { + source: "balance", + amount: p.amount, + recipient: recipient.recipient_code, + reason: "Quick Pay wallet withdrawal", + reference: p.reference, + }, + ); + } catch (error) { + if (!(error instanceof DomainError) || error.code !== "PROVIDER_REJECTED") + throw error; + await settlePayment(id, { + status: "failed", amount: p.amount, - recipient: recipient.recipient_code, - reason: "Quick Pay wallet withdrawal", + currency: p.currency, reference: p.reference, - }, - ); + recipient: recipient.recipient_code, + }); + return; + } } else if (p.kind === "payment") { const claimed = await pool.query( "UPDATE transactions SET details=details||'{\"initiationStarted\":true}'::jsonb WHERE id=$1 AND NOT(details ? 'initiationStarted') RETURNING id", diff --git a/apps/api/src/v1/modules/payments/routes/handler.ts b/apps/api/src/v1/modules/payments/routes/handler.ts index b824582..6e18956 100644 --- a/apps/api/src/v1/modules/payments/routes/handler.ts +++ b/apps/api/src/v1/modules/payments/routes/handler.ts @@ -20,9 +20,19 @@ export async function listPayments(req: Request) { } export async function getPayment(req: Request, id: string) { const s = await identity(req); - return json({ - transaction: publicTransaction(await ownPayment(id, s.user.id)), - }); + const payment = await ownPayment(id, s.user.id); + if ( + ["processing", "awaiting_authorization"].includes(payment.status) && + (payment.kind === "deposit" || payment.details.initiationStarted) + ) { + await enqueue( + pool, + "verify-provider", + { reference: payment.reference }, + `status:${payment.id}:${Math.floor(Date.now() / 30000)}`, + ); + } + return json({ transaction: publicTransaction(payment) }); } export async function checkPayment(req: Request, id: string) { const s = await identity(req); diff --git a/apps/api/src/v1/modules/payments/services/create-payment.ts b/apps/api/src/v1/modules/payments/services/create-payment.ts index 1589cb1..89a578e 100644 --- a/apps/api/src/v1/modules/payments/services/create-payment.ts +++ b/apps/api/src/v1/modules/payments/services/create-payment.ts @@ -21,8 +21,10 @@ import { vtReference, variationSchema, } from "../../billers/providers/vtpass"; -import { paystackConfigured } from "../../deposits/providers/paystack"; -import { env } from "../../../../shared/infrastructure/env"; +import { + paystackConfigured, + withdrawalsConfigured, +} from "../../deposits/providers/paystack"; import { parseNaira, phone } from "@quickpay/contracts"; import { walletLimits } from "../../wallets/domain/limits"; export async function createOperation( @@ -125,6 +127,13 @@ export async function createOperation( const normalized = phone.parse(v.beneficiary); v.beneficiary = `0${normalized.slice(4)}`; } + if (!["airtime", "data"].includes(service.category)) + assert( + v.phone, + "PHONE_REQUIRED", + "Enter a valid contact phone number.", + 422, + ); Object.assign(details, { beneficiary: v.beneficiary, phone: v.phone ? `0${v.phone.slice(4)}` : undefined, @@ -184,7 +193,7 @@ export async function createOperation( } if (v.kind === "withdrawal") { assert( - paystackConfigured() && env().PAYSTACK_TRANSFERS_ENABLED === "true", + withdrawalsConfigured(), "WITHDRAWAL_UNAVAILABLE", "Bank withdrawals are not available yet.", 503, diff --git a/apps/api/src/v1/modules/payments/services/receipt.ts b/apps/api/src/v1/modules/payments/services/receipt.ts new file mode 100644 index 0000000..1b38178 --- /dev/null +++ b/apps/api/src/v1/modules/payments/services/receipt.ts @@ -0,0 +1,108 @@ +import { readFile } from "node:fs/promises"; +import { resolve } from "node:path"; +import sharp from "sharp"; +import { PDFDocument } from "pdf-lib"; +import { formatMoney, type Transaction } from "@quickpay/contracts"; +const escape = (value: unknown) => + String(value).replace( + /[&<>"']/g, + (c) => + ({ + "&": "&", + "<": "<", + ">": ">", + '"': """, + "'": "'", + })[c]!, + ); +async function logo() { + const name = + "assets/brand/quick-pay-brand-pack-v1/website/header-light@2x.png"; + try { + return await readFile(resolve(process.cwd(), name)); + } catch { + return readFile(resolve(process.cwd(), "../..", name)); + } +} +export async function renderReceipt(t: Transaction, format: "pdf" | "png") { + const brand = await logo(); + const status = t.status.replaceAll("_", " "); + const color = + t.status === "successful" + ? "#166534" + : ["processing", "created", "awaiting_authorization"].includes(t.status) + ? "#92400e" + : "#991b1b"; + const rows = [ + ["Transaction type", t.kind], + ["Service", t.serviceId || "Wallet"], + ["Reference", t.reference], + [ + "Date · Africa/Lagos", + new Date(t.createdAt).toLocaleString("en-GB", { + timeZone: "Africa/Lagos", + dateStyle: "medium", + timeStyle: "short", + }), + ], + ...(t.details.beneficiary + ? [ + [ + "Recipient", + String(t.details.beneficiaryName || t.details.beneficiary), + ], + ] + : []), + ...(t.details.accountName + ? [ + [ + "Bank account", + `${t.details.accountName} · •••• ${t.details.accountLast4 || ""}`, + ], + ] + : []), + ["Amount", formatMoney(t.amount)], + ["Fee", formatMoney(t.fee)], + ["Total", formatMoney(BigInt(t.amount) + BigInt(t.fee))], + ]; + const lines = rows + .map(([label, value], index) => { + const y = 590 + index * 88; + const text = String(value).slice(0, 160); + const parts = text.match(/.{1,53}/g) || [""]; + return `${escape(label)}${parts + .slice(0, 2) + .map( + (part, i) => + `${escape(part)}`, + ) + .join( + "", + )}`; + }) + .join(""); + const svg = ` + + + + TRANSACTION RECEIPT + ${escape(formatMoney(BigInt(t.amount) + BigInt(t.fee)))} + ${escape(status.toUpperCase())} + ${lines} + Less paying. More living. + ${t.status === "successful" ? "Payment confirmed. Keep this receipt for your records." : "This receipt records the status shown above; it is not proof of a completed payment."} + Quick Pay · NGN · Reference above identifies this transaction.`; + const png = await sharp(Buffer.from(svg)).png().toBuffer(); + if (format === "png") return png; + const pdf = await PDFDocument.create(); + pdf.setTitle(`Quick Pay receipt · ${t.reference}`); + pdf.setAuthor("Quick Pay"); + const page = pdf.addPage([595.28, 841.89]); + page.drawImage(await pdf.embedPng(png), { + x: 0, + y: 0, + width: 595.28, + height: 841.89, + }); + return Buffer.from(await pdf.save()); +} diff --git a/apps/api/src/v1/modules/users/routes/beneficiaries.ts b/apps/api/src/v1/modules/users/routes/beneficiaries.ts index 0f9a709..cd7a131 100644 --- a/apps/api/src/v1/modules/users/routes/beneficiaries.ts +++ b/apps/api/src/v1/modules/users/routes/beneficiaries.ts @@ -1,3 +1,4 @@ +import { phone } from "@quickpay/contracts"; import { z } from "zod"; import { pool } from "@quickpay/database"; import { identity } from "../../../../shared/auth"; @@ -40,6 +41,17 @@ export async function beneficiaries(req: Request) { }), }), ); + const service = v.details.serviceId + ? ( + await pool.query("SELECT category FROM service_catalog WHERE id=$1", [ + v.details.serviceId, + ]) + ).rows[0] + : null; + if (v.kind === "phone" || ["airtime", "data"].includes(service?.category)) { + v.details.account = phone.parse(v.details.account); + v.kind = "phone"; + } const id = crypto.randomUUID(); await pool.query( "INSERT INTO beneficiaries(id,user_id,name,kind,details) VALUES($1,$2,$3,$4,$5)", diff --git a/apps/api/src/v1/modules/wallets/routes/capabilities.ts b/apps/api/src/v1/modules/wallets/routes/capabilities.ts index d2fa60f..321b00c 100644 --- a/apps/api/src/v1/modules/wallets/routes/capabilities.ts +++ b/apps/api/src/v1/modules/wallets/routes/capabilities.ts @@ -1,12 +1,14 @@ import { identity } from "../../../../shared/auth"; import { json } from "../../../../shared/infrastructure/http"; -import { env } from "../../../../shared/infrastructure/env"; -import { paystackConfigured } from "../../deposits/providers/paystack"; +import { + paystackConfigured, + withdrawalsConfigured, +} from "../../deposits/providers/paystack"; import { walletLimits } from "../domain/limits"; export async function walletCapabilities(req: Request) { await identity(req); const deposit = paystackConfigured(); - const withdrawal = deposit && env().PAYSTACK_TRANSFERS_ENABLED === "true"; + const withdrawal = withdrawalsConfigured(); return json({ currency: "NGN", deposit: { diff --git a/apps/api/src/v1/modules/withdrawals/routes/handler.ts b/apps/api/src/v1/modules/withdrawals/routes/handler.ts index c6bebc1..e283090 100644 --- a/apps/api/src/v1/modules/withdrawals/routes/handler.ts +++ b/apps/api/src/v1/modules/withdrawals/routes/handler.ts @@ -1,15 +1,27 @@ import { z } from "zod"; import { pool } from "@quickpay/database"; +import { assert } from "../../../../shared/errors"; import { identity } from "../../../../shared/auth"; import { body, json, rateLimit } from "../../../../shared/infrastructure/http"; import { hash } from "../../../../shared/infrastructure/security"; import { paystack } from "../../deposits/providers/paystack"; export async function banks(req: Request) { await identity(req); - const banks = await paystack( - "bank?country=nigeria¤cy=NGN", - z.array(z.object({ name: z.string(), code: z.string() })), - ); + const banks: { name: string; code: string }[] = []; + const seen = new Set(); + for (let page = 1; page <= 20; page++) { + const entries = await paystack( + `bank?country=nigeria¤cy=NGN&perPage=100&page=${page}`, + z.array(z.object({ name: z.string(), code: z.string() })), + ); + const fresh = entries.filter((bank) => !seen.has(bank.code)); + for (const bank of fresh) { + banks.push(bank); + seen.add(bank.code); + } + if (entries.length < 100 || fresh.length === 0) break; + } + banks.sort((a, b) => a.name.localeCompare(b.name)); return json({ banks }); } export async function resolveBank(req: Request) { @@ -26,6 +38,12 @@ export async function resolveBank(req: Request) { `bank/resolve?account_number=${v.accountNumber}&bank_code=${v.bankCode}`, z.object({ account_number: z.string(), account_name: z.string() }), ); + assert( + result.account_number === v.accountNumber, + "ACCOUNT_MISMATCH", + "The bank returned a different account. Please verify your details again.", + 422, + ); const id = crypto.randomUUID(); await pool.query( "INSERT INTO beneficiary_validations(id,user_id,kind,destination_hash,result,expires_at) VALUES($1,$2,'bank',$3,$4,now()+interval '10 minutes')", diff --git a/apps/mobile/package.json b/apps/mobile/package.json index dfcc166..bc16578 100644 --- a/apps/mobile/package.json +++ b/apps/mobile/package.json @@ -34,6 +34,7 @@ "expo-notifications": "~57.0.25", "expo-router": "~57.0.30", "expo-secure-store": "~57.0.4", + "expo-sharing": "~57.0.25", "expo-splash-screen": "~57.0.11", "expo-status-bar": "~57.0.1", "expo-system-ui": "57.0.4", diff --git a/apps/mobile/src/features/auth/components/sign-up-form/SignUpForm.tsx b/apps/mobile/src/features/auth/components/sign-up-form/SignUpForm.tsx index eaea254..ea52dd5 100644 --- a/apps/mobile/src/features/auth/components/sign-up-form/SignUpForm.tsx +++ b/apps/mobile/src/features/auth/components/sign-up-form/SignUpForm.tsx @@ -52,7 +52,7 @@ export function SignUpForm() { name="phoneNumber" label="Phone number" keyboardType="phone-pad" - placeholder="0801 234 5678" + placeholder="0803 123 4567" autoComplete="tel" textContentType="telephoneNumber" /> diff --git a/apps/mobile/src/features/beneficiaries/screens/BeneficiariesScreen.tsx b/apps/mobile/src/features/beneficiaries/screens/BeneficiariesScreen.tsx index 940f1d6..4a28d31 100644 --- a/apps/mobile/src/features/beneficiaries/screens/BeneficiariesScreen.tsx +++ b/apps/mobile/src/features/beneficiaries/screens/BeneficiariesScreen.tsx @@ -1,7 +1,7 @@ import { useState } from "react"; import { router, useLocalSearchParams } from "expo-router"; import { z } from "zod"; -import type { Beneficiary, Service } from "@quickpay/contracts"; +import { phone, type Beneficiary, type Service } from "@quickpay/contracts"; import { mutation } from "@quickpay/api-client"; import { api } from "../../../services/api"; import { useResource } from "../../../services/api/use-resource"; @@ -129,6 +129,8 @@ export function BeneficiariesScreen() { const service = catalog.data?.services.find( (s) => s.id === v.serviceId, ); + if (service && ["airtime", "data"].includes(service.category)) + v.account = phone.parse(v.account); await api( "/beneficiaries", mutation({ diff --git a/apps/mobile/src/features/bills/screens/BillsScreen.tsx b/apps/mobile/src/features/bills/screens/BillsScreen.tsx index f0f79bd..8129744 100644 --- a/apps/mobile/src/features/bills/screens/BillsScreen.tsx +++ b/apps/mobile/src/features/bills/screens/BillsScreen.tsx @@ -53,9 +53,13 @@ export function BillsScreen() { ); const form = useValidatedForm( z.object({ - beneficiary: z.string().trim().min(3, "Enter the recipient’s details."), + beneficiary: ["airtime", "data"].includes(category) + ? phone + : z.string().trim().min(3, "Enter the recipient’s details."), amount: z.string(), - phone: z.string(), + phone: ["airtime", "data"].includes(category) + ? z.union([z.literal(""), phone]) + : phone, }), { beneficiary: params.account || "", amount: "", phone: "" }, ); diff --git a/apps/mobile/src/features/transactions/components/ReceiptMenu.tsx b/apps/mobile/src/features/transactions/components/ReceiptMenu.tsx new file mode 100644 index 0000000..de87fc1 --- /dev/null +++ b/apps/mobile/src/features/transactions/components/ReceiptMenu.tsx @@ -0,0 +1,108 @@ +import { useState } from "react"; +import { Platform, View, Pressable, Text } from "react-native"; +import { SlidersHorizontal } from "lucide-react-native"; +import { File, Paths } from "expo-file-system"; +import * as Sharing from "expo-sharing"; +import { connection } from "../../../services/api/connection"; +import { secure } from "../../../services/secure-storage"; +import { rawApiUrl } from "../../../lib/config"; +import { Notice } from "../../../components/feedback/Feedback"; +export function ReceiptMenu({ id }: { id: string }) { + const [open, setOpen] = useState(false), + [busy, setBusy] = useState(false), + [message, setMessage] = useState(""); + async function save(format: "pdf" | "png", share: boolean) { + setOpen(false); + setBusy(true); + setMessage(""); + try { + const token = await secure.get("token"); + const response = await connection.fetch( + `${rawApiUrl?.replace(/\/$/, "")}/payments/${encodeURIComponent(id)}/receipt?format=${format}`, + { headers: { Authorization: `Bearer ${token}` } }, + ); + if (!response.ok) + throw new Error( + "We could not generate your receipt. Please try again.", + ); + const bytes = new Uint8Array(await response.arrayBuffer()); + const name = `QuickPay-receipt-${id}.${format}`, + mime = format === "pdf" ? "application/pdf" : "image/png"; + if (Platform.OS === "web") { + const file = new globalThis.File([bytes], name, { type: mime }); + if (share && navigator.canShare?.({ files: [file] })) + await navigator.share({ files: [file], title: "Quick Pay receipt" }); + else { + const url = URL.createObjectURL(file), + link = document.createElement("a"); + link.href = url; + link.download = name; + document.body.append(link); + link.click(); + link.remove(); + setTimeout(() => URL.revokeObjectURL(url), 60000); + } + } else { + const file = new File(Paths.document, name); + file.create({ overwrite: true }); + file.write(bytes); + if (share && (await Sharing.isAvailableAsync())) + await Sharing.shareAsync(file.uri, { + mimeType: mime, + UTI: format === "pdf" ? "com.adobe.pdf" : "public.png", + dialogTitle: "Quick Pay receipt", + }); + else + setMessage( + "Receipt downloaded. Choose Share to send it or save a copy outside Quick Pay.", + ); + } + } catch (error) { + if (!(error instanceof Error && error.name === "AbortError")) + setMessage( + error instanceof Error ? error.message : "Please try again.", + ); + } finally { + setBusy(false); + } + } + return ( + + setOpen(!open)} + className="min-h-11 flex-row items-center gap-2 rounded-xl border border-line bg-white px-4" + > + + + {busy ? "Preparing…" : "Receipt"} + + + {open && ( + + {( + [ + ["Download PDF", "pdf", false], + ["Download image", "png", false], + ["Share PDF", "pdf", true], + ["Share image", "png", true], + ] as const + ).map(([label, format, share]) => ( + void save(format, share)} + className="min-h-12 justify-center rounded-xl px-4" + > + {label} + + ))} + + )} + {!!message && {message}} + + ); +} diff --git a/apps/mobile/src/features/transactions/screens/TransactionScreen.tsx b/apps/mobile/src/features/transactions/screens/TransactionScreen.tsx index 5f1d039..1732282 100644 --- a/apps/mobile/src/features/transactions/screens/TransactionScreen.tsx +++ b/apps/mobile/src/features/transactions/screens/TransactionScreen.tsx @@ -1,6 +1,6 @@ import { useEffect, useState } from "react"; import { useQueryClient } from "@tanstack/react-query"; -import { AppState, Share, Text } from "react-native"; +import { AppState, Text } from "react-native"; import { router, useLocalSearchParams } from "expo-router"; import * as WebBrowser from "expo-web-browser"; import Animated, { FadeIn } from "react-native-reanimated"; @@ -25,6 +25,7 @@ import { } from "../lib/status"; import { validTransactionId } from "../../../services/deep-links/validate"; import { loadPending, savePending } from "../services/native-operation"; +import { ReceiptMenu } from "../components/ReceiptMenu"; export function safeCheckout(value: unknown) { try { const u = new URL(String(value)); @@ -44,7 +45,7 @@ export function TransactionScreen() { const valid = validTransactionId(id); const query = useResource<{ transaction: Transaction }>( `/payments/${valid ? id : "invalid"}`, - { enabled: valid, poll: 8000 }, + { enabled: valid }, ); const [busy, setBusy] = useState(false), [message, setMessage] = useState(""); @@ -72,22 +73,30 @@ export function TransactionScreen() { if (p?.transactionId === t.id) return savePending(null); }); }, [t?.id, t?.status]); + useEffect(() => { + if (!t || !isPending(t.status)) return; + const timer = setInterval(() => { + if (AppState.currentState === "active") void query.refetch(); + }, 30000); + return () => clearInterval(timer); + }, [t?.id, t?.status, query.refetch]); const checkout = safeCheckout(t?.details.checkoutUrl); return ( void query.refetch()} - refreshing={query.isRefetching} + refreshing={false} > {!valid ? ( This transaction link is invalid. ) : query.isPending ? ( - ) : query.error ? ( + ) : query.error && !query.data ? ( void query.refetch()} /> ) : ( t && ( <> + )} {message && {message}} - + {open && ( +
+ {( + [ + ["Download PDF", "pdf", false], + ["Download image", "png", false], + ["Share PDF", "pdf", true], + ["Share image", "png", true], + ] as const + ).map(([label, format, share]) => ( + + ))} +
+ )} + + ); +} diff --git a/apps/web/src/features/transactions/TransactionDetails.tsx b/apps/web/src/features/transactions/TransactionDetails.tsx index faa5a00..4e8cc2b 100644 --- a/apps/web/src/features/transactions/TransactionDetails.tsx +++ b/apps/web/src/features/transactions/TransactionDetails.tsx @@ -2,13 +2,14 @@ import { useEffect, useState } from "react"; import Link from "next/link"; import { toast } from "sonner"; -import { ArrowLeft, Printer, RefreshCw, ExternalLink } from "lucide-react"; +import { ArrowLeft, RefreshCw, ExternalLink } from "lucide-react"; import { api, mutation } from "@quickpay/api-client"; import { formatMoney, type Transaction } from "@quickpay/contracts"; import { useApi } from "../../lib/use-api"; import { StatusBadge } from "../../components/ui/status-badge"; import { Button } from "../../components/ui/button"; import { LoadingState, ErrorState } from "../../components/feedback"; +import { ReceiptMenu } from "./ReceiptMenu"; export function TransactionDetails({ id }: { id: string }) { const { data, error, loading, refresh } = useApi<{ transaction: Transaction; @@ -19,8 +20,8 @@ export function TransactionDetails({ id }: { id: string }) { if (!t || !["processing", "awaiting_authorization"].includes(t.status)) return; const timer = setInterval(() => { - void refresh(); - }, 5000); + if (document.visibilityState === "visible") void refresh(); + }, 30000); return () => clearInterval(timer); }, [t?.status, refresh]); async function check() { @@ -39,7 +40,7 @@ export function TransactionDetails({ id }: { id: string }) { } } if (loading) return ; - if (error) return ; + if (error && !data) return ; if (!t) return null; const success = t.status === "successful"; return ( @@ -56,7 +57,10 @@ export function TransactionDetails({ id }: { id: string }) {

{success ? "Payment receipt" : "Payment details"}

- +
+ + +

{formatMoney(t.amount)} @@ -130,12 +134,9 @@ export function TransactionDetails({ id }: { id: string }) { Open secure checkout )} - {success ? ( - - ) : ( + {["created", "processing", "awaiting_authorization"].includes( + t.status, + ) && ( ) : ( - - Set up two-step verification in Settings + + Set up your authenticator in Settings (use your existing login + password, then the app-generated code) )} diff --git a/apps/web/src/features/bills/BillsPage.tsx b/apps/web/src/features/bills/BillsPage.tsx index 49f1853..2e75ae4 100644 --- a/apps/web/src/features/bills/BillsPage.tsx +++ b/apps/web/src/features/bills/BillsPage.tsx @@ -1,4 +1,5 @@ "use client"; +import { TransactionPinField } from "../security/TransactionPinField"; import { useState, useEffect } from "react"; import { useRouter } from "next/navigation"; import { @@ -21,7 +22,7 @@ import { } from "@quickpay/contracts"; import { useApi } from "../../lib/use-api"; import { Field } from "../../components/ui/form-field"; -import { PasswordInput, inputClass } from "../../components/ui/password-input"; +import { inputClass } from "../../components/ui/password-input"; import { Button } from "../../components/ui/button"; import { LoadingState, @@ -153,7 +154,7 @@ export function BillsPage({ ...(data.plan ? { plan: data.plan } : {}), ...(data.phone ? { phone: data.phone } : {}), validationId: validation?.id, - password: new FormData(e.currentTarget).get("password"), + pin: new FormData(e.currentTarget).get("pin"), }, key, ), @@ -463,13 +464,7 @@ export function BillsPage({ ))} - +

Check the recipient carefully. Once confirmed, your payment may not be refundable. diff --git a/apps/web/src/features/referrals/ReferralsPage.tsx b/apps/web/src/features/referrals/ReferralsPage.tsx index 020d8cc..3b2ab95 100644 --- a/apps/web/src/features/referrals/ReferralsPage.tsx +++ b/apps/web/src/features/referrals/ReferralsPage.tsx @@ -1,11 +1,11 @@ "use client"; +import { TransactionPinField } from "../security/TransactionPinField"; import { useState } from "react"; import { toast } from "sonner"; import { Copy, Users } from "lucide-react"; import { formatMoney } from "@quickpay/contracts"; import { api, mutation } from "@quickpay/api-client"; import { useApi } from "../../lib/use-api"; -import { PasswordInput } from "../../components/ui/password-input"; import { Button } from "../../components/ui/button"; import { StatusBadge } from "../../components/ui/status-badge"; import { @@ -38,7 +38,7 @@ export function ReferralsPage() { try { await api( `/rewards/${claim}/claim`, - mutation({ password: new FormData(e.currentTarget).get("password") }), + mutation({ pin: new FormData(e.currentTarget).get("pin") }), ); toast.success("Your reward is in your wallet."); setClaim(""); @@ -150,13 +150,7 @@ export function ReferralsPage() { className="max-w-md space-y-4 rounded-2xl border border-brand/20 bg-white p-6" >

Confirm reward claim

- + +

+ )} + + + + + ); +} diff --git a/apps/web/src/features/security/TransactionPinField.tsx b/apps/web/src/features/security/TransactionPinField.tsx new file mode 100644 index 0000000..3f87bf1 --- /dev/null +++ b/apps/web/src/features/security/TransactionPinField.tsx @@ -0,0 +1,47 @@ +"use client"; +import { useEffect } from "react"; +import { useRouter } from "next/navigation"; +import { useApi } from "../../lib/use-api"; +import { PasswordInput } from "../../components/ui/password-input"; +export function TransactionPinField() { + const status = useApi<{ configured: boolean }>("/security/pin"), + router = useRouter(); + useEffect(() => { + if (status.data && !status.data.configured) + router.push( + `/settings?returnTo=${encodeURIComponent(window.location.pathname + window.location.search)}#transaction-pin`, + ); + }, [status.data?.configured, router]); + return ( +
+ +

+ Enter your six-digit payment PIN. It is different from your login + password and authenticator code. +

+ {status.error && ( +

+ {status.error}{" "} + +

+ )} +
+ ); +} diff --git a/apps/web/src/features/settings/SettingsPage.tsx b/apps/web/src/features/settings/SettingsPage.tsx index 9908dec..f52ba75 100644 --- a/apps/web/src/features/settings/SettingsPage.tsx +++ b/apps/web/src/features/settings/SettingsPage.tsx @@ -1,4 +1,6 @@ "use client"; +import QRCode from "react-qr-code"; +import { PinSettings } from "../security/PinSettings"; import { useState } from "react"; import { toast } from "sonner"; import { api, mutation } from "@quickpay/api-client"; @@ -37,7 +39,9 @@ export function SettingsPage() { toast.success( task === "email" ? "A verification link is on its way." - : "Your settings have been updated.", + : task === "mfa" + ? "Scan the QR code, then confirm the code generated by your authenticator." + : "Your settings have been updated.", ); await r.refresh(); return result; @@ -165,12 +169,16 @@ export function SettingsPage() { /> -
+ +

Two-step verification

{u.two_factor_enabled ? "Your authenticator adds an extra step when you sign in." - : "Protect your account with an authenticator app. Required for administrators."} + : "First enter your existing Quick Pay login password to authorize setup. Then scan the QR code in an authenticator app and enter its generated code. Do not choose a new password or a random code here. Required for administrators."}

{!u.two_factor_enabled && !setup && (
@@ -199,8 +207,13 @@ export function SettingsPage() { {setup && (

Add Quick Pay to your authenticator

+
+ +

- Choose “Enter setup key” in your app. Keep this key private. + Scan this QR code in Google Authenticator, Microsoft + Authenticator or a similar app, or choose “Enter setup key” in + your app. Keep this key private.

{new URL(setup.totpURI).searchParams.get("secret")} @@ -226,12 +239,13 @@ export function SettingsPage() { className="space-y-4" > diff --git a/apps/web/src/features/wallet/DepositPage.tsx b/apps/web/src/features/wallet/DepositPage.tsx index c9edfe5..6467482 100644 --- a/apps/web/src/features/wallet/DepositPage.tsx +++ b/apps/web/src/features/wallet/DepositPage.tsx @@ -1,4 +1,5 @@ "use client"; +import { TransactionPinField } from "../security/TransactionPinField"; import { useState } from "react"; import { useRouter } from "next/navigation"; import { api, mutation } from "@quickpay/api-client"; @@ -21,9 +22,14 @@ export function DepositPage() { ); const r = await api<{ transaction: Transaction }>( "/deposits", - mutation({ amount }, key), + mutation( + { amount, pin: new FormData(e.currentTarget).get("pin") }, + key, + ), + ); + router.push( + `/transactions/detail?id=${encodeURIComponent(r.transaction.id)}`, ); - router.push(`/transactions/detail?id=${encodeURIComponent(r.transaction.id)}`); } catch (e) { setError(e instanceof Error ? e.message : "Please try again."); } finally { @@ -52,6 +58,7 @@ export function DepositPage() { placeholder="5,000" />

Minimum ₦100. Maximum ₦1,000,000.

+ {error && }
- + )} {error && } diff --git a/docs/API.md b/docs/API.md index 5d3c15f..0d80432 100644 --- a/docs/API.md +++ b/docs/API.md @@ -4,7 +4,7 @@ Base URL: `/api/v1`. Machine-readable reference: `/api/v1/openapi`; Swagger view Use JSON and bearer sessions for mobile; browser calls use HttpOnly SameSite cookies through the same-origin web rewrite. Browser mutations need a matching Origin. Auth responses use Better Auth’s documented JSON/session conventions; sign-in may return `twoFactorRedirect`. Store mobile session tokens only in secure OS storage. Logout revokes the session. No core operation requires a React component or Server Action. -Money is an integer-kobo string, e.g. `"150000"` means ₦1,500.00. Timestamps are ISO UTC. Financial POSTs require an `Idempotency-Key` of 16–100 safe characters, scoped to the user. Retrying an identical body returns the original transaction; changing details with the same key gives 409. A payment password is authorization, excluded from the persisted request hash and transaction details. +Money is an integer-kobo string, e.g. `"150000"` means ₦1,500.00. Timestamps are ISO UTC. Financial POSTs require an `Idempotency-Key` of 16–100 safe characters, scoped to the user. Retrying an identical body returns the original transaction; changing details with the same key gives 409. A six-digit transaction PIN authorizes deposits, withdrawals, payments and reward claims. The PIN is excluded from the persisted request hash and transaction details. ## Native additions @@ -21,19 +21,19 @@ See [mobile capability map](MOBILE_CAPABILITIES.md) and [push/link setup](mobile ## Primary flows -| Flow | Requests and result | -| -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| Signup | POST `/auth/sign-up/email`: name, email, Nigerian phoneNumber, password, confirmPassword, optional referralCode, terms=true. Server records policy version/time; queues verification. | -| Verify/reset | GET signed `/auth/verify-email` link; POST `/auth/request-password-reset` and `/auth/reset-password`. New passwords meet the shared requirements. | -| Wallet | GET `/wallet`: available, reserved, rewards, reward_debt, debt and currency. | -| Deposit | POST `/deposits` with amount + idempotency. Returns transaction; poll owned `/payments/{id}` until checkoutUrl appears, then open hosted checkout. Redirect alone does not credit funds. | -| Withdrawal | GET `/banks`; POST `/banks/resolve` with bankCode/accountNumber; POST `/withdrawals` with amount, the same destination, validationId, password + idempotency. Destination checks expire after ten minutes. | -| Bill | GET `/catalog`; GET `/catalog/{serviceId}/plans`; POST `/billers/validate` where required; POST `/payments` with serviceId, beneficiary, amount, optional plan/phone/validationId, password + idempotency. Current fixed-plan amounts are rechecked. | -| Status/receipt | GET `/payments` with optional `before` ISO cursor; GET `/payments/{id}`; POST `/payments/{id}/check`. Only owned resources are returned. Receipt fulfillment appears only after verified success. | -| Gifts | GET `/gift-cards/products`; POST `/gift-cards/quotes` with productId/whole units; multipart POST `/gift-cards/evidence`; POST `/gift-cards/sales` with quoteId/evidenceId; GET sales. No credit on upload. Buying is unavailable. | -| Rewards | GET `/rewards/active-rule`, GET `/referrals`; POST `/rewards/{id}/claim` with password. Claim is idempotent by reward identity and uses the original rule. | -| Support | GET/POST `/support`: subject, message, optional owned transactionId. Notifications are GET/PATCH `/notifications`. | -| Profile | GET/PATCH `/profile`; POST `/auth/change-password`; MFA enable/verify through Better Auth. GET/POST/DELETE `/beneficiaries` is ownership scoped. | +| Flow | Requests and result | +| -------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| Signup | POST `/auth/sign-up/email`: name, email, Nigerian phoneNumber, password, confirmPassword, optional referralCode, terms=true. Server records policy version/time; queues verification. | +| Verify/reset | GET signed `/auth/verify-email` link; POST `/auth/request-password-reset` and `/auth/reset-password`. New passwords meet the shared requirements. | +| Wallet | GET `/wallet`: available, reserved, rewards, reward_debt, debt and currency. | +| Deposit | POST `/deposits` with amount, pin + idempotency. Returns transaction; poll owned `/payments/{id}` until checkoutUrl appears, then open hosted checkout. Redirect alone does not credit funds. | +| Withdrawal | GET `/banks`; POST `/banks/resolve` with bankCode/accountNumber; POST `/withdrawals` with amount, the same destination, validationId, pin + idempotency. Destination checks expire after ten minutes. | +| Bill | GET `/catalog`; GET `/catalog/{serviceId}/plans`; POST `/billers/validate` where required; POST `/payments` with serviceId, beneficiary, amount, optional plan/phone/validationId, pin + idempotency. Current fixed-plan amounts are rechecked. | +| Status/receipt | GET `/payments` with optional `before` ISO cursor; GET `/payments/{id}`; POST `/payments/{id}/check`. Only owned resources are returned. Receipt fulfillment appears only after verified success. | +| Gifts | GET `/gift-cards/products`; POST `/gift-cards/quotes` with productId/whole units; multipart POST `/gift-cards/evidence`; POST `/gift-cards/sales` with quoteId/evidenceId; GET sales. No credit on upload. Buying is unavailable. | +| Rewards | GET `/rewards/active-rule`, GET `/referrals`; POST `/rewards/{id}/claim` with pin. Claim is idempotent by reward identity and uses the original rule. | +| Support | GET/POST `/support`: subject, message, optional owned transactionId. Notifications are GET/PATCH `/notifications`. | +| Profile | GET/PATCH `/profile`; POST `/auth/change-password`; MFA enable/verify through Better Auth. GET/POST/DELETE `/beneficiaries` is ownership scoped. | ## Admin permissions and mutations @@ -57,3 +57,5 @@ All admin data endpoints require verified admin identity, relevant explicit perm Application errors are `{error:{code,message,fields?,correlationId}}` with safe customer wording. Auth endpoints may return Better Auth `{code,message}` errors, normalized by the API client. 401 means sign in; 403 means insufficient permission/verification/elevation; 409 means a state or idempotency conflict; 422 identifies invalid fields; 429 requires waiting; 503 indicates unavailable or uncertain provider work. Transactions model created, awaiting_authorization, processing, successful, failed, reversed and cancelled. A provider timeout remains processing. Reversed is a compensating outcome, including a release when the provider reversed before settlement. Never infer money movement from a browser fixture or a pending API response. + +Transaction PIN settings: GET `/security/pin` returns setup and lock status. POST `/security/pin` takes `password`, `newPin`, `confirmPin` and, when changing an existing PIN, `currentPin`. POST `/security/pin/reset` requires the login `password` to request an email code; submit `code`, `newPin` and `confirmPin` with that password to consume it. Reset codes expire after ten minutes, allow five attempts and are single use. Five incorrect PIN attempts lock payment authorization for fifteen minutes. diff --git a/packages/contracts/src/index.ts b/packages/contracts/src/index.ts index 2d7e752..fbdf41b 100644 --- a/packages/contracts/src/index.ts +++ b/packages/contracts/src/index.ts @@ -95,6 +95,16 @@ export const states = [ "cancelled", ] as const; export type PaymentState = (typeof states)[number]; +export const transactionPin = z + .string() + .regex(/^\d{6}$/, "Enter your six-digit transaction PIN."); +export const newTransactionPin = transactionPin.refine( + (v) => + !/^(\d)\1{5}$/.test(v) && + !"01234567890123456789".includes(v) && + !"98765432109876543210".includes(v), + "Choose a PIN without repeated or sequential digits.", +); export const paymentSchema = z.object({ serviceId: z.string().min(1), beneficiary: z.string().trim().min(3).max(100), @@ -102,16 +112,16 @@ export const paymentSchema = z.object({ plan: z.string().max(100).optional(), phone: phone.optional(), validationId: z.string().uuid().optional(), - password: z.string().min(1), + pin: transactionPin, }); export const withdrawalSchema = z.object({ amount: money, bankCode: z.string().regex(/^\d{3,6}$/), accountNumber: z.string().regex(/^\d{10}$/), validationId: z.string().uuid(), - password: z.string().min(1), + pin: transactionPin, }); -export const depositSchema = z.object({ amount: money }); +export const depositSchema = z.object({ amount: money, pin: transactionPin }); export const rewardRuleSchema = z .object({ name: z.string().trim().min(3).max(100), diff --git a/packages/database/migrations/0013_transaction_pin.sql b/packages/database/migrations/0013_transaction_pin.sql new file mode 100644 index 0000000..7c5d527 --- /dev/null +++ b/packages/database/migrations/0013_transaction_pin.sql @@ -0,0 +1,14 @@ +CREATE TABLE transaction_pins ( + user_id text PRIMARY KEY REFERENCES users(id) ON DELETE CASCADE, + pin_hash text NOT NULL, + failed_attempts integer NOT NULL DEFAULT 0 CHECK(failed_attempts>=0), + locked_until timestamptz, + updated_at timestamptz NOT NULL DEFAULT now() +); +CREATE TABLE pin_reset_challenges ( + user_id text PRIMARY KEY REFERENCES users(id) ON DELETE CASCADE, + code_hash text NOT NULL, + expires_at timestamptz NOT NULL, + attempts integer NOT NULL DEFAULT 0 CHECK(attempts>=0), + created_at timestamptz NOT NULL DEFAULT now() +); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f2a7a03..d19886c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -195,6 +195,9 @@ importers: react-native-gesture-handler: specifier: ~2.32.0 version: 2.32.0(react-native@0.86.3(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.86.3(@babel/core@7.29.7(supports-color@8.1.1))(supports-color@8.1.1))(@types/react@19.2.18)(react@19.2.3)(supports-color@8.1.1))(react@19.2.3) + react-native-qrcode-svg: + specifier: ^6.3.53 + version: 6.3.53(react-native-svg@15.15.4(react-native@0.86.3(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.86.3(@babel/core@7.29.7(supports-color@8.1.1))(supports-color@8.1.1))(@types/react@19.2.18)(react@19.2.3)(supports-color@8.1.1))(react@19.2.3))(react-native@0.86.3(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.86.3(@babel/core@7.29.7(supports-color@8.1.1))(supports-color@8.1.1))(@types/react@19.2.18)(react@19.2.3)(supports-color@8.1.1))(react@19.2.3) react-native-reanimated: specifier: 4.5.1 version: 4.5.1(react-native-worklets@0.10.1(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.86.3(@babel/core@7.29.7(supports-color@8.1.1))(supports-color@8.1.1))(react-native@0.86.3(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.86.3(@babel/core@7.29.7(supports-color@8.1.1))(supports-color@8.1.1))(@types/react@19.2.18)(react@19.2.3)(supports-color@8.1.1))(react@19.2.3)(supports-color@8.1.1))(react-native@0.86.3(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.86.3(@babel/core@7.29.7(supports-color@8.1.1))(supports-color@8.1.1))(@types/react@19.2.18)(react@19.2.3)(supports-color@8.1.1))(react@19.2.3) @@ -259,6 +262,9 @@ importers: react-dom: specifier: 19.3.1 version: 19.3.1(react@19.3.1) + react-qr-code: + specifier: ^2.2.0 + version: 2.2.0(react@19.3.1) sonner: specifier: 2.0.8 version: 2.0.8(@types/react@19.3.0)(react-dom@19.3.1(react@19.3.1))(react@19.3.1) @@ -2491,6 +2497,10 @@ packages: resolution: {integrity: sha512-QOSvevhslijgYwRx6Rv7zKdMF8lbRmx+uQGx2+vDc+KI/eBnsy9kit5aj23AgGu3pa4t9AgwbnXWqS+iOY+2aA==} engines: {node: '>= 6'} + camelcase@5.3.1: + resolution: {integrity: sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==} + engines: {node: '>=6'} + camelcase@6.3.0: resolution: {integrity: sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==} engines: {node: '>=10'} @@ -2540,6 +2550,9 @@ packages: client-only@0.0.1: resolution: {integrity: sha512-IV3Ou0jSMzZrd3pZ48nLkT9DA7Ag1pnPzaiQhpW7c3RbcqqzvzzVu+L8gfqMp/8IM2MQtSiqaCxrrcfu8I8rMA==} + cliui@6.0.0: + resolution: {integrity: sha512-t6wbgtoCXvAzst7QgXxJYqPt0usEfbgQdftEPbLL/cvv6HPE5VgvqCuAIDR0NgU52ds6rFwqrgakNLrHEjCbrQ==} + cliui@8.0.1: resolution: {integrity: sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ==} engines: {node: '>=12'} @@ -2664,6 +2677,10 @@ packages: supports-color: optional: true + decamelize@1.2.0: + resolution: {integrity: sha512-z2S+W9X73hAUUki+N+9Za2lBlun89zigOyGrsax+KUQ6wKW4ZoWpEYBkGhQjwAjjDCkWxhY0VKEhk8wzY7F5cA==} + engines: {node: '>=0.10.0'} + decode-uri-component@0.2.2: resolution: {integrity: sha512-FqUYQ+8o158GyGTrMFJms9qh3CqTKvAqgqsTnkLI8sKu0028orqBhxNMFkFen0zGyg6epACD32pjVk58ngIErQ==} engines: {node: '>=0.10'} @@ -2700,6 +2717,9 @@ packages: didyoumean@1.2.2: resolution: {integrity: sha512-gxtyfqMg7GKyhQmb056K7M3xszy/myH8w+B4RT+QXBQsvAOdc3XymqDDPHx1BgPgsdAA5SIifona89YtRATDzw==} + dijkstrajs@1.0.3: + resolution: {integrity: sha512-qiSlmBq9+BCdCA/L46dw8Uy93mloxsPSbwnm5yrKn2vMPiy8KyAskTF6zuV/j5BMsmOGZDPs7KjU+mjb670kfA==} + dlv@1.1.3: resolution: {integrity: sha512-+HlytyjlPKnIG8XuRG8WvmBP8xs8P71y+SKKS6ZXWoEgLuePxtDoUEiH7WkdePWrQ5JBpE6aoVqfZfJUQkjXwA==} @@ -3240,6 +3260,10 @@ packages: resolution: {integrity: sha512-aAWcW57uxVNrQZqFXjITpW3sIUQmHGG3qSb9mUah9MgMC4NeWhNOlNjXEYq3HjRAvL6arUviZGGJsBg6z0zsWA==} engines: {node: '>= 0.8'} + find-up@4.1.0: + resolution: {integrity: sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw==} + engines: {node: '>=8'} + find-up@5.0.0: resolution: {integrity: sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng==} engines: {node: '>=10'} @@ -3672,6 +3696,10 @@ packages: lines-and-columns@1.2.4: resolution: {integrity: sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg==} + locate-path@5.0.0: + resolution: {integrity: sha512-t7hw9pI+WvuwNJXwk5zVHpyhIqzg2qTlklJOf0mVxGSbe3Fp2VieZcduNYjaLDoy6p9uGpQEGWG87WpMKlNq8g==} + engines: {node: '>=8'} + locate-path@6.0.0: resolution: {integrity: sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw==} engines: {node: '>=10'} @@ -4072,14 +4100,26 @@ packages: resolution: {integrity: sha512-eNwHudNbO1folBP3JsZ19v9azXWtQZjICdr3Q0TDPIaeBQ3mXLrh54wM+er0+hSp+dWKf+Z8KM58CYzEyIYxYg==} engines: {node: '>=6'} + p-limit@2.3.0: + resolution: {integrity: sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==} + engines: {node: '>=6'} + p-limit@3.1.0: resolution: {integrity: sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==} engines: {node: '>=10'} + p-locate@4.1.0: + resolution: {integrity: sha512-R79ZZ/0wAxKGu3oYMlz8jy/kbhsNrS7SKZ7PxEHBgJ5+F2mtFW2fK2cOtBh1cHYkQsbzFV7I+EoRKe6Yt0oK7A==} + engines: {node: '>=8'} + p-locate@5.0.0: resolution: {integrity: sha512-LaNjtRWUBY++zB5nE/NwcaoMylSPk+S+ZHNB1TzdbMJMny6dynpAGt7X/tl/QYq3TIeE6nxHppbo2LGymrG5Pw==} engines: {node: '>=10'} + p-try@2.2.0: + resolution: {integrity: sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==} + engines: {node: '>=6'} + pako@1.0.11: resolution: {integrity: sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==} @@ -4189,6 +4229,10 @@ packages: resolution: {integrity: sha512-NCrCHhWmnQklfH4MtJMRjZ2a8c80qXeMlQMv2uVp9ISJMTt562SbGd6n2oq0PaPgKm7Z6pL9E2UlLIhC+SHL3w==} engines: {node: '>=4.0.0'} + pngjs@5.0.0: + resolution: {integrity: sha512-40QW5YalBNfQo5yRYmiw7Yz6TKKVr3h6970B2YE+3fQpsWcrbj1PzJgxeJ19DRQjhMbKPIuMY8rFaXc8moolVw==} + engines: {node: '>=10.13.0'} + postcss-import@15.1.0: resolution: {integrity: sha512-hpr+J05B2FVYUAXHeK1YyI267J/dDDhMU6B6civm8hSY1jYJnBXxzKDKDswzJmtLHryrjhnDjqqp/49t8FALew==} engines: {node: '>=14.0.0'} @@ -4287,6 +4331,9 @@ packages: resolution: {integrity: sha512-NxNv/kLguCA7p3jE8oL2aEBsrJWgAakBpgmgK6lpPWV+WuOmY6r2/zbAVnP+T8bQlA0nzHXSJSJW0Hq7ylaD2Q==} engines: {node: '>= 6'} + prop-types@15.8.1: + resolution: {integrity: sha512-oj87CgZICdulUohogVAR7AjlC0327U4el4L6eAvOqCeudMDVU0NThNaV+b9Df4dXgSP1gXMTnPdhfe/2qDH5cg==} + punycode@2.3.1: resolution: {integrity: sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==} engines: {node: '>=6'} @@ -4295,6 +4342,14 @@ packages: resolution: {integrity: sha512-+Owyggi9IxT1ePKGafcI87ubSmxol6smwJ+RAHDQlx9+9cPwFWDiKFFCPuWhr9ignlGpZ9vDQLw67N4dcTVFEA==} engines: {node: '>=20'} + qrcode-generator@2.0.4: + resolution: {integrity: sha512-mZSiP6RnbHl4xL2Ap5HfkjLnmxfKcPWpWe/c+5XxCuetEenqmNFf1FH/ftXPCtFG5/TDobjsjz6sSNL0Sr8Z9g==} + + qrcode@1.5.4: + resolution: {integrity: sha512-1ca71Zgiu6ORjHqFBDpnSMTR2ReToX4l1Au1VFLyVeBTFavzQnv5JxMFr3ukHVKpSrSA2MCk0lNJSykjUfz7Zg==} + engines: {node: '>=10.13.0'} + hasBin: true + query-string@7.1.3: resolution: {integrity: sha512-hh2WYhq4fi8+b+/2Kg9CEge4fDPvHS534aOOvOZeQ3+Vf2mCFsaFBYj0i+iXcAq6I9Vzp5fjMFBlONvayDC1qg==} engines: {node: '>=6'} @@ -4383,6 +4438,13 @@ packages: react: '*' react-native: '*' + react-native-qrcode-svg@6.3.53: + resolution: {integrity: sha512-Csx2ejz3n3irUB1DQCjsYwOS3NKL7Ci4vsb+rerxp9IZ+5tsbOVC1+ZZEzwiYE84fOUnPOOoRJ7rztBuAN4Luw==} + peerDependencies: + react: '*' + react-native: '>=0.63.4' + react-native-svg: '>=14.0.0' + react-native-reanimated@4.5.1: resolution: {integrity: sha512-RnMvtDuR+68ig864gAvZCOdZehqhC5rFmMo0kn+ARfgVSTvFeF6IFLBVgMPUu0KwihaapEyW24WRi6nEyy1kSA==} peerDependencies: @@ -4436,6 +4498,11 @@ packages: '@types/react': optional: true + react-qr-code@2.2.0: + resolution: {integrity: sha512-e5nS0UUN22K3Nf8KBRUzemfdJ6OmnN5w+kbnj1lvJaol9RyVRFeGl05bCkxSN2ZegbLxjjYjX1+mmAoX9+fAhw==} + peerDependencies: + react: '*' + react-refresh@0.14.2: resolution: {integrity: sha512-jCvmsr+1IUSMUyzOkRcvnVbX3ZYC6g9TDrDbFuFmRDq7PD4yaGbLKNQL6k2jnArV8hjYxh7hVhAZB6s9HDGpZA==} engines: {node: '>=0.10.0'} @@ -4510,6 +4577,9 @@ packages: resolution: {integrity: sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==} engines: {node: '>=0.10.0'} + require-main-filename@2.0.0: + resolution: {integrity: sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==} + resolve-from@5.0.0: resolution: {integrity: sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw==} engines: {node: '>=8'} @@ -4583,6 +4653,9 @@ packages: server-only@0.0.1: resolution: {integrity: sha512-qepMx2JxAa5jjfzxG79yPPq+8BuFToHd1hm7kI+Z4zAq1ftQiP7HcxMhDDItrbtwVeLg/cY2JnKnrcFkmiswNA==} + set-blocking@2.0.0: + resolution: {integrity: sha512-KiKBS8AnWGEyLzofFfmvKwpdPzqiy16LvQfK3yv/fVH7Bj13/wl3JSR1J+rfgRE9q7xUJK4qvgS8raSOeLUehw==} + set-cookie-parser@3.2.2: resolution: {integrity: sha512-df017qMeYuXo4emL09nlyMpi2i2MtEIKS/6jtXH3vmjFgIRsOi852/5RmhJ4EkvN3ZF8jXadM/EkTPXgc8yPIw==} @@ -4775,6 +4848,10 @@ packages: engines: {node: '>=10'} hasBin: true + text-encoding@0.7.0: + resolution: {integrity: sha512-oJQ3f1hrOnbRLOcwKz0Liq2IcrvDeZRHXhd9RgLrsT+DjWY/nty1Hi7v3dtkaEYbPYe0mUoOfzRrMwfXXwgPUA==} + deprecated: no longer maintained + thenify-all@1.6.0: resolution: {integrity: sha512-RNxQH/qI8/t3thXJDwcstUO4zeqo64+Uy/+sNVRBx4Xn2OX+OZ9oP+iJnNFqplFra2ZUVeKCSa2oVWi3T4uVmA==} engines: {node: '>=0.8'} @@ -5057,6 +5134,9 @@ packages: whatwg-url@5.0.0: resolution: {integrity: sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==} + which-module@2.0.1: + resolution: {integrity: sha512-iBdZ57RDvnOR9AGBhML2vFZf7h8vmBjhoaZqODJBFWHVtKkDmKuHai3cx5PgVMrX5YDNp27AofYbAwctSS+vhQ==} + which@2.0.2: resolution: {integrity: sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==} engines: {node: '>= 8'} @@ -5071,6 +5151,10 @@ packages: resolution: {integrity: sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==} engines: {node: '>=0.10.0'} + wrap-ansi@6.2.0: + resolution: {integrity: sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA==} + engines: {node: '>=8'} + wrap-ansi@7.0.0: resolution: {integrity: sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==} engines: {node: '>=10'} @@ -5119,6 +5203,9 @@ packages: resolution: {integrity: sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==} engines: {node: '>=0.4'} + y18n@4.0.3: + resolution: {integrity: sha512-JKhqTOwSrqNA1NY5lSztJ1GrBiUodLMmIZuLiDaMRJ+itFd+ABVE8XBjOvIWL+rSqNDC74LCSFmlb/U4UZ4hJQ==} + y18n@5.0.8: resolution: {integrity: sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==} engines: {node: '>=10'} @@ -5131,10 +5218,18 @@ packages: engines: {node: '>= 14.6'} hasBin: true + yargs-parser@18.1.3: + resolution: {integrity: sha512-o50j0JeToy/4K6OZcaQmW6lyXXKhq7csREXcDwk2omFPJEwUNOVtJKvmDr9EI1fAJZUyZcRF7kxGBWmRXudrCQ==} + engines: {node: '>=6'} + yargs-parser@21.1.1: resolution: {integrity: sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==} engines: {node: '>=12'} + yargs@15.4.1: + resolution: {integrity: sha512-aePbxDmcYW++PaqBsJ+HYUFwCdv4LVvdnhBy78E57PIor8/OVvhMrADFFEDh8DHDFRv/O9i3lPhsENjO7QX0+A==} + engines: {node: '>=8'} + yargs@17.7.3: resolution: {integrity: sha512-GZtjxm/J/4TSxuL3FNYjCmLktBTnIw/rVmKSIyKeYAZpmJB2ig9VauCC5xsa82GNKVKDAqpOn3KVzNt0zmrU0g==} engines: {node: '>=12'} @@ -8016,6 +8111,8 @@ snapshots: camelcase-css@2.0.1: {} + camelcase@5.3.1: {} + camelcase@6.3.0: {} caniuse-lite@1.0.30001820: {} @@ -8076,6 +8173,12 @@ snapshots: client-only@0.0.1: {} + cliui@6.0.0: + dependencies: + string-width: 4.2.3 + strip-ansi: 6.0.1 + wrap-ansi: 6.2.0 + cliui@8.0.1: dependencies: string-width: 4.2.3 @@ -8206,6 +8309,8 @@ snapshots: optionalDependencies: supports-color: 8.1.1 + decamelize@1.2.0: {} + decode-uri-component@0.2.2: {} deep-is@0.1.4: {} @@ -8228,6 +8333,8 @@ snapshots: didyoumean@1.2.2: {} + dijkstrajs@1.0.3: {} + dlv@1.1.3: {} dnssd-advertise@1.1.6: {} @@ -8980,6 +9087,11 @@ snapshots: transitivePeerDependencies: - supports-color + find-up@4.1.0: + dependencies: + locate-path: 5.0.0 + path-exists: 4.0.0 + find-up@5.0.0: dependencies: locate-path: 6.0.0 @@ -9323,6 +9435,10 @@ snapshots: lines-and-columns@1.2.4: {} + locate-path@5.0.0: + dependencies: + p-locate: 4.1.0 + locate-path@6.0.0: dependencies: p-locate: 5.0.0 @@ -9946,14 +10062,24 @@ snapshots: strip-ansi: 5.2.0 wcwidth: 1.0.1 + p-limit@2.3.0: + dependencies: + p-try: 2.2.0 + p-limit@3.1.0: dependencies: yocto-queue: 0.1.0 + p-locate@4.1.0: + dependencies: + p-limit: 2.3.0 + p-locate@5.0.0: dependencies: p-limit: 3.1.0 + p-try@2.2.0: {} + pako@1.0.11: {} parse-png@2.1.0: @@ -10056,6 +10182,8 @@ snapshots: pngjs@3.4.0: {} + pngjs@5.0.0: {} + postcss-import@15.1.0(postcss@8.5.32): dependencies: postcss: 8.5.32 @@ -10138,12 +10266,26 @@ snapshots: kleur: 3.0.3 sisteransi: 1.0.5 + prop-types@15.8.1: + dependencies: + loose-envify: 1.4.0 + object-assign: 4.1.1 + react-is: 16.13.1 + punycode@2.3.1: {} qified@0.10.1: dependencies: hookified: 2.2.0 + qrcode-generator@2.0.4: {} + + qrcode@1.5.4: + dependencies: + dijkstrajs: 1.0.3 + pngjs: 5.0.0 + yargs: 15.4.1 + query-string@7.1.3: dependencies: decode-uri-component: 0.2.2 @@ -10263,6 +10405,15 @@ snapshots: react-native: 0.86.3(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.86.3(@babel/core@7.29.7(supports-color@8.1.1))(supports-color@8.1.1))(@types/react@19.3.0)(react@19.3.1)(supports-color@8.1.1) optional: true + react-native-qrcode-svg@6.3.53(react-native-svg@15.15.4(react-native@0.86.3(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.86.3(@babel/core@7.29.7(supports-color@8.1.1))(supports-color@8.1.1))(@types/react@19.2.18)(react@19.2.3)(supports-color@8.1.1))(react@19.2.3))(react-native@0.86.3(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.86.3(@babel/core@7.29.7(supports-color@8.1.1))(supports-color@8.1.1))(@types/react@19.2.18)(react@19.2.3)(supports-color@8.1.1))(react@19.2.3): + dependencies: + prop-types: 15.8.1 + qrcode: 1.5.4 + react: 19.2.3 + react-native: 0.86.3(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.86.3(@babel/core@7.29.7(supports-color@8.1.1))(supports-color@8.1.1))(@types/react@19.2.18)(react@19.2.3)(supports-color@8.1.1) + react-native-svg: 15.15.4(react-native@0.86.3(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.86.3(@babel/core@7.29.7(supports-color@8.1.1))(supports-color@8.1.1))(@types/react@19.2.18)(react@19.2.3)(supports-color@8.1.1))(react@19.2.3) + text-encoding: 0.7.0 + react-native-reanimated@4.5.1(react-native-worklets@0.10.1(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.86.3(@babel/core@7.29.7(supports-color@8.1.1))(supports-color@8.1.1))(react-native@0.86.3(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.86.3(@babel/core@7.29.7(supports-color@8.1.1))(supports-color@8.1.1))(@types/react@19.2.18)(react@19.2.3)(supports-color@8.1.1))(react@19.2.3)(supports-color@8.1.1))(react-native@0.86.3(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.86.3(@babel/core@7.29.7(supports-color@8.1.1))(supports-color@8.1.1))(@types/react@19.2.18)(react@19.2.3)(supports-color@8.1.1))(react@19.2.3): dependencies: react: 19.2.3 @@ -10479,6 +10630,12 @@ snapshots: - utf-8-validate optional: true + react-qr-code@2.2.0(react@19.3.1): + dependencies: + prop-types: 15.8.1 + qrcode-generator: 2.0.4 + react: 19.3.1 + react-refresh@0.14.2: {} react-remove-scroll-bar@2.3.8(@types/react@19.2.18)(react@19.2.3): @@ -10570,6 +10727,8 @@ snapshots: require-directory@2.1.1: {} + require-main-filename@2.0.0: {} + resolve-from@5.0.0: {} resolve-workspace-root@2.0.1: {} @@ -10660,6 +10819,8 @@ snapshots: server-only@0.0.1: {} + set-blocking@2.0.0: {} + set-cookie-parser@3.2.2: {} setimmediate@1.0.5: {} @@ -10873,6 +11034,8 @@ snapshots: commander: 2.20.3 source-map-support: 0.5.21 + text-encoding@0.7.0: {} + thenify-all@1.6.0: dependencies: thenify: 3.3.1 @@ -11137,6 +11300,8 @@ snapshots: tr46: 0.0.3 webidl-conversions: 3.0.1 + which-module@2.0.1: {} + which@2.0.2: dependencies: isexe: 2.0.0 @@ -11145,6 +11310,12 @@ snapshots: word-wrap@1.2.5: {} + wrap-ansi@6.2.0: + dependencies: + ansi-styles: 4.3.0 + string-width: 4.2.3 + strip-ansi: 6.0.1 + wrap-ansi@7.0.0: dependencies: ansi-styles: 4.3.0 @@ -11170,14 +11341,35 @@ snapshots: xtend@4.0.2: {} + y18n@4.0.3: {} + y18n@5.0.8: {} yallist@3.1.1: {} yaml@2.9.1: {} + yargs-parser@18.1.3: + dependencies: + camelcase: 5.3.1 + decamelize: 1.2.0 + yargs-parser@21.1.1: {} + yargs@15.4.1: + dependencies: + cliui: 6.0.0 + decamelize: 1.2.0 + find-up: 4.1.0 + get-caller-file: 2.0.5 + require-directory: 2.1.1 + require-main-filename: 2.0.0 + set-blocking: 2.0.0 + string-width: 4.2.3 + which-module: 2.0.1 + y18n: 4.0.3 + yargs-parser: 18.1.3 + yargs@17.7.3: dependencies: cliui: 8.0.1 diff --git a/tests/browser/account-lifecycle.spec.ts b/tests/browser/account-lifecycle.spec.ts index cb54173..20bcade 100644 --- a/tests/browser/account-lifecycle.spec.ts +++ b/tests/browser/account-lifecycle.spec.ts @@ -115,6 +115,35 @@ test("real HTTP account lifecycle and customer pages", async ({ await expect( page.getByText("We could not complete this request.", { exact: false }), ).toHaveCount(0); + if (path === "/settings") { + await page + .getByLabel("Current login password", { exact: true }) + .fill(password); + await page + .getByLabel("New transaction PIN", { exact: true }) + .fill("572904"); + await page + .getByLabel("Confirm transaction PIN", { exact: true }) + .fill("572904"); + await page + .getByRole("button", { name: "Set transaction PIN", exact: true }) + .click(); + await expect( + page + .getByRole("status") + .filter({ hasText: "Your transaction PIN is ready." }), + ).toBeVisible(); + expect( + await (await page.request.get("/api/v1/security/pin")).json(), + ).toMatchObject({ configured: true }); + const stored = ( + await db.query( + "SELECT p.pin_hash FROM transaction_pins p JOIN users u ON u.id=p.user_id WHERE u.email=$1", + [email], + ) + ).rows[0]; + expect(stored.pin_hash).not.toBe("572904"); + } } await page .getByLabel("What do you need help with?") diff --git a/tests/browser/quickpay.spec.ts b/tests/browser/quickpay.spec.ts index db41826..e926ba0 100644 --- a/tests/browser/quickpay.spec.ts +++ b/tests/browser/quickpay.spec.ts @@ -95,27 +95,29 @@ async function fixture( const custom = extra(path, req.method(), body); const data = custom ?? - (path === "/health" - ? { status: "ok" } - : path === "/admin/access" - ? { allowed: true, mfaEnabled: true } - : path === "/auth/get-session" - ? session - : path === "/profile" - ? { user: { name: "Browser Test", email_verified: true } } - : path === "/wallet" - ? { - available: "2500000", - reserved: "0", - rewards: "0", - reward_debt: "0", - currency: "NGN", - } - : path.startsWith("/payments/") - ? { transaction } - : path === "/payments" - ? { transactions: [] } - : {}); + (path === "/security/pin" + ? { configured: true } + : path === "/health" + ? { status: "ok" } + : path === "/admin/access" + ? { allowed: true, mfaEnabled: true } + : path === "/auth/get-session" + ? session + : path === "/profile" + ? { user: { name: "Browser Test", email_verified: true } } + : path === "/wallet" + ? { + available: "2500000", + reserved: "0", + rewards: "0", + reward_debt: "0", + currency: "NGN", + } + : path.startsWith("/payments/") + ? { transaction } + : path === "/payments" + ? { transactions: [] } + : {}); await route.fulfill({ status: 200, contentType: "application/json", @@ -356,9 +358,7 @@ test("bill wizard reviews beneficiary, fee and total then shows pending state", await page.getByLabel("Amount (₦)").fill("1000"); await page.getByRole("button", { name: "Review payment" }).click(); await expect(page.getByText("₦1,000.00").first()).toBeVisible(); - await page - .getByLabel("Confirm with your password", { exact: true }) - .fill("StrongPassword123!"); + await page.getByLabel("Transaction PIN", { exact: true }).fill("572904"); await page.getByRole("button", { name: "Confirm and pay" }).click(); await expect(page).toHaveURL(/\/transactions\//); await expect(page.getByText("processing", { exact: true })).toBeVisible(); @@ -396,9 +396,7 @@ test("withdrawal validates bank details before authorization and reservation", a await page.getByLabel("Amount (₦)").fill("1000"); await page.getByRole("button", { name: "Check account and review" }).click(); await expect(page.getByText("BROWSER TEST", { exact: true })).toBeVisible(); - await page - .getByLabel("Confirm with your password", { exact: true }) - .fill("StrongPassword123!"); + await page.getByLabel("Transaction PIN", { exact: true }).fill("572904"); await page.getByRole("button", { name: "Confirm withdrawal" }).click(); await expect(page).toHaveURL(/transactions/); expect(submitted?.validationId).toBe("22222222-2222-4222-8222-222222222222"); @@ -508,3 +506,82 @@ test("transaction status refreshes quietly after thirty seconds and receipts dow `QuickPay-receipt-${transaction.id}.pdf`, ); }); + +test("missing PIN redirects to setup and resumes deposit after saving", async ({ + page, +}) => { + let configured = false; + await fixture(page, (path, method, body) => { + if (path === "/security/pin") { + if (method === "POST") { + expect(body).toMatchObject({ + password: "StrongPassword123!", + newPin: "572904", + confirmPin: "572904", + }); + configured = true; + return { message: "Your transaction PIN is ready." }; + } + return { configured }; + } + if (path === "/wallet/capabilities") + return { + deposits: true, + withdrawals: true, + depositMethods: ["card"], + minimumDeposit: "10000", + maximumDeposit: "100000000", + withdrawalFee: "0", + }; + }); + await page.goto("/deposit"); + await expect(page).toHaveURL(/settings\/?\?returnTo=.*#transaction-pin/); + await page + .getByLabel("Current login password", { exact: true }) + .fill("StrongPassword123!"); + await page.getByLabel("New transaction PIN", { exact: true }).fill("572904"); + await page + .getByLabel("Confirm transaction PIN", { exact: true }) + .fill("572904"); + await page + .getByRole("button", { name: "Set transaction PIN", exact: true }) + .click(); + await expect(page).toHaveURL(/\/deposit\/?$/); + await expect( + page.getByLabel("Transaction PIN", { exact: true }), + ).toBeEditable(); +}); + +test("authenticator setup explains existing password and displays a local QR code", async ({ + page, +}) => { + await fixture(page, (path) => { + if (path === "/auth/two-factor/enable") + return { + totpURI: + "otpauth://totp/Quick%20Pay:browser?secret=JBSWY3DPEHPK3PXP&issuer=Quick%20Pay", + backupCodes: ["backup-one", "backup-two"], + }; + }); + await page.goto("/settings#authenticator"); + await expect( + page.getByText(/First enter your existing Quick Pay login password/), + ).toBeVisible(); + await page + .getByLabel("Existing login password", { exact: true }) + .fill("StrongPassword123!"); + await page + .getByRole("button", { name: "Set up authenticator", exact: true }) + .click(); + await expect(page.locator("#authenticator svg")).toBeVisible(); + await expect( + page.getByLabel("Six-digit code generated by your authenticator"), + ).toBeVisible(); + await expect( + page.getByText("JBSWY3DPEHPK3PXP", { exact: true }), + ).toBeVisible(); + await page.screenshot({ + path: "/tmp/quickpay-security-settings.png", + fullPage: true, + }); +}); diff --git a/tests/financial.test.ts b/tests/financial.test.ts index eebd8f9..f51af9b 100644 --- a/tests/financial.test.ts +++ b/tests/financial.test.ts @@ -25,8 +25,17 @@ import { parseNaira, signUpSchema, phone, + newTransactionPin, type RewardRule, } from "@quickpay/contracts"; +import { + setTransactionPin, + verifyTransactionPin, + requestPinReset, + resetTransactionPin, +} from "../apps/api/src/v1/modules/security/services/pin"; +import { pinSettings } from "../apps/api/src/v1/modules/security/routes/pin"; +import { createOperation } from "../apps/api/src/v1/modules/payments/services/create-payment"; import { verifyAdminEmail } from "../apps/api/src/v1/modules/admin/services/verify-email"; import { auth } from "../apps/api/src/v1/modules/auth/auth"; import { authorized } from "../apps/api/src/shared/auth"; @@ -142,6 +151,8 @@ beforeAll(async () => { await user(ids.referrer); await user(ids.user, ids.referrer); await user(ids.other); + for (const id of [ids.user, ids.other, ids.referrer]) + await setTransactionPin(id, "572904"); }); afterAll(() => pool.end()); @@ -1229,7 +1240,7 @@ describe("account lifecycle and ledger enforcement", () => { authorization: `Bearer ${login.token}`, "content-type": "application/json", }, - body: JSON.stringify({ password: testPassword }), + body: JSON.stringify({ pin: "572904" }), }); const before = await balance(ids.referrer); await claimReward(request(), r.id); @@ -1343,3 +1354,238 @@ describe("gift-card review and settlement", () => { expect(await balance(seller)).toBe(BigInt(q.amount)); }); }); + +describe("transaction PIN security", () => { + it("persists failed attempts, locks, and resets only with a single-use verified email code", async () => { + const id = crypto.randomUUID(); + await user(id); + await expect(verifyTransactionPin(id, "572904")).rejects.toMatchObject({ + code: "PIN_REQUIRED", + }); + await setTransactionPin(id, "572904"); + expect( + ( + await pool.query( + "SELECT pin_hash FROM transaction_pins WHERE user_id=$1", + [id], + ) + ).rows[0].pin_hash, + ).not.toBe("572904"); + for (let i = 0; i < 5; i++) + await expect(verifyTransactionPin(id, "111111")).rejects.toMatchObject({ + code: i === 4 ? "PIN_LOCKED" : "PIN_INCORRECT", + }); + expect( + ( + await pool.query( + "SELECT failed_attempts FROM transaction_pins WHERE user_id=$1", + [id], + ) + ).rows[0].failed_attempts, + ).toBe(5); + await expect(verifyTransactionPin(id, "572904")).rejects.toMatchObject({ + code: "PIN_LOCKED", + }); + await requestPinReset(id); + const job = ( + await pool.query( + "SELECT payload FROM jobs WHERE type='email' AND payload->>'to'=$1 AND payload->>'subject'='Reset your transaction PIN' ORDER BY created_at DESC LIMIT 1", + [`${id}@quickpay.test`], + ) + ).rows[0].payload; + expect(job.text).toContain("{{code}}"); + const code = unseal(job.otpEncrypted); + const wrong = String((Number(code) + 1) % 1000000).padStart(6, "0"); + await expect( + resetTransactionPin(id, wrong, "684207"), + ).rejects.toMatchObject({ code: "OTP_INVALID" }); + expect( + ( + await pool.query( + "SELECT attempts FROM pin_reset_challenges WHERE user_id=$1", + [id], + ) + ).rows[0].attempts, + ).toBe(1); + await resetTransactionPin(id, code, "684207"); + await verifyTransactionPin(id, "684207"); + await expect(resetTransactionPin(id, code, "906248")).rejects.toMatchObject( + { code: "OTP_INVALID" }, + ); + await expect(verifyTransactionPin(id, "572904")).rejects.toMatchObject({ + code: "PIN_INCORRECT", + }); + }); + it("requires the separate PIN for deposits, withdrawals and payments before any provider submission", async () => { + const id = crypto.randomUUID(); + await user(id); + await setTransactionPin(id, "572904"); + const login = await auth().api.signInEmail({ + body: { email: `${id}@quickpay.test`, password: testPassword }, + headers: new Headers({ "x-forwarded-for": "127.0.0.9" }), + }); + const variants = [ + ["deposit", { amount: "10000" }], + [ + "withdrawal", + { + amount: "10000", + bankCode: "999", + accountNumber: "1234567890", + validationId: crypto.randomUUID(), + }, + ], + [ + "payment", + { amount: "10000", serviceId: "mtn", beneficiary: "08031234567" }, + ], + ] as const; + for (const [kind, fields] of variants) { + const req = new Request(`http://localhost:3001/api/v1/${kind}`, { + method: "POST", + headers: { + Authorization: `Bearer ${login.token}`, + "Content-Type": "application/json", + "Idempotency-Key": crypto.randomUUID(), + }, + body: JSON.stringify({ ...fields, pin: "111111" }), + }); + await expect(createOperation(req, kind)).rejects.toMatchObject({ + code: "PIN_INCORRECT", + }); + } + expect( + ( + await pool.query( + "SELECT count(*)::int AS count FROM transactions WHERE user_id=$1", + [id], + ) + ).rows[0].count, + ).toBe(0); + }); +}); + +describe("PIN settings and account security alerts", () => { + it("rejects weak PINs and requires both the login password and old PIN for a change", async () => { + for (const value of ["111111", "123456", "987654", "1234", "abcdef"]) + expect(newTransactionPin.safeParse(value).success).toBe(false); + const id = crypto.randomUUID(); + await user(id); + const login = await auth().api.signInEmail({ + body: { email: `${id}@quickpay.test`, password: testPassword }, + headers: new Headers({ "x-forwarded-for": "127.0.0.12" }), + }); + const req = (value?: unknown) => + new Request("http://localhost:3001/api/v1/security/pin", { + method: value ? "POST" : "GET", + headers: { + Authorization: `Bearer ${login.token}`, + "Content-Type": "application/json", + }, + ...(value ? { body: JSON.stringify(value) } : {}), + }); + expect(await (await pinSettings(req())).json()).toEqual({ + configured: false, + lockedUntil: null, + }); + await expect( + pinSettings( + req({ + password: "wrong-password", + newPin: "572904", + confirmPin: "572904", + }), + ), + ).rejects.toMatchObject({ code: "AUTHORIZATION_FAILED" }); + await pinSettings( + req({ password: testPassword, newPin: "572904", confirmPin: "572904" }), + ); + expect(await (await pinSettings(req())).json()).toEqual({ + configured: true, + lockedUntil: null, + }); + await expect( + pinSettings( + req({ + password: testPassword, + currentPin: "684207", + newPin: "906248", + confirmPin: "906248", + }), + ), + ).rejects.toMatchObject({ code: "PIN_INCORRECT" }); + await pinSettings( + req({ + password: testPassword, + currentPin: "572904", + newPin: "906248", + confirmPin: "906248", + }), + ); + await verifyTransactionPin(id, "906248"); + const jobs = ( + await pool.query( + "SELECT payload FROM jobs WHERE type='email' AND payload->>'to'=$1", + [`${id}@quickpay.test`], + ) + ).rows; + expect(jobs.map((j) => j.payload.subject)).toEqual( + expect.arrayContaining([ + "Transaction PIN set", + "Transaction PIN changed", + ]), + ); + expect(JSON.stringify(jobs)).not.toMatch(/572904|906248|StrongPassword123/); + }); + it("queues branded-delivery jobs for successful login and password change without exposing credentials", async () => { + const id = crypto.randomUUID(); + await user(id); + const headers = { + "content-type": "application/json", + "expo-origin": "quickpay-dev://", + "x-real-ip": "127.0.0.13", + "x-forwarded-for": "127.0.0.13", + "user-agent": "QuickPay Android", + }; + const response = await handleAuth( + new Request("http://localhost:3001/api/v1/auth/sign-in/email", { + method: "POST", + headers, + body: JSON.stringify({ + email: `${id}@quickpay.test`, + password: testPassword, + }), + }), + ); + expect(response.status).toBe(200); + const login = await response.json(); + const changed = await handleAuth( + new Request("http://localhost:3001/api/v1/auth/change-password", { + method: "POST", + headers: { ...headers, Authorization: `Bearer ${login.token}` }, + body: JSON.stringify({ + currentPassword: testPassword, + newPassword: "NewPassword456!", + revokeOtherSessions: true, + }), + }), + ); + expect(changed.status).toBe(200); + const jobs = ( + await pool.query( + "SELECT payload FROM jobs WHERE type='email' AND payload->>'to'=$1", + [`${id}@quickpay.test`], + ) + ).rows; + expect(jobs.map((j) => j.payload.subject)).toEqual( + expect.arrayContaining([ + "New sign-in to Quick Pay", + "Your password changed", + ]), + ); + expect(JSON.stringify(jobs)).not.toContain(login.token); + expect(JSON.stringify(jobs)).not.toMatch( + /StrongPassword123|NewPassword456/, + ); + }); +}); diff --git a/tests/mailjet.test.ts b/tests/mailjet.test.ts index 5c7aeb2..7708dcf 100644 --- a/tests/mailjet.test.ts +++ b/tests/mailjet.test.ts @@ -4,6 +4,8 @@ const config = vi.hoisted(() => ({ MAILJET_SECRET_KEY: "test-secret-key", MAILJET_FROM_EMAIL: "sender@example.com", MAILJET_FROM_NAME: "Quick Pay", + WEB_ORIGIN: "https://example.com", + DATA_ENCRYPTION_KEY: "a".repeat(64), })); vi.mock("../apps/api/src/shared/infrastructure/env", () => ({ env: () => config, @@ -41,12 +43,20 @@ describe("Mailjet email delivery", () => { expect(init?.signal).toBeDefined(); expect(JSON.parse(String(init?.body))).toEqual({ Messages: [ - { + expect.objectContaining({ From: { Email: "sender@example.com", Name: "Quick Pay" }, To: [{ Email: job.to }], Subject: job.subject, TextPart: job.text, - }, + HTMLPart: expect.stringContaining("cid:quickpay-logo"), + InlinedAttachments: [ + expect.objectContaining({ + ContentID: "quickpay-logo", + ContentType: "image/png", + Base64Content: expect.any(String), + }), + ], + }), ], }); }); @@ -79,3 +89,48 @@ describe("Mailjet email delivery", () => { await expect(sendEmail(job)).rejects.toThrow("Network timeout"); }); }); + +describe("branded email security", () => { + it("escapes message content and permits action buttons only for the app origin", async () => { + const { emailTemplate } = + await import("../apps/api/src/shared/infrastructure/email/template"); + const html = emailTemplate({ + subject: '', + text: " https://attacker.example/verify", + siteUrl: "https://example.com", + }); + expect(html).not.toContain("