mercadopago-sdk 1.3.0 → 2.0.1
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 +6 -1
- data/Gemfile.lock +45 -17
- data/LICENSE.txt +21 -0
- data/README.md +51 -27
- 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.html +123 -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/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.rb +24 -295
- 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/mercadopago.gemspec +11 -11
- data/tests/test_card.rb +79 -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_user.rb +17 -0
- data/tests/tests.rb +12 -56
- metadata +127 -24
- 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,295 +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
|
-
@rest_client.set_access_token(get_access_token)
|
27
|
-
@sandbox = false
|
28
|
-
end
|
29
|
-
|
30
|
-
def set_debug_logger(debug_logger)
|
31
|
-
@rest_client.set_debug_logger(debug_logger)
|
32
|
-
end
|
33
|
-
|
34
|
-
def set_platform_id(platform_id)
|
35
|
-
@rest_client.set_platform_id(platform_id)
|
36
|
-
end
|
37
|
-
|
38
|
-
def set_integrator_id(integrator_id)
|
39
|
-
@rest_client.set_integrator_id(integrator_id)
|
40
|
-
end
|
41
|
-
|
42
|
-
def set_corporation_id(corporation_id)
|
43
|
-
@rest_client.set_corporation_id(corporation_id)
|
44
|
-
end
|
45
|
-
|
46
|
-
def sandbox_mode(enable=nil)
|
47
|
-
if not enable.nil?
|
48
|
-
@sandbox = enable
|
49
|
-
end
|
50
|
-
|
51
|
-
return @sandbox
|
52
|
-
end
|
53
|
-
|
54
|
-
# Get Access Token for API use
|
55
|
-
def get_access_token
|
56
|
-
if @ll_access_token
|
57
|
-
@ll_access_token
|
58
|
-
else
|
59
|
-
app_client_values = {
|
60
|
-
'grant_type' => 'client_credentials',
|
61
|
-
'client_id' => @client_id,
|
62
|
-
'client_secret' => @client_secret
|
63
|
-
}
|
64
|
-
|
65
|
-
@access_data = @rest_client.post("/oauth/token", build_query(app_client_values), RestClient::MIME_FORM)
|
66
|
-
|
67
|
-
if @access_data['status'] == "200"
|
68
|
-
@access_data = @access_data["response"]
|
69
|
-
@access_data['access_token']
|
70
|
-
else
|
71
|
-
raise @access_data.inspect
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
# Get information for specific payment
|
77
|
-
def get_payment(id)
|
78
|
-
uri_prefix = @sandbox ? "/sandbox" : ""
|
79
|
-
|
80
|
-
@rest_client.get(uri_prefix + "/v1/payments/" + id)
|
81
|
-
|
82
|
-
end
|
83
|
-
|
84
|
-
def get_payment_info(id)
|
85
|
-
get_payment(id)
|
86
|
-
end
|
87
|
-
|
88
|
-
# Get information for specific authorized payment
|
89
|
-
def get_authorized_payment(id)
|
90
|
-
@rest_client.get("/authorized_payments/" + id)
|
91
|
-
end
|
92
|
-
|
93
|
-
# Refund accredited payment
|
94
|
-
def refund_payment(id)
|
95
|
-
refund_status = {}
|
96
|
-
@rest_client.post("/v1/payments/" + id, refund_status)
|
97
|
-
|
98
|
-
end
|
99
|
-
|
100
|
-
# Cancel pending payment
|
101
|
-
def cancel_payment(id)
|
102
|
-
cancel_status = {"status" => "cancelled"}
|
103
|
-
@rest_client.put("/v1/payments/" + id, cancel_status)
|
104
|
-
end
|
105
|
-
|
106
|
-
# Cancel preapproval payment
|
107
|
-
def cancel_preapproval_payment(id)
|
108
|
-
cancel_status = {"status" => "cancelled"}
|
109
|
-
@rest_client.put("/preapproval/" + id, cancel_status)
|
110
|
-
end
|
111
|
-
|
112
|
-
# Search payments according to filters, with pagination
|
113
|
-
def search_payment(filters, offset=0, limit=0)
|
114
|
-
filters["offset"] = offset
|
115
|
-
filters["limit"] = limit
|
116
|
-
|
117
|
-
filters = build_query(filters)
|
118
|
-
|
119
|
-
uri_prefix = @sandbox ? "/sandbox" : ""
|
120
|
-
|
121
|
-
@rest_client.get(uri_prefix + "/v1/payments/search?" + filters)
|
122
|
-
|
123
|
-
end
|
124
|
-
|
125
|
-
# Create a checkout preference
|
126
|
-
def create_preference(preference)
|
127
|
-
@rest_client.post("/checkout/preferences", preference)
|
128
|
-
end
|
129
|
-
|
130
|
-
# Update a checkout preference
|
131
|
-
def update_preference(id, preference)
|
132
|
-
@rest_client.put("/checkout/preferences/" + id, preference)
|
133
|
-
end
|
134
|
-
|
135
|
-
# Get a checkout preference
|
136
|
-
def get_preference(id)
|
137
|
-
@rest_client.get("/checkout/preferences/" + id)
|
138
|
-
end
|
139
|
-
|
140
|
-
# Create a preapproval payment
|
141
|
-
def create_preapproval_payment(preapproval_payment)
|
142
|
-
@rest_client.post("/preapproval", preapproval_payment)
|
143
|
-
end
|
144
|
-
|
145
|
-
# Get a preapproval payment
|
146
|
-
def get_preapproval_payment(id)
|
147
|
-
@rest_client.get("/preapproval/" + id)
|
148
|
-
end
|
149
|
-
|
150
|
-
# Generic resource get
|
151
|
-
def get(uri, params = nil, authenticate = true)
|
152
|
-
if not params.class == Hash
|
153
|
-
params = Hash.new
|
154
|
-
end
|
155
|
-
|
156
|
-
if not params.empty?
|
157
|
-
uri << (if uri.include? "?" then "&" else "?" end) << build_query(params)
|
158
|
-
end
|
159
|
-
|
160
|
-
@rest_client.get(uri)
|
161
|
-
end
|
162
|
-
|
163
|
-
# Generic resource post
|
164
|
-
def post(uri, data, params = nil)
|
165
|
-
if not params.class == Hash
|
166
|
-
params = Hash.new
|
167
|
-
end
|
168
|
-
|
169
|
-
if not params.empty?
|
170
|
-
uri << (if uri.include? "?" then "&" else "?" end) << build_query(params)
|
171
|
-
end
|
172
|
-
|
173
|
-
@rest_client.post(uri, data)
|
174
|
-
end
|
175
|
-
|
176
|
-
# Generic resource put
|
177
|
-
def put(uri, data, params = nil)
|
178
|
-
if not params.class == Hash
|
179
|
-
params = Hash.new
|
180
|
-
end
|
181
|
-
|
182
|
-
if not params.empty?
|
183
|
-
uri << (if uri.include? "?" then "&" else "?" end) << build_query(params)
|
184
|
-
end
|
185
|
-
|
186
|
-
@rest_client.put(uri, data)
|
187
|
-
end
|
188
|
-
|
189
|
-
# Generic resource delete
|
190
|
-
def delete(uri, params = nil)
|
191
|
-
if not params.class == Hash
|
192
|
-
params = Hash.new
|
193
|
-
end
|
194
|
-
|
195
|
-
if not params.empty?
|
196
|
-
uri << (if uri.include? "?" then "&" else "?" end) << build_query(params)
|
197
|
-
end
|
198
|
-
|
199
|
-
@rest_client.delete(uri)
|
200
|
-
end
|
201
|
-
|
202
|
-
def build_query(params)
|
203
|
-
URI.escape(params.collect { |k, v| "#{k}=#{v}" }.join('&'))
|
204
|
-
end
|
205
|
-
|
206
|
-
private
|
207
|
-
|
208
|
-
class RestClient
|
209
|
-
|
210
|
-
MIME_JSON = 'application/json'
|
211
|
-
MIME_FORM = 'application/x-www-form-urlencoded'
|
212
|
-
API_BASE_URL = URI.parse('https://api.mercadopago.com')
|
213
|
-
|
214
|
-
def initialize(debug_logger=nil)
|
215
|
-
@http = Net::HTTP.new(API_BASE_URL.host, API_BASE_URL.port)
|
216
|
-
|
217
|
-
if API_BASE_URL.scheme == "https" # enable SSL/TLS
|
218
|
-
@http.use_ssl = true
|
219
|
-
@http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
220
|
-
|
221
|
-
# explicitly tell OpenSSL not to use SSL3 nor TLS 1.0
|
222
|
-
@http.ssl_options = OpenSSL::SSL::OP_NO_SSLv3 + OpenSSL::SSL::OP_NO_TLSv1
|
223
|
-
end
|
224
|
-
|
225
|
-
@http.set_debug_output debug_logger if debug_logger
|
226
|
-
|
227
|
-
@platform_id = nil
|
228
|
-
@integrator_id = nil
|
229
|
-
@corporation_id = nil
|
230
|
-
@access_token = nil
|
231
|
-
end
|
232
|
-
|
233
|
-
def set_debug_logger(debug_logger)
|
234
|
-
@http.set_debug_output debug_logger
|
235
|
-
end
|
236
|
-
|
237
|
-
def set_platform_id(platform_id)
|
238
|
-
@platform_id = platform_id
|
239
|
-
end
|
240
|
-
|
241
|
-
def set_integrator_id(integrator_id)
|
242
|
-
@integrator_id = integrator_id
|
243
|
-
end
|
244
|
-
|
245
|
-
def set_corporation_id(corporation_id)
|
246
|
-
@corporation_id = corporation_id
|
247
|
-
end
|
248
|
-
|
249
|
-
def set_access_token(access_token)
|
250
|
-
@access_token = access_token
|
251
|
-
end
|
252
|
-
|
253
|
-
def exec(method, uri, data, content_type)
|
254
|
-
if not data.nil? and content_type == MIME_JSON
|
255
|
-
data = data.to_json
|
256
|
-
end
|
257
|
-
|
258
|
-
headers = {
|
259
|
-
'x-product-id' => PRODUCT_ID,
|
260
|
-
'x-tracking-id' => "platform:"+RUBY_VERSION.split('.')[0]+"|"+RUBY_VERSION+",type:SDK"+MERCADO_PAGO_VERSION+",so;",
|
261
|
-
'User-Agent' => "MercadoPago Ruby SDK v" + MERCADO_PAGO_VERSION,
|
262
|
-
'Content-type' => content_type,
|
263
|
-
'Accept' => MIME_JSON
|
264
|
-
}
|
265
|
-
|
266
|
-
headers['Authorization'] = "Bearer " + @access_token if @access_token != nil
|
267
|
-
headers['x-platform-id'] = @platform_id if @platform_id != nil
|
268
|
-
headers['x-integrator-id'] = @integrator_id if @integrator_id != nil
|
269
|
-
headers['x-corporation-id'] = @corporation_id if @corporation_id != nil
|
270
|
-
|
271
|
-
api_result = @http.send_request(method, uri, data, headers)
|
272
|
-
|
273
|
-
{
|
274
|
-
"status" => api_result.code,
|
275
|
-
"response" => JSON.parse(api_result.body)
|
276
|
-
}
|
277
|
-
end
|
278
|
-
|
279
|
-
def get(uri, content_type=MIME_JSON)
|
280
|
-
exec("GET", uri, nil, content_type)
|
281
|
-
end
|
282
|
-
|
283
|
-
def post(uri, data = nil, content_type=MIME_JSON)
|
284
|
-
exec("POST", uri, data, content_type)
|
285
|
-
end
|
286
|
-
|
287
|
-
def put(uri, data = nil, content_type=MIME_JSON)
|
288
|
-
exec("PUT", uri, data, content_type)
|
289
|
-
end
|
290
|
-
|
291
|
-
def delete(uri, content_type=MIME_JSON)
|
292
|
-
exec("DELETE", uri, nil, content_type)
|
293
|
-
end
|
294
|
-
end
|
295
|
-
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.1'
|
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
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# typed: false
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module Mercadopago
|
5
|
+
##
|
6
|
+
# Module Base
|
7
|
+
class MPBase
|
8
|
+
def initialize(request_options, http_client)
|
9
|
+
unless request_options.is_a?(RequestOptions)
|
10
|
+
raise TypeError,
|
11
|
+
'Param request_options must be a RequestOptions object'
|
12
|
+
end
|
13
|
+
|
14
|
+
@request_options = request_options
|
15
|
+
@http_client = http_client
|
16
|
+
@config = Config.new
|
17
|
+
end
|
18
|
+
|
19
|
+
def _check_request_options(request_options = nil)
|
20
|
+
request_options = @request_options if request_options.nil?
|
21
|
+
unless request_options.is_a?(RequestOptions)
|
22
|
+
raise TypeError,
|
23
|
+
'Param request_options must be a RequestOptions object'
|
24
|
+
end
|
25
|
+
|
26
|
+
request_options.access_token = @request_options.access_token if request_options.access_token.nil?
|
27
|
+
|
28
|
+
request_options
|
29
|
+
end
|
30
|
+
|
31
|
+
def _check_headers(request_options = nil, extra_headers = nil)
|
32
|
+
headers = request_options.nil? ? request_options.get_headers : @request_options.get_headers
|
33
|
+
|
34
|
+
headers.merge!(extra_headers) unless extra_headers.nil?
|
35
|
+
|
36
|
+
headers
|
37
|
+
end
|
38
|
+
|
39
|
+
def _get(uri:, filters: nil, request_options: nil)
|
40
|
+
raise TypeError, 'Filters must be a Hash' unless filters.nil? || filters.is_a?(Hash)
|
41
|
+
|
42
|
+
request_options = _check_request_options(request_options)
|
43
|
+
headers = _check_headers(request_options)
|
44
|
+
|
45
|
+
@http_client.get(url: @config.api_base_url + uri, headers: headers, params: filters,
|
46
|
+
timeout: request_options.connection_timeout, maxretries: request_options.max_retries)
|
47
|
+
end
|
48
|
+
|
49
|
+
def _post(uri:, data:, request_options: nil)
|
50
|
+
raise TypeError, 'Data must be a Hash' unless data.nil? || data.is_a?(Hash)
|
51
|
+
|
52
|
+
request_options = _check_request_options(request_options)
|
53
|
+
headers = _check_headers(request_options, { 'Content-Type': @config.mime_json })
|
54
|
+
|
55
|
+
@http_client.post(url: @config.api_base_url + uri, data: data.to_json, headers: headers,
|
56
|
+
timeout: request_options.connection_timeout)
|
57
|
+
end
|
58
|
+
|
59
|
+
def _put(uri:, data:, request_options: nil)
|
60
|
+
raise TypeError, 'Data must be a Hash' unless data.nil? || data.is_a?(Hash)
|
61
|
+
|
62
|
+
request_options = _check_request_options(request_options)
|
63
|
+
headers = _check_headers(request_options, { 'Content-Type': @config.mime_json })
|
64
|
+
|
65
|
+
@http_client.put(url: @config.api_base_url + uri, data: data.to_json, headers: headers,
|
66
|
+
timeout: request_options.connection_timeout)
|
67
|
+
end
|
68
|
+
|
69
|
+
def _delete(uri:, request_options: nil)
|
70
|
+
request_options = _check_request_options(request_options)
|
71
|
+
headers = _check_headers(request_options)
|
72
|
+
|
73
|
+
@http_client.delete(url: @config.api_base_url + uri, headers: headers,
|
74
|
+
timeout: request_options.connection_timeout)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|