mercadopago-sdk 0.2.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
- ---
2
- SHA512:
3
- data.tar.gz: 8dc115b70071090b1f2302935463d8e123acdeac553fefbe8bf7001abdb80d2dc91fc5b7461070f2e27f7fbef6a13b327b3f62e87e092bd5520ae2c92ce95f36
4
- metadata.gz: 231f603d21cbbaf887675e4e5269d1f4484bfd7cbf1a8061a83afce4bfe885ff858356bc03cb0ece80b090f34862d343195f30f38da63233aa86e53534960ed7
5
- SHA1:
6
- data.tar.gz: 313cfa7db52697a68753f34d017e5d2bacb7f389
7
- metadata.gz: d250d507f91f7526658421c5e3fee250366d6fa5
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 88788ab965bf79e060243222e404f9990e46a501
4
+ data.tar.gz: ed6d70c55b1443423b86f8710cd7d79346935a84
5
+ SHA512:
6
+ metadata.gz: 5db8450d79eb3169605dd51aa35ae88dac8d043fdf5f72b6644231b7b375f0398ba5426ccd838c6c62578ffa9c603bd970a828bfec05f552910287376c2aeb21
7
+ data.tar.gz: 495a68af2210a23893a73237eb97abb7b80a62ed38a9e98e7217349cfe8d0538010260234ba316d0c6e2b613ce38bfb4d6b2d3bfbb4494698b6d58ea9bedd0f2
data/README.md CHANGED
@@ -11,10 +11,11 @@
11
11
  2. Copy lib/cacert.pem to the same folder (for SSL access to MercadoPago APIs).
12
12
 
13
13
  * Get your **CLIENT_ID** and **CLIENT_SECRET** in the following address:
