Commit Graph
34 Commits
Author SHA1 Message Date
b41aad26ce Migrated the Currency module to Doctrine (#2963)
* Migrated the Currency module to Doctrine

* Caching and other improvements

* Types, error handling and other improvements

* Don't return false but throw an exception

* Types

* Refactor currency model usage to new Currency entity

* Remove Fastnetmon submodule

Deleted the Fastnetmon submodule from src/modules. This change may be part of a cleanup or migration away from using Fastnetmon as a submodule.

* Refactor currency API admin get test

* Fix failing Currency-related tests after Doctrine migration

Updated test files to work with the new Doctrine-based Currency implementation.

* Refactor currency retrieval to use repository

* Refactor Currency database handling in several services and tests

* Replace anonymous class mocks with standard PHPUnit mocks in Invoice tests (#3037)

* Refactor currency retrieval and currency service

* Apply suggestions from code review

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Confirm updateCurrencyRates() method signature alignment (#3034)

* Add null check for currency in Cart::toApiArray to prevent fatal error (#3035)

* Initial plan

* Add null check for currency in toApiArray method

Co-authored-by: admdly <2807620+admdly@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: admdly <2807620+admdly@users.noreply.github.com>

* Initial plan

* Replace anonymous class mocks with standard PHPUnit mocks for consistency

Co-authored-by: admdly <2807620+admdly@users.noreply.github.com>

---------

Co-authored-by: Adam Daley <admdly@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: admdly <2807620+admdly@users.noreply.github.com>

* Fix incorrect getRateByCode call in Order service (#3039)

* Initial plan

* Fix getRateByCode call and add null check with proper exception

Co-authored-by: admdly <2807620+admdly@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: admdly <2807620+admdly@users.noreply.github.com>

* Fix silent failure in Currency::getBaseCurrencyRate when currency not found (#3040)

* Initial plan

* Throw exception when currency not found in getBaseCurrencyRate

Co-authored-by: admdly <2807620+admdly@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: admdly <2807620+admdly@users.noreply.github.com>

* Use FOSSBilling\Exception for currency conversion rate failures (#3041)

Use FOSSBilling\Exception for conversion rate fetch failures

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: admdly <2807620+admdly@users.noreply.github.com>

* Remove problematic reflection usage in Cart service tests (#3042)

Remove problematic reflection usage in Cart test

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: admdly <2807620+admdly@users.noreply.github.com>

* Update tests-legacy/modules/Cart/Api/GuestTest.php

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update src/modules/Currency/Service.php

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update src/modules/Currency/Entity/Currency.php

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Use FOSSBilling\Exception for null currency check in Cart service (#3058)

* Initial plan

* Use FOSSBilling\Exception for null currency check in Cart service

Co-authored-by: admdly <2807620+admdly@users.noreply.github.com>

* Use consistent error message for default currency not found

Co-authored-by: admdly <2807620+admdly@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: admdly <2807620+admdly@users.noreply.github.com>

* Remove silent fallback in CurrencyRepository::findDefault() (#3057)

* Add logging for default currency fallback behavior

- Log warning when no default currency is found and falling back to ID 1
- Log critical error when neither default currency nor ID 1 exists
- Clarify return type documentation
- Cache result even if null to avoid repeated warnings

Co-authored-by: admdly <2807620+admdly@users.noreply.github.com>

* Remove silent fallback to currency ID 1 in findDefault()

Instead of silently falling back to currency ID 1 when no default
is found, the method now returns null and lets callers handle it.

This addresses the feedback about the silent fallback hiding
configuration issues. All existing callers already properly handle
null by throwing exceptions, so this change makes the error
visible rather than hidden.

Benefits:
- No silent failures hiding misconfiguration
- Cleaner separation of concerns (repositories for data access only)
- Better adherence to Doctrine repository pattern
- All callers already handle null appropriately

Co-authored-by: admdly <2807620+admdly@users.noreply.github.com>

* Remove redundant documentation in findDefault()

Simplified @return annotation to avoid redundancy with the description.

Co-authored-by: admdly <2807620+admdly@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: admdly <2807620+admdly@users.noreply.github.com>

* Fix Currency entity getId() to handle uninitialized state (#3059)

Make Currency::getId() return nullable int to prevent runtime errors

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: admdly <2807620+admdly@users.noreply.github.com>

* Remove static cache from CurrencyRepository to fix long-running process issues (#3061)

* Initial plan

* Remove static cache from CurrencyRepository to fix long-running process issues

Co-authored-by: admdly <2807620+admdly@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: admdly <2807620+admdly@users.noreply.github.com>

* Fix inconsistent null handling in CurrencyRepository::getRateByCode callers (#3062)

* Fix null handling in Invoice/Service.php getRateByCode call

Co-authored-by: admdly <2807620+admdly@users.noreply.github.com>

* Fix Invoice test to mock getRateByCode with valid return value

Co-authored-by: admdly <2807620+admdly@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: admdly <2807620+admdly@users.noreply.github.com>

* Refactor Qwen `settings.json` structure and update version

* Verify null handling consistency in CurrencyRepository::getRateByCode (#3073)

Initial plan

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>

* Update src/modules/Order/Service.php

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update src/modules/Currency/Service.php

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update src/modules/Currency/Repository/CurrencyRepository.php

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update src/modules/Currency/Service.php

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update src/modules/Currency/Service.php

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Improve return type annotation for Currency Admin API get_pairs method (#3075)

* Initial plan

* Improve return type annotation for get_pairs method in Currency Admin API

Co-authored-by: admdly <2807620+admdly@users.noreply.github.com>

* Fix return type description to accurately reflect the return format

Co-authored-by: admdly <2807620+admdly@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: admdly <2807620+admdly@users.noreply.github.com>

* Fix nullable type inconsistency in Currency entity setCode/getCode methods (#3074)

* Initial plan

* Fix nullable type in Currency entity setCode and getCode methods

Co-authored-by: admdly <2807620+admdly@users.noreply.github.com>

* Fix PHPUnit test failures by updating mock return values for getCode

Co-authored-by: admdly <2807620+admdly@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: admdly <2807620+admdly@users.noreply.github.com>

* Restore deleted Cart API Guest tests for Doctrine Currency migration (#3076)

* Initial plan

* Restore deleted Cart API Guest tests and update for Doctrine Currency migration

Co-authored-by: admdly <2807620+admdly@users.noreply.github.com>

* Fix testAddItemSingle mock to return boolean instead of cart object

Co-authored-by: admdly <2807620+admdly@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: admdly <2807620+admdly@users.noreply.github.com>

* Refactor currency handling in `Cart` and `Invoice` services

Updated `Cart` and `Invoice` services to consistently use `CurrencyRepository` for retrieving currency entities and default currency. Improved error handling for missing currencies and updated related tests to mock new repository methods. Also fixed minor typos and improved code clarity in tests.

* Refactor currency handling in `Cart` Service

Replaced direct property access of currency code and conversion rate with getter methods in `Cart` Service. This improves encapsulation and consistency when handling currency-related operations.

* Update src/modules/Cart/Service.php

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update tests-legacy/modules/Order/ServiceTest.php

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update src/modules/Currency/Service.php

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update src/modules/Currency/Entity/Currency.php

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Fix exception signature and type hint in `Currency` service

Updated the exception thrown in `validateCurrencyForma`t to include a null second parameter for compatibility. Also added a return type to the closure in `Cart` `ServiceTest` for better type safety.

* Refactor currency selection logic in `Cart` Service

Improves clarity by separating client currency retrieval and default currency fallback. Ensures that the default currency is only checked and exception thrown if both client and default currencies are unavailable.

* Add precision handling and caching for Currency conversionRate property (#3082)

* Add documentation and caching for conversionRate precision handling

Co-authored-by: admdly <2807620+admdly@users.noreply.github.com>

* Use sprintf for float-to-string conversion to avoid scientific notation

Co-authored-by: admdly <2807620+admdly@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: admdly <2807620+admdly@users.noreply.github.com>

* Fix Doctrine identity map caching issue when changing default currency (#3081)

* Fix Doctrine identity map caching issue in setAsDefault method

Co-authored-by: admdly <2807620+admdly@users.noreply.github.com>

* Store currency code before clearing identity map to avoid detached entity access

Co-authored-by: admdly <2807620+admdly@users.noreply.github.com>

* Fix PHPUnit test for setAsDefault method by mocking findOneByCode and clear

Co-authored-by: admdly <2807620+admdly@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: admdly <2807620+admdly@users.noreply.github.com>

* Refactor currency test mocks for static data providers

Replaces direct mock object creation in static data providers with string flags or placeholders, enabling proper mock instantiation within test methods. Updates test signatures and logic to handle these flags, improving test maintainability and compatibility with PHPUnit static context constraints.

---------

Co-authored-by: Adam Daley <admdly@users.noreply.github.com>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: admdly <2807620+admdly@users.noreply.github.com>
2025-12-24 02:28:57 +00:00
Adam Daley a9b903c222 Codebase modernisation, configuration cleanup, and improved type safety (#2957)
* Refactor tests to replace depreciated functions

* Update Rector config and dependencies

* Rector: Add explicit string casting for stricter type safety

* Rector: Add return type hints to methods across codebase

* Rector: Increase dead code level and refactor invoice item logic

* Remove unnecessary `willReturn` from test mocks

Eliminate redundant `willReturn(null)` and similar calls from PHPUnit mock setups in legacy module tests, leaving only method expectations. Also update some test values to use floats for consistency.

* Refactor API controller and email adapter return values

* Update formatting and guidelines in `AGENTS.md`
2025-10-11 23:39:44 +01:00
Belle Aerni 996ff15a3e Partial revert of added strict types (#2881) 2025-08-29 15:06:49 -07:00
Adam DaleyandCopilot 315f9f3944 Refactor Filesystem and Path handling (#2836)
* Removed legacy files

* Refactor Filesystem and Path handling

* Removed `FOSSBilling\Tools` legacy functions

* Update live-tests to include file check for `php_error.log`

* Update Extension module tables to fix wrapping issue

* Apply suggestions from @Copilot

Co-Authored-By: Copilot <175728472+Copilot@users.noreply.github.com>

* Update Extension module icon URL handling

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-08-09 21:50:11 +01:00
Belle Aerni 1c7b15e700 Fix a bunch of exception logging (#2850) 2025-08-07 13:06:56 -07:00
5da80c043a Fix renewal date extension issue when marking first invoice as paid. (#2750)
* Incorrect renewal date extension

* Update src/modules/Order/Service.php

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Fix Order Service Test

* Add PHPDoc for `findPaidInvoicesForOrder`

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Adam Daley <admdly@users.noreply.github.com>
2025-05-31 03:08:36 +01:00
Belle Aerni 368f8cd6ad Bump the year (#2581) 2025-01-23 15:11:53 -08:00
Belle Aerni 549b05af3e Slight cleanup of the library folder (#2260)
* Slight cleanup of the library folder

* Test fixes

* More fixes for the tests
2024-05-01 15:36:59 -07:00
Belle Aerni 303f4cfa2d Code styling & rector config improvements (#2254)
* Bumped the Rector deadcode level

* Added the instanceof setlist

* Increasded type coverage and updated tests config too

* Bumped type coverage & ran PHP-cs-fixer
2024-04-23 10:38:18 -07:00
Belle Aerni 96dcfce0c6 Some UI & usability improvements (#2215) 2024-04-03 12:31:56 -07:00
Belle Aerni f7de859af0 Allow admins to force deletion of orders (#2207)
* Allow admins to bypass deletion errors for orders

* Code styling
2024-03-26 08:50:38 -07:00
Belle Aerni 9f7daf82eb Very minor fixes (#2199)
* Resolve various errors

* Fix a copy & paste error
2024-03-21 22:04:30 -07:00
Belle AerniandJohn @ S4 037acce702 Bulk fix of many grammar / phraseology mistakes (#2166)
* Bulk fix of many grammar / phraseology mistakes

* Small fixes after self-review

* Corrections

* Update mod_currency_settings.html.twig

* Update mod_currency_settings.html.twig

* Update mod_formbuilder_field.html.twig

---------

Co-authored-by: John @ S4 <64874788+John-S4@users.noreply.github.com>
2024-02-27 03:01:07 -08:00
Belle Aerni d771457efc Bump the year (#2167)
* Bump the year

* And fix the spelling
2024-02-25 02:45:38 -08:00
Belle Aerni 50043e6211 Run Rector against our tests (#1761)
* Update rector config to include tests

* Run Rector against the tests

* Delete test-results

* Update .gitignore

* Correctly set the PHP min to 8.1, split the configs

* Corrected PHPDoc

* Deleted tests we can't really get to pass

PHPunit is hard-coded to fail when a class has a return type of `never`, which is the correct return type of our redirect function (and rightfully so).

No way to disable the exception as far as we can tell
2023-11-11 18:41:09 +00:00
Belle Aerni 602b537996 Opt-in error reporting via Sentry.io (#1732)
* Began implementing Sentry.io support

* Added to the installer

* Added the ID to the bug report template and UI

* Hook it into our error handler, added the ability to filter by error code

* Attempting to add the DSN via GH actions

* Spelling and making PHPstan happy

* Skip exceptions for various incomplete configurations

Also brings in some of the category suggestions made by @Anuril in #195

* Update tests to account for changes

* Added & renamed exception classes

* Fix tests

* Change a bunch of items to be InformationExceptions

* Use a lighter HTTP client, fixed API error reporting

* I guess that's not needed now?

Arighty then

* Improvements, additional info added

* Update SentryHelper.php

* Improved error logging, added instance ID to error page

Also made it so that errors are correctly sent to Sentry rather than exclusively exceptions

* Make the tests happy

* Added the link, improved wording

Also removed the "performance" part of the reporting as it needs to be added to the front-end and I'm not currently implementing that

* Began implementing UI alerts and info

* Added the ability to toggle, fixed tests, use path constants

* Added some useful info & links to the page

* These should be InformationException

* Fix the automated Sentry DSN entry

* Fix the install number text

* Minor cleanup, converted more to InformationException

* Replaced some direct config references with constants

We have the BB_DEBUG constant to indicate if we have debug mode enabled or not, so we shouldn't be directly referencing it in the config file unless we actually need to do so.

Using the constant means there's less locations to update the reference if the config structure is changed

* Bugfix

* Consistency & fixed a PHPDoc

* Corrections

* We actually do want exceptions thrown here

* Change how we get the instance ID

* Stability improvements

Having support for translatable error pages was proving to be problematic, so I had to remove it.

I also had to update the exception class to handle cases where the trans function wasn't setup yet (needed for the /run-patcher page if an error occurs)

* Missed this change on git

* Also fix the variable names...

* Re-added new deps after rebase

* This should also accept "Error" types

* Added more info to the bug report and removed a dug line

* This wasn't supposed to get renamed

* Updated some missed references to Box_Exception
2023-10-28 18:40:39 -07:00
FOSSBilling Bot 1970b320e1 Apply PHP Code Styling & Quality Changes (#1617) 2023-09-19 17:22:00 +03:00
fefbcd21b0 Apply PHP Code Styling & Quality Changes (#1498)
* Apply PHP Code Styling & Quality Changes

* Delete these

* Update .gitignore

* Fixes for PHPStan

* Ignore spelling in the gitnore

* Allow null for that type

Honestly doing so makes ZERO sense, but it matches the current behavior.

---------

Co-authored-by: FOSSBilling Bot <fossbilling-bot>
Co-authored-by: Belle Aerni <belleaerni@gmail.com>
2023-07-30 08:57:44 -07:00
Yağızhanandfossbilling-bot fd872ac941 Implement PHP-CS-Fixer as an automated workflow (#1240)
* Implement PHP-CS-Fixer as an automated workflow

* Apply PHP-CS-Fixer changes

---------

Co-authored-by: fossbilling-bot <121974958+fossbilling-bot@users.noreply.github.com>
2023-07-30 06:49:11 -07:00
Yağızhan d909d77f7e -Unnecessary whitespace in the class headers (#1219) 2023-05-07 13:24:29 -07:00
Yağızhan 412e4a9fbd Standardized the class headers (#1212) 2023-05-06 13:06:17 +01:00
Adam Daley e54569d2cd Introduce namespaces and strict typing for FOSSBilling library classes (#1206) 2023-05-04 01:02:06 +01:00
Yağızhan 950e4dccef Type hinting the DI methods and variables (#1201) 2023-05-01 21:01:35 +03:00
Yağızhan 884e66aa4b Removed getSettingsRoutes & hasSettingsRoutes (#1196) 2023-05-01 13:27:39 +03:00
Belle Aerni 9faa981c58 Replace usage of array_get (#989)
* Replace usage of array_get

* Fixes

* And a few more

* Remove remaining references

* Update Service.php

* Few more fixes

* Fix.. I think?

* Fix Client / Invoice updates

* Fix stats

* Fix issues noticed during code review

* More fixes

* And some more fixes :)
2023-03-27 23:44:30 -07:00
Adam Daley 9fb19e02d7 Improve date/datetime format handling and customisability (#948)
* Replace custom Twig bb_date/bb_datetime filters

Replace bb_date and bb_datetime Twig filters with format_date / format_datetime to better support i18n and customisability.

* Update templates to use format_date/format_datetime

Update all templates to use format_date/format_datetime (where appropriate and where not already used).

* Update locale configuration options

Update configuration options to include new locale settings, and ensure new options are used throughout.

* Add reset button to admin theme date picker

Add a reset button to the admin_default theme date picker to allow dates to be cleared, and fix an issue with Order module not allow blank dates. Resolves #938.
2023-03-24 23:16:07 +00:00
Belle Aerni 7c2148fc28 Basic CSV export functionality (#925)
* Basic client CSV exporting

* Basic CSV export for orders

* Orders CSV export

* +inline doc
2023-03-13 17:44:25 +00:00
Belle Aerni 0710474d06 Restore old functionality in the order module 2023-02-12 06:59:10 -08:00
Belle Aerni 2cc0bfd132 Re-add support for prependOrderConfig
Looks like the Servicehosting module still relies on this, so let's add it back for now
2023-02-02 17:54:18 -08:00
Belle Aerni 4d7b341e03 Removed / cleaned up deprecated functions (#755)
* Add PHPStan extension for deprecation function usage

* Removed some deprecated functions

* And a few more

* Also remove the deprecated API calls

* Fix references to deprecated API calls

* Oh, and this too
2023-02-01 03:36:02 -08:00
Belle Aerni dcdf1ea83c Make module's settings labels translatable 2023-01-26 15:40:03 -08:00
Belle Aerni 774f0d5c95 Use Rector to modernize code for PHP 8.0 2023-01-12 00:40:54 -08:00
DataLores 3ed96e2c7f BugFix: Renewal failures do not properly save in order history (#673)
* BugFix: Renewal failures do not properly save in order history

Bugfixes found running regression tests of registering a domain (activate new order), followed by various sequences of renewing the domain order. Intentionally insert fatal exceptions in the renewal process demonstrated that you could renew a product and the order would update its length and status despite the underlying renewal action having failed. Additionally, renewal action failure reason was not getting captured and saved to the order history.

This corrects those behaviors to be in parity with what would happen on an activation failure. Also, minor javascript warning fixes when testing this workflow through the Stripe payment adapter.

* BugFix: Renewal failures do not properly save in order history

Bugfixes found running regression tests of registering a domain (activate new order), followed by various sequences of renewing the domain order. Intentionally insert fatal exceptions in the renewal process demonstrated that you could renew a product and the order would update its length and status despite the underlying renewal action having failed. Additionally, renewal action failure reason was not getting captured and saved to the order history.

This corrects those behaviors to be in parity with what would happen on an activation failure. Also, minor javascript warning fixes when testing this workflow through the Stripe payment adapter.
2023-01-09 11:19:02 +01:00
Belle Aerni edd6f72634 Drop the "BB" prefix 2022-11-28 17:22:50 +03:00