-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expression of monetary amounts #40
Comments
Expressing monetary amounts using a mantissa and exponent is going to feel foreign to most Web developers. I couldn't find a popular API that uses mantissa and exponent. |
There should be enough payment related APIs already in wide use for us to establish the "standard" way of expressing amounts. Any volunteers to do this research and come back with findings? |
The use of
Furthermore, using In my view, it would be better to just use a string that represents an arbitrary precision number that may contain a decimal point. |
I'm 100% in agreement with dlongley's comment above - use a string that represents an arbitrary precision... If we want to constrain the string in our spec, we could consider using a RegEx (in the spec) to be unequivocal. Or something simpler :-). Discussion of binary formats (long, double, etc.) is a very slippery slope. |
The standard for dealing with amounts in older payment protocols such as ISO8583 is to always use the minor currency and express amounts as integers. One may argue this is not very developer friendly but it has worked for the card industry for a few decades. Is this a viable solution? See the following related issues for the paymentRequest proposal: |
I think using a JSON number (which is how an integer would be represented) is problematic; different parsers may interpret certain values in different ways. In my view, the best way to protect integrity (with respect to parsing) is to use a string. Whether we express the value using the minor currency is another matter -- but I do think that if we use a currency code such as "USD", people will be confused if the amount is meant to be interpreted as cents. |
I'm not sure how this could be true. Do different JSON parsers interpret integers differently? There is no precision problem that I foresee or am I missing the obvious?
Developers using ISO8583 have managed for some decades as I say. There is a finite set of global currencies and knowing how to convert them from minor currency to a decimal if required is pretty easy to accomplish. Any new currencies like Bitcoin have to define what their minimum unit of account is and anyone using that currency can fairly be expected to need to know that. This approach's appeal is in it's simplicity and yet interoperability and flexibility. |
If they are large enough, sure. node.js/Chrome/Firefox: console.log(JSON.parse('{"key": 123456789123456789}').key); Result:
Python: import json
print(json.loads('{"key": 123456789123456789}')['key']) Result:
PHP: <?php
echo json_decode('{"key": 123456789123456789}')->key;
?> Result:
Increase the number enough and Python will work just fine but PHP with start throwing integer overflow errors. I didn't test any other parsers. I think we should serialize these numbers in a way that is guaranteed not to lose any precision. We could declare "X bits should be enough for any currency" or we could use a string and avoid that (potentially incorrect) assumption.
Will they be the only developers using this new API? |
Can ISO8583 support payments with a fractional part of the standard minimum unit of account? For instance USD $0.0005 or USD $1.005. Such a feature would be useful for micropayments or other exact precision payments. This may not be a common use case, but would be nice to to make it possible at the protocol level. |
I would suggest using ISO20022 instead of ISO8583 as 20022 is newer. Currencies should be defined using ISO4217. ISO20022 differentiates between a fractional digit portion and further states that the separator is a dot (addressing concerns of non standard separators somewhat) So in short, a string type, using a dot as the separator would be compliant and I would support this approach from both a standardisation and an ease of use perspective. One complication is that is doesn't appear to allow micro-payments as ISO20022 states the "number of fractional digits must comply with ISO 4217". This implies to me that, for example in USD an amount of "100.001" would be non-compliant as the fractional part is smaller that the ISO4217 exponent for USD which is 2. Furthermore ISO20022 states the fractional part can only be 5 digits, so even if we relaxed the ISO4217 limitation, the smallest micro-payment that could be made would be "0.00001" or 1/1000th of a cent if using USD as the currency. I'm not expert on these standards, so would appreciate Vincent or Kris's view of my interpretation of the standards and how they might feel about some revisions to them to support micro-payments. |
I fully support the proposal from Matt to use ISO 20022 instead of ISO 8583, for 2 reasons: ISO 8583 is cards industry specific and does not support all payments flows and the cards industry in Europe is in the process to convert all existing ISO 8583 messages to ISO 20022: several sets of messages have already been converted and published as ISO 20022 messages. Coming back to the question from Matt on the fractional digits, ISO 20022 provides for some flexibility. The CurrencyAmount is actually the validation rule of the CurrencyAndAmount, which is the "normal" data type used for in most of the ISO 20022 Payments messages, and follows the ISO 4217 standards on currencies. Finally I fully support the use of the dot, only to ensure the interoperability with ISO 20022. |
Closing as the related proposal was resolved on 28 Jan. Note the following comments from @vkuntz as we develop our specs:
|
The paymentRequest API currently suggests that we express monetary amounts using a mantissa and exponent:
http://wicg.github.io/paymentrequest/specs/paymentrequest.html#currencyamount
The Web Payments CG Browser API suggests that we use strings for the amounts with a currency code:
http://wicg.github.io/web-payments-browser-api/#processing-a-payment-request
How should monetary amounts be expressed in the API?
The text was updated successfully, but these errors were encountered: