pronamic / wp-money Goto Github PK
View Code? Open in Web Editor NEWWordPress Money library.
Home Page: https://pronamic.github.io/wp-money/
WordPress Money library.
Home Page: https://pronamic.github.io/wp-money/
In both functions the $format
parameter is optional, but the parameter doesn't work the same way. If null
is passed in Money->format_i18n( $format = null )
function it will fall back to Money::get_default_format()
:
Lines 71 to 73 in 86b41ad
If null
is passed in Money->format( $format = null )
function it will fall back to '%2$s'
:
Lines 127 to 129 in 86b41ad
Currently it's very imported that Money->format( $format = null )
falls back to '%2$s'
, otherwise some of the gateways will break:
pronamic/wp-pronamic-pay-mollie@08bc30c
However, it is not very logical that the Money->format( $format = null )
does not process currency information by default, without currency information it's just a number.
We could make this more clear like this: Money->format_amount( $number_decimals = null );
, if $number_decimals
is null
we can fall back to the currency $number_decimals
value, similarly an i18n
version: $money->format_i18n_amount( $number_decimals );
.
Naming can also be different:
Money->number_format( $number_decimals = null )
Money->amount_format( $number_decimals = null )
Money->number_format_i18n( $number_decimals = null )
Money->amount_format_i18n( $number_decimals = null )
I think i prefer number_format
and number_format_i18n
:
The default format for Money->format( $format = null )
can then be changed to '%3$s%2$s
' so that it contains at least the currency code by default.
Maybe we should also consider replacing the printf
directives with placeholders:
$placeholders = array(
'{non_breaking_space}' => ...,
'{currency_symbol}' => ...,
'{currency_alphabetic_code}' => ...,
'{currency_numeric_code}' => ...,
'{currency_name}' => ...,
'{amount}' => ...,
'{amount_i18n}' => ...,
'{amount_no_trailing_zeros}' => ...,
'{amount_i18n_no_trailing_zeros}' => ...,
);
Current use is not very clear:
echo $money->format( '%3$s%2$s' );
You have no idea what the result is, following is more clear:
echo $money->format( '{currency_alphabetic_code}{non_breaking_space}{amount}' );
@rvdsteege thoughts?
When performing calculations in a TaxedMoney
object, the tax details are removed.
$taxed = new TaxedMoney( 10, 'EUR', 2.10 );
var_dump( $taxed->get_tax_value() ); // string '2.1'
var_dump( $taxed->multiply( 5 )->get_tax_value() ); // null
This is caused by the fact that we're instantiating a new static
(either Money
or TaxedMoney
) object from e.g. the multiply()
method.
Lines 328 to 344 in 6b144b3
Also, PHPStan currently warns that the method signature of TaxedMoney::__construct()
is not enforced to be equal to the Money
constructor signature:
Unsafe usage of new static().
๐ก See: https://phpstan.org/blog/solving-phpstan-error-unsafe-usage-of-new-static
Both issues can be resolved by introducing a MoneyInterface
class, which needs to be implemented by both the Money
and TaxedMoney
classes. The interface should contain abstract methods for the constructor and calculation methods.
The multiply()
method is currently in use in Gravity Forms subscription period alignment, where losing tax details is fine as we're not specifying taxes for the payment lines in this integration.
In internal HelpScout ticket https://secure.helpscout.net/conversation/1642566698/22781?folderId=1425720 we had a customer with issues with a Pronamic Pay payment form. It seems there are problems parsing user amount input. That's why I decided to switch to HTML5 number
input fields. The Pronamic\WordPress\Money\Parser
is still used in a few places, we should remove this.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.