mymoip 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +12 -5
- data/README.md +4 -4
- data/VERSION +1 -1
- data/lib/mymoip/credit_card.rb +4 -0
- data/lib/mymoip/credit_card_payment.rb +1 -1
- data/lib/mymoip/request.rb +8 -7
- data/lib/mymoip/requests/payment_request.rb +7 -7
- data/lib/mymoip/requests/transparent_request.rb +3 -4
- data/mymoip.gemspec +2 -2
- data/test/fixtures/fixture.rb +4 -3
- data/test/test_credit_card_payment.rb +14 -0
- data/test/test_payment_request.rb +1 -1
- data/test/test_request.rb +20 -6
- metadata +3 -3
data/CHANGELOG.md
CHANGED
@@ -1,22 +1,29 @@
|
|
1
1
|
CHANGELOG
|
2
2
|
=========
|
3
3
|
|
4
|
+
**0.2.5**
|
5
|
+
* Request's log messages moved to debug level.
|
6
|
+
* Make CreditCard class accept string and symbol logos.
|
7
|
+
* Create MyMoip::CreditCard::AVAILABLE_LOGOS constant.
|
8
|
+
* Standardise Request#api_call parameters.
|
9
|
+
|
4
10
|
**0.2.4**
|
11
|
+
* Fix American Express logo format expected by Moip.
|
5
12
|
|
6
13
|
**0.2.3**
|
7
14
|
* Remove .rvmrc
|
8
|
-
* CreditCardPayment's initialization can now receive a hash of options
|
9
|
-
* lib/requests folder created
|
10
|
-
* Requests has methods to return its response id
|
15
|
+
* CreditCardPayment's initialization can now receive a hash of options.
|
16
|
+
* lib/requests folder created.
|
17
|
+
* Requests has methods to return its response id.
|
11
18
|
|
12
19
|
**0.2.2**
|
13
|
-
* Explicitly require order for Requests classes
|
20
|
+
* Explicitly require order for Requests classes.
|
14
21
|
|
15
22
|
**0.2.1**
|
16
23
|
* Bugfix related to explicitly require MyMoip class being needed.
|
17
24
|
|
18
25
|
**0.2.0**
|
19
|
-
* Update production url from `https://desenvolvedor.moip.com.br` to `https://www.moip.com.br
|
26
|
+
* Update production url from `https://desenvolvedor.moip.com.br` to `https://www.moip.com.br`.
|
20
27
|
|
21
28
|
**0.1.0**
|
22
29
|
* First version of the gem.
|
data/README.md
CHANGED
@@ -37,7 +37,7 @@ MyMoip.key = "your_moip_dev_key"
|
|
37
37
|
**First request: what and from who**
|
38
38
|
```ruby
|
39
39
|
payer = MyMoip::Payer.new(
|
40
|
-
id: "
|
40
|
+
id: "payer_id_defined_by_you",
|
41
41
|
name: "Juquinha da Rocha",
|
42
42
|
email: "juquinha@rocha.com",
|
43
43
|
address_street: "Felipe Neri",
|
@@ -52,13 +52,13 @@ payer = MyMoip::Payer.new(
|
|
52
52
|
) # 9 digit phones must be in "(11)93040-5060" format
|
53
53
|
|
54
54
|
instruction = MyMoip::Instruction.new(
|
55
|
-
id: "
|
55
|
+
id: "instruction_id_defined_by_you",
|
56
56
|
payment_reason: "Order in Buy Everything Store",
|
57
57
|
values: [100.0],
|
58
58
|
payer: payer
|
59
59
|
)
|
60
60
|
|
61
|
-
transparent_request = MyMoip::TransparentRequest.new("
|
61
|
+
transparent_request = MyMoip::TransparentRequest.new("your_logging_id")
|
62
62
|
transparent_request.api_call(instruction)
|
63
63
|
```
|
64
64
|
|
@@ -76,7 +76,7 @@ credit_card = MyMoip::CreditCard.new(
|
|
76
76
|
)
|
77
77
|
|
78
78
|
credit_card_payment = MyMoip::CreditCardPayment.new(credit_card, installments: 1)
|
79
|
-
payment_request = MyMoip::PaymentRequest.new("
|
79
|
+
payment_request = MyMoip::PaymentRequest.new("your_logging_id")
|
80
80
|
payment_request.api_call(credit_card_payment, token: transparent_request.token)
|
81
81
|
```
|
82
82
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.5
|
data/lib/mymoip/credit_card.rb
CHANGED
@@ -3,6 +3,10 @@ module MyMoip
|
|
3
3
|
attr_accessor :logo, :card_number, :expiration_date, :security_code,
|
4
4
|
:owner_name, :owner_birthday, :owner_phone, :owner_rg
|
5
5
|
|
6
|
+
AVAILABLE_LOGOS = [
|
7
|
+
:american_express, :diners, :hipercard, :mastercard, :visa
|
8
|
+
]
|
9
|
+
|
6
10
|
def initialize(params)
|
7
11
|
@logo = params[:logo] if params.has_key? :logo
|
8
12
|
@card_number = params[:card_number] if params.has_key? :card_number
|
data/lib/mymoip/request.rb
CHANGED
@@ -8,19 +8,20 @@ module MyMoip
|
|
8
8
|
@id = id
|
9
9
|
end
|
10
10
|
|
11
|
-
def api_call(params,
|
12
|
-
logger ||= MyMoip.logger
|
13
|
-
username ||= MyMoip.token
|
14
|
-
password ||= MyMoip.key
|
11
|
+
def api_call(params, opts = {})
|
12
|
+
opts[:logger] ||= MyMoip.logger
|
13
|
+
opts[:username] ||= MyMoip.token
|
14
|
+
opts[:password] ||= MyMoip.key
|
15
15
|
|
16
|
-
logger.info "
|
16
|
+
opts[:logger].info "New #{self.class} being sent to MoIP."
|
17
|
+
opts[:logger].debug "#{self.class} of ##{@id} with #{params.inspect}"
|
17
18
|
|
18
19
|
url = MyMoip.api_url + params.delete(:path)
|
19
|
-
params[:basic_auth] = { username: username, password: password }
|
20
|
+
params[:basic_auth] = { username: opts[:username], password: opts[:password] }
|
20
21
|
|
21
22
|
@response = HTTParty.send params.delete(:http_method), url, params
|
22
23
|
|
23
|
-
logger.
|
24
|
+
opts[:logger].debug "#{self.class} of ##{@id} to #{url} had response #{@response.inspect}"
|
24
25
|
end
|
25
26
|
end
|
26
27
|
end
|
@@ -6,14 +6,14 @@ module MyMoip
|
|
6
6
|
REQUIRES_AUTH = false
|
7
7
|
FORMAT = :json
|
8
8
|
|
9
|
-
def api_call(data,
|
10
|
-
|
11
|
-
|
9
|
+
def api_call(data, opts)
|
10
|
+
opts[:referer_url] ||= MyMoip.default_referer_url
|
11
|
+
opts[:parser] ||= MyMoip::JsonParser
|
12
12
|
|
13
13
|
json = JSON.generate({
|
14
14
|
pagamentoWidget: {
|
15
|
-
referer:
|
16
|
-
token:
|
15
|
+
referer: opts[:referer_url],
|
16
|
+
token: opts[:token],
|
17
17
|
dadosPagamento: data.to_json
|
18
18
|
}
|
19
19
|
})
|
@@ -25,9 +25,9 @@ module MyMoip
|
|
25
25
|
path: PATH,
|
26
26
|
format: FORMAT
|
27
27
|
}
|
28
|
-
params[:parser] =
|
28
|
+
params[:parser] = opts.delete(:parser) unless opts[:parser].nil?
|
29
29
|
|
30
|
-
super
|
30
|
+
super(params)
|
31
31
|
end
|
32
32
|
|
33
33
|
def success?
|
@@ -5,16 +5,15 @@ module MyMoip
|
|
5
5
|
PATH = "/ws/alpha/EnviarInstrucao/Unica"
|
6
6
|
REQUIRES_AUTH = true
|
7
7
|
|
8
|
-
def api_call(data,
|
8
|
+
def api_call(data, opts = {})
|
9
9
|
params = {
|
10
10
|
body: data.to_xml,
|
11
11
|
http_method: HTTP_METHOD,
|
12
12
|
requires_auth: REQUIRES_AUTH,
|
13
|
-
path: PATH
|
14
|
-
logger: logger
|
13
|
+
path: PATH
|
15
14
|
}
|
16
15
|
|
17
|
-
super
|
16
|
+
super(params, opts)
|
18
17
|
end
|
19
18
|
|
20
19
|
def success?
|
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.5"
|
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-28"
|
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 = [
|
data/test/fixtures/fixture.rb
CHANGED
@@ -25,8 +25,8 @@ class Fixture
|
|
25
25
|
)
|
26
26
|
end
|
27
27
|
|
28
|
-
def self.credit_card
|
29
|
-
|
28
|
+
def self.credit_card(params = {})
|
29
|
+
params = {
|
30
30
|
logo: :visa,
|
31
31
|
card_number: "4916654211627608",
|
32
32
|
expiration_date: "06/15",
|
@@ -35,7 +35,8 @@ class Fixture
|
|
35
35
|
owner_birthday: Date.new(1984, 11, 3),
|
36
36
|
owner_phone: "(51)3040-5060",
|
37
37
|
owner_rg: "1010202030"
|
38
|
-
)
|
38
|
+
}.merge(params)
|
39
|
+
MyMoip::CreditCard.new(params)
|
39
40
|
end
|
40
41
|
|
41
42
|
end
|
@@ -52,4 +52,18 @@ class TestCreditCardPayment < Test::Unit::TestCase
|
|
52
52
|
assert_match /\A\d+\z/, payment.to_json[:CartaoCredito][:Portador][:Identidade]
|
53
53
|
end
|
54
54
|
|
55
|
+
def test_to_json_should_accept_any_creditcard_from_available_logos_constant
|
56
|
+
MyMoip::CreditCard::AVAILABLE_LOGOS.each do |logo|
|
57
|
+
payment = MyMoip::CreditCardPayment.new(Fixture.credit_card(logo: logo))
|
58
|
+
assert_nothing_raised(KeyError) { payment.to_json }
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_to_json_should_accept_any_creditcard_logo_as_string
|
63
|
+
MyMoip::CreditCard::AVAILABLE_LOGOS.each do |logo|
|
64
|
+
payment = MyMoip::CreditCardPayment.new(Fixture.credit_card(logo: logo.to_s))
|
65
|
+
assert_nothing_raised(KeyError) { payment.to_json }
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
55
69
|
end
|
@@ -46,7 +46,7 @@ class TestPaymentRequest < Test::Unit::TestCase
|
|
46
46
|
request.api_call(request_data, token: "big_transparent_token")
|
47
47
|
end
|
48
48
|
|
49
|
-
def
|
49
|
+
def test_successful_status
|
50
50
|
MyMoip.default_referer_url = "http://localhost/default"
|
51
51
|
HTTParty.stubs(:send).returns(
|
52
52
|
JSON.parse '{"Status":"EmAnalise","Codigo":0,"CodigoRetorno":"","TaxaMoIP":"7.79","StatusPagamento":"Sucesso","Classificacao":{"Codigo":999,"Descricao":"Não suportado no ambiente Sandbox"},"CodigoMoIP":77316,"Mensagem":"Requisição processada com sucesso","TotalPago":"100.00"}'
|
data/test/test_request.rb
CHANGED
@@ -6,7 +6,7 @@ class TestRequest < Test::Unit::TestCase
|
|
6
6
|
assert_equal "request_id", request.id
|
7
7
|
end
|
8
8
|
|
9
|
-
def
|
9
|
+
def test_logs_api_call_method_in_info_level
|
10
10
|
logger = stub_everything
|
11
11
|
request = MyMoip::Request.new("request_id")
|
12
12
|
params = {
|
@@ -15,12 +15,12 @@ class TestRequest < Test::Unit::TestCase
|
|
15
15
|
|
16
16
|
HTTParty.stubs(:send).returns("<html>some_result</html>")
|
17
17
|
logger.expects(:info).at_least_once.
|
18
|
-
with(regexp_matches(/
|
18
|
+
with(regexp_matches(/being sent to MoIP/))
|
19
19
|
|
20
|
-
request.api_call(params, logger)
|
20
|
+
request.api_call(params, logger: logger)
|
21
21
|
end
|
22
22
|
|
23
|
-
def
|
23
|
+
def test_logs_api_call_method_parameters_in_debug_level
|
24
24
|
logger = stub_everything
|
25
25
|
request = MyMoip::Request.new("request_id")
|
26
26
|
params = {
|
@@ -28,10 +28,24 @@ class TestRequest < Test::Unit::TestCase
|
|
28
28
|
}
|
29
29
|
|
30
30
|
HTTParty.stubs(:send).returns("<html>some_result</html>")
|
31
|
-
logger.expects(:
|
31
|
+
logger.expects(:debug).at_least_once.
|
32
|
+
with(regexp_matches(/request_id.+<pretty><xml><\/xml><\/pretty>/))
|
33
|
+
|
34
|
+
request.api_call(params, logger: logger)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_logs_api_call_response_in_debug_level
|
38
|
+
logger = stub_everything
|
39
|
+
request = MyMoip::Request.new("request_id")
|
40
|
+
params = {
|
41
|
+
http_method: :post, body: "<pretty><xml></xml></pretty>", path: "/ws/alpha/EnviarInstrucao/Unica"
|
42
|
+
}
|
43
|
+
|
44
|
+
HTTParty.stubs(:send).returns("<html>some_result</html>")
|
45
|
+
logger.expects(:debug).at_least_once.
|
32
46
|
with(regexp_matches(/request_id.+<html>some_result<\/html>/))
|
33
47
|
|
34
|
-
request.api_call(params, logger)
|
48
|
+
request.api_call(params, logger: logger)
|
35
49
|
end
|
36
50
|
|
37
51
|
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.5
|
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-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: builder
|
@@ -209,7 +209,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
209
209
|
version: '0'
|
210
210
|
segments:
|
211
211
|
- 0
|
212
|
-
hash:
|
212
|
+
hash: -300341393790101532
|
213
213
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
214
214
|
none: false
|
215
215
|
requirements:
|