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

[Mercadopago] Implemented refund #155

Closed
wants to merge 60 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
961dfcb
Added project logo
pkrawat1 Dec 29, 2017
90e8b3e
Added version for inch_ex
oyeb Jan 2, 2018
907723b
test case added for network failure
jyotigautam Jan 2, 2018
609a92c
[ci skip] Get more Open Source Helpers
schneems Jan 2, 2018
41f1de5
Codeclimate fixes (#68)
sivagollapalli Jan 3, 2018
2680289
FIX# code style for large numbers (#67)
sivagollapalli Jan 3, 2018
6e402e9
Stripe gateway minor fixes and docs update (#75)
chandradot99 Jan 4, 2018
ea11367
Using Address and Credit Card struct (#74)
jyotigautam Jan 4, 2018
df44753
Cams : Added error response handling (#65)
gopalshimpi Jan 4, 2018
afdd12e
test authorize net
arjun289 Dec 25, 2017
d5fda24
Introducing the Money protocol (#71)
oyeb Jan 10, 2018
6fafa1d
Update README.md
pkrawat1 Jan 10, 2018
9a4c89b
Adds a super useful mix task: gringotts.new
oyeb Jan 9, 2018
365c3f1
[money-protocol] Expansion: `to_string` and `to_integer` (#86)
oyeb Jan 19, 2018
6d1828f
add mix task for tests, mocks and integration
arjun289 Jan 17, 2018
a135692
[monei] Implements optional/extra params (#79)
oyeb Jan 21, 2018
ce7c6bd
Money integration with ANet and Anet test modification (#82)
arjun289 Jan 21, 2018
db9190b
[ANet] Corrected use of money protocol and examples (#92)
oyeb Jan 25, 2018
5e748e7
[trexle] Adds Money protocol (#84)
jyotigautam Jan 25, 2018
f3c0d58
[CAMS] Adds money protocol (#89)
gopalshimpi Jan 25, 2018
f2796b4
Fix doc example typos, and mock tests (#93)
oyeb Jan 25, 2018
fa1cd11
[mix-task] Fixed arg order in capture (#94)
oyeb Jan 25, 2018
5b15d30
Global Collect payment gateway integration. (#95)
jyotigautam Jan 25, 2018
99850ab
Introduces `Response.t` with docs (#119)
oyeb Feb 6, 2018
1920ced
Removes payment worker.
oyeb Feb 5, 2018
8622ded
Removed offending (now useless) test case
oyeb Feb 5, 2018
6aa6a86
Removed GenServer import. Fixes #8.
oyeb Feb 15, 2018
3768649
Refactored ResponseHandler, for new Response.t
oyeb Feb 9, 2018
e16fe72
Refactored `commit` and corrected avs, cvc result
oyeb Feb 9, 2018
6eef8ef
Correct a few doc examples
oyeb Feb 9, 2018
e3c86ce
Adds changelog, contributing guide and improves mix task (#117)
oyeb Mar 15, 2018
71a5bc3
[monei] Test fixes (#116)
oyeb Mar 15, 2018
cf39d54
Fix gringotts.new Option.parse call. (#125)
oyeb Mar 19, 2018
a9b76db
Adapts Stripe with the money protocol
oyeb Jan 29, 2018
f99f258
Adapted Trexle for new `Response.t`
oyeb Feb 9, 2018
a91deec
[CAMS] Adapt for new Response.t (#120)
oyeb Mar 21, 2018
7bf1857
Format project and migrate to CodeCov (#135)
oyeb Mar 22, 2018
a4082cb
[global-collect] Layout, docs improvements and code refactors (#111)
jyotigautam Mar 30, 2018
a444179
Initial Commit \n Implemented Authorize
subpal Mar 20, 2018
ea9c912
Implemented authorize
subpal Mar 20, 2018
2127fe9
Refined authorize function
subpal Mar 21, 2018
d7d74b9
Implemented authorize
subpal Mar 21, 2018
b776dc9
jgkg
subpal Mar 26, 2018
4a99128
Modification in authorize/3, and implemented capture
subpal Mar 26, 2018
a6b4298
Modification in authorize/3, and implemented capture
subpal Mar 26, 2018
94f5b1c
Modification in authorize/3, and implemented capture
subpal Mar 26, 2018
1d46184
Modification in authorize/3, and implemented capture
subpal Mar 26, 2018
5956d5b
Updated authorize/3
subpal Mar 27, 2018
fd135db
Updated authorize/3
subpal Mar 27, 2018
e7349da
Updated authorize/3
subpal Mar 28, 2018
5eabe34
Updated authorize/3
subpal Mar 31, 2018
b51e7f1
Authorize integration test cases created
subpal Mar 31, 2018
d0277b2
Authorize integration test cases created
subpal Mar 31, 2018
0e159ab
Authorize integration test cases created
subpal Mar 31, 2018
d0bda62
Applied elixer formatter.
subpal Apr 17, 2018
1357aa8
Capture and test cases
subpal Apr 17, 2018
699876f
Added test cases for capture
subpal Apr 17, 2018
3254c54
Implemented purchase
subpal Apr 17, 2018
9d52afa
Implemented void
subpal Apr 17, 2018
96f729c
Implemented Refund
subpal Apr 17, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Using Address and Credit Card struct (#74)
* Address and Credit Card struct usage
  • Loading branch information
jyotigautam authored and pkrawat1 committed Jan 4, 2018
commit ea113679cb473eb4b34cdcd6a74848afad914ba5
142 changes: 92 additions & 50 deletions lib/gringotts/gateways/trexle.ex
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ defmodule Gringotts.Gateways.Trexle do
use Gringotts.Gateways.Base
use Gringotts.Adapter, required_config: [:api_key, :default_currency]
import Poison, only: [decode: 1]
alias Gringotts.{Response}
alias Gringotts.{Response, CreditCard, Address}

@doc """
Performs the authorization of the card to be used for payment.
Expand All @@ -50,26 +50,33 @@ defmodule Gringotts.Gateways.Trexle do
```
iex> amount = 100

iex> card = %{
name: "John Doe",
iex> card = %CreditCard{
number: "5200828282828210",
expiry_month: 1,
expiry_year: 2018,
cvc: "123",
address_line1: "456 My Street",
address_city: "Ottawa",
address_postcode: "K1C2N6",
address_state: "ON",
address_country: "CA"
month: 12,
year: 2018,
first_name: "John",
last_name: "Doe",
verification_code: "123",
brand: "visa"
}

iex> options = [email: "john@trexle.com", ip_address: "66.249.79.118" , description: "Store Purchase 1437598192"]
iex> address = %Address{
street1: "123 Main",
street2: "Suite 100",
city: "New York",
region: "NY",
country: "US",
postal_code: "11111",
phone: "(555)555-5555"
}

iex> options = [email: "john@trexle.com", ip_address: "66.249.79.118", billing_address: address, description: "Store Purchase 1437598192"]

iex> Gringotts.authorize(:payment_worker, Gringotts.Gateways.Trexle, amount, card, options)
```
"""

@spec authorize(float, map, list) :: map
@spec authorize(float, CreditCard.t, list) :: map
def authorize(amount, payment, opts \\ []) do
params = create_params_for_auth_or_purchase(amount, payment, opts, false)
commit(:post, "charges", params, opts)
Expand All @@ -82,28 +89,47 @@ defmodule Gringotts.Gateways.Trexle do

## Example
```
iex> card = %{
name: "John Doe",
iex> card = %CreditCard{
number: "5200828282828210",
expiry_month: 1,
expiry_year: 2018,
cvc: "123",
address_line1: "456 My Street",
address_city: "Ottawa",
address_postcode: "K1C2N6",
address_state: "ON",
address_country: "CA"
month: 12,
year: 2018,
first_name: "John",
last_name: "Doe",
verification_code: "123",
brand: "visa"
}

iex> address = %Address{
street1: "123 Main",
street2: "Suite 100",
city: "New York",
region: "NY",
country: "US",
postal_code: "11111",
phone: "(555)555-5555"
}

iex> options = [email: "john@trexle.com", ip_address: "66.249.79.118" ,billing_address: address, description: "Store Purchase 1437598192"]

iex> @address %Address{
street1: "123 Main",
street2: "Suite 100",
city: "New York",
region: "NY",
country: "US",
postal_code: "11111",
phone: "(555)555-5555"
}

iex> options = [email: "john@trexle.com", ip_address: "66.249.79.118" ,description: "Store Purchase 1437598192"]
iex> options = [email: "john@trexle.com", ip_address: "66.249.79.118" ,billing_address: @address, description: "Store Purchase 1437598192"]

iex> amount = 50

iex> Gringotts.purchase(:payment_worker, Gringotts.Gateways.Trexle, amount, card, options)
```
"""

@spec purchase(float, map, list) :: map
@spec purchase(float, CreditCard.t, list) :: map
def purchase(amount, payment, opts \\ []) do
params = create_params_for_auth_or_purchase(amount, payment, opts)
commit(:post, "charges", params, opts)
Expand Down Expand Up @@ -165,28 +191,37 @@ defmodule Gringotts.Gateways.Trexle do
## Example
The following session shows how one would store a card (a payment-source) for future use.
```
iex> card = %{
name: "John Doe",
iex> card = %CreditCard{
number: "5200828282828210",
expiry_month: 1,
expiry_year: 2018,
cvc: "123",
address_line1: "456 My Street",
address_city: "Ottawa",
address_postcode: "K1C2N6",
address_state: "ON",
address_country: "CA"
month: 12,
year: 2018,
first_name: "John",
last_name: "Doe",
verification_code: "123",
brand: "visa"
}

iex> options = [email: "john@trexle.com", ip_address: "66.249.79.118", description: "Store Purchase 1437598192"]
iex> address = %Address{
street1: "123 Main",
street2: "Suite 100",
city: "New York",
region: "NY",
country: "US",
postal_code: "11111",
phone: "(555)555-5555"
}

iex> options = [email: "john@trexle.com", ip_address: "66.249.79.118", billing_address: address, description: "Store Purchase 1437598192"]

iex> Gringotts.store(:payment_worker, Gringotts.Gateways.Trexle, card, options)
```
"""

@spec store(map, list) :: map
@spec store(CreditCard.t, list) :: map
def store(payment, opts \\ []) do
params = [email: opts[:email]]++card_params(payment)
params = [email: opts[:email]]
++ card_params(payment)
++ address_params(opts[:billing_address])
commit(:post, "customers", params, opts)
end

Expand All @@ -199,24 +234,31 @@ defmodule Gringotts.Gateways.Trexle do
ip_address: opts[:ip_address],
description: opts[:description]
] ++ card_params(payment)
++ address_params(opts[:billing_address])
end

defp card_params(%CreditCard{} = card) do
[
"card[name]": CreditCard.full_name(card),
"card[number]": card.number,
"card[expiry_year]": card.year,
"card[expiry_month]": card.month,
"card[cvc]": card.verification_code
]
end

defp card_params(%{} = card) do
defp address_params(%Address{} = address) do
[
"card[name]": card[:name],
"card[number]": card[:number],
"card[expiry_year]": card[:expiry_year],
"card[expiry_month]": card[:expiry_month],
"card[cvc]": card[:cvc],
"card[address_line1]": card[:address_line1],
"card[address_city]": card[:address_city],
"card[address_postcode]": card[:address_postcode],
"card[address_state]": card[:address_state],
"card[address_country]": card[:address_country]
"card[address_line1]": address.street1,
"card[address_line2]": address.street2,
"card[address_city]": address.city,
"card[address_postcode]": address.postal_code,
"card[address_state]": address.region,
"card[address_country]": address.country
]
end

defp commit(method, path, params \\ [], opts \\ []) do
defp commit(method, path, params, opts) do
auth_token = "Basic #{Base.encode64(opts[:config][:api_key])}"
headers = [{"Content-Type", "application/x-www-form-urlencoded"}, {"Authorization", auth_token}]
data = params_to_string(params)
Expand Down
51 changes: 31 additions & 20 deletions test/gateways/trexle_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,41 @@ defmodule Gringotts.Gateways.TrexleTest do
use ExUnit.Case, async: false
alias Gringotts.Gateways.TrexleMock, as: MockResponse
alias Gringotts.Gateways.Trexle
alias Gringotts.{
CreditCard,
Address
}

import Mock

@valid_card %{
name: "John Doe",
@valid_card %CreditCard{
number: "5200828282828210",
expiry_month: 1,
expiry_year: 2018,
cvc: "123",
address_line1: "456 My Street",
address_city: "Ottawa",
address_postcode: "K1C2N6",
address_state: "ON",
address_country: "CA"
month: 12,
year: 2018,
first_name: "John",
last_name: "Doe",
verification_code: "123",
brand: "visa"
}

@invalid_card %{
name: "John Doe",
@invalid_card %CreditCard{
number: "5200828282828210",
expiry_month: 1,
expiry_year: 2010,
cvc: "123",
address_line1: "456 My Street",
address_city: "Ottawa",
address_postcode: "K1C2N6",
address_state: "ON",
address_country: "CA"
month: 12,
year: 2010,
first_name: "John",
last_name: "Doe",
verification_code: "123",
brand: "visa"
}

@address %Address{
street1: "123 Main",
street2: "Suite 100",
city: "New York",
region: "NY",
country: "US",
postal_code: "11111",
phone: "(555)555-5555"
}

@amount 100
Expand All @@ -42,19 +50,22 @@ defmodule Gringotts.Gateways.TrexleTest do
@opts [
config: %{api_key: "J5RGMpDlFlTfv9mEFvNWYoqHufyukPP4", default_currency: "USD"},
email: "john@trexle.com",
billing_address: @address,
ip_address: "66.249.79.118",
description: "Store Purchase 1437598192"
]

@missingip_opts [
config: %{api_key: "J5RGMpDlFlTfv9mEFvNWYoqHufyukPP4", default_currency: "USD"},
email: "john@trexle.com",
billing_address: @address,
description: "Store Purchase 1437598192"
]

@invalid_opts [
config: %{api_key: "J5RGMpDlFlTfv9mEFvNWYoqHufyukPP4"},
email: "john@trexle.com",
billing_address: @address,
ip_address: "66.249.79.118",
description: "Store Purchase 1437598192"
]
Expand Down