14
- * Argentina: [https://www.mercadopago.com/mla/herramientas/aplicaciones](https://www.mercadopago.com/mla/herramientas/aplicaciones)
15
- * Brazil: [https://www.mercadopago.com/mlb/ferramentas/aplicacoes](https://www.mercadopago.com/mlb/ferramentas/aplicacoes)
16
- * México: [https://www.mercadopago.com/mlm/herramientas/aplicaciones](https://www.mercadopago.com/mlm/herramientas/aplicaciones)
17
- * Venezuela: [https://www.mercadopago.com/mlv/herramientas/aplicaciones](https://www.mercadopago.com/mlv/herramientas/aplicaciones)
14
+ * Argentina: [https://www.mercadopago.com/mla/herramientas/aplicaciones](https://www.mercadopago.com/mla/herramientas/aplicaciones)
15
+ * Brazil: [https://www.mercadopago.com/mlb/ferramentas/aplicacoes](https://www.mercadopago.com/mlb/ferramentas/aplicacoes)
16
+ * México: [https://www.mercadopago.com/mlm/herramientas/aplicaciones](https://www.mercadopago.com/mlm/herramientas/aplicaciones)
17
+ * Venezuela: [https://www.mercadopago.com/mlv/herramientas/aplicaciones](https://www.mercadopago.com/mlv/herramientas/aplicaciones)
18
+ * Colombia: [https://www.mercadopago.com/mco/herramientas/aplicaciones](https://www.mercadopago.com/mco/herramientas/aplicaciones)
18
19
 
19
20
  ```ruby
20
21
  require 'mercadopago.rb'
@@ -25,7 +26,7 @@ $mp = MercadoPago.new('CLIENT_ID', 'CLIENT_SECRET')
25
26
  ### Get your Access Token:
26
27
 
27
28
  ```ruby
28
- $accessToken = $mp.getAccessToken()
29
+ $accessToken = $mp.get_access_token()
29
30
 
30
31
  puts (accessToken)
31
32
  ```
@@ -45,7 +46,7 @@ puts $preferenceResult
45
46
 
46
47
  ```ruby
47
48
  preferenceData = Hash["items" => Array(Array["title"=>"testCreate", "quantity"=>1, "unit_price"=>10.2, "currency_id"=>"ARS"])]
48
-
49
+
49
50
  preference = $mp.create_preference(preferenceData)
50
51
 
51
52
  puts preference
@@ -79,10 +80,11 @@ puts searchResult
79
80
  ### Receiving IPN notification:
80
81
 
81
82
  * Go to **Mercadopago IPN configuration**:
82
- * Argentina: [https://www.mercadopago.com/mla/herramientas/notificaciones](https://www.mercadopago.com/mla/herramientas/notificaciones)
83
- * Brasil: [https://www.mercadopago.com/mlb/ferramentas/notificacoes](https://www.mercadopago.com/mlb/ferramentas/notificacoes)
84
- * México: [https://www.mercadopago.com/mlm/herramientas/notificaciones](https://www.mercadopago.com/mlm/herramientas/notificaciones)
85
- * Venezuela: [https://www.mercadopago.com/mlv/herramientas/notificaciones](https://www.mercadopago.com/mlv/herramientas/notificaciones)<br />
83
+ * Argentina: [https://www.mercadopago.com/mla/herramientas/notificaciones](https://www.mercadopago.com/mla/herramientas/notificaciones)
84
+ * Brasil: [https://www.mercadopago.com/mlb/ferramentas/notificacoes](https://www.mercadopago.com/mlb/ferramentas/notificacoes)
85
+ * México: [https://www.mercadopago.com/mlm/herramientas/notificaciones](https://www.mercadopago.com/mlm/herramientas/notificaciones)
86
+ * Venezuela: [https://www.mercadopago.com/mlv/herramientas/notificaciones](https://www.mercadopago.com/mlv/herramientas/notificaciones)
87
+ * Colombia: [https://www.mercadopago.com/mco/herramientas/notificaciones](https://www.mercadopago.com/mco/herramientas/notificaciones)<br />
86
88
 
87
89
  ```ruby
88
90
 
@@ -109,3 +111,26 @@ result = $mp.refund_payment("ID");
109
111
  puts result
110
112
  ```
111
113
  <a href=http://developers.mercadopago.com/documentacion/devolucion-y-cancelacion>About Cancel & Refund</a>
114
+
115
+ ### Generic resources methods
116
+
117
+ You can access any other resource from the MercadoPago API using the generic methods:
118
+
119
+ ```ruby
120
+ // Get a resource, with optional URL params. Also you can disable authentication for public APIs
121
+ $mp.get ("/resource/uri", [params], [authenticate=true])
122
+
123
+ // Create a resource with "data" and optional URL params.
124
+ $mp.post ("/resource/uri", data, [params])
125
+
126
+ // Update a resource with "data" and optional URL params.
127
+ $mp.put ("/resource/uri", data, [params])
128
+ ```
129
+
130
+ For example, if you want to get the Sites list (no params and no authentication):
131
+
132
+ ```ruby
133
+ $sites = $mp.get ("/sites", null, false)
134
+
135
+ puts $sites
136
+ ```
@@ -7,7 +7,7 @@ class Button
7
7
 
8
8
  def call(env)
9
9
  mp = MercadoPago.new('CLIENT_ID', 'CLIENT_SECRET')
10
- preferenceData = Hash["items" => Array(Hash["title"=>"sdk-ruby", "quantity"=>1, "unit_price"=>10.2, "currency_id"=>"ARS"])]
10
+ preferenceData = {"items" => ["title"=>"testCreate", "quantity"=>1, "unit_price"=>10.2, "currency_id"=>"ARS"]}
11
11
  preference = mp.create_preference(preferenceData)
12
12
 
13
13
  html = '<!doctype html>
@@ -0,0 +1,42 @@
1
+ require 'rubygems'
2
+ require 'rack'
3
+ $LOAD_PATH << '../../lib'
4
+ require 'mercadopago.rb'
5
+
6
+ class Button
7
+
8
+ def call(env)
9
+ mp = MercadoPago.new('CLIENT_ID', 'CLIENT_SECRET')
10
+ preapprovalPayment = Hash[
11
+ "payer_email" => "my_customer@my_site.com",
12
+ "back_url" => "http://www.my_site.com",
13
+ "reason" => "Monthly subscription to premium package",
14
+ "external_reference" => "OP-1234",
15
+ "auto_recurring" => Hash[
16
+ "frequency" => 1,
17
+ "frequency_type" => "months",
18
+ "transaction_amount" => 60,
19
+ "currency_id" => "BRL",
20
+ "start_date" => "2012-12-10T14:58:11.778-03:00",
21
+ "end_date" => "2013-06-10T14:58:11.778-03:00"
22
+ ]
23
+ ]
24
+
25
+ preapprovalPaymentResult = mp.create_preference(preapprovalPayment)
26
+
27
+ html = '<!doctype html>
28
+ <html>
29
+ <head>
30
+ <title>MercadoPago SDK - Create Preapproval Payment and Show Subscription Example</title>
31
+ </head>
32
+ <body>
33
+ <a href="' + preapprovalPaymentResult['response']['init_point'] + '" name="MP-Checkout" class="orange-ar-m-sq-arall">Pay</a>
34
+ <script type="text/javascript" src="http://mp-tools.mlstatic.com/buttons/render.js"></script>
35
+ </body>
36
+ </html>'
37
+
38
+ return [200, {'Content-Type' => 'text/html'}, [html]]
39
+ end
40
+ end
41
+
42
+ Rack::Handler::WEBrick.run(Button.new, :Port => 9000)
data/lib/mercadopago.rb CHANGED
@@ -184,6 +184,71 @@ class MercadoPago
184
184
  @rest_client.get("/preapproval/" + id + "?access_token=" + access_token)
185
185
  end
186
186
 
187
+ # Generic resource get
188
+ def get(uri, params = nil, authenticate = true)
189
+ if not params.class == Hash
190
+ params = Hash.new
191
+ end
192
+
193
+ if authenticate
194
+ begin
195
+ access_token = get_access_token
196
+ rescue => e
197
+ return e.message
198
+ end
199
+
200
+ params["access_token"] = access_token
201
+ end
202
+
203
+ if not params.empty?
204
+ uri << (if uri.include? "?" then "&" else "?" end) << build_query(params)
205
+ end
206
+
207
+ @rest_client.get(uri)
208
+ end
209
+
210
+ # Generic resource post
211
+ def post(uri, data, params = nil)
212
+ if not params.class == Hash
213
+ params = Hash.new
214
+ end
215
+
216
+ begin
217
+ access_token = get_access_token
218
+ rescue => e
219
+ return e.message
220
+ end
221
+
222
+ params["access_token"] = access_token
223
+
224
+ if not params.empty?
225
+ uri << (if uri.include? "?" then "&" else "?" end) << build_query(params)
226
+ end
227
+
228
+ @rest_client.post(uri, data)
229
+ end
230
+
231
+ # Generic resource put
232
+ def put(uri, data, params = nil)
233
+ if not params.class == Hash
234
+ params = Hash.new
235
+ end
236
+
237
+ begin
238
+ access_token = get_access_token
239
+ rescue => e
240
+ return e.message
241
+ end
242
+
243
+ params["access_token"] = access_token
244
+
245
+ if not params.empty?
246
+ uri << (if uri.include? "?" then "&" else "?" end) << build_query(params)
247
+ end
248
+
249
+ @rest_client.put(uri, data)
250
+ end
251
+
187
252
  def build_query(params)
188
253
  URI.escape(params.collect { |k, v| "#{k}=#{v}" }.join('&'))
189
254
  end
@@ -201,6 +266,7 @@ class MercadoPago
201
266
 
202
267
  if API_BASE_URL.scheme == "https" # enable SSL/TLS
203
268
  @http.use_ssl = true
269
+ @http.ssl_version = :SSLv3 if @http.respond_to? :ssl_version
204
270
  @http.verify_mode = OpenSSL::SSL::VERIFY_PEER
205
271
  @http.ca_file = File.join(File.dirname(__FILE__), "cacert.pem")
206
272
  end
data/lib/version.rb CHANGED
@@ -1 +1 @@
1
- MERCADO_PAGO_VERSION = '0.2.0' unless defined?(MERCADO_PAGO_VERSION)
1
+ MERCADO_PAGO_VERSION = '0.3.1' unless defined?(MERCADO_PAGO_VERSION)
Binary file
Binary file
data/tests/tests.rb CHANGED
@@ -11,7 +11,7 @@ class MercadoPagoTest < Test::Unit::TestCase
11
11
 
12
12
  # Call preference added through button flow
13
13
  def test_get_preference
14
- preferenceData = Hash["items" => Array(Array["title"=>"testCreate", "quantity"=>1, "unit_price"=>10.2, "currency_id"=>"ARS"])]
14
+ preferenceData = {"items" => ["title"=>"testCreate", "quantity"=>1, "unit_price"=>10.2, "currency_id"=>"ARS"]}
15
15
 
16
16
  preference = @mp.create_preference(preferenceData)
17
17
 
metadata CHANGED
@@ -1,53 +1,64 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: mercadopago-sdk
3
- version: !ruby/object:Gem::Version
4
- version: 0.2.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.1
5
5
  platform: ruby
6
- authors:
6
+ authors:
7
7
  - maticompiano
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
-
12
- date: 2013-05-07 00:00:00 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
11
+ date: 2014-12-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
15
14
  name: json
16
- prerelease: false
17
- requirement: &id001 !ruby/object:Gem::Requirement
18
- requirements:
19
- - &id002
20
- - ">="
21
- - !ruby/object:Gem::Version
22
- version: "0"
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
23
20
  type: :runtime
24
- version_requirements: *id001
25
- - !ruby/object:Gem::Dependency
26
- name: pry
27
21
  prerelease: false
28
- requirement: &id003 !ruby/object:Gem::Requirement
29
- requirements:
30
- - *id002
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
31
34
  type: :development
32
- version_requirements: *id003
33
- - !ruby/object:Gem::Dependency
34
- name: rake
35
35
  prerelease: false
36
- requirement: &id004 !ruby/object:Gem::Requirement
37
- requirements:
38
- - *id002
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
39
48
  type: :development
40
- version_requirements: *id004
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  description: MercadoPago Ruby SDK
42
- email:
56
+ email:
43
57
  - matias.compiano@mercadolibre.com
44
58
  executables: []
45
-
46
59
  extensions: []
47
-
48
60
  extra_rdoc_files: []
49
-
50
- files:
61
+ files:
51
62
  - .gitignore
52
63
  - Gemfile
53
64
  - Gemfile.lock
@@ -60,34 +71,36 @@ files:
60
71
  - examples/payment-search/search-funded-payments-by-name.rb
61
72
  - examples/payment-search/search-payments-from-email-and-date.rb
62
73
  - examples/payment-search/search-payments.rb
74
+ - examples/preapproval-payments/button.rb
63
75
  - lib/cacert.pem
64
76
  - lib/mercadopago.rb
65
77
  - lib/version.rb
66
- - mercadopago-sdk-0.1.9.gem
78
+ - mercadopago-sdk-0.2.0.gem
79
+ - mercadopago-sdk-0.3.0.gem
67
80
  - mercadopago.gemspec
68
81
  - tests/tests.rb
69
82
  homepage: http://github.com/mercadopago/sdk-ruby
70
83
  licenses: []
71
-
72
84
  metadata: {}
73
-
74
85
  post_install_message:
75
86
  rdoc_options: []
76
-
77
- require_paths:
87
+ require_paths:
78
88
  - lib
79
- required_ruby_version: !ruby/object:Gem::Requirement
80
- requirements:
81
- - *id002
82
- required_rubygems_version: !ruby/object:Gem::Requirement
83
- requirements:
84
- - *id002
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
85
99
  requirements: []
86
-
87
100
  rubyforge_project:
88
- rubygems_version: 2.0.3
101
+ rubygems_version: 2.0.14
89
102
  signing_key:
90
103
  specification_version: 4
91
104
  summary: MercadoPago Ruby SDK
92
- test_files:
105
+ test_files:
93
106
  - tests/tests.rb
Binary file