-
Notifications
You must be signed in to change notification settings - Fork 52
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
[money-protocol] Expansion: to_string
and to_integer
#86
Conversation
* Also ran the formatter against `money.ex`
lib/gringotts/gateways/monei.ex
Outdated
@@ -184,11 +184,12 @@ defmodule Gringotts.Gateways.Monei do | |||
""" | |||
@spec authorize(Money.t, CreditCard.t(), keyword) :: {:ok | :error, Response} | |||
def authorize(amount, card = %CreditCard{}, opts) do | |||
{currency, value} = Money.to_string amount |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use parens when passing params, its a better way IMO Money.to_string(amount)
lib/gringotts/money.ex
Outdated
|
||
and the API will accept it (as long as the currency is valid [ISO 4217 currency | ||
code](https://www.iso.org/iso-4217-currency-codes.html)). | ||
price = %{amount: Decimal.new(20.18), currency: "USD"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happened to value
suggestion for representing amount map. I remember we had a discussion about it internally.
eg:
%{value: Decimal.new(20.18), currency: "USD"}
cc @aviabird/all
lib/gringotts/money.ex
Outdated
{"USD", 412, -2} | ||
|
||
iex> bhd_price = MoneyLib.new(4.1234, :BHD) | ||
#MoneyLib<4.1234, "USD"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo "USD" in place of "BHD"
lib/gringotts/money.ex
Outdated
|
||
# the money lib is aliased as "MoneyLib" | ||
|
||
iex> usd_price = MoneyLib.new(4.1234, :USD) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think USD is ever dealt like this upto 4 decimal places, typo?
test/integration/money.exs
Outdated
@ex_money Money.new(42, :EUR) | ||
@ex_money_long Money.new("42.126456", :EUR) | ||
@ex_money_bhd Money.new(42, :BHD) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add test cases to cover Any
implementation as well. test cases would help understand our implementation better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this test suit has to be more extensive IMO.
* The default rounding strategy for implementations of Gringotts.Money protocol is HALF-EVEN. * Updated public API docs with "perils of rounding".
* Adds `to_string` and `to_integer` to the protocol * Fixes #62 and #85 * Implements all protocol methods for `ex_money` * Adds integration test with ex_money * Adapted Monei with protocol updates * Adds test for `Any` * The default rounding strategy for implementations of Gringotts.Money protocol is HALF-EVEN. * Updated public API docs with "perils of rounding".
ex_money
(makes use of theCldr.Currency
package).amount
in MONEI!We'll remove the implementations once the lib authors implement it in their
master
.