mercadopago-sdk 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +9 -105
  3. data/lib/mercadopago.rb +18 -112
  4. data/lib/version.rb +1 -1
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 40a42ea53dd82c6c9932c0c603b23920bf03c89d6823a3779a99f778b99d361d
4
- data.tar.gz: 1c8bea06955578aff4de9afcd4ae03f4a375ae3f1a2bda31014c301148997740
3
+ metadata.gz: da34e332c43d8d31d53ed4b4057aefcf3b1b3998c4641ae213f30688d4e3ea5e
4
+ data.tar.gz: 52d00679df1618c0a4fb1709b902f379982b6c918b8290b47be7f815c0781f77
5
5
  SHA512:
6
- metadata.gz: f1da53205f33babf2452c51a242b2cd2e8b87d069cfe8b61fc634ec04a53c46f5cbee8e0c88cf86fb7b6fe3dcc1e596e028b2255bd6a1ee738b551ee09f43d16
7
- data.tar.gz: eca076db10b08db2074d4703dbd69bd645855e06a23847f4ef05f8625276f4188eef81ed4c8175f9cb28074a40e895a10b051eb8ce92559964e39428564c0968
6
+ metadata.gz: efa5823c5ed784e5252096764105d520936dd9a722bbf8206671b053cb28e2a23fa44378c067199d9e8d91d5b1cebee7d4709d003b88f63d7d302d7e7343a4c6
7
+ data.tar.gz: cd7ba8c4e5b6ed53eed2f737d98d2294cbe153327a9d461aa4866f8e31fe75c414bb77a41d1bd37161d787009ffdfbf3eba6ad814120dd5317d47fa062b206c9
data/README.md CHANGED
@@ -18,13 +18,7 @@ First time using Mercado Pago? Create your [Mercado Pago account](https://www.me
18
18
 
19
19
  2. Copy the access_token in the [credentials](https://www.mercadopago.com/mlb/account/credentials) section of the page and replace YOUR_ACCESS_TOKEN with it.
20
20
 
21
- Thats all, you have Mercado Pago SDK installed.
22
-
23
- ```ruby
24
- preference = $mp.get_preference('PREFERENCE_ID')
25
-
26
- puts $preferenceResult
27
- ```
21
+ That's it! Mercado Pago SDK has been successfully installed.
28
22
 
29
23
  ## 🌟 Getting Started
30
24
 
@@ -48,112 +42,22 @@ preference = $mp.create_preference(preference_data)
48
42
  puts preference
49
43
  ```
50
44
 
51
- #### Update an existent Checkout preference
52
-
53
- ```ruby
54
- preferenceDataToUpdate = Hash["items" => Array(Array["title"=>"testUpdated", "quantity"=>1, "unit_price"=>2])]
55
-
56
- preferenceUpdate = $mp.update_preference("PREFERENCE_ID", preferenceDataToUpdate)
57
-
58
- puts preferenceUpdate
59
- ```
60
-
61
- ### Payments/Collections
62
-
63
- #### Search for payments
64
-
65
- ```ruby
66
- filters = Array["id"=>null, "external_reference"=>null]
67
-
68
- searchResult = $mp.search_payment(filters)
69
-
70
- puts searchResult
71
- ```
72
-
73
- #### Get payment data
74
-
75
- ```ruby
76
- paymentInfo = $mp.get_payment("ID")
77
-
78
- puts paymentInfo
79
- ```
80
-
81
- ### Cancel (only for pending payments)
45
+ ## 📚 Documentation
82
46
 
83
- ```ruby
84
- result = $mp.cancel_payment("ID");
85
-
86
- // Show result
87
- puts result
88
- ```
89
-
90
- ### Refund (only for accredited payments)
91
-
92
- ```ruby
93
- result = $mp.refund_payment("ID");
94
-
95
- // Show result
96
- puts result
97
- ```
98
-
99
- <a name="custom-checkout"></a>
100
- ## Customized checkout
101
-
102
- ### Configure your credentials
103
-
104
- * Get your **ACCESS_TOKEN** in the following address:
105
- * Argentina: [https://www.mercadopago.com/mla/account/credentials](https://www.mercadopago.com/mla/account/credentials)
106
- * Brazil: [https://www.mercadopago.com/mlb/account/credentials](https://www.mercadopago.com/mlb/account/credentials)
107
- * Mexico: [https://www.mercadopago.com/mlm/account/credentials](https://www.mercadopago.com/mlm/account/credentials)
108
- * Venezuela: [https://www.mercadopago.com/mlv/account/credentials](https://www.mercadopago.com/mlv/account/credentials)
109
- * Colombia: [https://www.mercadopago.com/mco/account/credentials](https://www.mercadopago.com/mco/account/credentials)
110
-
111
- ```ruby
112
- require 'mercadopago.rb'
113
-
114
- $mp = MercadoPago.new('ACCESS_TOKEN')
115
- ```
116
-
117
- ### Create payment
118
-
119
- ```ruby
120
- $mp.post ("/v1/payments", payment_data);
121
- ```
122
-
123
- ### Create customer
124
-
125
- ```ruby
126
- $mp.post ("/v1/customers", Hash["email" => "email@test.com"]);
127
- ```
47
+ Visit our Dev Site for further information regarding:
48
+ - Payments APIs: [Spanish](https://www.mercadopago.com.ar/developers/es/guides/payments/api/introduction/) / [Portuguese](https://www.mercadopago.com.br/developers/pt/guides/payments/api/introduction/)
49
+ - Mercado Pago checkout: [Spanish](https://www.mercadopago.com.ar/developers/es/guides/payments/web-payment-checkout/introduction/) / [Portuguese](https://www.mercadopago.com.br/developers/pt/guides/payments/web-payment-checkout/introduction/)
50
+ - Web Tokenize checkout: [Spanish](https://www.mercadopago.com.ar/developers/es/guides/payments/web-tokenize-checkout/introduction/) / [Portuguese](https://www.mercadopago.com.br/developers/pt/guides/payments/web-tokenize-checkout/introduction/)
128
51
 
129
52
  Check our official code reference to explore all available functionalities.
130
53
 
131
- ```ruby
132
- $mp.get ("/v1/customers/CUSTOMER_ID");
133
- ```
54
+ ## ❤️ Support
134
55
 
135
56
  If you require technical support, please contact our support team at [developers.mercadopago.com](https://developers.mercadopago.com)
136
57
 
137
58
  ## 🏻 License
138
59
 
139
- ```ruby
140
- // Get a resource, with optional URL params. Also you can disable authentication for public APIs
141
- $mp.get ("/resource/uri", [params], [authenticate=true])
142
-
143
- // Create a resource with "data" and optional URL params.
144
- $mp.post ("/resource/uri", data, [params])
145
-
146
- // Update a resource with "data" and optional URL params.
147
- $mp.put ("/resource/uri", data, [params])
148
-
149
- // Delete a resource with optional URL params.
150
- $mp.delete ("/resource/uri", [params])
151
60
  ```
152
-
153
- For example, if you want to get the Sites list (no params and no authentication):
154
-
155
- ```ruby
156
- $sites = $mp.get ("/sites", null, false)
157
-
158
- puts $sites
61
+ MIT license. Copyright (c) 2018 - Mercado Pago / Mercado Libre
62
+ For more information, see the LICENSE file.
159
63
  ```
@@ -23,6 +23,7 @@ class MercadoPago
23
23
  @ll_access_token = args.at(0) if args.size == 1
24
24
 
25
25
  @rest_client = RestClient.new()
26
+ @rest_client.set_access_token(get_access_token)
26
27
  @sandbox = false
27
28
  end
28
29
 
@@ -74,15 +75,9 @@ class MercadoPago
74
75
 
75
76
  # Get information for specific payment
76
77
  def get_payment(id)
77
- begin
78
- access_token = get_access_token
79
- rescue => e
80
- return e.message
81
- end
82
-
83
78
  uri_prefix = @sandbox ? "/sandbox" : ""
84
79
 
85
- @rest_client.get(uri_prefix + "/v1/payments/" + id + "?access_token=" + access_token)
80
+ @rest_client.get(uri_prefix + "/v1/payments/" + id)
86
81
 
87
82
  end
88
83
 
@@ -92,61 +87,30 @@ class MercadoPago
92
87
 
93
88
  # Get information for specific authorized payment
94
89
  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)
90
+ @rest_client.get("/authorized_payments/" + id)
102
91
  end
103
92
 
104
93
  # Refund accredited payment
105
94
  def refund_payment(id)
106
- begin
107
- access_token = get_access_token
108
- rescue => e
109
- return e.message
110
- end
111
-
112
-
113
95
  refund_status = {}
114
- @rest_client.post("/v1/payments/" + id + "/refunds?access_token=" + access_token, refund_status)
96
+ @rest_client.post("/v1/payments/" + id, refund_status)
115
97
 
116
98
  end
117
99
 
118
100
  # Cancel pending payment
119
101
  def cancel_payment(id)
120
- begin
121
- access_token = get_access_token
122
- rescue => e
123
- return e.message
124
- end
125
-
126
102
  cancel_status = {"status" => "cancelled"}
127
- @rest_client.put("/v1/payments/" + id + "?access_token=" + access_token, cancel_status)
103
+ @rest_client.put("/v1/payments/" + id, cancel_status)
128
104
  end
129
105
 
130
106
  # Cancel preapproval payment
131
107
  def cancel_preapproval_payment(id)
132
- begin
133
- access_token = get_access_token
134
- rescue => e
135
- return e.message
136
- end
137
-
138
108
  cancel_status = {"status" => "cancelled"}
139
- @rest_client.put("/preapproval/" + id + "?access_token=" + access_token, cancel_status)
109
+ @rest_client.put("/preapproval/" + id, cancel_status)
140
110
  end
141
111
 
142
112
  # Search payments according to filters, with pagination
143
113
  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
114
  filters["offset"] = offset
151
115
  filters["limit"] = limit
152
116
 
@@ -154,63 +118,33 @@ class MercadoPago
154
118
 
155
119
  uri_prefix = @sandbox ? "/sandbox" : ""
156
120
 
157
- @rest_client.get(uri_prefix + "/v1/payments/search?" + filters + "&access_token=" + access_token)
121
+ @rest_client.get(uri_prefix + "/v1/payments/search?" + filters)
158
122
 
159
123
  end
160
124
 
161
125
  # Create a checkout preference
162
126
  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)
127
+ @rest_client.post("/checkout/preferences", preference)
170
128
  end
171
129
 
172
130
  # Update a checkout preference
173
131
  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)
132
+ @rest_client.put("/checkout/preferences/" + id, preference)
181
133
  end
182
134
 
183
135
  # Get a checkout preference
184
136
  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)
137
+ @rest_client.get("/checkout/preferences/" + id)
192
138
  end
193
139
 
194
140
  # Create a preapproval payment
195
141
  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)
142
+ @rest_client.post("/preapproval", preapproval_payment)
203
143
  end
204
144
 
205
145
  # Get a preapproval payment
206
146
  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)
147
+ @rest_client.get("/preapproval/" + id)
214
148
  end
215
149
 
216
150
  # Generic resource get
@@ -219,16 +153,6 @@ class MercadoPago
219
153
  params = Hash.new
220
154
  end
221
155
 
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
156
  if not params.empty?
233
157
  uri << (if uri.include? "?" then "&" else "?" end) << build_query(params)
234
158
  end
@@ -242,14 +166,6 @@ class MercadoPago
242
166
  params = Hash.new
243
167
  end
244
168
 
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
169
  if not params.empty?
254
170
  uri << (if uri.include? "?" then "&" else "?" end) << build_query(params)
255
171
  end
@@ -263,14 +179,6 @@ class MercadoPago
263
179
  params = Hash.new
264
180
  end
265
181
 
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
182
  if not params.empty?
275
183
  uri << (if uri.include? "?" then "&" else "?" end) << build_query(params)
276
184
  end
@@ -284,14 +192,6 @@ class MercadoPago
284
192
  params = Hash.new
285
193
  end
286
194
 
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
195
  if not params.empty?
296
196
  uri << (if uri.include? "?" then "&" else "?" end) << build_query(params)
297
197
  end
@@ -327,6 +227,7 @@ class MercadoPago
327
227
  @platform_id = nil
328
228
  @integrator_id = nil
329
229
  @corporation_id = nil
230
+ @access_token = nil
330
231
  end
331
232
 
332
233
  def set_debug_logger(debug_logger)
@@ -345,6 +246,10 @@ class MercadoPago
345
246
  @corporation_id = corporation_id
346
247
  end
347
248
 
249
+ def set_access_token(access_token)
250
+ @access_token = access_token
251
+ end
252
+
348
253
  def exec(method, uri, data, content_type)
349
254
  if not data.nil? and content_type == MIME_JSON
350
255
  data = data.to_json
@@ -358,6 +263,7 @@ class MercadoPago
358
263
  'Accept' => MIME_JSON
359
264
  }
360
265
 
266
+ headers['Authorization'] = "Bearer " + @access_token if @access_token != nil
361
267
  headers['x-platform-id'] = @platform_id if @platform_id != nil
362
268
  headers['x-integrator-id'] = @integrator_id if @integrator_id != nil
363
269
  headers['x-corporation-id'] = @corporation_id if @corporation_id != nil
@@ -1,2 +1,2 @@
1
- MERCADO_PAGO_VERSION = '1.2.0' unless defined?(MERCADO_PAGO_VERSION)
1
+ MERCADO_PAGO_VERSION = '1.3.0' unless defined?(MERCADO_PAGO_VERSION)
2
2
  PRODUCT_ID = 'bc32a7vtrpp001u8nhjg'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mercadopago-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - maticompiano
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-27 00:00:00.000000000 Z
11
+ date: 2020-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json