mymoip 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +6 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +8 -0
- data/README.md +3 -1
- data/VERSION +1 -1
- data/lib/mymoip/credit_card_payment.rb +11 -5
- data/lib/mymoip/request.rb +3 -0
- data/lib/mymoip/{payment_request.rb → requests/payment_request.rb} +6 -2
- data/lib/mymoip/{transparent_request.rb → requests/transparent_request.rb} +6 -2
- data/lib/mymoip.rb +1 -5
- data/mymoip.gemspec +14 -6
- data/test/{fixture.rb → fixtures/fixture.rb} +13 -13
- data/test/fixtures/vcr_cassettes/payment_request.yml +37 -0
- data/test/fixtures/vcr_cassettes/transparent_request.yml +33 -0
- data/test/helper.rb +9 -1
- data/test/live_test.rb +4 -0
- data/test/test_credit_card_payment.rb +29 -3
- data/test/test_instruction.rb +9 -0
- data/test/test_mymoip.rb +11 -3
- data/test/test_payment_request.rb +25 -0
- data/test/test_transparent_request.rb +8 -0
- metadata +41 -7
- data/.rvmrc +0 -40
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
CHANGELOG
|
2
2
|
=========
|
3
3
|
|
4
|
+
**0.2.3**
|
5
|
+
* Remove .rvmrc
|
6
|
+
* CreditCardPayment's initialization can now receive a hash of options
|
7
|
+
* lib/requests folder created
|
8
|
+
* Requests has methods to return its response id
|
9
|
+
|
4
10
|
**0.2.2**
|
5
11
|
* Explicitly require order for Requests classes
|
6
12
|
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
+
addressable (2.3.2)
|
4
5
|
ansi (1.4.3)
|
5
6
|
builder (3.0.0)
|
7
|
+
crack (0.3.1)
|
6
8
|
git (1.2.5)
|
7
9
|
httparty (0.8.3)
|
8
10
|
multi_json (~> 1.0)
|
@@ -23,6 +25,10 @@ GEM
|
|
23
25
|
json (~> 1.4)
|
24
26
|
turn (0.9.6)
|
25
27
|
ansi
|
28
|
+
vcr (2.2.5)
|
29
|
+
webmock (1.8.11)
|
30
|
+
addressable (>= 2.2.7)
|
31
|
+
crack (>= 0.1.7)
|
26
32
|
|
27
33
|
PLATFORMS
|
28
34
|
ruby
|
@@ -35,3 +41,5 @@ DEPENDENCIES
|
|
35
41
|
mocha
|
36
42
|
rdoc (~> 3.12)
|
37
43
|
turn
|
44
|
+
vcr
|
45
|
+
webmock
|
data/README.md
CHANGED
@@ -8,6 +8,8 @@ Provides a implementation of MoIP's transparent checkout.
|
|
8
8
|
Contributing to MyMoip
|
9
9
|
----------------------
|
10
10
|
|
11
|
+
[](http://travis-ci.org/Irio/mymoip)
|
12
|
+
|
11
13
|
What would you do if you could make your own implementation of MoIP?
|
12
14
|
|
13
15
|
Any patch are welcome, even removing extra blank spaces.
|
@@ -73,7 +75,7 @@ credit_card = MyMoip::CreditCard.new(
|
|
73
75
|
owner_rg: "1010202030"
|
74
76
|
)
|
75
77
|
|
76
|
-
credit_card_payment = MyMoip::CreditCardPayment.new(credit_card, 1)
|
78
|
+
credit_card_payment = MyMoip::CreditCardPayment.new(credit_card, installments: 1)
|
77
79
|
payment_request = MyMoip::PaymentRequest.new("your_own_id")
|
78
80
|
payment_request.api_call(credit_card_payment, token: transparent_request.token)
|
79
81
|
```
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.3
|
@@ -1,9 +1,15 @@
|
|
1
1
|
module MyMoip
|
2
2
|
class CreditCardPayment
|
3
|
-
attr_accessor :credit_card, :
|
3
|
+
attr_accessor :credit_card, :installments
|
4
4
|
|
5
|
-
def initialize(credit_card,
|
6
|
-
@credit_card
|
5
|
+
def initialize(credit_card, opts = {})
|
6
|
+
@credit_card = credit_card
|
7
|
+
# Backward compatibility. See 0.2.3 CHANGELOG
|
8
|
+
@installments = if opts.kind_of?(Integer)
|
9
|
+
opts
|
10
|
+
else
|
11
|
+
opts[:installments] || 1
|
12
|
+
end
|
7
13
|
end
|
8
14
|
|
9
15
|
def to_json
|
@@ -11,7 +17,7 @@ module MyMoip
|
|
11
17
|
|
12
18
|
json = {
|
13
19
|
Forma: "CartaoCredito",
|
14
|
-
Parcelas: @
|
20
|
+
Parcelas: @installments,
|
15
21
|
CartaoCredito: {
|
16
22
|
Numero: credit_card.card_number,
|
17
23
|
Expiracao: credit_card.expiration_date,
|
@@ -41,7 +47,7 @@ module MyMoip
|
|
41
47
|
end
|
42
48
|
|
43
49
|
def cash?
|
44
|
-
@
|
50
|
+
@installments == 1
|
45
51
|
end
|
46
52
|
end
|
47
53
|
end
|
data/lib/mymoip/request.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'request'
|
2
|
-
|
3
1
|
module MyMoip
|
4
2
|
class PaymentRequest < Request
|
5
3
|
|
@@ -36,5 +34,11 @@ module MyMoip
|
|
36
34
|
@response && @response["StatusPagamento"] == "Sucesso"
|
37
35
|
end
|
38
36
|
|
37
|
+
def code
|
38
|
+
@response["CodigoMoIP"]
|
39
|
+
rescue NoMethodError => e
|
40
|
+
nil
|
41
|
+
end
|
42
|
+
|
39
43
|
end
|
40
44
|
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require "request"
|
2
|
-
|
3
1
|
module MyMoip
|
4
2
|
class TransparentRequest < Request
|
5
3
|
|
@@ -31,5 +29,11 @@ module MyMoip
|
|
31
29
|
nil
|
32
30
|
end
|
33
31
|
|
32
|
+
def id
|
33
|
+
@response["EnviarInstrucaoUnicaResponse"]["Resposta"]["ID"]
|
34
|
+
rescue NoMethodError => e
|
35
|
+
nil
|
36
|
+
end
|
37
|
+
|
34
38
|
end
|
35
39
|
end
|
data/lib/mymoip.rb
CHANGED
@@ -19,12 +19,8 @@ end
|
|
19
19
|
|
20
20
|
$LOAD_PATH << "./lib/mymoip"
|
21
21
|
|
22
|
-
require 'mymoip/request'
|
23
|
-
|
24
22
|
files = Dir[File.dirname(__FILE__) + "/mymoip/*.rb"]
|
25
|
-
|
23
|
+
files.each { |f| require f }
|
26
24
|
|
27
|
-
after_request.each { |f| require f }
|
28
|
-
|
29
25
|
MyMoip.environment = "sandbox"
|
30
26
|
MyMoip.logger = Logger.new(STDOUT)
|
data/mymoip.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "mymoip"
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Irio Irineu Musskopf Junior"]
|
12
|
-
s.date = "2012-10-
|
12
|
+
s.date = "2012-10-18"
|
13
13
|
s.description = "Provides a implementation of MoIP's transparent checkout."
|
14
14
|
s.email = "irio.musskopf@caixadeideias.com.br"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -18,7 +18,6 @@ Gem::Specification.new do |s|
|
|
18
18
|
]
|
19
19
|
s.files = [
|
20
20
|
".document",
|
21
|
-
".rvmrc",
|
22
21
|
"CHANGELOG.md",
|
23
22
|
"Gemfile",
|
24
23
|
"Gemfile.lock",
|
@@ -32,12 +31,15 @@ Gem::Specification.new do |s|
|
|
32
31
|
"lib/mymoip/instruction.rb",
|
33
32
|
"lib/mymoip/json_parser.rb",
|
34
33
|
"lib/mymoip/payer.rb",
|
35
|
-
"lib/mymoip/payment_request.rb",
|
36
34
|
"lib/mymoip/request.rb",
|
37
|
-
"lib/mymoip/
|
35
|
+
"lib/mymoip/requests/payment_request.rb",
|
36
|
+
"lib/mymoip/requests/transparent_request.rb",
|
38
37
|
"mymoip.gemspec",
|
39
|
-
"test/fixture.rb",
|
38
|
+
"test/fixtures/fixture.rb",
|
39
|
+
"test/fixtures/vcr_cassettes/payment_request.yml",
|
40
|
+
"test/fixtures/vcr_cassettes/transparent_request.yml",
|
40
41
|
"test/helper.rb",
|
42
|
+
"test/live_test.rb",
|
41
43
|
"test/test_credit_card_payment.rb",
|
42
44
|
"test/test_creditcard.rb",
|
43
45
|
"test/test_instruction.rb",
|
@@ -64,6 +66,8 @@ Gem::Specification.new do |s|
|
|
64
66
|
s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
|
65
67
|
s.add_development_dependency(%q<turn>, [">= 0"])
|
66
68
|
s.add_development_dependency(%q<mocha>, [">= 0"])
|
69
|
+
s.add_development_dependency(%q<vcr>, [">= 0"])
|
70
|
+
s.add_development_dependency(%q<webmock>, [">= 0"])
|
67
71
|
else
|
68
72
|
s.add_dependency(%q<builder>, [">= 0"])
|
69
73
|
s.add_dependency(%q<httparty>, [">= 0"])
|
@@ -72,6 +76,8 @@ Gem::Specification.new do |s|
|
|
72
76
|
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
73
77
|
s.add_dependency(%q<turn>, [">= 0"])
|
74
78
|
s.add_dependency(%q<mocha>, [">= 0"])
|
79
|
+
s.add_dependency(%q<vcr>, [">= 0"])
|
80
|
+
s.add_dependency(%q<webmock>, [">= 0"])
|
75
81
|
end
|
76
82
|
else
|
77
83
|
s.add_dependency(%q<builder>, [">= 0"])
|
@@ -81,6 +87,8 @@ Gem::Specification.new do |s|
|
|
81
87
|
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
82
88
|
s.add_dependency(%q<turn>, [">= 0"])
|
83
89
|
s.add_dependency(%q<mocha>, [">= 0"])
|
90
|
+
s.add_dependency(%q<vcr>, [">= 0"])
|
91
|
+
s.add_dependency(%q<webmock>, [">= 0"])
|
84
92
|
end
|
85
93
|
end
|
86
94
|
|
@@ -1,24 +1,24 @@
|
|
1
1
|
class Fixture
|
2
2
|
def self.payer
|
3
3
|
MyMoip::Payer.new(
|
4
|
-
id: "
|
5
|
-
name: "
|
6
|
-
email: "
|
7
|
-
address_street: "
|
8
|
-
address_street_number: "
|
9
|
-
address_street_extra: "
|
10
|
-
address_neighbourhood: "
|
11
|
-
address_city: "
|
12
|
-
address_state: "
|
13
|
-
address_country: "
|
14
|
-
address_cep: "
|
15
|
-
address_phone: "
|
4
|
+
id: "your_own_payer_id",
|
5
|
+
name: "Juquinha da Rocha",
|
6
|
+
email: "juquinha@rocha.com",
|
7
|
+
address_street: "Felipe Neri",
|
8
|
+
address_street_number: "406",
|
9
|
+
address_street_extra: "Sala 501",
|
10
|
+
address_neighbourhood: "Auxiliadora",
|
11
|
+
address_city: "Porto Alegre",
|
12
|
+
address_state: "RS",
|
13
|
+
address_country: "BRA",
|
14
|
+
address_cep: "90440-150",
|
15
|
+
address_phone: "(51)3040-5060"
|
16
16
|
)
|
17
17
|
end
|
18
18
|
|
19
19
|
def self.instruction(payer)
|
20
20
|
MyMoip::Instruction.new(
|
21
|
-
id: "
|
21
|
+
id: "your_own_instruction_id",
|
22
22
|
payment_reason: "some payment_reason",
|
23
23
|
values: [100.0, 200.0],
|
24
24
|
payer: payer
|
@@ -0,0 +1,37 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://YOUR_MOIP_TOKEN:YOUR_MOIP_KEY@desenvolvedor.moip.com.br/sandbox/rest/pagamento?callback=?&pagamentoWidget=%7B%22pagamentoWidget%22:%7B%22referer%22:%22http://localhost/default%22,%22token%22:%22M2F021Z2U1O0C1X761K1S1N8C5D0J1V1S0O0F0Y0Q0B0V0A1J1O0C2P6Z965%22,%22dadosPagamento%22:%7B%22Forma%22:%22CartaoCredito%22,%22Parcelas%22:1,%22CartaoCredito%22:%7B%22Numero%22:%224916654211627608%22,%22Expiracao%22:%2206/15%22,%22CodigoSeguranca%22:%22000%22,%22Portador%22:%7B%22Nome%22:%22Juquinha%20da%20Rocha%22,%22DataNascimento%22:%2203/11/1984%22,%22Telefone%22:%22(51)3040-5060%22,%22Identidade%22:%221010202030%22%7D%7D,%22Instituicao%22:%22Visa%22,%22Recebimento%22:%22AVista%22%7D%7D%7D
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers: {}
|
10
|
+
response:
|
11
|
+
status:
|
12
|
+
code: 200
|
13
|
+
message: OK
|
14
|
+
headers:
|
15
|
+
Date:
|
16
|
+
- Wed, 17 Oct 2012 18:23:26 GMT
|
17
|
+
Server:
|
18
|
+
- Apache/2.2.23 (CentOS)
|
19
|
+
Content-Length:
|
20
|
+
- '271'
|
21
|
+
Vary:
|
22
|
+
- Accept-Encoding
|
23
|
+
Content-Type:
|
24
|
+
- application/json
|
25
|
+
body:
|
26
|
+
encoding: ASCII-8BIT
|
27
|
+
string: !binary |-
|
28
|
+
Pyh7IlN0YXR1cyI6IkVtQW5hbGlzZSIsIkNvZGlnbyI6MCwiQ29kaWdvUmV0
|
29
|
+
b3JubyI6IiIsIlRheGFNb0lQIjoiMTUuMTkiLCJTdGF0dXNQYWdhbWVudG8i
|
30
|
+
OiJTdWNlc3NvIiwiQ2xhc3NpZmljYWNhbyI6eyJDb2RpZ28iOjk5OSwiRGVz
|
31
|
+
Y3JpY2FvIjoiTsOjbyBzdXBvcnRhZG8gbm8gYW1iaWVudGUgU2FuZGJveCJ9
|
32
|
+
LCJDb2RpZ29Nb0lQIjo5NTY5NSwiTWVuc2FnZW0iOiJSZXF1aXNpw6fDo28g
|
33
|
+
cHJvY2Vzc2FkYSBjb20gc3VjZXNzbyIsIlRvdGFsUGFnbyI6IjIwMC4wMCJ9
|
34
|
+
KQ==
|
35
|
+
http_version:
|
36
|
+
recorded_at: Wed, 17 Oct 2012 18:21:35 GMT
|
37
|
+
recorded_with: VCR 2.2.5
|
@@ -0,0 +1,33 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://YOUR_MOIP_TOKEN:YOUR_MOIP_KEY@desenvolvedor.moip.com.br/sandbox/ws/alpha/EnviarInstrucao/Unica
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: <EnviarInstrucao><InstrucaoUnica TipoValidacao="Transparente"><Razao>some
|
9
|
+
payment_reason</Razao><Valores><Valor moeda="BRL">100.00</Valor><Valor moeda="BRL">200.00</Valor></Valores><IdProprio>your_own_instruction_id</IdProprio><Pagador><Nome>Juquinha da Rocha</Nome><Email>juquinha@rocha.com</Email><IdPagador>your_own_payer_id</IdPagador><EnderecoCobranca><Logradouro>Felipe
|
10
|
+
Neri</Logradouro><Numero>406</Numero><Complemento>Sala 501</Complemento><Bairro>Auxiliadora</Bairro><Cidade>Porto
|
11
|
+
Alegre</Cidade><Estado>RS</Estado><Pais>BRA</Pais><CEP>90440-150</CEP><TelefoneFixo>(51)3040-5060</TelefoneFixo></EnderecoCobranca></Pagador></InstrucaoUnica></EnviarInstrucao>
|
12
|
+
headers: {}
|
13
|
+
response:
|
14
|
+
status:
|
15
|
+
code: 200
|
16
|
+
message: OK
|
17
|
+
headers:
|
18
|
+
Date:
|
19
|
+
- Wed, 17 Oct 2012 14:18:49 GMT
|
20
|
+
Server:
|
21
|
+
- Apache/2.2.23 (CentOS)
|
22
|
+
Content-Length:
|
23
|
+
- '273'
|
24
|
+
Vary:
|
25
|
+
- Accept-Encoding
|
26
|
+
Content-Type:
|
27
|
+
- text/xml;charset=UTF-8
|
28
|
+
body:
|
29
|
+
encoding: US-ASCII
|
30
|
+
string: <ns1:EnviarInstrucaoUnicaResponse xmlns:ns1="http://www.moip.com.br/ws/alpha/"><Resposta><ID>201210171118501100000001102691</ID><Status>Sucesso</Status><Token>M2F021Z2U1O0C1X761K1S1N8C5D0J1V1S0O0F0Y0Q0B0V0A1J1O0C2P6Z965</Token></Resposta></ns1:EnviarInstrucaoUnicaResponse>
|
31
|
+
http_version:
|
32
|
+
recorded_at: Wed, 17 Oct 2012 14:16:59 GMT
|
33
|
+
recorded_with: VCR 2.2.5
|
data/test/helper.rb
CHANGED
@@ -10,8 +10,16 @@ end
|
|
10
10
|
require 'test/unit'
|
11
11
|
require 'turn/autorun'
|
12
12
|
require 'mocha'
|
13
|
+
require 'vcr'
|
13
14
|
|
14
|
-
|
15
|
+
VCR.configure do |c|
|
16
|
+
c.cassette_library_dir = 'test/fixtures/vcr_cassettes'
|
17
|
+
c.hook_into :webmock
|
18
|
+
end
|
19
|
+
|
20
|
+
require 'live_test'
|
21
|
+
|
22
|
+
require 'fixtures/fixture'
|
15
23
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
16
24
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
17
25
|
|
data/test/live_test.rb
ADDED
@@ -6,7 +6,14 @@ class TestCreditCardPayment < Test::Unit::TestCase
|
|
6
6
|
credit_card = Fixture.credit_card
|
7
7
|
subject = MyMoip::CreditCardPayment.new(credit_card, 1)
|
8
8
|
assert_equal credit_card, subject.credit_card
|
9
|
-
assert_equal 1, subject.
|
9
|
+
assert_equal 1, subject.installments
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_allow_initialization_with_a_hash_of_options
|
13
|
+
credit_card = Fixture.credit_card
|
14
|
+
subject = MyMoip::CreditCardPayment.new(credit_card, installments: 2)
|
15
|
+
assert_equal credit_card, subject.credit_card
|
16
|
+
assert_equal 2, subject.installments
|
10
17
|
end
|
11
18
|
|
12
19
|
def test_cash_method_with_one_tranch
|
@@ -15,7 +22,7 @@ class TestCreditCardPayment < Test::Unit::TestCase
|
|
15
22
|
assert_equal true, subject.cash?
|
16
23
|
end
|
17
24
|
|
18
|
-
def
|
25
|
+
def test_cash_method_with_more_than_one_installments
|
19
26
|
credit_card = Fixture.credit_card
|
20
27
|
subject = MyMoip::CreditCardPayment.new(credit_card, 3)
|
21
28
|
assert_equal false, subject.cash?
|
@@ -24,6 +31,25 @@ class TestCreditCardPayment < Test::Unit::TestCase
|
|
24
31
|
def test_default_initialization_with_one_tranch
|
25
32
|
credit_card = Fixture.credit_card
|
26
33
|
subject = MyMoip::CreditCardPayment.new(credit_card)
|
27
|
-
assert_equal 1, subject.
|
34
|
+
assert_equal 1, subject.installments
|
28
35
|
end
|
36
|
+
|
37
|
+
def test_json_format
|
38
|
+
payment = MyMoip::CreditCardPayment.new(Fixture.credit_card)
|
39
|
+
assert_equal "CartaoCredito", payment.to_json[:Forma]
|
40
|
+
assert payment.to_json[:Parcelas].kind_of?(Integer), "'Parcelas' must be a kind of integer."
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_json_credit_card_format
|
44
|
+
payment = MyMoip::CreditCardPayment.new(Fixture.credit_card)
|
45
|
+
assert_match /\A\d+\z/, payment.to_json[:CartaoCredito][:Numero]
|
46
|
+
assert_match /\A((0[1-9])|(1[02]))\/\d{2}\z/, payment.to_json[:CartaoCredito][:Expiracao]
|
47
|
+
assert_match /\A\d{3}\z/, payment.to_json[:CartaoCredito][:CodigoSeguranca]
|
48
|
+
original_date = Date.new(1980, 11, 3)
|
49
|
+
MyMoip::CreditCard.any_instance.stubs(:owner_birthday).returns(original_date)
|
50
|
+
assert_equal original_date.strftime("%d/%m/%Y"), payment.to_json[:CartaoCredito][:Portador][:DataNascimento]
|
51
|
+
assert_match /\A\(\d{2}\)\d{4,5}-\d{4}/, payment.to_json[:CartaoCredito][:Portador][:Telefone]
|
52
|
+
assert_match /\A\d+\z/, payment.to_json[:CartaoCredito][:Portador][:Identidade]
|
53
|
+
end
|
54
|
+
|
29
55
|
end
|
data/test/test_instruction.rb
CHANGED
@@ -25,4 +25,13 @@ class TestInstruction < Test::Unit::TestCase
|
|
25
25
|
assert_equal String, instruction.to_xml.class
|
26
26
|
end
|
27
27
|
|
28
|
+
def test_xml_format
|
29
|
+
payer = Fixture.payer
|
30
|
+
instruction = Fixture.instruction(payer)
|
31
|
+
expected_format = <<XML
|
32
|
+
<EnviarInstrucao><InstrucaoUnica TipoValidacao=\"Transparente\"><Razao>some payment_reason</Razao><Valores><Valor moeda=\"BRL\">100.00</Valor><Valor moeda=\"BRL\">200.00</Valor></Valores><IdProprio>your_own_instruction_id</IdProprio><Pagador><Nome>Juquinha da Rocha</Nome><Email>juquinha@rocha.com</Email><IdPagador>your_own_payer_id</IdPagador><EnderecoCobranca><Logradouro>Felipe Neri</Logradouro><Numero>406</Numero><Complemento>Sala 501</Complemento><Bairro>Auxiliadora</Bairro><Cidade>Porto Alegre</Cidade><Estado>RS</Estado><Pais>BRA</Pais><CEP>90440-150</CEP><TelefoneFixo>(51)3040-5060</TelefoneFixo></EnderecoCobranca></Pagador></InstrucaoUnica></EnviarInstrucao>
|
33
|
+
XML
|
34
|
+
assert_equal expected_format.rstrip, instruction.to_xml
|
35
|
+
end
|
36
|
+
|
28
37
|
end
|
data/test/test_mymoip.rb
CHANGED
@@ -1,13 +1,23 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
3
|
class TestMymoip < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@default_env = MyMoip.environment
|
6
|
+
@default_token = MyMoip.token
|
7
|
+
@default_key = MyMoip.key
|
8
|
+
end
|
9
|
+
|
10
|
+
def teardown
|
11
|
+
MyMoip.environment = @default_env
|
12
|
+
MyMoip.token = @default_token
|
13
|
+
MyMoip.key = @default_key
|
14
|
+
end
|
4
15
|
|
5
16
|
def test_default_environment_is_sandbox
|
6
17
|
assert_equal "sandbox", MyMoip.environment
|
7
18
|
end
|
8
19
|
|
9
20
|
def test_set_auth_configuration
|
10
|
-
default_env = MyMoip.environment
|
11
21
|
MyMoip.token = "my_token"
|
12
22
|
MyMoip.key = "my_key"
|
13
23
|
MyMoip.environment = "production"
|
@@ -17,8 +27,6 @@ class TestMymoip < Test::Unit::TestCase
|
|
17
27
|
assert_equal "my_key", MyMoip.key
|
18
28
|
assert_equal "production", MyMoip.environment
|
19
29
|
assert_equal "http://localhost", MyMoip.default_referer_url
|
20
|
-
|
21
|
-
MyMoip.environment = default_env
|
22
30
|
end
|
23
31
|
|
24
32
|
def test_choose_right_api_url_by_sandbox_environment
|
@@ -70,4 +70,29 @@ class TestPaymentRequest < Test::Unit::TestCase
|
|
70
70
|
assert !request.success?
|
71
71
|
end
|
72
72
|
|
73
|
+
def test_method_to_get_moip_code
|
74
|
+
instruction = Fixture.instruction(Fixture.payer)
|
75
|
+
transparent_request = MyMoip::TransparentRequest.new("your_own_id")
|
76
|
+
VCR.use_cassette('transparent_request') do
|
77
|
+
transparent_request.api_call(instruction)
|
78
|
+
end
|
79
|
+
credit_card_payment = MyMoip::CreditCardPayment.new(Fixture.credit_card, 1)
|
80
|
+
payment_request = MyMoip::PaymentRequest.new("your_own_id")
|
81
|
+
VCR.use_cassette('payment_request') do
|
82
|
+
payment_request.api_call(credit_card_payment, token: transparent_request.token)
|
83
|
+
end
|
84
|
+
assert_equal 95695, payment_request.code
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_code_method_should_return_nil_with_blank_response
|
88
|
+
instruction = Fixture.instruction(Fixture.payer)
|
89
|
+
transparent_request = MyMoip::TransparentRequest.new("your_own_id")
|
90
|
+
VCR.use_cassette('transparent_request') do
|
91
|
+
transparent_request.api_call(instruction)
|
92
|
+
end
|
93
|
+
credit_card_payment = MyMoip::CreditCardPayment.new(Fixture.credit_card, 1)
|
94
|
+
payment_request = MyMoip::PaymentRequest.new("your_own_id")
|
95
|
+
assert_nil payment_request.code
|
96
|
+
end
|
97
|
+
|
73
98
|
end
|
@@ -53,4 +53,12 @@ class TestTransparentRequest < Test::Unit::TestCase
|
|
53
53
|
request = MyMoip::TransparentRequest.new("some_id")
|
54
54
|
assert_equal nil, request.token
|
55
55
|
end
|
56
|
+
|
57
|
+
def test_should_provide_the_transaction_id_get_by_the_request
|
58
|
+
request = MyMoip::TransparentRequest.new("some_id")
|
59
|
+
VCR.use_cassette('transparent_request') do
|
60
|
+
request.api_call(Fixture.instruction(Fixture.payer))
|
61
|
+
end
|
62
|
+
assert_equal "201210171118501100000001102691", request.id
|
63
|
+
end
|
56
64
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mymoip
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: builder
|
@@ -123,6 +123,38 @@ dependencies:
|
|
123
123
|
- - ! '>='
|
124
124
|
- !ruby/object:Gem::Version
|
125
125
|
version: '0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: vcr
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ! '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
type: :development
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
- !ruby/object:Gem::Dependency
|
143
|
+
name: webmock
|
144
|
+
requirement: !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
146
|
+
requirements:
|
147
|
+
- - ! '>='
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '0'
|
150
|
+
type: :development
|
151
|
+
prerelease: false
|
152
|
+
version_requirements: !ruby/object:Gem::Requirement
|
153
|
+
none: false
|
154
|
+
requirements:
|
155
|
+
- - ! '>='
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
126
158
|
description: Provides a implementation of MoIP's transparent checkout.
|
127
159
|
email: irio.musskopf@caixadeideias.com.br
|
128
160
|
executables: []
|
@@ -132,7 +164,6 @@ extra_rdoc_files:
|
|
132
164
|
- README.md
|
133
165
|
files:
|
134
166
|
- .document
|
135
|
-
- .rvmrc
|
136
167
|
- CHANGELOG.md
|
137
168
|
- Gemfile
|
138
169
|
- Gemfile.lock
|
@@ -146,12 +177,15 @@ files:
|
|
146
177
|
- lib/mymoip/instruction.rb
|
147
178
|
- lib/mymoip/json_parser.rb
|
148
179
|
- lib/mymoip/payer.rb
|
149
|
-
- lib/mymoip/payment_request.rb
|
150
180
|
- lib/mymoip/request.rb
|
151
|
-
- lib/mymoip/
|
181
|
+
- lib/mymoip/requests/payment_request.rb
|
182
|
+
- lib/mymoip/requests/transparent_request.rb
|
152
183
|
- mymoip.gemspec
|
153
|
-
- test/fixture.rb
|
184
|
+
- test/fixtures/fixture.rb
|
185
|
+
- test/fixtures/vcr_cassettes/payment_request.yml
|
186
|
+
- test/fixtures/vcr_cassettes/transparent_request.yml
|
154
187
|
- test/helper.rb
|
188
|
+
- test/live_test.rb
|
155
189
|
- test/test_credit_card_payment.rb
|
156
190
|
- test/test_creditcard.rb
|
157
191
|
- test/test_instruction.rb
|
@@ -175,7 +209,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
175
209
|
version: '0'
|
176
210
|
segments:
|
177
211
|
- 0
|
178
|
-
hash:
|
212
|
+
hash: 2414227471847759887
|
179
213
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
180
214
|
none: false
|
181
215
|
requirements:
|
data/.rvmrc
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
#!/usr/bin/env bash
|
2
|
-
|
3
|
-
# This is an RVM Project .rvmrc file, used to automatically load the ruby
|
4
|
-
# development environment upon cd'ing into the directory
|
5
|
-
|
6
|
-
# Specify our desired <ruby>[@<gemset>]
|
7
|
-
environment_id="ruby-1.9.3-p194@mymoip"
|
8
|
-
|
9
|
-
# First we attempt to load the desired environment directly from the environment
|
10
|
-
# file. This is very fast and efficient compared to running through the entire
|
11
|
-
# CLI and selector. If you want feedback on which environment was used then
|
12
|
-
# insert the word 'use' after --create as this triggers verbose mode.
|
13
|
-
|
14
|
-
if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
|
15
|
-
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
|
16
|
-
then
|
17
|
-
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
|
18
|
-
|
19
|
-
if [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]]
|
20
|
-
then
|
21
|
-
. "${rvm_path:-$HOME/.rvm}/hooks/after_use"
|
22
|
-
fi
|
23
|
-
else
|
24
|
-
# If the environment file has not yet been created, use the RVM CLI to select.
|
25
|
-
if ! rvm --create "$environment_id"
|
26
|
-
then
|
27
|
-
echo "Failed to create RVM environment '${environment_id}'."
|
28
|
-
return 1
|
29
|
-
fi
|
30
|
-
fi
|
31
|
-
|
32
|
-
# User feedback
|
33
|
-
|
34
|
-
if [[ $- == *i* ]] # check for interactive shells
|
35
|
-
then
|
36
|
-
echo "Using: $(tput setaf 2)$GEM_HOME$(tput sgr0)" # show the user the ruby and gemset they are using in green
|
37
|
-
else
|
38
|
-
echo "Using: $GEM_HOME" # don't use colors in interactive shells
|
39
|
-
fi
|
40
|
-
|