Comments (7)
My biggest concern on my implementation is that to_string/1
has a fixed format of 2 decimal places. I'm sure you indicated that this is what most gateways expect. But I know that some currencies have 3 or 4 decimal places and at least one crypto currency has up to 8 decimal places. The current implementation the Gringotts.Money
protocol has currently:
@simple_format "###.##"
def to_string(%Money{} = money) do
rounded_string =
money
|> Money.round
|> Map.get(:amount)
|> Cldr.Number.to_string!(format: @simple_format)
{currency(money), rounded_string}
end
Any comments would be welcome.
from gringotts.
Thank you @kipcole9!
Addition of more gateways has been the focus in the last few months, but we did manage to bring out 1.1
somehow 😄
We're aware of those annoying compile time warnings and hate them as much as everyone else, I'll take some time out and release 1.1.1-rc
this weekend with some fixes.
Though most gateways expect just 2 places, Gringotts.Money.to_string/1
does not require that all values have only 2 decimal places.
In 1.1.0
, we've shipped our own implementation for the Money
type, and our to_string/1
takes the into consideration the currency's precision.
Many gateways (even the major players) don't take the effort to document such details, but we've seen that they generally work as we expect them to, or at least return a descriptive error message.
I'll probably add a section on the README to explain how we work with amounts and how this protocol protects the users' interest.
For example, it is best if the user performs the rounding and handle any remainder amount themselves, otherwise Gringotts.Money
will do an unsafe rounding!
from gringotts.
@oyeb Totally understand your focus. I'll remove the forced formatting for the string output on my implementation so that it defaults to the currencies defined precision. My implementation does do the correct rounding (as far as I can test at least) so that should be all good.
Let me know if there is anything else you need me to do. And if you have your own implementation then perhaps I shouldn't provide one so as to avoid confusion?
Let me know what you think!
from gringotts.
Yeah, the default formatting should do it.
IMO, it is best if the implementation is in ex_money
, because it can be maintained and tested better there.
We'll remove our implementation when we bump up the ex_money
version in our deps.
We can't write a test in gringotts
to test the implementation in ex_money
, (because ex_money
will get compiled before gringotts
), so you'll have to write tests like this one.
from gringotts.
@kipcole9 I see that the protocol is implemented in ex_money
v2.6.0
but there are no tests for it.
Could you please add a few tests to your library, just to stay protected from future regression (failures).
I've written down some tests that represent the contract well in this gist, feel free to drop them as is in your tests.
from gringotts.
Arrgggghh thats embarrassing that I let that slip in that way. And thanks much for the tests which I will add right away.
from gringotts.
Done on master and all tests pass. Thanks for the prompt.
from gringotts.
Related Issues (20)
- [Stripe] does not use Money protocol HOT 1
- Multiple Payment Processors HOT 2
- HPS payment processor HOT 1
- Paypal / Payflow HOT 1
- Integrate pagseguro payment gateway
- Intergrate mercadopago payment gateway
- Response struct should allow multiple tokens HOT 1
- Mistakes in gringotts.new template
- Enforce the type of `required_config`
- Fix "cyclomatic_complexity" issue in lib/mix/new.ex HOT 5
- Add Braintree gateway HOT 2
- Add some html.eex templates for the forms HOT 2
- This repo is a fork!
- Authorize.Net optional fields are not optional HOT 1
- Stripe Gateway: "Must provide source or customer." HOT 2
- Adding Bitpay payment gateway
- heroku link from the readme is down,
- Can't install due to outdated "decimal" dependency HOT 1
- Monei API outdated?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gringotts.