Skip to content

Feature: Payment reference code - #4587

Merged
objecttothis merged 21 commits into
masterfrom
feature-payment-reference-code
Jul 10, 2026
Merged

objecttothis merged 21 commits into
masterfrom
feature-payment-reference-code

Conversation

@objecttothis

@objecttothis objecttothis commented Jun 29, 2026 •

Copy link
Copy Markdown
Member

app/Database/Migrations/20190427100000_paymenttracking.php adds the reference_code column to the sales_payments table but this column was never used in the code itself. This is now needed for Credit Card Retrieval Reference Numbers (RRN), Transaction Number or Acquirer Reference Number (ARN) depending on the payment implementation. This number is manually entered when using a card payment system not integrated with OpensourcePOS and can be used by plugins when sending API data to government-required sales registers.

  • Update Language strings
  • Update register view
  • Add Unit Tests
  • Think through adding configurable length requirements as 12-character RRN is not universal. Maybe set a min/max in settings?

Summary by CodeRabbit

  • New Features
    • Improved sales payment handling for payment types that require a reference code, including gift card and rewards remainder updates plus dynamic reference-code length validation.
    • Added localized UI text for displaying reference-code length limits in supported locales.
  • Bug Fixes
    • Updated sales register/edit and completion flows to reliably refresh payment details after validation and error states.
  • Documentation
    • Expanded localization conventions to require adding new translation keys across all language variants, using empty values to safely fall back to English.
  • Chores
    • Standardized formatting across configuration and many language files.

Payment Reference Code appears with Debit and Credit type payments
image

Customizable length limits
image

reference_code is now stored in the database
image

Validation on limits and content
image

image image

Travis Garrison added 5 commits June 29, 2026 15:24
…nd replace snake_case with camelCase variables

Signed-off-by: Travis Garrison <[email protected]>
…ys like `must_enter_rrn` and `reference_code`

Signed-off-by: Travis Garrison <[email protected]>
…ment` with `referenceCode` support

Signed-off-by: Travis Garrison <[email protected]>
…e naming conventions and improve readability

Signed-off-by: Travis Garrison <[email protected]>
@objecttothis objecttothis added this to the 3.5.0 milestone Jun 29, 2026
@objecttothis objecttothis self-assigned this Jun 29, 2026
@coderabbitai

This comment was marked as low quality.

Travis Garrison added 4 commits June 29, 2026 18:28
…erence_code` across language files and update `Sales` controller to replace `must_enter_rrn` with the new key

Signed-off-by: Travis Garrison <[email protected]>
- Add `get_reference_code_payment_types()` to locale_helper as single
  source of truth for card-requiring payment types
- Add reference code row to register view, shown/hidden via JS based
  on selected payment type
- Fix payment type dropdown width to 100% for consistent layout
- Add min-width to payment buttons and right-padding to button group

Signed-off-by: Travis Garrison <[email protected]>
- Add payment_reference_code_min and payment_reference_code_max fields
  to Config controller save logic
- Add translation keys for reference code length limits across all
  language files (min/max label + section header)
- Align array key formatting in Config controller for readability

Signed-off-by: Travis Garrison <[email protected]>
…language files

Convert double-quoted array keys and values to single quotes in all
app/Language/*/Config.php and app/Language/*/Sales.php variants.
No translation content changed — formatting only.

Also add Localization section to AGENTS.md documenting language file
conventions for new keys and fallback behavior.

Signed-off-by: Travis Garrison <[email protected]>
@objecttothis

This comment was marked as resolved.

@coderabbitai

This comment was marked as resolved.

@coderabbitai

This comment was marked as resolved.

Travis Garrison added 2 commits July 2, 2026 01:21
Add localized strings for payment_reference_code_length_limits,
payment_reference_code_length_max_label, and
payment_reference_code_length_min_label across all supported locales.

Signed-off-by: Travis Garrison <[email protected]>
- Add baseLocalePayload() helper in ConfigTest for postSaveLocale tests
- Add testSaveLocale_AcceptsValidReferenceCodeMinMax and related boundary tests
- Add Sale_libPaymentTest for payment reference code validation in Sale_lib

Signed-off-by: Travis Garrison <[email protected]>
@objecttothis
objecttothis marked this pull request as ready for review July 1, 2026 21:37

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 7

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@app/Controllers/Sales.php`:
- Line 1394: The sale edit save flow is dropping reference codes because
postSave() does not carry reference_code through when rebuilding payment rows.
Update the Sales controller’s postSave() handling so edited and newly added
payments persist reference_code the same way postAddPayment() does, including
validation and assignment into the payment data structures before saving.
- Around line 489-492: The payment handling in Sales::addPayment is passing raw
reference_code for every tender type and the Sale_lib::addPayment aggregation is
collapsing distinct card references under the same payment_type. Update the
addPayment flow and its session keying/contract so only reference-code payment
types carry a sanitized validated reference_code, and distinct Credit/Debit
reference codes are preserved while non-reference tender types ignore stray
codes without changing the stored payment_type.
- Around line 405-407: The payment validation rules in Sales::... currently only
require amount_tendered, which lets non-numeric input reach parse_decimals() and
downstream totals. Update the rules array for the card/reference-code payment
flow to include the normal decimal/numeric validation for amount_tendered while
keeping the existing required checks, and make sure the sanitization/validation
path used in this controller still enforces numeric input before calling
parse_decimals().

In `@app/Language/ar-EG/Config.php`:
- Around line 229-232: The translation entry in Config.php for
payment_reference_code_length_limits uses a malformed line-break tag, so update
that label to use the proper br tag instead of the closing form. Make the change
in the Config array entry for payment_reference_code_length_limits, keeping the
rest of the Arabic text unchanged, and ensure the label renders with the
intended break.

In `@app/Language/ar-LB/Config.php`:
- Around line 229-232: The translation entry for
payment_reference_code_length_limits uses a malformed HTML break tag, so update
the string in Config.php to use a proper br tag format instead of the
closing-only form. Make this change in the language array alongside
payment_reference_code_length_max_label and
payment_reference_code_length_min_label, keeping the rest of the translation
text unchanged.

In `@app/Language/az/Config.php`:
- Around line 229-232: Fix the malformed HTML in the language string for
payment_reference_code_length_limits in Config::az so the label uses a proper
line break tag. Replace the closing-only break markup with the standard <br> tag
in that translation entry, and keep the adjacent
payment_reference_code_length_max_label and
payment_reference_code_length_min_label entries unchanged.

In `@app/Language/bg/Config.php`:
- Around line 229-232: The translation string in Config.php for
payment_reference_code_length_limits uses a malformed closing break tag, so
update that label to use the correct HTML break syntax instead of the current
closing form; keep the change limited to the
payment_reference_code_length_limits entry alongside the related
payment_reference_code_length_max_label and
payment_reference_code_length_min_label strings.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ed0a4eea-4d24-42ad-a8d9-7ce7a874a642

📥 Commits

Reviewing files that changed from the base of the PR and between 632d4ea and c5a280f.

📒 Files selected for processing (101)
  • AGENTS.md
  • app/Controllers/Config.php
  • app/Controllers/Sales.php
  • app/Helpers/locale_helper.php
  • app/Language/ar-EG/Config.php
  • app/Language/ar-EG/Sales.php
  • app/Language/ar-LB/Config.php
  • app/Language/ar-LB/Sales.php
  • app/Language/az/Config.php
  • app/Language/az/Sales.php
  • app/Language/bg/Config.php
  • app/Language/bg/Sales.php
  • app/Language/bs/Config.php
  • app/Language/bs/Sales.php
  • app/Language/ckb/Config.php
  • app/Language/ckb/Sales.php
  • app/Language/cs/Config.php
  • app/Language/cs/Sales.php
  • app/Language/da/Config.php
  • app/Language/da/Sales.php
  • app/Language/de-CH/Config.php
  • app/Language/de-CH/Sales.php
  • app/Language/de-DE/Config.php
  • app/Language/de-DE/Sales.php
  • app/Language/el/Config.php
  • app/Language/el/Sales.php
  • app/Language/en-GB/Config.php
  • app/Language/en-GB/Sales.php
  • app/Language/en/Config.php
  • app/Language/en/Sales.php
  • app/Language/es-ES/Config.php
  • app/Language/es-ES/Sales.php
  • app/Language/es-MX/Config.php
  • app/Language/es-MX/Sales.php
  • app/Language/fa/Config.php
  • app/Language/fa/Sales.php
  • app/Language/fr/Config.php
  • app/Language/fr/Sales.php
  • app/Language/he/Config.php
  • app/Language/he/Sales.php
  • app/Language/hr-HR/Config.php
  • app/Language/hr-HR/Sales.php
  • app/Language/hu/Config.php
  • app/Language/hu/Sales.php
  • app/Language/hy/Config.php
  • app/Language/hy/Sales.php
  • app/Language/id/Config.php
  • app/Language/id/Sales.php
  • app/Language/it/Config.php
  • app/Language/it/Sales.php
  • app/Language/km/Config.php
  • app/Language/km/Sales.php
  • app/Language/lo/Config.php
  • app/Language/lo/Sales.php
  • app/Language/ml/Config.php
  • app/Language/ml/Sales.php
  • app/Language/nb/Config.php
  • app/Language/nb/Sales.php
  • app/Language/nl-BE/Config.php
  • app/Language/nl-BE/Sales.php
  • app/Language/nl-NL/Config.php
  • app/Language/nl-NL/Sales.php
  • app/Language/pl/Config.php
  • app/Language/pl/Sales.php
  • app/Language/pt-BR/Config.php
  • app/Language/pt-BR/Sales.php
  • app/Language/ro/Config.php
  • app/Language/ro/Sales.php
  • app/Language/ru/Config.php
  • app/Language/ru/Sales.php
  • app/Language/sv/Config.php
  • app/Language/sv/Sales.php
  • app/Language/sw-KE/Config.php
  • app/Language/sw-KE/Sales.php
  • app/Language/sw-TZ/Config.php
  • app/Language/sw-TZ/Sales.php
  • app/Language/ta/Config.php
  • app/Language/ta/Sales.php
  • app/Language/th/Config.php
  • app/Language/th/Sales.php
  • app/Language/tl/Config.php
  • app/Language/tl/Sales.php
  • app/Language/tr/Config.php
  • app/Language/tr/Sales.php
  • app/Language/uk/Config.php
  • app/Language/uk/Sales.php
  • app/Language/ur/Config.php
  • app/Language/ur/Sales.php
  • app/Language/vi/Config.php
  • app/Language/vi/Sales.php
  • app/Language/zh-Hans/Config.php
  • app/Language/zh-Hans/Sales.php
  • app/Language/zh-Hant/Config.php
  • app/Language/zh-Hant/Sales.php
  • app/Libraries/Sale_lib.php
  • app/Models/Sale.php
  • app/Views/configs/locale_config.php
  • app/Views/sales/register.php
  • public/css/register.css
  • tests/Controllers/ConfigTest.php
  • tests/Libraries/Sale_libPaymentTest.php

Comment thread app/Controllers/Sales.php Resolved
Comment thread app/Controllers/Sales.php Resolved
Comment thread app/Controllers/Sales.php Resolved
Comment thread app/Language/ar-EG/Config.php Resolved
Comment thread app/Language/ar-LB/Config.php Resolved
Comment thread app/Language/az/Config.php Resolved
Comment thread app/Language/bg/Config.php Resolved
@objecttothis

This comment was marked as resolved.

@coderabbitai

This comment was marked as resolved.

Gift card payments use amount_tendered as giftcard number (integer);
cash/other payments require decimal_locale format. Apply correct
validation rule per payment type instead of generic required.

Signed-off-by: Travis Garrison <[email protected]>
coderabbitai[bot]

This comment was marked as resolved.

Travis Garrison added 4 commits July 2, 2026 02:06
Replace hardcoded precision 2 with totals_decimals() when comparing
discount against item total via bccomp/bcmul, so discount validation
respects the configured decimal precision setting.

Signed-off-by: Travis Garrison <[email protected]>
Replace placeholder/mismatched strings with accurate translations:
- email_mailpath, email_smtp_pass, invoice_email_message
- number_locale_invalid/required, receipt_template
- reward_configuration, right, tax_decimals, theme

Signed-off-by: Travis Garrison <[email protected]>
- Add reference_code field to new payment row in sale edit form
- Persist reference_code on insert in Sale model
- Validate reference_code_new in Sales controller using configurable min/max length rules

Signed-off-by: Travis Garrison <[email protected]>
@objecttothis objecttothis changed the title Feature payment reference code Feature: Payment reference code Jul 2, 2026
@objecttothis
objecttothis requested a review from jekkos July 2, 2026 05:48
@objecttothis

Copy link
Copy Markdown
Member Author

@jekkos this PR is blocking a plugin. Any chance we can review it and get it into the master? It's a fairly minor feature. It should be fairly straightforward to review as there are only 11 changed files outside of the language files.

@objecttothis

Copy link
Copy Markdown
Member Author

@jekkos when do you think you'll be able to take a look at this PR?

jekkos
jekkos previously approved these changes Jul 8, 2026

@jekkos jekkos left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not going to hold this back in case you think it's working, but I do have one minor style remark and a question.

Comment thread app/Controllers/Sales.php Resolved
Comment thread app/Controllers/Sales.php Resolved
Comment thread app/Views/sales/form.php Resolved
Comment thread app/Views/sales/form.php Resolved
@github-actions
github-actions Bot had a problem deploying to staging July 8, 2026 21:41 Failure
@github-actions

This comment was marked as resolved.

- Add validation of UI settings to prevent overridden values from being passed.
- Correct maximum value in JS for payment_reference_code maximum length to 40.
- Fix bug causing copy_entire_sale() to incorrectly copy the reference code and cash_adjustment

Signed-off-by: Travis Garrison <[email protected]>
@objecttothis
objecttothis merged commit 9c542ef into master Jul 10, 2026
14 checks passed
@objecttothis
objecttothis deleted the feature-payment-reference-code branch July 10, 2026 09:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants