mercadopago-sdk 0.3.6 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (127) hide show
  1. checksums.yaml +5 -5
  2. data/.editorconfig +10 -0
  3. data/.github/ISSUE_TEMPLATE/bug_report.md +28 -0
  4. data/.github/ISSUE_TEMPLATE/feature_request.md +19 -0
  5. data/.github/workflows/ruby.yml +35 -0
  6. data/.gitignore +2 -1
  7. data/.rubocop.yml +1 -0
  8. data/.rubocop_todo.yml +104 -0
  9. data/.ruby-version +1 -0
  10. data/CODE_OF_CONDUCT.md +74 -0
  11. data/CODING_GUIDELINES.md +70 -0
  12. data/CONTRIBUTING.md +57 -0
  13. data/Gemfile +8 -0
  14. data/Gemfile.lock +51 -12
  15. data/LICENSE.txt +21 -0
  16. data/README.md +54 -143
  17. data/Rakefile +3 -1
  18. data/docs/CODE_OF_CONDUCT_md.html +154 -0
  19. data/docs/CODING_GUIDELINES_md.html +188 -0
  20. data/docs/CONTRIBUTING_md.html +165 -0
  21. data/docs/LICENSE_txt.html +96 -0
  22. data/docs/Mercadopago.html +123 -0
  23. data/docs/Mercadopago/AdvancedPayment.html +279 -0
  24. data/docs/Mercadopago/Card.html +204 -0
  25. data/docs/Mercadopago/CardToken.html +160 -0
  26. data/docs/Mercadopago/Config.html +266 -0
  27. data/docs/Mercadopago/Customer.html +228 -0
  28. data/docs/Mercadopago/DisbursementRefund.html +183 -0
  29. data/docs/Mercadopago/HttpClient.html +249 -0
  30. data/docs/Mercadopago/IdentificationType.html +136 -0
  31. data/docs/Mercadopago/MPBase.html +316 -0
  32. data/docs/Mercadopago/MerchantOrder.html +209 -0
  33. data/docs/Mercadopago/Payment.html +208 -0
  34. data/docs/Mercadopago/PaymentMethods.html +136 -0
  35. data/docs/Mercadopago/Preference.html +184 -0
  36. data/docs/Mercadopago/Refund.html +160 -0
  37. data/docs/Mercadopago/RequestOptions.html +433 -0
  38. data/docs/Mercadopago/SDK.html +528 -0
  39. data/docs/Mercadopago/User.html +136 -0
  40. data/docs/README_md.html +181 -0
  41. data/docs/created.rid +25 -0
  42. data/docs/css/fonts.css +167 -0
  43. data/docs/css/rdoc.css +619 -0
  44. data/docs/fonts/Lato-Light.ttf +0 -0
  45. data/docs/fonts/Lato-LightItalic.ttf +0 -0
  46. data/docs/fonts/Lato-Regular.ttf +0 -0
  47. data/docs/fonts/Lato-RegularItalic.ttf +0 -0
  48. data/docs/fonts/SourceCodePro-Bold.ttf +0 -0
  49. data/docs/fonts/SourceCodePro-Regular.ttf +0 -0
  50. data/docs/images/add.png +0 -0
  51. data/docs/images/arrow_up.png +0 -0
  52. data/docs/images/brick.png +0 -0
  53. data/docs/images/brick_link.png +0 -0
  54. data/docs/images/bug.png +0 -0
  55. data/docs/images/bullet_black.png +0 -0
  56. data/docs/images/bullet_toggle_minus.png +0 -0
  57. data/docs/images/bullet_toggle_plus.png +0 -0
  58. data/docs/images/date.png +0 -0
  59. data/docs/images/delete.png +0 -0
  60. data/docs/images/find.png +0 -0
  61. data/docs/images/loadingAnimation.gif +0 -0
  62. data/docs/images/macFFBgHack.png +0 -0
  63. data/docs/images/package.png +0 -0
  64. data/docs/images/page_green.png +0 -0
  65. data/docs/images/page_white_text.png +0 -0
  66. data/docs/images/page_white_width.png +0 -0
  67. data/docs/images/plugin.png +0 -0
  68. data/docs/images/ruby.png +0 -0
  69. data/docs/images/tag_blue.png +0 -0
  70. data/docs/images/tag_green.png +0 -0
  71. data/docs/images/transparent.png +0 -0
  72. data/docs/images/wrench.png +0 -0
  73. data/docs/images/wrench_orange.png +0 -0
  74. data/docs/images/zoom.png +0 -0
  75. data/docs/index.html +109 -0
  76. data/docs/js/darkfish.js +84 -0
  77. data/docs/js/navigation.js +105 -0
  78. data/docs/js/navigation.js.gz +0 -0
  79. data/docs/js/search.js +110 -0
  80. data/docs/js/search_index.js +1 -0
  81. data/docs/js/search_index.js.gz +0 -0
  82. data/docs/js/searcher.js +229 -0
  83. data/docs/js/searcher.js.gz +0 -0
  84. data/docs/table_of_contents.html +562 -0
  85. data/lib/mercadopago.rb +24 -349
  86. data/lib/mercadopago/config/config.rb +42 -0
  87. data/lib/mercadopago/config/request_options.rb +85 -0
  88. data/lib/mercadopago/core/mp_base.rb +77 -0
  89. data/lib/mercadopago/http/http_client.rb +74 -0
  90. data/lib/mercadopago/resources/advanced_payment.rb +48 -0
  91. data/lib/mercadopago/resources/card.rb +31 -0
  92. data/lib/mercadopago/resources/card_token.rb +19 -0
  93. data/lib/mercadopago/resources/customer.rb +36 -0
  94. data/lib/mercadopago/resources/disbursement_refund.rb +24 -0
  95. data/lib/mercadopago/resources/identification_type.rb +13 -0
  96. data/lib/mercadopago/resources/merchant_order.rb +32 -0
  97. data/lib/mercadopago/resources/payment.rb +35 -0
  98. data/lib/mercadopago/resources/payment_methods.rb +13 -0
  99. data/lib/mercadopago/resources/preference.rb +26 -0
  100. data/lib/mercadopago/resources/refund.rb +24 -0
  101. data/lib/mercadopago/resources/user.rb +13 -0
  102. data/lib/mercadopago/sdk.rb +85 -0
  103. data/mercadopago.gemspec +15 -15
  104. data/tests/test_card.rb +79 -0
  105. data/tests/test_card_token.rb +39 -0
  106. data/tests/test_customer.rb +54 -0
  107. data/tests/test_identification_type.rb +16 -0
  108. data/tests/test_merchant_order.rb +94 -0
  109. data/tests/test_payment.rb +102 -0
  110. data/tests/test_payment_methods.rb +14 -0
  111. data/tests/test_preference.rb +49 -0
  112. data/tests/test_refund.rb +88 -0
  113. data/tests/test_user.rb +17 -0
  114. data/tests/tests.rb +12 -56
  115. metadata +154 -37
  116. data/examples/checkout-buttons/basic_preference/button.rb +0 -28
  117. data/examples/instant-payment-notifications/receive-ipn.rb +0 -25
  118. data/examples/payment-search/search-approved-payments.rb +0 -23
  119. data/examples/payment-search/search-creditcard-payments.rb +0 -23
  120. data/examples/payment-search/search-funded-payments-by-name.rb +0 -23
  121. data/examples/payment-search/search-payments-from-email-and-date.rb +0 -23
  122. data/examples/payment-search/search-payments.rb +0 -23
  123. data/examples/preapproval-payments/button.rb +0 -42
  124. data/lib/ssl_options_patch.rb +0 -15
  125. data/lib/version.rb +0 -1
  126. data/mercadopago-sdk-0.3.2.gem +0 -0
  127. data/mercadopago-sdk-0.3.3.gem +0 -0
data/lib/mercadopago.rb CHANGED
@@ -1,349 +1,24 @@
1
- #MercadoPago Integration Library
2
- #Access MercadoPago for payments integration
3
- #
4
- #@author @maticompiano
5
- #@contributors @chrismo
6
-
7
- require 'rubygems'
8
- require 'json'
9
- require 'uri'
10
- require 'net/https'
11
- require 'yaml'
12
- require File.dirname(__FILE__) + '/version'
13
- require 'ssl_options_patch'
14
-
15
- class MercadoPago
16
- def initialize(*args)
17
- if args.size < 1 or args.size > 2
18
- raise "Invalid arguments. Use CLIENT_ID and CLIENT SECRET, or ACCESS_TOKEN"
19
- end
20
-
21
- @client_id = args.at(0) if args.size == 2
22
- @client_secret = args.at(1) if args.size == 2
23
- @ll_access_token = args.at(0) if args.size == 1
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 sandbox_mode(enable=nil)
34
- if not enable.nil?
35
- @sandbox = enable
36
- end
37
-
38
- return @sandbox
39
- end
40
-
41
- # Get Access Token for API use
42
- def get_access_token
43
- if @ll_access_token
44
- @ll_access_token
45
- else
46
- app_client_values = {
47
- 'grant_type' => 'client_credentials',
48
- 'client_id' => @client_id,
49
- 'client_secret' => @client_secret
50
- }
51
-
52
- @access_data = @rest_client.post("/oauth/token", build_query(app_client_values), RestClient::MIME_FORM)
53
-
54
- if @access_data['status'] == "200"
55
- @access_data = @access_data["response"]
56
- @access_data['access_token']
57
- else
58
- raise @access_data.inspect
59
- end
60
- end
61
- end
62
-
63
- # Get information for specific payment
64
- def get_payment(id)
65
- begin
66
- access_token = get_access_token
67
- rescue => e
68
- return e.message
69
- end
70
-
71
- uri_prefix = @sandbox ? "/sandbox" : ""
72
- @rest_client.get("/v1/payments/" + id + "?access_token=" + access_token)
73
- end
74
-
75
- def get_payment_info(id)
76
- get_payment(id)
77
- end
78
-
79
- # Get information for specific authorized payment
80
- def get_authorized_payment(id)
81
- begin
82
- access_token = get_access_token
83
- rescue => e
84
- return e.message
85
- end
86
-
87
- @rest_client.get("/authorized_payments/" + id + "?access_token=" + access_token)
88
- end
89
-
90
- # Refund accredited payment
91
- def refund_payment(id)
92
- begin
93
- access_token = get_access_token
94
- rescue => e
95
- return e.message
96
- end
97
-
98
- refund_status = {}
99
- @rest_client.post("/v1/payments/" + id + "/refunds?access_token=" + access_token, refund_status)
100
- end
101
-
102
- # Cancel pending payment
103
- def cancel_payment(id)
104
- begin
105
- access_token = get_access_token
106
- rescue => e
107
- return e.message
108
- end
109
-
110
- cancel_status = {"status" => "cancelled"}
111
- @rest_client.put("/v1/payments/" + id + "?access_token=" + access_token, cancel_status)
112
- end
113
-
114
- # Cancel preapproval payment
115
- def cancel_preapproval_payment(id)
116
- begin
117
- access_token = get_access_token
118
- rescue => e
119
- return e.message
120
- end
121
-
122
- cancel_status = {"status" => "cancelled"}
123
- @rest_client.put("/preapproval/" + id + "?access_token=" + access_token, cancel_status)
124
- end
125
-
126
- # Search payments according to filters, with pagination
127
- def search_payment(filters, offset=0, limit=0)
128
- begin
129
- access_token = get_access_token
130
- rescue => e
131
- return e.message
132
- end
133
-
134
- filters["offset"] = offset
135
- filters["limit"] = limit
136
-
137
- filters = build_query(filters)
138
-
139
- uri_prefix = @sandbox ? "/sandbox" : ""
140
- @rest_client.get("/v1/payments/search?" + filters + "&access_token=" + access_token)
141
- end
142
-
143
- # Create a checkout preference
144
- def create_preference(preference)
145
- begin
146
- access_token = get_access_token
147
- rescue => e
148
- return e.message
149
- end
150
-
151
- @rest_client.post("/checkout/preferences?access_token=" + access_token, preference)
152
- end
153
-
154
- # Update a checkout preference
155
- def update_preference(id, preference)
156
- begin
157
- access_token = get_access_token
158
- rescue => e
159
- return e.message
160
- end
161
-
162
- @rest_client.put("/checkout/preferences/" + id + "?access_token=" + access_token, preference)
163
- end
164
-
165
- # Get a checkout preference
166
- def get_preference(id)
167
- begin
168
- access_token = get_access_token
169
- rescue => e
170
- return e.message
171
- end
172
-
173
- @rest_client.get("/checkout/preferences/" + id + "?access_token=" + access_token)
174
- end
175
-
176
- # Create a preapproval payment
177
- def create_preapproval_payment(preapproval_payment)
178
- begin
179
- access_token = get_access_token
180
- rescue => e
181
- return e.message
182
- end
183
-
184
- @rest_client.post("/preapproval?access_token=" + access_token, preapproval_payment)
185
- end
186
-
187
- # Get a preapproval payment
188
- def get_preapproval_payment(id)
189
- begin
190
- access_token = get_access_token
191
- rescue => e
192
- return e.message
193
- end
194
-
195
- @rest_client.get("/preapproval/" + id + "?access_token=" + access_token)
196
- end
197
-
198
- # Generic resource get
199
- def get(uri, params = nil, authenticate = true)
200
- if not params.class == Hash
201
- params = Hash.new
202
- end
203
-
204
- if authenticate
205
- begin
206
- access_token = get_access_token
207
- rescue => e
208
- return e.message
209
- end
210
-
211
- params["access_token"] = access_token
212
- end
213
-
214
- if not params.empty?
215
- uri << (if uri.include? "?" then "&" else "?" end) << build_query(params)
216
- end
217
-
218
- @rest_client.get(uri)
219
- end
220
-
221
- # Generic resource post
222
- def post(uri, data, params = nil)
223
- if not params.class == Hash
224
- params = Hash.new
225
- end
226
-
227
- begin
228
- access_token = get_access_token
229
- rescue => e
230
- return e.message
231
- end
232
-
233
- params["access_token"] = access_token
234
-
235
- if not params.empty?
236
- uri << (if uri.include? "?" then "&" else "?" end) << build_query(params)
237
- end
238
-
239
- @rest_client.post(uri, data)
240
- end
241
-
242
- # Generic resource put
243
- def put(uri, data, params = nil)
244
- if not params.class == Hash
245
- params = Hash.new
246
- end
247
-
248
- begin
249
- access_token = get_access_token
250
- rescue => e
251
- return e.message
252
- end
253
-
254
- params["access_token"] = access_token
255
-
256
- if not params.empty?
257
- uri << (if uri.include? "?" then "&" else "?" end) << build_query(params)
258
- end
259
-
260
- @rest_client.put(uri, data)
261
- end
262
-
263
- # Generic resource delete
264
- def delete(uri, params = nil)
265
- if not params.class == Hash
266
- params = Hash.new
267
- end
268
-
269
- begin
270
- access_token = get_access_token
271
- rescue => e
272
- return e.message
273
- end
274
-
275
- params["access_token"] = access_token
276
-
277
- if not params.empty?
278
- uri << (if uri.include? "?" then "&" else "?" end) << build_query(params)
279
- end
280
-
281
- @rest_client.delete(uri)
282
- end
283
-
284
- def build_query(params)
285
- URI.escape(params.collect { |k, v| "#{k}=#{v}" }.join('&'))
286
- end
287
-
288
- private
289
-
290
- class RestClient
291
-
292
- MIME_JSON = 'application/json'
293
- MIME_FORM = 'application/x-www-form-urlencoded'
294
- API_BASE_URL = URI.parse('https://api.mercadopago.com')
295
-
296
- def initialize(debug_logger=nil)
297
- @http = Net::HTTP.new(API_BASE_URL.host, API_BASE_URL.port)
298
-
299
- if API_BASE_URL.scheme == "https" # enable SSL/TLS
300
- @http.use_ssl = true
301
- @http.verify_mode = OpenSSL::SSL::VERIFY_PEER
302
-
303
- # explicitly tell OpenSSL not to use SSL3 nor TLS 1.0
304
- @http.ssl_options = OpenSSL::SSL::OP_NO_SSLv3 + OpenSSL::SSL::OP_NO_TLSv1
305
- end
306
-
307
- @http.set_debug_output debug_logger if debug_logger
308
- end
309
-
310
- def set_debug_logger(debug_logger)
311
- @http.set_debug_output debug_logger
312
- end
313
-
314
- def exec(method, uri, data, content_type)
315
- if not data.nil? and content_type == MIME_JSON
316
- data = data.to_json
317
- end
318
-
319
- headers = {
320
- 'User-Agent' => "MercadoPago Ruby SDK v" + MERCADO_PAGO_VERSION,
321
- 'Content-type' => content_type,
322
- 'Accept' => MIME_JSON
323
- }
324
-
325
- api_result = @http.send_request(method, uri, data, headers)
326
-
327
- {
328
- "status" => api_result.code,
329
- "response" => JSON.parse(api_result.body)
330
- }
331
- end
332
-
333
- def get(uri, content_type=MIME_JSON)
334
- exec("GET", uri, nil, content_type)
335
- end
336
-
337
- def post(uri, data = nil, content_type=MIME_JSON)
338
- exec("POST", uri, data, content_type)
339
- end
340
-
341
- def put(uri, data = nil, content_type=MIME_JSON)
342
- exec("PUT", uri, data, content_type)
343
- end
344
-
345
- def delete(uri, content_type=MIME_JSON)
346
- exec("DELETE", uri, nil, content_type)
347
- end
348
- end
349
- 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'
@@ -0,0 +1,42 @@
1
+ # typed: true
2
+ # frozen_string_literal: true
3
+
4
+ module Mercadopago
5
+ class Config
6
+ @@VERSION = '2.0.2'
7
+ @@USER_AGENT = "MercadoPago Ruby SDK v#{@@VERSION}"
8
+ @@PRODUCT_ID = 'bc32a7vtrpp001u8nhjg'
9
+ @@TRACKING_ID = "plataform: ?,type:SDK#{@@VERSION},so;"
10
+ @@API_BASE_URL = 'https://api.mercadopago.com'
11
+ @@MIME_JSON = 'application/json'
12
+ @@MIME_FORM = 'application/x-www-form-urlencoded'
13
+
14
+ def version
15
+ @@VERSION
16
+ end
17
+
18
+ def user_agent
19
+ @@USER_AGENT
20
+ end
21
+
22
+ def product_id
23
+ @@PRODUCT_ID
24
+ end
25
+
26
+ def tracking_id
27
+ @@TRACKING_ID
28
+ end
29
+
30
+ def api_base_url
31
+ @@API_BASE_URL
32
+ end
33
+
34
+ def mime_json
35
+ @@MIME_JSON
36
+ end
37
+
38
+ def mime_form
39
+ @@MIME_FORM
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,85 @@
1
+ # typed: true
2
+ # frozen_string_literal: true
3
+
4
+ module Mercadopago
5
+ class RequestOptions
6
+ attr_reader :access_token, :connection_timeout, :custom_headers, :corporation_id, :integrator_id,
7
+ :platform_id, :max_retries
8
+
9
+ def initialize(access_token: nil,
10
+ connection_timeout: 60.0,
11
+ custom_headers: nil,
12
+ corporation_id: nil,
13
+ integrator_id: nil,
14
+ platform_id: nil,
15
+ max_retries: 3)
16
+ self.access_token = access_token
17
+ self.connection_timeout = connection_timeout
18
+ self.custom_headers = custom_headers
19
+ self.corporation_id = corporation_id
20
+ self.integrator_id = integrator_id
21
+ self.platform_id = platform_id
22
+ self.max_retries = max_retries
23
+
24
+ @config = Config.new
25
+ end
26
+
27
+ def get_headers
28
+ headers = { 'Authorization': "Bearer #{@access_token}",
29
+ 'x-product-id' => @config.product_id,
30
+ 'x-tracking-id' => @config.tracking_id,
31
+ 'User-Agent' => @config.user_agent,
32
+ 'Accept': @config.mime_json }
33
+
34
+ headers['x-corporation-id'] = @corporation_id unless @corporation_id.nil?
35
+ headers['x-integrator-id'] = @integrator_id unless @integrator_id.nil?
36
+ headers['x-platform-id'] = @platform_id unless @platform_id.nil?
37
+
38
+ headers.merge(@custom_headers) unless @custom_headers.nil?
39
+
40
+ headers
41
+ end
42
+
43
+ def access_token=(value)
44
+ raise TypeError, 'Param access_token must be a String' unless access_token.nil? || value.is_a?(String)
45
+
46
+ @access_token = value
47
+ end
48
+
49
+ def custom_headers=(value)
50
+ raise TypeError, 'Param custom_headers must be a Hash' unless value.nil? || value.is_a?(Hash)
51
+
52
+ @custom_headers = value
53
+ end
54
+
55
+ def connection_timeout=(value)
56
+ raise TypeError, 'Param connection_timeout must be a Float' unless value.is_a?(Float)
57
+
58
+ @connection_timeout = value
59
+ end
60
+
61
+ def corporation_id=(value)
62
+ raise TypeError, 'Param corporation_id must be a String' unless value.nil? || value.is_a?(String)
63
+
64
+ @corporation_id = value
65
+ end
66
+
67
+ def integrator_id=(value)
68
+ raise TypeError, 'Param integrator_id must be a String' unless value.nil? || value.is_a?(String)
69
+
70
+ @integrator_id = value
71
+ end
72
+
73
+ def platform_id=(value)
74
+ raise TypeError, 'Param platform_id must be a String' unless value.nil? || value.is_a?(String)
75
+
76
+ @platform_id = value
77
+ end
78
+
79
+ def max_retries=(value)
80
+ raise TypeError, 'Param max_retries must be a Integer' unless value.is_a?(Integer)
81
+
82
+ @max_retries = value
83
+ end
84
+ end
85
+ end