-
Notifications
You must be signed in to change notification settings - Fork 14
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
[new rule] create rule for formatting prices #29
Comments
Comment historyFeb 22, 2023 by @cfranzen
Feb 22, 2023 by @thake
|
Feb 23, 2023 by @thake I've compiled an overview of some possible formats and their pro's and con's: |
Feb 23, 2023 by @jensfischer1515 Historical background after some software archaeological research:
|
Feb 28, 2023 by @thake OrderEvent of kraken uses: {
"price": {"amount": 10.34, "currency": "EUR"}
} |
Feb 28, 2023 by @thake ProposalMy proposed format after a discussion with @jensfischer1515, @JanKlasser3000, @BastianSperrhacke-Otto, and @sergey-kolodiev Example{
"price": {"amount": "1.45", "currency": "EUR" /* optional, defaults to EUR */}
} Schematitle: Money
description: Common format for money amounts.
type: object
required:
- amount
properties:
amount:
type: string
description: The money amount without currency. "." is used as a decimal separator.
pattern: ^\d+(\.\d+)?$
currency:
type: string
description: The alphabetic currency code for the amount as defined in ISO 4217.
enum:
- "EUR"
default: "EUR"
pattern: "^[A-Z]{3}$" ReasoningThe object format has been used in preference to eurocents because of the following reasons:
let a = 2.2
let b = 2.1
console.log(a+b) //logs 4.300000000000001
RemarksAll participants of today's meeting were fully aware that introducing a new currency will always be a breaking change. APIs and their clients need to make adaptions to handle a new currency. |
Mar 2, 2023 by @cfranzen
|
Mar 2, 2023 by @thake
|
Mar 2, 2023 by @jensfischer1515
|
Many APIs on OTTO Market currently use |
@BirgitBader @AntjeGruenewald4789 "Number" with which precision? |
@AntjeGruenewald4789 as mentioned above: using number type for the amount definitely is a good option from a pure API perspective, however, it makes implementation harder for many popular frameworks on the client side. These frameworks typically convert a number type in JSON to a floating-point precision number in the client language, which is a really bad idea for storing amounts of money. Hence, all these clients would be forced to work around this issue. Furthermore, I don't understand why it has any value to limit the decimal places to 2 digits, which is definitely not enough for some currencies. What is the purpose of that limitation? Just allow a sufficiently larger number of decimal places to be able to handle all currencies that might come in the future. |
@cfranzen I can only say something for the interface of our team the Receipts API. If there is really a decision for OTTO market to show in future all amounts of our prices as strings, we could care about it in newer versions, so we and all partner using the current interface do not have extra effort. |
@AntjeGruenewald4789 I think if you only show the amount of money as a result it is completely fine to show it only with two digits, since that is how the currency EURO is designed. You would only run into problems when using a different currency as the result, e.g. Dinar. But such foreign currencies might not be a realistic problem for now, I would more probably see that Otto is going to support an "international" currency like Bitcoin. No idea how realistic that is, however. Besides that, I see this discussion as a "Guideline" containing a suggestion. There is in my opinion no intent to force teams to comply to these discussion or even change existing APIs. If we agree on above proposal, it will be visible at https://api.otto.de/portal/guidelines. Do you have some better place in mind? |
@cfranzen How about adding a link to the project here: https://internal.api.otto.market/docs#section/API-Guidelines. |
Sounds reasonable to me |
(i) This issue has been manually transferred from a former internal repository, as a private repository issue cannot be transferred to a public repository.
Context
We currently have no rule defining the format of a money amount in an API.
As money amounts are very common in our APIs (checkout, order-positions, transactional-communication), we would like to introduce a rule that ensures that money amounts are always formatted the same.
Currently, a money amount is formatted as eurocents (integer) in the APIs checkout, order-positions, and transactional-communication.
The text was updated successfully, but these errors were encountered: