mercadopago 2.2.1 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +8 -0
- data/README.md +55 -11
- data/fixtures/vcr_cassettes/cancel_preapproval.yml +65 -0
- data/fixtures/vcr_cassettes/create_preapproval.yml +68 -0
- data/fixtures/vcr_cassettes/create_preference.yml +102 -0
- data/fixtures/vcr_cassettes/get_preference.yml +97 -0
- data/fixtures/vcr_cassettes/login.yml +63 -0
- data/fixtures/vcr_cassettes/wrong_login.yml +63 -0
- data/fixtures/vcr_cassettes/wrong_token.yml +63 -0
- data/lib/mercadopago/authentication.rb +15 -8
- data/lib/mercadopago/checkout.rb +22 -8
- data/lib/mercadopago/client.rb +47 -7
- data/lib/mercadopago/request.rb +22 -3
- data/lib/mercadopago/version.rb +1 -1
- data/mercadopago.gemspec +4 -1
- data/test/test_mercado_pago.rb +176 -58
- metadata +54 -3
data/lib/mercadopago/version.rb
CHANGED
data/mercadopago.gemspec
CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
|
|
7
7
|
s.version = MercadoPago::VERSION
|
8
8
|
s.licenses = ['MIT']
|
9
9
|
s.authors = ["Kauplus Social Commerce", "Ombu Shop, Tu Tienda Online"]
|
10
|
-
s.email = ["suporte@kauplus.com.br"]
|
10
|
+
s.email = ["suporte@kauplus.com.br", "hola@ombushop.com"]
|
11
11
|
s.homepage = "https://github.com/kauplus/mercadopago"
|
12
12
|
s.summary = %q{Client for the MercadoPago API}
|
13
13
|
s.description = %q{This gem allows developers to use the services available in the MercadoPago API (http://www.mercadopago.com)}
|
@@ -23,6 +23,9 @@ Gem::Specification.new do |s|
|
|
23
23
|
s.add_dependency 'json', '>= 1.4.6'
|
24
24
|
s.add_dependency 'faraday', '>= 0.9.0'
|
25
25
|
s.add_development_dependency 'pry'
|
26
|
+
s.add_development_dependency 'rake'
|
26
27
|
s.add_development_dependency 'byebug'
|
27
28
|
s.add_development_dependency 'test-unit'
|
29
|
+
s.add_development_dependency 'vcr'
|
30
|
+
s.add_development_dependency 'webmock'
|
28
31
|
end
|
data/test/test_mercado_pago.rb
CHANGED
@@ -1,15 +1,26 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
+
require File.expand_path('../../lib/mercadopago', __FILE__)
|
4
|
+
|
3
5
|
require 'test/unit'
|
4
|
-
require '
|
6
|
+
require 'webmock/test_unit'
|
7
|
+
require 'vcr'
|
8
|
+
|
9
|
+
#
|
10
|
+
# Valid credentials to be used in the tests.
|
11
|
+
#
|
12
|
+
CREDENTIALS = {
|
13
|
+
client_id: 'CLIENT-ID',
|
14
|
+
client_secret: 'CLIENT-SECRET' }
|
15
|
+
|
16
|
+
VCR.configure do |config|
|
17
|
+
config.cassette_library_dir = "fixtures/vcr_cassettes"
|
18
|
+
config.hook_into :webmock
|
19
|
+
config.filter_sensitive_data('<CLIENT-ID>') { CREDENTIALS[:client_id] }
|
20
|
+
config.filter_sensitive_data('<CLIENT-SECRET>') { CREDENTIALS[:client_secret] }
|
21
|
+
end
|
5
22
|
|
6
23
|
class TestMercadoPago < Test::Unit::TestCase
|
7
|
-
|
8
|
-
#
|
9
|
-
# Valid credentials to be used in the tests.
|
10
|
-
#
|
11
|
-
CREDENTIALS = { client_id: '3962917649351233', client_secret: 'rp7Ec38haoig7zWQXekXMiqA068eS376' }
|
12
|
-
|
13
24
|
#
|
14
25
|
# Example payment request.
|
15
26
|
#
|
@@ -38,91 +49,198 @@ class TestMercadoPago < Test::Unit::TestCase
|
|
38
49
|
}
|
39
50
|
}
|
40
51
|
|
52
|
+
#
|
53
|
+
# Example preapproval request
|
54
|
+
#
|
55
|
+
PREAPPROVAL_REQUEST = {
|
56
|
+
payer_email: "buyer@email.com",
|
57
|
+
back_url: "http://www.example.com/payment_complete",
|
58
|
+
reason: "reason text",
|
59
|
+
external_reference: "order_id 1234",
|
60
|
+
auto_recurring: {
|
61
|
+
frequency: 1,
|
62
|
+
frequency_type: :months,
|
63
|
+
transaction_amount: 12.99,
|
64
|
+
currency_id: "ARS"
|
65
|
+
}
|
66
|
+
}
|
67
|
+
|
41
68
|
# With a valid client id and secret (test account)
|
42
69
|
def test_that_authentication_returns_access_token
|
43
|
-
|
44
|
-
|
70
|
+
VCR.use_cassette("login", match_requests_on: [:path]) do
|
71
|
+
@response = MercadoPago::Authentication
|
72
|
+
.access_token(CREDENTIALS[:client_id],
|
73
|
+
CREDENTIALS[:client_secret])
|
74
|
+
end
|
75
|
+
|
76
|
+
assert @response['access_token']
|
45
77
|
end
|
46
78
|
|
47
79
|
# Using fake client id and client secret
|
48
80
|
def test_that_authentication_fails_with_wrong_parameters
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
def test_that_refresh_token_works
|
55
|
-
auth = MercadoPago::Authentication.access_token(CREDENTIALS[:client_id], CREDENTIALS[:client_secret])
|
56
|
-
refresh = MercadoPago::Authentication.refresh_access_token(CREDENTIALS[:client_id], CREDENTIALS[:client_secret], auth['refresh_token'])
|
81
|
+
VCR.use_cassette("wrong login") do
|
82
|
+
@response = MercadoPago::Authentication.access_token('fake_client_id',
|
83
|
+
'fake_client_secret')
|
84
|
+
end
|
57
85
|
|
58
|
-
|
59
|
-
|
60
|
-
assert refresh['access_token'] != auth['access_token']
|
61
|
-
assert refresh['refresh_token'] != auth['refresh_token']
|
86
|
+
assert_nil @response['access_token']
|
87
|
+
assert_equal "bad_request", @response['error']
|
62
88
|
end
|
63
89
|
|
64
|
-
#
|
90
|
+
# TODO: make test work again
|
91
|
+
# def test_that_refresh_token_works
|
92
|
+
# VCR.use_cassette("access_token") do
|
93
|
+
# @auth = MercadoPago::Authentication
|
94
|
+
# .access_token(CREDENTIALS[:client_id],
|
95
|
+
# CREDENTIALS[:client_secret])
|
96
|
+
# end
|
97
|
+
# VCR.use_cassette("refresh_token") do
|
98
|
+
# @refresh = MercadoPago::Authentication.refresh_access_token(
|
99
|
+
# CREDENTIALS[:client_id],
|
100
|
+
# CREDENTIALS[:client_secret],
|
101
|
+
# @auth['refresh_token']
|
102
|
+
# )
|
103
|
+
# end
|
104
|
+
#
|
105
|
+
# assert @refresh['access_token']
|
106
|
+
# assert @refresh['refresh_token']
|
107
|
+
# assert @refresh['access_token'] != @auth['access_token']
|
108
|
+
# assert @refresh['refresh_token'] != @auth['refresh_token']
|
109
|
+
# end
|
110
|
+
|
65
111
|
def test_that_request_fails_with_wrong_token
|
66
|
-
|
67
|
-
|
68
|
-
|
112
|
+
VCR.use_cassette("wrong token") do
|
113
|
+
@response = MercadoPago::Checkout.create_preference('fake_token', {})
|
114
|
+
end
|
115
|
+
assert_equal 'Malformed access_token: null', @response['message']
|
116
|
+
assert_equal 'bad_request', @response['error']
|
69
117
|
end
|
70
118
|
|
71
119
|
def test_that_client_initializes_okay_with_valid_details
|
72
|
-
|
73
|
-
|
120
|
+
VCR.use_cassette("login", match_requests_on: [:path]) do
|
121
|
+
@mp_client = MercadoPago::Client.new(CREDENTIALS[:client_id],
|
122
|
+
CREDENTIALS[:client_secret])
|
123
|
+
end
|
124
|
+
|
125
|
+
assert @mp_client.access_token
|
74
126
|
end
|
75
127
|
|
76
128
|
def test_that_client_fails_with_wrong_details
|
77
129
|
assert_raises(MercadoPago::AccessError) do
|
78
|
-
|
130
|
+
VCR.use_cassette("wrong login") do
|
131
|
+
@mp_client = MercadoPago::Client.new('fake_client_id',
|
132
|
+
'fake_client_secret')
|
133
|
+
end
|
79
134
|
end
|
80
135
|
end
|
81
136
|
|
82
137
|
def test_that_client_can_create_payment_preference
|
83
|
-
|
84
|
-
|
85
|
-
|
138
|
+
VCR.use_cassette("login", match_requests_on: [:path]) do
|
139
|
+
@mp_client = MercadoPago::Client.new(CREDENTIALS[:client_id],
|
140
|
+
CREDENTIALS[:client_secret])
|
141
|
+
end
|
142
|
+
|
143
|
+
VCR.use_cassette("create preference", match_requests_on: [:method, :path]) do
|
144
|
+
@response = @mp_client.create_preference(PAYMENT_REQUEST)
|
145
|
+
end
|
146
|
+
assert @response['init_point']
|
86
147
|
end
|
87
148
|
|
88
149
|
def test_that_client_can_get_preference
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
response = mp_client.get_preference(pref_id)
|
95
|
-
assert_equal "https://www.mercadopago.com/mlb/checkout/pay?pref_id=#{pref_id}", response['init_point']
|
96
|
-
end
|
150
|
+
VCR.use_cassette("login", match_requests_on: [:path]) do
|
151
|
+
@mp_client = MercadoPago::Client.new(CREDENTIALS[:client_id],
|
152
|
+
CREDENTIALS[:client_secret])
|
153
|
+
end
|
97
154
|
|
98
|
-
|
99
|
-
|
100
|
-
|
155
|
+
VCR.use_cassette("create preference", match_requests_on: [:method, :path]) do
|
156
|
+
@response = @mp_client.create_preference(PAYMENT_REQUEST)
|
157
|
+
end
|
158
|
+
assert @pref_id = @response['id']
|
101
159
|
|
102
|
-
|
103
|
-
|
160
|
+
VCR.use_cassette("get preference", match_requests_on: [:method, :path]) do
|
161
|
+
@response = @mp_client.get_preference(@pref_id)
|
162
|
+
end
|
163
|
+
assert_match /https\:\/\/www\.mercadopago\.com\/ml(a|b)\/checkout\/start\?pref\_id\=#{@pref_id}/, @response['init_point']
|
104
164
|
end
|
105
165
|
|
106
|
-
def
|
107
|
-
|
108
|
-
|
166
|
+
def test_that_client_can_create_preapproval_payment
|
167
|
+
VCR.use_cassette("login", match_requests_on: [:path]) do
|
168
|
+
@mp_client = MercadoPago::Client.new(
|
169
|
+
CREDENTIALS[:client_id], CREDENTIALS[:client_secret])
|
170
|
+
end
|
109
171
|
|
110
|
-
|
111
|
-
|
172
|
+
VCR.use_cassette("create_preapproval", match_requests_on: [:path]) do
|
173
|
+
@response = @mp_client.create_preapproval_payment(PREAPPROVAL_REQUEST)
|
174
|
+
end
|
175
|
+
assert @response['init_point']
|
112
176
|
end
|
113
177
|
|
114
|
-
def
|
115
|
-
|
116
|
-
|
178
|
+
def test_that_client_can_cancel_preapproval
|
179
|
+
VCR.use_cassette("login", match_requests_on: [:path]) do
|
180
|
+
@mp_client = MercadoPago::Client.new(
|
181
|
+
CREDENTIALS[:client_id], CREDENTIALS[:client_secret])
|
182
|
+
end
|
117
183
|
|
118
|
-
|
184
|
+
VCR.use_cassette("create_preapproval", match_requests_on: [:path]) do
|
185
|
+
@response = @mp_client.create_preapproval_payment(PREAPPROVAL_REQUEST)
|
186
|
+
end
|
187
|
+
assert preap_id = @response['id']
|
119
188
|
|
120
|
-
|
121
|
-
|
122
|
-
|
189
|
+
VCR.use_cassette("cancel_preapproval", match_requests_on: [:path]) do
|
190
|
+
@response = @mp_client.cancel_preapproval_payment(preap_id)
|
191
|
+
end
|
123
192
|
|
124
|
-
assert_equal
|
125
|
-
assert_equal
|
193
|
+
assert_equal "cancelled", @response['status']
|
194
|
+
assert_equal "http://www.example.com/payment_complete", @response['back_url']
|
126
195
|
end
|
127
196
|
|
197
|
+
# TODO: make test work again
|
198
|
+
# def test_that_client_can_get_payment_notification
|
199
|
+
# VCR.use_cassette("login", match_requests_on: [:path]) do
|
200
|
+
# @mp_client = MercadoPago::Client.new(CREDENTIALS[:client_id], CREDENTIALS[:client_secret])
|
201
|
+
# end
|
202
|
+
#
|
203
|
+
# @payment_id = 849707350
|
204
|
+
# VCR.use_cassette("notification") do
|
205
|
+
# @response = @mp_client.notification(@payment_id)
|
206
|
+
# end
|
207
|
+
#
|
208
|
+
# assert_equal @payment_id, @response['collection']['id']
|
209
|
+
# end
|
210
|
+
|
211
|
+
# TODO: make test work again
|
212
|
+
# def test_that_client_can_get_merchant_order_notification
|
213
|
+
# payment_id = 61166827
|
214
|
+
# VCR.use_cassette("login", match_requests_on: [:path]) do
|
215
|
+
# @mp_client = MercadoPago::Client.new(CREDENTIALS[:client_id], CREDENTIALS[:client_secret])
|
216
|
+
# end
|
217
|
+
#
|
218
|
+
# VCR.use_cassette("merchant notification") do
|
219
|
+
# @response = @mp_client.notification(payment_id, 'merchant_order')
|
220
|
+
# end
|
221
|
+
# assert_equal payment_id, @response['id']
|
222
|
+
# end
|
223
|
+
|
224
|
+
# TODO: make test work again
|
225
|
+
# def test_that_client_can_search
|
226
|
+
# VCR.use_cassette("login", match_requests_on: [:path]) do
|
227
|
+
# @mp_client = MercadoPago::Client.new(CREDENTIALS[:client_id], CREDENTIALS[:client_secret])
|
228
|
+
# end
|
229
|
+
#
|
230
|
+
# VCR.use_cassette("search status") do
|
231
|
+
# @response = @mp_client.search(status: :refunded)
|
232
|
+
# end
|
233
|
+
#
|
234
|
+
# assert @response.has_key?('results')
|
235
|
+
#
|
236
|
+
# external_reference = '55723'
|
237
|
+
#
|
238
|
+
# VCR.use_cassette("search external reference") do
|
239
|
+
# @response = @mp_client.search(external_reference: external_reference)
|
240
|
+
# end
|
241
|
+
# results = @response['results']
|
242
|
+
#
|
243
|
+
# assert_equal 1, results.length
|
244
|
+
# assert_equal external_reference, results[0]['collection']['external_reference']
|
245
|
+
# end
|
128
246
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mercadopago
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kauplus Social Commerce
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2017-05-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
@@ -53,6 +53,20 @@ dependencies:
|
|
53
53
|
- - ">="
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rake
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
56
70
|
- !ruby/object:Gem::Dependency
|
57
71
|
name: byebug
|
58
72
|
requirement: !ruby/object:Gem::Requirement
|
@@ -81,18 +95,55 @@ dependencies:
|
|
81
95
|
- - ">="
|
82
96
|
- !ruby/object:Gem::Version
|
83
97
|
version: '0'
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: vcr
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
- !ruby/object:Gem::Dependency
|
113
|
+
name: webmock
|
114
|
+
requirement: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
type: :development
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
84
126
|
description: This gem allows developers to use the services available in the MercadoPago
|
85
127
|
API (http://www.mercadopago.com)
|
86
128
|
email:
|
87
129
|
- suporte@kauplus.com.br
|
130
|
+
- hola@ombushop.com
|
88
131
|
executables: []
|
89
132
|
extensions: []
|
90
133
|
extra_rdoc_files: []
|
91
134
|
files:
|
92
135
|
- ".gitignore"
|
136
|
+
- ".travis.yml"
|
93
137
|
- Gemfile
|
94
138
|
- README.md
|
95
139
|
- Rakefile
|
140
|
+
- fixtures/vcr_cassettes/cancel_preapproval.yml
|
141
|
+
- fixtures/vcr_cassettes/create_preapproval.yml
|
142
|
+
- fixtures/vcr_cassettes/create_preference.yml
|
143
|
+
- fixtures/vcr_cassettes/get_preference.yml
|
144
|
+
- fixtures/vcr_cassettes/login.yml
|
145
|
+
- fixtures/vcr_cassettes/wrong_login.yml
|
146
|
+
- fixtures/vcr_cassettes/wrong_token.yml
|
96
147
|
- lib/mercadopago.rb
|
97
148
|
- lib/mercadopago/authentication.rb
|
98
149
|
- lib/mercadopago/checkout.rb
|
@@ -123,7 +174,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
174
|
version: '0'
|
124
175
|
requirements: []
|
125
176
|
rubyforge_project: mercadopago
|
126
|
-
rubygems_version: 2.4.
|
177
|
+
rubygems_version: 2.4.8
|
127
178
|
signing_key:
|
128
179
|
specification_version: 4
|
129
180
|
summary: Client for the MercadoPago API
|