mercadopago-sdk 1.2.0 → 2.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.editorconfig +10 -0
- data/.github/ISSUE_TEMPLATE/bug_report.md +28 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +19 -0
- data/.github/workflows/ruby.yml +35 -0
- data/.rubocop.yml +1 -0
- data/.rubocop_todo.yml +104 -0
- data/.ruby-version +1 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/CODING_GUIDELINES.md +70 -0
- data/CONTRIBUTING.md +57 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +51 -12
- data/LICENSE.txt +21 -0
- data/README.md +45 -117
- data/Rakefile +3 -1
- data/docs/CODE_OF_CONDUCT_md.html +154 -0
- data/docs/CODING_GUIDELINES_md.html +188 -0
- data/docs/CONTRIBUTING_md.html +165 -0
- data/docs/LICENSE_txt.html +96 -0
- data/docs/Mercadopago/AdvancedPayment.html +279 -0
- data/docs/Mercadopago/Card.html +204 -0
- data/docs/Mercadopago/CardToken.html +160 -0
- data/docs/Mercadopago/Config.html +266 -0
- data/docs/Mercadopago/Customer.html +228 -0
- data/docs/Mercadopago/DisbursementRefund.html +183 -0
- data/docs/Mercadopago/HttpClient.html +249 -0
- data/docs/Mercadopago/IdentificationType.html +136 -0
- data/docs/Mercadopago/MPBase.html +316 -0
- data/docs/Mercadopago/MerchantOrder.html +209 -0
- data/docs/Mercadopago/Payment.html +208 -0
- data/docs/Mercadopago/PaymentMethods.html +136 -0
- data/docs/Mercadopago/Preference.html +184 -0
- data/docs/Mercadopago/Refund.html +160 -0
- data/docs/Mercadopago/RequestOptions.html +433 -0
- data/docs/Mercadopago/SDK.html +528 -0
- data/docs/Mercadopago/User.html +136 -0
- data/docs/Mercadopago.html +123 -0
- data/docs/README_md.html +181 -0
- data/docs/created.rid +25 -0
- data/docs/css/fonts.css +167 -0
- data/docs/css/rdoc.css +619 -0
- data/docs/fonts/Lato-Light.ttf +0 -0
- data/docs/fonts/Lato-LightItalic.ttf +0 -0
- data/docs/fonts/Lato-Regular.ttf +0 -0
- data/docs/fonts/Lato-RegularItalic.ttf +0 -0
- data/docs/fonts/SourceCodePro-Bold.ttf +0 -0
- data/docs/fonts/SourceCodePro-Regular.ttf +0 -0
- data/docs/images/add.png +0 -0
- data/docs/images/arrow_up.png +0 -0
- data/docs/images/brick.png +0 -0
- data/docs/images/brick_link.png +0 -0
- data/docs/images/bug.png +0 -0
- data/docs/images/bullet_black.png +0 -0
- data/docs/images/bullet_toggle_minus.png +0 -0
- data/docs/images/bullet_toggle_plus.png +0 -0
- data/docs/images/date.png +0 -0
- data/docs/images/delete.png +0 -0
- data/docs/images/find.png +0 -0
- data/docs/images/loadingAnimation.gif +0 -0
- data/docs/images/macFFBgHack.png +0 -0
- data/docs/images/package.png +0 -0
- data/docs/images/page_green.png +0 -0
- data/docs/images/page_white_text.png +0 -0
- data/docs/images/page_white_width.png +0 -0
- data/docs/images/plugin.png +0 -0
- data/docs/images/ruby.png +0 -0
- data/docs/images/tag_blue.png +0 -0
- data/docs/images/tag_green.png +0 -0
- data/docs/images/transparent.png +0 -0
- data/docs/images/wrench.png +0 -0
- data/docs/images/wrench_orange.png +0 -0
- data/docs/images/zoom.png +0 -0
- data/docs/index.html +109 -0
- data/docs/js/darkfish.js +84 -0
- data/docs/js/navigation.js +105 -0
- data/docs/js/navigation.js.gz +0 -0
- data/docs/js/search.js +110 -0
- data/docs/js/search_index.js +1 -0
- data/docs/js/search_index.js.gz +0 -0
- data/docs/js/searcher.js +229 -0
- data/docs/js/searcher.js.gz +0 -0
- data/docs/table_of_contents.html +562 -0
- data/lib/mercadopago/config/config.rb +42 -0
- data/lib/mercadopago/config/request_options.rb +85 -0
- data/lib/mercadopago/core/mp_base.rb +77 -0
- data/lib/mercadopago/http/http_client.rb +74 -0
- data/lib/mercadopago/resources/advanced_payment.rb +48 -0
- data/lib/mercadopago/resources/card.rb +31 -0
- data/lib/mercadopago/resources/card_token.rb +19 -0
- data/lib/mercadopago/resources/customer.rb +36 -0
- data/lib/mercadopago/resources/disbursement_refund.rb +24 -0
- data/lib/mercadopago/resources/identification_type.rb +13 -0
- data/lib/mercadopago/resources/merchant_order.rb +32 -0
- data/lib/mercadopago/resources/payment.rb +35 -0
- data/lib/mercadopago/resources/payment_methods.rb +13 -0
- data/lib/mercadopago/resources/preference.rb +26 -0
- data/lib/mercadopago/resources/refund.rb +24 -0
- data/lib/mercadopago/resources/user.rb +13 -0
- data/lib/mercadopago/sdk.rb +85 -0
- data/lib/mercadopago.rb +24 -389
- data/mercadopago.gemspec +15 -15
- data/tests/test_card.rb +78 -0
- data/tests/test_card_token.rb +39 -0
- data/tests/test_customer.rb +54 -0
- data/tests/test_identification_type.rb +16 -0
- data/tests/test_merchant_order.rb +94 -0
- data/tests/test_payment.rb +102 -0
- data/tests/test_payment_methods.rb +14 -0
- data/tests/test_preference.rb +49 -0
- data/tests/test_refund.rb +88 -0
- data/tests/test_refund_with_custom_headers.rb +97 -0
- data/tests/test_user.rb +17 -0
- data/tests/tests.rb +13 -56
- metadata +155 -36
- data/.travis.yml +0 -14
- data/examples/checkout-buttons/basic_preference/button.rb +0 -28
- data/examples/instant-payment-notifications/receive-ipn.rb +0 -25
- data/examples/payment-search/search-approved-payments.rb +0 -23
- data/examples/payment-search/search-creditcard-payments.rb +0 -23
- data/examples/payment-search/search-funded-payments-by-name.rb +0 -23
- data/examples/payment-search/search-payments-from-email-and-date.rb +0 -23
- data/examples/payment-search/search-payments.rb +0 -23
- data/examples/preapproval-payments/button.rb +0 -42
- data/lib/ssl_options_patch.rb +0 -15
- data/lib/version.rb +0 -2
- data/travis_Gemfile +0 -4
data/lib/mercadopago.rb
CHANGED
@@ -1,389 +1,24 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
@rest_client = RestClient.new()
|
26
|
-
@sandbox = false
|
27
|
-
end
|
28
|
-
|
29
|
-
def set_debug_logger(debug_logger)
|
30
|
-
@rest_client.set_debug_logger(debug_logger)
|
31
|
-
end
|
32
|
-
|
33
|
-
def set_platform_id(platform_id)
|
34
|
-
@rest_client.set_platform_id(platform_id)
|
35
|
-
end
|
36
|
-
|
37
|
-
def set_integrator_id(integrator_id)
|
38
|
-
@rest_client.set_integrator_id(integrator_id)
|
39
|
-
end
|
40
|
-
|
41
|
-
def set_corporation_id(corporation_id)
|
42
|
-
@rest_client.set_corporation_id(corporation_id)
|
43
|
-
end
|
44
|
-
|
45
|
-
def sandbox_mode(enable=nil)
|
46
|
-
if not enable.nil?
|
47
|
-
@sandbox = enable
|
48
|
-
end
|
49
|
-
|
50
|
-
return @sandbox
|
51
|
-
end
|
52
|
-
|
53
|
-
# Get Access Token for API use
|
54
|
-
def get_access_token
|
55
|
-
if @ll_access_token
|
56
|
-
@ll_access_token
|
57
|
-
else
|
58
|
-
app_client_values = {
|
59
|
-
'grant_type' => 'client_credentials',
|
60
|
-
'client_id' => @client_id,
|
61
|
-
'client_secret' => @client_secret
|
62
|
-
}
|
63
|
-
|
64
|
-
@access_data = @rest_client.post("/oauth/token", build_query(app_client_values), RestClient::MIME_FORM)
|
65
|
-
|
66
|
-
if @access_data['status'] == "200"
|
67
|
-
@access_data = @access_data["response"]
|
68
|
-
@access_data['access_token']
|
69
|
-
else
|
70
|
-
raise @access_data.inspect
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
# Get information for specific payment
|
76
|
-
def get_payment(id)
|
77
|
-
begin
|
78
|
-
access_token = get_access_token
|
79
|
-
rescue => e
|
80
|
-
return e.message
|
81
|
-
end
|
82
|
-
|
83
|
-
uri_prefix = @sandbox ? "/sandbox" : ""
|
84
|
-
|
85
|
-
@rest_client.get(uri_prefix + "/v1/payments/" + id + "?access_token=" + access_token)
|
86
|
-
|
87
|
-
end
|
88
|
-
|
89
|
-
def get_payment_info(id)
|
90
|
-
get_payment(id)
|
91
|
-
end
|
92
|
-
|
93
|
-
# Get information for specific authorized payment
|
94
|
-
def get_authorized_payment(id)
|
95
|
-
begin
|
96
|
-
access_token = get_access_token
|
97
|
-
rescue => e
|
98
|
-
return e.message
|
99
|
-
end
|
100
|
-
|
101
|
-
@rest_client.get("/authorized_payments/" + id + "?access_token=" + access_token)
|
102
|
-
end
|
103
|
-
|
104
|
-
# Refund accredited payment
|
105
|
-
def refund_payment(id)
|
106
|
-
begin
|
107
|
-
access_token = get_access_token
|
108
|
-
rescue => e
|
109
|
-
return e.message
|
110
|
-
end
|
111
|
-
|
112
|
-
|
113
|
-
refund_status = {}
|
114
|
-
@rest_client.post("/v1/payments/" + id + "/refunds?access_token=" + access_token, refund_status)
|
115
|
-
|
116
|
-
end
|
117
|
-
|
118
|
-
# Cancel pending payment
|
119
|
-
def cancel_payment(id)
|
120
|
-
begin
|
121
|
-
access_token = get_access_token
|
122
|
-
rescue => e
|
123
|
-
return e.message
|
124
|
-
end
|
125
|
-
|
126
|
-
cancel_status = {"status" => "cancelled"}
|
127
|
-
@rest_client.put("/v1/payments/" + id + "?access_token=" + access_token, cancel_status)
|
128
|
-
end
|
129
|
-
|
130
|
-
# Cancel preapproval payment
|
131
|
-
def cancel_preapproval_payment(id)
|
132
|
-
begin
|
133
|
-
access_token = get_access_token
|
134
|
-
rescue => e
|
135
|
-
return e.message
|
136
|
-
end
|
137
|
-
|
138
|
-
cancel_status = {"status" => "cancelled"}
|
139
|
-
@rest_client.put("/preapproval/" + id + "?access_token=" + access_token, cancel_status)
|
140
|
-
end
|
141
|
-
|
142
|
-
# Search payments according to filters, with pagination
|
143
|
-
def search_payment(filters, offset=0, limit=0)
|
144
|
-
begin
|
145
|
-
access_token = get_access_token
|
146
|
-
rescue => e
|
147
|
-
return e.message
|
148
|
-
end
|
149
|
-
|
150
|
-
filters["offset"] = offset
|
151
|
-
filters["limit"] = limit
|
152
|
-
|
153
|
-
filters = build_query(filters)
|
154
|
-
|
155
|
-
uri_prefix = @sandbox ? "/sandbox" : ""
|
156
|
-
|
157
|
-
@rest_client.get(uri_prefix + "/v1/payments/search?" + filters + "&access_token=" + access_token)
|
158
|
-
|
159
|
-
end
|
160
|
-
|
161
|
-
# Create a checkout preference
|
162
|
-
def create_preference(preference)
|
163
|
-
begin
|
164
|
-
access_token = get_access_token
|
165
|
-
rescue => e
|
166
|
-
return e.message
|
167
|
-
end
|
168
|
-
|
169
|
-
@rest_client.post("/checkout/preferences?access_token=" + access_token, preference)
|
170
|
-
end
|
171
|
-
|
172
|
-
# Update a checkout preference
|
173
|
-
def update_preference(id, preference)
|
174
|
-
begin
|
175
|
-
access_token = get_access_token
|
176
|
-
rescue => e
|
177
|
-
return e.message
|
178
|
-
end
|
179
|
-
|
180
|
-
@rest_client.put("/checkout/preferences/" + id + "?access_token=" + access_token, preference)
|
181
|
-
end
|
182
|
-
|
183
|
-
# Get a checkout preference
|
184
|
-
def get_preference(id)
|
185
|
-
begin
|
186
|
-
access_token = get_access_token
|
187
|
-
rescue => e
|
188
|
-
return e.message
|
189
|
-
end
|
190
|
-
|
191
|
-
@rest_client.get("/checkout/preferences/" + id + "?access_token=" + access_token)
|
192
|
-
end
|
193
|
-
|
194
|
-
# Create a preapproval payment
|
195
|
-
def create_preapproval_payment(preapproval_payment)
|
196
|
-
begin
|
197
|
-
access_token = get_access_token
|
198
|
-
rescue => e
|
199
|
-
return e.message
|
200
|
-
end
|
201
|
-
|
202
|
-
@rest_client.post("/preapproval?access_token=" + access_token, preapproval_payment)
|
203
|
-
end
|
204
|
-
|
205
|
-
# Get a preapproval payment
|
206
|
-
def get_preapproval_payment(id)
|
207
|
-
begin
|
208
|
-
access_token = get_access_token
|
209
|
-
rescue => e
|
210
|
-
return e.message
|
211
|
-
end
|
212
|
-
|
213
|
-
@rest_client.get("/preapproval/" + id + "?access_token=" + access_token)
|
214
|
-
end
|
215
|
-
|
216
|
-
# Generic resource get
|
217
|
-
def get(uri, params = nil, authenticate = true)
|
218
|
-
if not params.class == Hash
|
219
|
-
params = Hash.new
|
220
|
-
end
|
221
|
-
|
222
|
-
if authenticate
|
223
|
-
begin
|
224
|
-
access_token = get_access_token
|
225
|
-
rescue => e
|
226
|
-
return e.message
|
227
|
-
end
|
228
|
-
|
229
|
-
params["access_token"] = access_token
|
230
|
-
end
|
231
|
-
|
232
|
-
if not params.empty?
|
233
|
-
uri << (if uri.include? "?" then "&" else "?" end) << build_query(params)
|
234
|
-
end
|
235
|
-
|
236
|
-
@rest_client.get(uri)
|
237
|
-
end
|
238
|
-
|
239
|
-
# Generic resource post
|
240
|
-
def post(uri, data, params = nil)
|
241
|
-
if not params.class == Hash
|
242
|
-
params = Hash.new
|
243
|
-
end
|
244
|
-
|
245
|
-
begin
|
246
|
-
access_token = get_access_token
|
247
|
-
rescue => e
|
248
|
-
return e.message
|
249
|
-
end
|
250
|
-
|
251
|
-
params["access_token"] = access_token
|
252
|
-
|
253
|
-
if not params.empty?
|
254
|
-
uri << (if uri.include? "?" then "&" else "?" end) << build_query(params)
|
255
|
-
end
|
256
|
-
|
257
|
-
@rest_client.post(uri, data)
|
258
|
-
end
|
259
|
-
|
260
|
-
# Generic resource put
|
261
|
-
def put(uri, data, params = nil)
|
262
|
-
if not params.class == Hash
|
263
|
-
params = Hash.new
|
264
|
-
end
|
265
|
-
|
266
|
-
begin
|
267
|
-
access_token = get_access_token
|
268
|
-
rescue => e
|
269
|
-
return e.message
|
270
|
-
end
|
271
|
-
|
272
|
-
params["access_token"] = access_token
|
273
|
-
|
274
|
-
if not params.empty?
|
275
|
-
uri << (if uri.include? "?" then "&" else "?" end) << build_query(params)
|
276
|
-
end
|
277
|
-
|
278
|
-
@rest_client.put(uri, data)
|
279
|
-
end
|
280
|
-
|
281
|
-
# Generic resource delete
|
282
|
-
def delete(uri, params = nil)
|
283
|
-
if not params.class == Hash
|
284
|
-
params = Hash.new
|
285
|
-
end
|
286
|
-
|
287
|
-
begin
|
288
|
-
access_token = get_access_token
|
289
|
-
rescue => e
|
290
|
-
return e.message
|
291
|
-
end
|
292
|
-
|
293
|
-
params["access_token"] = access_token
|
294
|
-
|
295
|
-
if not params.empty?
|
296
|
-
uri << (if uri.include? "?" then "&" else "?" end) << build_query(params)
|
297
|
-
end
|
298
|
-
|
299
|
-
@rest_client.delete(uri)
|
300
|
-
end
|
301
|
-
|
302
|
-
def build_query(params)
|
303
|
-
URI.escape(params.collect { |k, v| "#{k}=#{v}" }.join('&'))
|
304
|
-
end
|
305
|
-
|
306
|
-
private
|
307
|
-
|
308
|
-
class RestClient
|
309
|
-
|
310
|
-
MIME_JSON = 'application/json'
|
311
|
-
MIME_FORM = 'application/x-www-form-urlencoded'
|
312
|
-
API_BASE_URL = URI.parse('https://api.mercadopago.com')
|
313
|
-
|
314
|
-
def initialize(debug_logger=nil)
|
315
|
-
@http = Net::HTTP.new(API_BASE_URL.host, API_BASE_URL.port)
|
316
|
-
|
317
|
-
if API_BASE_URL.scheme == "https" # enable SSL/TLS
|
318
|
-
@http.use_ssl = true
|
319
|
-
@http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
320
|
-
|
321
|
-
# explicitly tell OpenSSL not to use SSL3 nor TLS 1.0
|
322
|
-
@http.ssl_options = OpenSSL::SSL::OP_NO_SSLv3 + OpenSSL::SSL::OP_NO_TLSv1
|
323
|
-
end
|
324
|
-
|
325
|
-
@http.set_debug_output debug_logger if debug_logger
|
326
|
-
|
327
|
-
@platform_id = nil
|
328
|
-
@integrator_id = nil
|
329
|
-
@corporation_id = nil
|
330
|
-
end
|
331
|
-
|
332
|
-
def set_debug_logger(debug_logger)
|
333
|
-
@http.set_debug_output debug_logger
|
334
|
-
end
|
335
|
-
|
336
|
-
def set_platform_id(platform_id)
|
337
|
-
@platform_id = platform_id
|
338
|
-
end
|
339
|
-
|
340
|
-
def set_integrator_id(integrator_id)
|
341
|
-
@integrator_id = integrator_id
|
342
|
-
end
|
343
|
-
|
344
|
-
def set_corporation_id(corporation_id)
|
345
|
-
@corporation_id = corporation_id
|
346
|
-
end
|
347
|
-
|
348
|
-
def exec(method, uri, data, content_type)
|
349
|
-
if not data.nil? and content_type == MIME_JSON
|
350
|
-
data = data.to_json
|
351
|
-
end
|
352
|
-
|
353
|
-
headers = {
|
354
|
-
'x-product-id' => PRODUCT_ID,
|
355
|
-
'x-tracking-id' => "platform:"+RUBY_VERSION.split('.')[0]+"|"+RUBY_VERSION+",type:SDK"+MERCADO_PAGO_VERSION+",so;",
|
356
|
-
'User-Agent' => "MercadoPago Ruby SDK v" + MERCADO_PAGO_VERSION,
|
357
|
-
'Content-type' => content_type,
|
358
|
-
'Accept' => MIME_JSON
|
359
|
-
}
|
360
|
-
|
361
|
-
headers['x-platform-id'] = @platform_id if @platform_id != nil
|
362
|
-
headers['x-integrator-id'] = @integrator_id if @integrator_id != nil
|
363
|
-
headers['x-corporation-id'] = @corporation_id if @corporation_id != nil
|
364
|
-
|
365
|
-
api_result = @http.send_request(method, uri, data, headers)
|
366
|
-
|
367
|
-
{
|
368
|
-
"status" => api_result.code,
|
369
|
-
"response" => JSON.parse(api_result.body)
|
370
|
-
}
|
371
|
-
end
|
372
|
-
|
373
|
-
def get(uri, content_type=MIME_JSON)
|
374
|
-
exec("GET", uri, nil, content_type)
|
375
|
-
end
|
376
|
-
|
377
|
-
def post(uri, data = nil, content_type=MIME_JSON)
|
378
|
-
exec("POST", uri, data, content_type)
|
379
|
-
end
|
380
|
-
|
381
|
-
def put(uri, data = nil, content_type=MIME_JSON)
|
382
|
-
exec("PUT", uri, data, content_type)
|
383
|
-
end
|
384
|
-
|
385
|
-
def delete(uri, content_type=MIME_JSON)
|
386
|
-
exec("DELETE", uri, nil, content_type)
|
387
|
-
end
|
388
|
-
end
|
389
|
-
end
|
1
|
+
# typed: strict
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require_relative './mercadopago/http/http_client'
|
5
|
+
|
6
|
+
require_relative './mercadopago/core/mp_base'
|
7
|
+
|
8
|
+
require_relative './mercadopago/config/config'
|
9
|
+
require_relative './mercadopago/config/request_options'
|
10
|
+
|
11
|
+
require_relative './mercadopago/resources/customer'
|
12
|
+
require_relative './mercadopago/resources/card'
|
13
|
+
require_relative './mercadopago/resources/user'
|
14
|
+
require_relative './mercadopago/resources/identification_type'
|
15
|
+
require_relative './mercadopago/resources/preference'
|
16
|
+
require_relative './mercadopago/resources/payment'
|
17
|
+
require_relative './mercadopago/resources/card_token'
|
18
|
+
require_relative './mercadopago/resources/refund'
|
19
|
+
require_relative './mercadopago/resources/merchant_order'
|
20
|
+
require_relative './mercadopago/resources/payment_methods'
|
21
|
+
require_relative './mercadopago/resources/advanced_payment'
|
22
|
+
require_relative './mercadopago/resources/disbursement_refund'
|
23
|
+
|
24
|
+
require_relative './mercadopago/sdk'
|
data/mercadopago.gemspec
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
#
|
2
|
-
require File.dirname(__FILE__) + '/lib/version'
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
3
|
Gem::Specification.new do |gem|
|
5
|
-
gem.name
|
6
|
-
gem.version
|
7
|
-
gem.
|
8
|
-
gem.
|
9
|
-
gem.description
|
10
|
-
gem.summary
|
11
|
-
gem.homepage
|
4
|
+
gem.name = 'mercadopago-sdk'
|
5
|
+
gem.version = '2.0.3'
|
6
|
+
gem.required_ruby_version = '>= 2.3.0'
|
7
|
+
gem.author = 'Mercado Pago'
|
8
|
+
gem.description = 'Mercado Pago Ruby SDK'
|
9
|
+
gem.summary = 'Mercado Pago Ruby SDK'
|
10
|
+
gem.homepage = 'http://github.com/mercadopago/sdk-ruby'
|
11
|
+
gem.license = 'MIT'
|
12
12
|
|
13
|
-
gem.files = `git ls-files`.split(
|
13
|
+
gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
14
14
|
gem.test_files = gem.files.grep(%r{^(tests)/})
|
15
|
-
gem.require_paths =
|
15
|
+
gem.require_paths = ['lib']
|
16
16
|
|
17
|
-
gem.add_dependency 'json'
|
18
|
-
|
19
|
-
gem.add_development_dependency 'pry'
|
20
|
-
gem.add_development_dependency 'rake'
|
17
|
+
gem.add_dependency 'json', '~>2.5'
|
18
|
+
gem.add_dependency 'rest-client', '~>2.1'
|
19
|
+
gem.add_development_dependency 'pry', '~>0.14'
|
20
|
+
gem.add_development_dependency 'rake', '~>13.0'
|
21
21
|
end
|
data/tests/test_card.rb
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
# typed: true
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require_relative '../lib/mercadopago'
|
5
|
+
|
6
|
+
require 'minitest/autorun'
|
7
|
+
|
8
|
+
class TestCard < Minitest::Test
|
9
|
+
def test_all
|
10
|
+
sdk = Mercadopago::SDK.new('TEST-783169576377080-082620-395ee7f82e0d55b1db606c118686c1db-464842924')
|
11
|
+
|
12
|
+
customer_object = {
|
13
|
+
email: 'test_payer_999944@testuser.com',
|
14
|
+
first_name: 'Rafa',
|
15
|
+
last_name: 'Williner',
|
16
|
+
phone: {
|
17
|
+
area_code: '03492',
|
18
|
+
number: '432334'
|
19
|
+
},
|
20
|
+
identification: {
|
21
|
+
type: 'DNI',
|
22
|
+
number: '29804555'
|
23
|
+
},
|
24
|
+
address: {
|
25
|
+
street_name: 'some street'
|
26
|
+
},
|
27
|
+
description: 'customer description'
|
28
|
+
}
|
29
|
+
|
30
|
+
customer_saved = sdk.customer.create(customer_object)
|
31
|
+
assert_equal 201, customer_saved[:status]
|
32
|
+
customer_id = customer_saved[:response]['id']
|
33
|
+
sleep(1)
|
34
|
+
|
35
|
+
card_token_object = {
|
36
|
+
card_number: '5031433215406351',
|
37
|
+
expiration_year: 2025,
|
38
|
+
expiration_month: 11,
|
39
|
+
security_code: '123',
|
40
|
+
cardholder: {
|
41
|
+
name: 'APRO'
|
42
|
+
}
|
43
|
+
}
|
44
|
+
|
45
|
+
begin
|
46
|
+
card_token = sdk.card_token.create(card_token_object)
|
47
|
+
|
48
|
+
card_object = {
|
49
|
+
token: card_token[:response]['id']
|
50
|
+
}
|
51
|
+
|
52
|
+
card_saved = sdk.card.create(customer_id, card_object)
|
53
|
+
assert !card_saved.nil?
|
54
|
+
assert !card_saved[:response].nil?
|
55
|
+
assert !card_saved[:response]['id'].nil?
|
56
|
+
sleep(1)
|
57
|
+
|
58
|
+
cards = sdk.card.list(customer_id)
|
59
|
+
assert !cards.nil?
|
60
|
+
assert !cards[:response].nil?
|
61
|
+
assert !cards[:response].empty?
|
62
|
+
sleep(1)
|
63
|
+
|
64
|
+
card_get = sdk.card.get(customer_id, card_saved[:response]['id'])
|
65
|
+
assert_equal 200, card_get[:status]
|
66
|
+
sleep(1)
|
67
|
+
|
68
|
+
card_deleted = sdk.card.delete(customer_id, card_saved[:response]['id'])
|
69
|
+
assert_equal 200, card_deleted[:status]
|
70
|
+
sleep(1)
|
71
|
+
ensure
|
72
|
+
if customer_saved.key?(:response) && customer_saved[:response].key?('id')
|
73
|
+
customer_deleted = sdk.customer.delete(customer_saved[:response]['id'])
|
74
|
+
assert_equal 200, customer_deleted[:status]
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# typed: true
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require_relative '../lib/mercadopago'
|
5
|
+
|
6
|
+
require 'minitest/autorun'
|
7
|
+
|
8
|
+
class CardToken < Minitest::Test
|
9
|
+
def test_method_get_id
|
10
|
+
sdk = Mercadopago::SDK.new('APP_USR-558881221729581-091712-44fdc612e60e3e638775d8b4003edd51-471763966')
|
11
|
+
card_token_object = {
|
12
|
+
card_number: '5031433215406351',
|
13
|
+
expiration_year: 2025,
|
14
|
+
expiration_month: 11,
|
15
|
+
security_code: '123',
|
16
|
+
cardholder: {
|
17
|
+
name: 'APRO'
|
18
|
+
}
|
19
|
+
}
|
20
|
+
result_card_token = sdk.card_token.create(card_token_object)
|
21
|
+
result = sdk.card_token.get(result_card_token[:response]['id'])
|
22
|
+
assert_equal 200, result[:status]
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_method_post
|
26
|
+
sdk = Mercadopago::SDK.new('APP_USR-558881221729581-091712-44fdc612e60e3e638775d8b4003edd51-471763966')
|
27
|
+
card_token_object = {
|
28
|
+
card_number: '5031433215406351',
|
29
|
+
expiration_year: 2025,
|
30
|
+
expiration_month: 11,
|
31
|
+
security_code: '123',
|
32
|
+
cardholder: {
|
33
|
+
name: 'APRO'
|
34
|
+
}
|
35
|
+
}
|
36
|
+
result = sdk.card_token.create(card_token_object)
|
37
|
+
assert_equal 201, result[:status]
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# typed: true
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require_relative '../lib/mercadopago'
|
5
|
+
|
6
|
+
require 'minitest/autorun'
|
7
|
+
|
8
|
+
class TestCustomer < Minitest::Test
|
9
|
+
def test_all
|
10
|
+
sdk = Mercadopago::SDK.new('TEST-783169576377080-082620-395ee7f82e0d55b1db606c118686c1db-464842924')
|
11
|
+
|
12
|
+
customer_object = {
|
13
|
+
email: 'test_payer_999922@testuser.com',
|
14
|
+
first_name: 'Rafa',
|
15
|
+
last_name: 'Williner',
|
16
|
+
phone: {
|
17
|
+
area_code: '03492',
|
18
|
+
number: '432334'
|
19
|
+
},
|
20
|
+
identification: {
|
21
|
+
type: 'DNI',
|
22
|
+
number: '29804555'
|
23
|
+
},
|
24
|
+
address: {
|
25
|
+
zip_code: '2300',
|
26
|
+
street_name: 'some street'
|
27
|
+
},
|
28
|
+
description: 'customer description'
|
29
|
+
}
|
30
|
+
|
31
|
+
begin
|
32
|
+
customer_saved = sdk.customer.create(customer_object)
|
33
|
+
assert_equal 201, customer_saved[:status]
|
34
|
+
sleep(1)
|
35
|
+
|
36
|
+
customers = sdk.customer.search(filters: { email: 'test_payer_999922@testuser.com' })
|
37
|
+
assert_equal 200, customers[:status]
|
38
|
+
sleep(1)
|
39
|
+
|
40
|
+
customer_update = sdk.customer.update(customer_saved[:response]['id'], { last_name: 'Payer' })
|
41
|
+
assert_equal 200, customer_update[:status]
|
42
|
+
sleep(1)
|
43
|
+
|
44
|
+
customer_updated = sdk.customer.get(customer_saved[:response]['id'])
|
45
|
+
assert_equal 'Payer', customer_updated[:response]['last_name']
|
46
|
+
sleep(1)
|
47
|
+
ensure
|
48
|
+
if customer_saved.key?(:response) && customer_saved[:response].key?('id')
|
49
|
+
customer_deleted = sdk.customer.delete(customer_saved[:response]['id'])
|
50
|
+
assert_equal 200, customer_deleted[:status]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# typed: true
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require_relative '../lib/mercadopago'
|
5
|
+
|
6
|
+
require 'minitest/autorun'
|
7
|
+
|
8
|
+
class TestIdentificationType < Minitest::Test
|
9
|
+
def test_method_get
|
10
|
+
sdk = Mercadopago::SDK.new('APP_USR-558881221729581-091712-44fdc612e60e3e638775d8b4003edd51-471763966')
|
11
|
+
sdk.request_options = Mercadopago::RequestOptions.new(corporation_id: 'abc')
|
12
|
+
result = sdk.identification_type.get
|
13
|
+
|
14
|
+
assert_equal 200, result[:status]
|
15
|
+
end
|
16
|
+
end
|