Skip to content

Commit

Permalink
Merge pull request #66 from aviabird/dev
Browse files Browse the repository at this point in the history
Release 1.0.2
  • Loading branch information
pkrawat1 authored Dec 29, 2017
2 parents cc71d06 + b5c7a72 commit 16ab9fe
Show file tree
Hide file tree
Showing 13 changed files with 768 additions and 93 deletions.
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ address = %Address{

opts = [address: address, currency: "eur"]

case Gringotts.purchase(:payment_worker, Stripe, 10, card, opts) do
case Gringotts.purchase(Stripe, 10, card, opts) do
{:ok, %{authorization: authorization}} ->
IO.puts("Payment authorized #{authorization}")

Expand All @@ -91,15 +91,14 @@ end

## Supported Gateways

* [Stripe](https://stripe.com/) - AT, AU, BE, CA, CH, DE, DK, ES, FI, FR, GB, IE, IN, IT, LU, NL, NO, SE, SG, US
* [PAYMILL](https://paymill.com) - AD, AT, BE, BG, CH, CY, CZ, DE, DK, EE, ES, FI, FO, FR, GB, GI, GR, HU, IE, IL, IS, IT, LI, LT, LU, LV, MT, NL, NO, PL, PT, RO, SE, SI, SK, TR, VA
* [Authorize.Net](http://www.authorize.net/) - AD, AT, AU, BE, BG, CA, CH, CY, CZ, DE, DK, ES, FI, FR, GB, GB, GI, GR, HU, IE, IT, LI, LU, MC, MT, NL, NO, PL, PT, RO, SE, SI, SK, SM, TR, US, VA

* [MONEI](http://www.monei.net/) - AD, AT, BE, BG, CA, CH, CY, CZ, DE, DK, EE, ES, FI, FO, FR, GB, GI, GR, HU, IE, IL, IS, IT, LI, LT, LU, LV, MT, NL, NO, PL, PT, RO, SE, SI, SK, TR, US, VA
* [CAMS: Central Account Management System](https://www.centralams.com/) - AU, US
* [MONEI](http://www.monei.net/) - AD, AT, BE, BG, CA, CH, CY, CZ, DE, DK, EE, ES, FI, FO, FR, GB, GI, GR, HU, IE, IL, IS, IT, LI, LT, LU, LV, MT, NL, NO, PL, PT, RO, SE, SI, SK, TR, US, VA
* [PAYMILL](https://paymill.com) - AD, AT, BE, BG, CH, CY, CZ, DE, DK, EE, ES, FI, FO, FR, GB, GI, GR, HU, IE, IL, IS, IT, LI, LT, LU, LV, MT, NL, NO, PL, PT, RO, SE, SI, SK, TR, VA
* [Stripe](https://stripe.com/) - AT, AU, BE, CA, CH, DE, DK, ES, FI, FR, GB, IE, IN, IT, LU, NL, NO, SE, SG, US
* [TREXLE](https://docs.trexle.com/) - AD, AE, AT, AU, BD, BE, BG, BN, CA, CH, CY, CZ, DE, DK, EE, EG, ES, FI, FR, GB, GI, GR, HK, HU, ID, IE, IL, IM, IN, IS, IT, JO, KW, LB, LI, LK, LT, LU, LV, MC, MT, MU, MV, MX, MY, NL, NO, NZ, OM, PH, PL, PT, QA, RO, SA, SE, SG, SI, SK, SM, TR, TT, UM, US, VA, VN, ZA
* [Wirecard](http://www.wirecard.com) - AD, CY, GI, IM, MT, RO, CH, AT, DK, GR, IT, MC, SM, TR, BE, EE, HU, LV, NL, SK, GB, BG, FI, IS, LI, NO, SI, VA, FR, IL, LT, PL, ES, CZ, DE, IE, LU, PT, SE


## Road Map

- Support more gateways on an on-going basis.
Expand Down
50 changes: 21 additions & 29 deletions lib/gringotts.ex
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,6 @@ defmodule Gringotts do
The public API is designed in such a way that library users end up passing mostly a
standard params for almost all requests.
### Worker Name
eg: :payment_worker
The standard central supervised worker responsible for delegating/calling all
the payment specific methods such as `authorise` & `purchase`.
> This option is going to be removed in our next version.
### Gateway Name
eg: Gringotts.Gateways.Stripe
Expand Down Expand Up @@ -103,15 +95,15 @@ defmodule Gringotts do
@options [currency: "usd"]
Gringotts.purchase(:payment_worker, Gringotts.Gateways.Stripe, 5, @payment, @options)
Gringotts.purchase(Gringotts.Gateways.Stripe, 5, @payment, @options)
This method is expected to authorize payment and transparently trigger eventual
settlement. Preferably it is implemented as a single call to the gateway,
but it can also be implemented as chained `authorize` and `capture` calls.
"""
def purchase(worker, gateway, amount, card, opts \\ []) do
def purchase(gateway, amount, card, opts \\ []) do
validate_config(gateway)
call(worker, {:purchase, gateway, amount, card, opts})
call(:payment_worker, {:purchase, gateway, amount, card, opts})
end

@doc """
Expand All @@ -135,11 +127,11 @@ defmodule Gringotts do
@options [currency: "usd"]
Gringotts.authorize(:payment_worker, Gringotts.Gateways.Stripe, 5, @payment, @options)
Gringotts.authorize(Gringotts.Gateways.Stripe, 5, @payment, @options)
"""
def authorize(worker, gateway, amount, card, opts \\ []) do
def authorize(gateway, amount, card, opts \\ []) do
validate_config(gateway)
call(worker, {:authorize, gateway, amount, card, opts})
call(:payment_worker, {:authorize, gateway, amount, card, opts})
end

@doc """
Expand Down Expand Up @@ -169,11 +161,11 @@ defmodule Gringotts do
id = "ch_1BYvGkBImdnrXiZwet3aKkQE"
Gringotts.capture(:payment_worker, Gringotts.Gateways.Stripe, id, 5)
Gringotts.capture(Gringotts.Gateways.Stripe, id, 5)
"""
def capture(worker, gateway, id, amount, opts \\ []) do
def capture(gateway, id, amount, opts \\ []) do
validate_config(gateway)
call(worker, {:capture, gateway, id, amount, opts})
call(:payment_worker, {:capture, gateway, id, amount, opts})
end

@doc """
Expand All @@ -198,12 +190,12 @@ defmodule Gringotts do
id = "ch_1BYvGkBImdnrXiZwet3aKkQE"
Gringotts.void(:payment_worker, Gringotts.Gateways.Stripe, id)
Gringotts.void(Gringotts.Gateways.Stripe, id)
"""
def void(worker, gateway, id, opts \\ []) do
def void(gateway, id, opts \\ []) do
validate_config(gateway)
call(worker, {:void, gateway, id, opts})
call(:payment_worker, {:void, gateway, id, opts})
end

@doc """
Expand All @@ -225,11 +217,11 @@ defmodule Gringotts do
id = "ch_1BYvGkBImdnrXiZwet3aKkQE"
Gringotts.refund(:payment_worker, Gringotts.Gateways.Stripe, 5, id)
Gringotts.refund(Gringotts.Gateways.Stripe, 5, id)
"""
def refund(worker, gateway, amount, id, opts \\ []) do
def refund(gateway, amount, id, opts \\ []) do
validate_config(gateway)
call(worker, {:refund, gateway, amount, id, opts})
call(:payment_worker, {:refund, gateway, amount, id, opts})
end

@doc """
Expand Down Expand Up @@ -258,11 +250,11 @@ defmodule Gringotts do
id = "ch_1BYvGkBImdnrXiZwet3aKkQE"
Gringotts.store(:payment_worker, Gringotts.Gateways.Stripe, @payment)
Gringotts.store(Gringotts.Gateways.Stripe, @payment)
"""
def store(worker, gateway, card, opts \\ []) do
def store(gateway, card, opts \\ []) do
validate_config(gateway)
call(worker, {:store, gateway, card, opts})
call(:payment_worker, {:store, gateway, card, opts})
end

@doc """
Expand All @@ -274,11 +266,11 @@ defmodule Gringotts do
customer_id = "random_customer"
Gringotts.unstore(:payment_worker, Gringotts.Gateways.Stripe, customer_id)
Gringotts.unstore(Gringotts.Gateways.Stripe, customer_id)
"""
def unstore(worker, gateway, customer_id, opts \\ []) do
def unstore(gateway, customer_id, opts \\ []) do
validate_config(gateway)
call(worker, {:unstore, gateway, customer_id, opts})
call(:payment_worker, {:unstore, gateway, customer_id, opts})
end

# TODO: This is runtime error reporting fix this so that it does compile
Expand Down
14 changes: 7 additions & 7 deletions lib/gringotts/gateways/authorize_net.ex
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ defmodule Gringotts.Gateways.AuthorizeNet do
]
iex> card = %CreditCard{number: "5424000000000015", year: 2020, month: 12, verification_code: "999"}
iex> amount = 5
iex> result = Gringotts.purchase(:payment_worker, Gringotts.Gateways.AuthorizeNet, amount, card, opts)
iex> result = Gringotts.purchase(Gringotts.Gateways.AuthorizeNet, amount, card, opts)
"""
@spec purchase(Float, CreditCard.t, Keyword.t) :: tuple
def purchase(amount, payment, opts) do
Expand Down Expand Up @@ -214,7 +214,7 @@ defmodule Gringotts.Gateways.AuthorizeNet do
]
iex> card = %CreditCard{number: "5424000000000015", year: 2020, month: 12, verification_code: "999"}
iex> amount = 5
iex> result = Gringotts.authorize(:payment_worker, Gringotts.Gateways.AuthorizeNet, amount, card, opts)
iex> result = Gringotts.authorize(Gringotts.Gateways.AuthorizeNet, amount, card, opts)
"""
@spec authorize(Float, CreditCard.t, Keyword.t) :: tuple
def authorize(amount, payment, opts) do
Expand Down Expand Up @@ -251,7 +251,7 @@ defmodule Gringotts.Gateways.AuthorizeNet do
]
iex> amount = 5
iex> id = "123456"
iex> result = Gringotts.capture(:payment_worker, Gringotts.Gateways.AuthorizeNet, id, amount, opts)
iex> result = Gringotts.capture(Gringotts.Gateways.AuthorizeNet, id, amount, opts)
"""
@spec capture(String.t, Float, Keyword.t) :: tuple
def capture(id, amount, opts) do
Expand Down Expand Up @@ -281,7 +281,7 @@ defmodule Gringotts.Gateways.AuthorizeNet do
]
iex> id = "123456"
iex> amount = 5
iex> result = Gringotts.refund(:payment_worker, Gringotts.Gateways.AuthorizeNet, amount, id, opts)
iex> result = Gringotts.refund(Gringotts.Gateways.AuthorizeNet, amount, id, opts)
"""
@spec refund(Float, String.t, Keyword.t) :: tuple
def refund(amount, id, opts) do
Expand All @@ -305,7 +305,7 @@ defmodule Gringotts.Gateways.AuthorizeNet do
ref_id: "123456"
]
iex> id = "123456"
iex> result = Gringotts.void(:payment_worker, Gringotts.Gateways.AuthorizeNet, id, opts)
iex> result = Gringotts.void(Gringotts.Gateways.AuthorizeNet, id, opts)
"""
@spec void(String.t, Keyword.t) :: tuple
def void(id, opts) do
Expand Down Expand Up @@ -348,7 +348,7 @@ defmodule Gringotts.Gateways.AuthorizeNet do
validation_mode: "testMode"
]
iex> card = %CreditCard{number: "5424000000000015", year: 2020, month: 12, verification_code: "999"}
iex> result = Gringotts.store(:payment_worker, Gringotts.Gateways.AuthorizeNet, card, opts)
iex> result = Gringotts.store(Gringotts.Gateways.AuthorizeNet, card, opts)
"""
@spec store(CreditCard.t, Keyword.t) :: tuple
def store(card, opts) do
Expand All @@ -369,7 +369,7 @@ defmodule Gringotts.Gateways.AuthorizeNet do
## Example
iex> id = "123456"
iex> opts = []
iex> result = Gringotts.store(:payment_worker, Gringotts.Gateways.AuthorizeNet, id, opts)
iex> result = Gringotts.store(Gringotts.Gateways.AuthorizeNet, id, opts)
"""

@spec unstore(String.t, Keyword.t) :: tuple
Expand Down
10 changes: 5 additions & 5 deletions lib/gringotts/gateways/cams.ex
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ defmodule Gringotts.Gateways.Cams do
options = [currency: "USD"]
money = 100
iex> Gringotts.purchase(:payment_worker, Gringotts.Gateways.Cams, money, payment, options)
iex> Gringotts.purchase(Gringotts.Gateways.Cams, money, payment, options)
"""
@spec purchase(number, CreditCard.t, Keyword) :: Response
def purchase(money, payment, options) do
Expand Down Expand Up @@ -150,7 +150,7 @@ defmodule Gringotts.Gateways.Cams do
options = [currency: "USD"]
money = 100
iex> Gringotts.authorize(:payment_worker, Gringotts.Gateways.Cams, money, payment, options)
iex> Gringotts.authorize(Gringotts.Gateways.Cams, money, payment, options)
"""
@spec authorize(number, CreditCard.t, Keyword) :: Response
def authorize(money, payment, options) do
Expand All @@ -175,7 +175,7 @@ defmodule Gringotts.Gateways.Cams do
options = [currency: "USD"]
money = 100
iex> Gringotts.capture(:payment_worker, Gringotts.Gateways.Cams, money, authorization, options)
iex> Gringotts.capture(Gringotts.Gateways.Cams, money, authorization, options)
"""
@spec capture(number, String.t, Keyword) :: Response
def capture(money, authorization, options) do
Expand All @@ -202,7 +202,7 @@ defmodule Gringotts.Gateways.Cams do
options = [currency: "USD"]
money = 100
iex> Gringotts.refund(:payment_worker, Gringotts.Gateways.Cams, money, authorization, options)
iex> Gringotts.refund(Gringotts.Gateways.Cams, money, authorization, options)
"""
@spec refund(number, String.t, Keyword) :: Response
def refund(money, authorization, options) do
Expand All @@ -223,7 +223,7 @@ defmodule Gringotts.Gateways.Cams do
authorization = "3904093075"
options = []
iex> Gringotts.void(:payment_worker, Gringotts.Gateways.Cams, authorization, options)
iex> Gringotts.void(Gringotts.Gateways.Cams, authorization, options)
"""
@spec void(String.t, Keyword) :: Response
def void(authorization , options) do
Expand Down
12 changes: 6 additions & 6 deletions lib/gringotts/gateways/monei.ex
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ defmodule Gringotts.Gateways.Monei do
iex> opts = [currency: "EUR"] # The default currency is EUR, and this is just for an example.
iex> card = %Gringotts.CreditCard{first_name: "Jo", last_name: "Doe", number: "4200000000000000", year: 2099, month: 12, verification_code: "123", brand: "VISA"}
iex> auth_result = Gringotts.authorize(:payment_worker, Gringotts.Gateways.Monei, 40, card, opts)
iex> auth_result = Gringotts.authorize(Gringotts.Gateways.Monei, 40, card, opts)
iex> auth_result.id # This is the authorization ID
"""
@spec authorize(number, CreditCard.t(), keyword) :: {:ok | :error, Response}
Expand Down Expand Up @@ -221,7 +221,7 @@ defmodule Gringotts.Gateways.Monei do
iex> opts = [currency: "EUR"] # The default currency is EUR, and this is just for an example.
iex> card = %Gringotts.CreditCard{first_name: "Jo", last_name: "Doe", number: "4200000000000000", year: 2099, month: 12, verification_code: "123", brand: "VISA"}
iex> capture_result = Gringotts.capture(:payment_worker, Gringotts.Gateways.Monei, 35, auth_result.id, opts)
iex> capture_result = Gringotts.capture(Gringotts.Gateways.Monei, 35, auth_result.id, opts)
"""
@spec capture(number, String.t(), keyword) :: {:ok | :error, Response}
def capture(amount, payment_id, opts)
Expand Down Expand Up @@ -254,7 +254,7 @@ defmodule Gringotts.Gateways.Monei do
iex> opts = [currency: "EUR"] # The default currency is EUR, and this is just for an example.
iex> card = %Gringotts.CreditCard{first_name: "Jo", last_name: "Doe", number: "4200000000000000", year: 2099, month: 12, verification_code: "123", brand: "VISA"}
iex> purchase_result = Gringotts.purchase(:payment_worker, Gringotts.Gateways.Monei, 40, card, opts)
iex> purchase_result = Gringotts.purchase(Gringotts.Gateways.Monei, 40, card, opts)
"""
@spec purchase(number, CreditCard.t(), keyword) :: {:ok | :error, Response}
def purchase(amount, card = %CreditCard{}, opts) when is_integer(amount) do
Expand Down Expand Up @@ -305,7 +305,7 @@ defmodule Gringotts.Gateways.Monei do
iex> opts = [currency: "EUR"] # The default currency is EUR, and this is just for an example.
iex> card = %Gringotts.CreditCard{first_name: "Jo", last_name: "Doe", number: "4200000000000000", year: 2099, month: 12, verification_code: "123", brand: "VISA"}
iex> void_result = Gringotts.void(:payment_worker, Gringotts.Gateways.Monei, auth_result.id, opts)
iex> void_result = Gringotts.void(Gringotts.Gateways.Monei, auth_result.id, opts)
"""
@spec void(String.t(), keyword) :: {:ok | :error, Response}
def void(payment_id, opts)
Expand Down Expand Up @@ -334,7 +334,7 @@ defmodule Gringotts.Gateways.Monei do
iex> opts = [currency: "EUR"] # The default currency is EUR, and this is just for an example.
iex> card = %Gringotts.CreditCard{first_name: "Jo", last_name: "Doe", number: "4200000000000000", year: 2099, month: 12, verification_code: "123", brand: "VISA"}
iex> refund_result = Gringotts.refund(:payment_worker, Gringotts.Gateways.Monei, purchase_result.id, opts)
iex> refund_result = Gringotts.refund(Gringotts.Gateways.Monei, purchase_result.id, opts)
"""
@spec refund(number, String.t(), keyword) :: {:ok | :error, Response}
def refund(amount, payment_id, opts) when is_integer(amount) do
Expand Down Expand Up @@ -374,7 +374,7 @@ defmodule Gringotts.Gateways.Monei do
iex> opts = [currency: "EUR"] # The default currency is EUR, and this is just for an example.
iex> card = %Gringotts.CreditCard{first_name: "Jo", last_name: "Doe", number: "4200000000000000", year: 2099, month: 12, verification_code: "123", brand: "VISA"}
iex> store_result = Gringotts.store(:payment_worker, Gringotts.Gateways.Monei, card, opts)
iex> store_result = Gringotts.store(Gringotts.Gateways.Monei, card, opts)
"""
@spec store(CreditCard.t(), keyword) :: {:ok | :error, Response}
def store(%CreditCard{} = card, opts) do
Expand Down
8 changes: 4 additions & 4 deletions lib/gringotts/gateways/paymill.ex
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ defmodule Gringotts.Gateways.Paymill do
options = []
iex> Gringotts.authorize(:payment_worker, Gringotts.Gateways.Paymill, amount, card, options)
iex> Gringotts.authorize(Gringotts.Gateways.Paymill, amount, card, options)
"""
@spec authorize(number, String.t | CreditCard.t, Keyword) :: {:ok | :error, Response}
def authorize(amount, card_or_token, options) do
Expand All @@ -80,7 +80,7 @@ defmodule Gringotts.Gateways.Paymill do
options = []
iex> Gringotts.purchase(:payment_worker, Gringotts.Gateways.Paymill, amount, card, options)
iex> Gringotts.purchase(Gringotts.Gateways.Paymill, amount, card, options)
"""
@spec purchase(number, CreditCard.t, Keyword) :: {:ok | :error, Response}
def purchase(amount, card, options) do
Expand All @@ -98,7 +98,7 @@ defmodule Gringotts.Gateways.Paymill do
options = []
iex> Gringotts.capture(:payment_worker, Gringotts.Gateways.Paymill, token, amount, options)
iex> Gringotts.capture(Gringotts.Gateways.Paymill, token, amount, options)
"""
@spec capture(String.t, number, Keyword) :: {:ok | :error, Response}
def capture(authorization, amount, options) do
Expand All @@ -115,7 +115,7 @@ defmodule Gringotts.Gateways.Paymill do
options = []
iex> Gringotts.void(:payment_worker, Gringotts.Gateways.Paymill, token, options)
iex> Gringotts.void(Gringotts.Gateways.Paymill, token, options)
"""
@spec void(String.t, Keyword) :: {:ok | :error, Response}
def void(authorization, options) do
Expand Down
Loading

0 comments on commit 16ab9fe

Please sign in to comment.