Skip to content
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

Merged
merged 5 commits into from
Jan 19, 2018
Merged

Conversation

oyeb
Copy link
Contributor

@oyeb oyeb commented Jan 18, 2018

  • Also implements the new methods for ex_money (makes use of the Cldr.Currency package).
  • See how easy it has become to format the amount in MONEI!

We'll remove the implementations once the lib authors implement it in their master.

* Also added an implementation of `to_string` for `ex_money`
* Also ran the formatter against `money.ex`
@@ -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
Copy link
Member

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)


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"}
Copy link
Member

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

{"USD", 412, -2}

iex> bhd_price = MoneyLib.new(4.1234, :BHD)
#MoneyLib<4.1234, "USD">
Copy link
Member

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"


# the money lib is aliased as "MoneyLib"

iex> usd_price = MoneyLib.new(4.1234, :USD)
Copy link
Member

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?

@ex_money Money.new(42, :EUR)
@ex_money_long Money.new("42.126456", :EUR)
@ex_money_bhd Money.new(42, :BHD)

Copy link
Member

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.

Copy link
Member

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".
@oyeb oyeb merged commit 365c3f1 into dev Jan 19, 2018
@oyeb oyeb deleted the protocol-expansion branch January 19, 2018 10:01
@oyeb oyeb moved this from In progress to Done in Gringotts [next-release] Jan 19, 2018
@oyeb oyeb restored the protocol-expansion branch January 19, 2018 10:12
pkrawat1 pushed a commit that referenced this pull request Jan 25, 2018
* 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".
@pkrawat1 pkrawat1 deleted the protocol-expansion branch January 26, 2018 09:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

2 participants