Skip to content

feat(payments): card transaction id & export - #1233

Merged
khaira777 merged 1 commit into
FreeOpenSourcePOS:mainfrom
jfernandogt:Numero-de-transaccion-de-tarjeta
Oct 22, 2026
Merged

khaira777 merged 1 commit into
FreeOpenSourcePOS:mainfrom
jfernandogt:Numero-de-transaccion-de-tarjeta

Conversation

@habet-alex

@habet-alex habet-alex commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Related work

Issue / Discussion: Contributor feature PR (#1233)

Summary

Adds an optional store setting (card_transaction_id_required, default false) under Settings -> Payment methods that requires cashiers to enter the card terminal's transaction reference number when settling a built-in card payment line, and extends the Daily Sales Export (GET /api/reports/daily-sales/export) with a Payments worksheet in XLSX and a part=payments CSV download so card terminal transaction numbers can be reconciled against batch settlement reports.

  • Settings & Backend Validation (main/routes/settings.ts, main/routes/bills.ts, main/lib/operation-failure.ts): Registers card_transaction_id_required in OPTIONAL_SETTING_DEFAULTS ('false') and ALLOWED_WILDCARD_KEYS with boolean validation. When enabled, built-in card payment lines without a non-empty trimmed transaction_id are rejected with HTTP 400 and display_code: 'card_transaction_id_required', while transaction_id values exceeding 256 characters continue to fail with display_code: 'payment_input_invalid'. Custom payment methods are unaffected.
  • POS Settlement & Order Detail (PaymentModal.tsx, PrepaidCheckoutModal.tsx, pos/page.tsx, OrderDetailPanel.tsx): Displays a transaction number input on active built-in card rows when card_transaction_id_required is enabled (or revealed by a card_transaction_id_required rejection), forwards trimmed transaction_id values in both post-order bill settlement and prepaid counter checkout, preserves transaction_id across stored prepaid attempt retries, and displays recorded payment transaction references in OrderDetailPanel.
  • Daily Sales Export (main/services/daily-sales-export.ts, main/services/daily-sales-export-files.ts, main/routes/reports.ts, dashboard/page.tsx): Adds payments ledger rows (bill_number, order_number, store-local payment_time, resolved method, amount, and verbatim transaction_id) to buildDailySalesExportDataset, appends a Payments sheet to the XLSX workbook, adds part=payments to CSV export, and updates the dashboard CSV export action to download all three CSV parts (summary, items, payments).
  • Translations (frontend/src/lib/i18n/messages/*.json): Adds localized strings for the setting toggle, hint, input label, and validation message across all 24 supported locales.

Scope

  • Only built-in card payment lines are gated by card_transaction_id_required; custom payment methods and non-card tenders (cash, upi, wallet) are unaffected.
  • No database schema migration is required (card_transaction_id_required is persisted in settings, and transaction_id is already stored in bills.payment_details JSON and payment_transaction_refs).

Verification

Commands run:

  • node tests/run-electron-node-test.cjs tests/card-transaction-id.test.ts
  • node tests/run-electron-node-test.cjs tests/daily-sales-export.test.ts
  • node tests/run-electron-node-test.cjs tests/issue-788-order-attempt-storage.test.ts
  • npm run test:script-coverage
  • npm run i18n:check
  • npm run test:translations
  • npm run docs:check
  • node scripts/ci/check-changed-format.cjs --base origin/main
  • npm run lint
  • npm run build
  • npm run build:frontend

Results:

  • tests/card-transaction-id.test.ts: 30/30 passed (including missing, empty "", whitespace " ", and > 256-char transaction_id validation, custom method exemption, verbatim ledger storage, and cross-bill 409 reuse rejection).
  • tests/daily-sales-export.test.ts: 76/76 passed (XLSX Summary + Items + Payments sheets, store-local payment_time, leading-zero preservation on transaction_id, part=payments CSV export, and empty-day header-only sheets).
  • tests/issue-788-order-attempt-storage.test.ts: passed (card_transaction_id_required classified as expected payment rejection).
  • npm run test:script-coverage: 256 reachable scripts, 314 test files covered.
  • npm run i18n:check & npm run test:translations: all 24 locales (3,200 leaf keys each) passed parity and ICU checks.
  • npm run docs:check, check-changed-format.cjs, npm run lint, npm run build, and npm run build:frontend: all passed with 0 errors.

Compatibility & data safety

  • Database/data impact: None. Uses the existing settings table (card_transaction_id_required, defaulting to 'false') and existing bills.payment_details / payment_transaction_refs columns.
  • Migration: None required. Existing installations default to card_transaction_id_required = 'false', preserving existing card checkout behavior unless enabled.
  • User-visible behavior: Optional setting in Settings -> Payment methods; when enabled, POS payment and prepaid checkout modals require a transaction number on built-in card payments. Daily sales export includes a Payments worksheet in XLSX and a third CSV download (daily-sales-YYYY-MM-DD-payments.csv).
  • Offline/network impact: None. Runs completely offline against local SQLite storage.

Cross-cutting surfaces

Surface Status
UI Verified (PaymentMethodsSettings, PaymentModal, PrepaidCheckoutModal, OrderDetailPanel, DashboardPage, POSPage, SupportPage)
API Verified (GET/PUT /api/settings/card_transaction_id_required, POST /api/bills/:id/payments, GET /api/reports/daily-sales/export)
Persistence Verified (settings key and bills.payment_details JSON ledger)
Upgrade path Not affected (no schema migration; default 'false' preserves existing behavior)
CSV Verified (part=payments CSV export with toCsvRow formula neutralization)
RTL Verified (<Ltr> wrapper used for transaction_id in OrderDetailPanel)
Timezone Verified (payment_time formatted in configured store timezone via storeLocalTimestamp)
Permissions Verified (owner-only daily sales export; settings fallback when unreadable by role)

Developer documentation

  • Existing developer documentation updated: docs/architecture/order-lifecycle.md, docs/reference/api.md, and docs/reference/daily-sales-export.md

Contributor checklist

  • This is a small isolated fix/doc update OR follows an approved issue/direction.
  • Unrelated cleanups, refactors, and dependency changes were kept out of this PR.
  • Tests were added or updated for any behavior changes.
  • Verification commands were run and documented above.
  • Customer data and upgrade safety were preserved (if touching database/storage).
  • Documentation or translations were updated where relevant.
  • I understand and can explain all submitted changes.

@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@khaira777

Copy link
Copy Markdown
Contributor

Hi @habet-alex, thank you for working on this! Adding card terminal transaction numbers to payment settlement and reports is a useful addition for cashier reconciliation.

CC @itsbkm for maintainer review and scope decision.

I completed a technical review of the changes across the backend, frontend, translations, and test suites. Storing card_transaction_id_required in the existing settings table avoids unnecessary schema migrations, and all 24 locale files pass npm run i18n:check and npm run test:translations cleanly.

Before this PR can be merged, there are two functional bugs and a scope question for @itsbkm that need to be addressed:


1. Functional Bug: transaction_id is omitted in PrepaidCheckoutModal.tsx

In frontend/src/components/pos/PrepaidCheckoutModal.tsx, you added the input field and validation (lines 457-464), but when mapping splitLines to pass to onConfirm (lines 475-481), transaction_id is omitted:

// frontend/src/components/pos/PrepaidCheckoutModal.tsx
const splitLines: PrepaidPayment[] = paymentRows
  .map((p) => ({
    method: p.payment_method_id === undefined ? p.method : 'custom',
    ...(p.payment_method_id !== undefined ? { payment_method_id: p.payment_method_id } : {}),
    amount: toStoredUnit(parseFloat(p.amount) || 0),
    ...(needsTransactionId(p) && p.transaction_id?.trim()
      ? { transaction_id: p.transaction_id.trim() }
      : {}),
  }))
  .filter((p) => p.amount > 0 && !isNaN(p.amount));

Because transaction_id is missing from splitLines, prepaid counter checkout always submits payments without the transaction number, causing the backend to reject the checkout with 400 (card_transaction_id_required) when the setting is enabled.


2. Backend Validation Bypass in main/routes/bills.ts

In main/routes/bills.ts (lines 2948-2962), the validation checks:

if (
  payment.method === 'card' &&
  payment.payment_method_id === undefined &&
  payment.transaction_id === undefined
)

If a client submits { method: 'card', transaction_id: '' } or whitespace (' '), payment.transaction_id === undefined is false, bypassing the required check.

Please tighten the backend check to require a non-empty trimmed string and enforce the 256-character bound:

if (
  payment.method === 'card' &&
  payment.payment_method_id === undefined &&
  (typeof payment.transaction_id !== 'string' || payment.transaction_id.trim() === '')
) {
  throw paymentValidationError(
    `Card transaction_id is required at line ${index + 1}`,
    'card_transaction_id_required',
  );
}
if (typeof payment.transaction_id === 'string' && payment.transaction_id.length > 256) {
  throw paymentValidationError(
    `Card transaction_id exceeds maximum length of 256 characters at line ${index + 1}`,
    'payment_input_invalid',
  );
}

3. Scope Decision Required from @itsbkm: Daily Sales Export Contract Change

This PR bundles two distinct changes:

  1. Card transaction number setting and enforcement in POS / bills.
  2. A new Payments export sheet in XLSX (main/services/daily-sales-export.ts) and a third CSV part (part=payments) in GET /api/reports/daily-sales/export (main/routes/reports.ts), changing the dashboard CSV export button (frontend/src/app/(dashboard)/dashboard/page.tsx) to trigger three file downloads instead of two.

@itsbkm: Please confirm whether you want to keep the Daily Sales Export Payments sheet and third CSV download bundled in this PR (once items 1 and 2 above are fixed), or split the export changes into a separate PR.

@khaira777
khaira777 force-pushed the Numero-de-transaccion-de-tarjeta branch from 7c4d333 to 026a6d2 Compare October 22, 2026 15:37
@khaira777 khaira777 changed the title FEAT: Agregar el numero de transaccion para pagos con tarjeta. feat(payments): card transaction id & export Oct 22, 2026
@khaira777

Copy link
Copy Markdown
Contributor

Rebased onto origin/main (026a6d28) and applied the follow-up review updates:

  1. Prepaid checkout & POS failure handling: Verified PrepaidCheckoutModal.tsx includes trimmed transaction_id in splitLines when needsTransactionId(p) holds, and POSPage maps card_transaction_id_required to cardTransactionIdMissing.
  2. Backend validation tightening (main/routes/bills.ts & tests/card-transaction-id.test.ts): Updated validatePaymentFields and preparePaymentBatch so built-in card payment lines with transaction_id: undefined, '', or whitespace ' ' consistently return HTTP 400 with display_code: 'card_transaction_id_required' when card_transaction_id_required === 'true', while values exceeding 256 characters return 400 with display_code: 'payment_input_invalid'. Added test assertions covering empty, whitespace, and > 256-character inputs in tests/card-transaction-id.test.ts (30/30 passing).
  3. Formatting & conflict resolution: Resolved merge conflicts in docs/reference/api.md, frontend/src/components/pos/PaymentModal.tsx, and package.json, and formatted all touched files with oxfmt.

@khaira777

Copy link
Copy Markdown
Contributor

@greptileai review this at apex

@greptile-apps

greptile-apps Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5 Tier: apex

[Medium impact] The PR appears safe to merge; no new actionable issues were found.

Summary

Adds an optional requirement for card terminal references and includes payment rows in daily sales exports.

  • Card payments can require terminal reference numbers.
  • Daily sales exports include payment-by-payment details.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  Setting["Optional card reference setting"] --> Checkout["Cashier enters terminal reference"]
  Checkout --> API["Backend checks payment"]
  API --> Ledger["Saved payment details"]
  Ledger --> Detail["Order details show reference"]
  Ledger --> Dataset["Daily sales payment rows"]
  Dataset --> XLSX["Payments worksheet"]
  Dataset --> CSV["payments CSV"]
Loading

Reviews (10) · Last reviewed commit: "feat(payments): card transaction id & ex..." · Reviewed by Greptile

Comment thread main/routes/bills.ts Resolved
@khaira777
khaira777 force-pushed the Numero-de-transaccion-de-tarjeta branch from 026a6d2 to 352d811 Compare October 22, 2026 16:08
@khaira777

Copy link
Copy Markdown
Contributor

@greptileai review this at apex

Comment thread tests/card-transaction-id.test.ts Resolved
@khaira777
khaira777 force-pushed the Numero-de-transaccion-de-tarjeta branch from 352d811 to 0054aad Compare October 22, 2026 16:30
@khaira777

Copy link
Copy Markdown
Contributor

@greptileai review this at apex

2 similar comments
@khaira777

Copy link
Copy Markdown
Contributor

@greptileai review this at apex

@khaira777

Copy link
Copy Markdown
Contributor

@greptileai review this at apex

@khaira777
khaira777 force-pushed the Numero-de-transaccion-de-tarjeta branch from 0054aad to ada9de2 Compare October 22, 2026 16:32
@khaira777

Copy link
Copy Markdown
Contributor

@greptileai review this at apex

@khaira777
khaira777 force-pushed the Numero-de-transaccion-de-tarjeta branch from ada9de2 to 2dc2e62 Compare October 22, 2026 17:12
@khaira777

Copy link
Copy Markdown
Contributor

Fixed in 2dc2e625:

  • Preserve saved discount and committed bill when retrying prepaid checkout (frontend/src/app/(dashboard)/pos/page.tsx, frontend/src/components/pos/PrepaidCheckoutModal.tsx): POSPage now reads the matching PrepaidAttempt before opening PrepaidCheckoutModal and passes initialDiscount={prepaidModalAttempt?.discount ?? null} and discountCommitted={Boolean(prepaidModalAttempt?.bill)}. PrepaidCheckoutModal initializes its discount state from initialDiscount so the reopened checkout keeps the discounted total (e.g., ฿57.78 instead of reverting to ฿64.20) and skips re-prompting for a manager PIN when the already-committed discount is unchanged, preserving attempt.bill on retry.
  • Regression coverage (tests/card-transaction-id.test.ts, frontend/e2e/prepaid-payment-reconciliation.spec.ts): Added regression tests verifying that reopening PrepaidCheckoutModal after a card_transaction_id_required rejection preserves the 10% discount and ฿57.78 payable total and settles the existing discounted bill without regenerating it.

@khaira777

Copy link
Copy Markdown
Contributor

@greptileai review this at apex

@khaira777
khaira777 force-pushed the Numero-de-transaccion-de-tarjeta branch from 2dc2e62 to 8c766ac Compare October 22, 2026 17:34
@khaira777

Copy link
Copy Markdown
Contributor

@greptileai review this at apex

@khaira777
khaira777 force-pushed the Numero-de-transaccion-de-tarjeta branch from 8c766ac to 64fc7ad Compare October 22, 2026 18:19
@khaira777

Copy link
Copy Markdown
Contributor

@greptileai review this at apex

@khaira777
khaira777 force-pushed the Numero-de-transaccion-de-tarjeta branch from 64fc7ad to 6052c8e Compare October 22, 2026 20:36
@khaira777

Copy link
Copy Markdown
Contributor

@greptileai review this at apex

@khaira777
khaira777 force-pushed the Numero-de-transaccion-de-tarjeta branch from 6052c8e to 3c682d1 Compare October 22, 2026 20:53
@khaira777

Copy link
Copy Markdown
Contributor

@greptileai review this at apex

@khaira777
khaira777 force-pushed the Numero-de-transaccion-de-tarjeta branch from 3c682d1 to 9cc5698 Compare October 22, 2026 21:21
@khaira777

Copy link
Copy Markdown
Contributor

@greptileai review this at apex

@khaira777
khaira777 force-pushed the Numero-de-transaccion-de-tarjeta branch from 9cc5698 to 9db261b Compare October 22, 2026 22:09
@khaira777
khaira777 merged commit 9d6261c into FreeOpenSourcePOS:main Oct 22, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants