mercadopago 2.0.2 → 2.1.0

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
1
  ---
2
2
  SHA1:
3
- metadata.gz: ac03eabc246d2feb42e79e390d21dcf3ecca5d89
4
- data.tar.gz: e33fdd761bf7100df62e782d66d693d3026c6135
3
+ metadata.gz: 5e1562b1e4de4f9ed87e54dda09f63f443a4d669
4
+ data.tar.gz: 374a4a7099b084264fb77ca72ecefdbea2f4724d
5
5
  SHA512:
6
- metadata.gz: eb8dd18062cb47b2cdf37404f3c21814a3ae09f0175558df86fbf5fe6c97c5a8bdce2e287155805958010025b08cf562616556670b916ce99b99dc6eb66c6f68
7
- data.tar.gz: b4b837900a8f2f2f698ea033de72e614ac96324cb82b2ff08188e1d38eb1349510bc80b8cba4e43bf486cad37d651b8e1ab03e0792ad419a54155a1d619709a7
6
+ metadata.gz: fc95d5f6f99a7cb3269b463b992e9f090ab6c5a0e0f9968308dcecb5ff3738c4ecbcc2e1e37e444deed6fc0b361e4d3f451adca5bd5bbd9b816cfb41e787d384
7
+ data.tar.gz: b74e252e8e6e81eb0e43373ab1538a6b24c20c1d7fcba4a517b9d9348427020c7ce86a1e140f8b9658cad1b3b8a84abea3de23d2b8ccdf0b82fb90da40d34e96
data/.gitignore CHANGED
@@ -9,3 +9,6 @@ pkg/*
9
9
  ## TEXTMATE
10
10
  *.tmproj
11
11
  tmtags
12
+
13
+ ## rvm/rbenv
14
+ .ruby-version
data/README.md CHANGED
@@ -16,7 +16,7 @@ You can read the documentation of the MercadoPago API here:
16
16
  Installation
17
17
  ------------
18
18
 
19
- mercadopago 2.0.0 needs Ruby 1.9. Version 1.0.2 runs fine with Ruby 1.8.
19
+ mercadopago 2.0.0+ needs Ruby 1.9+. Version 1.0.2 runs fine with Ruby 1.8.
20
20
 
21
21
  To install the last version of the gem:
22
22
 
@@ -283,6 +283,114 @@ And the parameters thay could be used in the search hash are:
283
283
  recurring_payment: Active subscription recurring payment.
284
284
  subscription_payment: Subscription fee.
285
285
 
286
+ ### Recurring Payment Creation
287
+
288
+ Your request will need a hash to explain what the recurring payment is for. For example:
289
+
290
+ data = {
291
+ payer_email: "xxx@test.com",
292
+ back_url: "http://www.site.com/return",
293
+ reason: "Monthly Magazine",
294
+ external_reference: "OPERATION-ID-1234",
295
+ auto_recurring: {
296
+ frequency: 1,
297
+ frequency_type: "months",
298
+ transaction_amount: 12.55,
299
+ currency_id: "BRL"
300
+ }
301
+ }
302
+
303
+ If everything worked out alright, you will get a response like this:
304
+
305
+ {
306
+ "id" => "f8ad8asd8asd98asd89add980",
307
+ "payer_id" => 131231333,
308
+ "payer_email" => "xxx@test.com",
309
+ "back_url" => "http://www.site.com/return",
310
+ "collector_id" => 3131231231,
311
+ "application_id" => 83818921839,
312
+ "status" => "authorized",
313
+ "reason" => "Monthly Magazine",
314
+ "external_reference" => "OPERATION-ID-1234",
315
+ "date_created" => "2014-08-03T20:47:53.970-04:00",
316
+ "last_modified" => "2014-08-03T20:51:00.264-04:00",
317
+ "init_point" => "https://www.mercadopago.com/mlb/debits/new?preapproval_id=8ad8asd8ada8da8dad88sa",
318
+ "auto_recurring" => {
319
+ "frequency" => 1,
320
+ "frequency_type" => "months",
321
+ "transaction_amount" => 12.55,
322
+ "currency_id" => "BRL"
323
+ }
324
+ }
325
+
326
+
327
+ ### Recurring Payment Status Verification Next Recurring Payments by IPN
328
+
329
+ To check the recurring payment status you will need the preapproval ID next recurring payments. Only then you can call the [MercadoPago IPN](https://developers.mercadopago.com/beta/documentacao/notificacoes-de-pagamentos#!/get-preapproval).
330
+
331
+ # Use the preapproval ID received on the IPN.
332
+ preapproval_id = '987654321'
333
+
334
+ notification = mp_client.notification_authorized(preapproval_id)
335
+
336
+ You will get a response like this one:
337
+
338
+ Status code: 200 OK
339
+
340
+ {
341
+ "preapproval_id": "preapproval_id",
342
+ "id": "authorized_payment_id",
343
+ "type": "online",
344
+ "status": "processed",
345
+ "date_created": "2014-05-22T11:53:37.074-04:00",
346
+ "last_modified": "2014-05-22T11:53:37.074-04:00",
347
+ "transaction_amount": 150,
348
+ "currency_id": "BRL",
349
+ "payment":
350
+ {
351
+ "id": "payment_id",
352
+ "status": "approved",
353
+ "status_detail": "accredited"
354
+ }
355
+ }
356
+
357
+ ### Recurring Payment Status Verification by IPN
358
+
359
+ To check the recurring payment status you will need the preapproval ID. Only then you can call the [MercadoPago IPN](https://developers.mercadopago.com/beta/documentacao/notificacoes-de-pagamentos#!/get-preapproval).
360
+
361
+ # Use the preapproval ID received on the IPN.
362
+ preapproval_id = '987654321'
363
+
364
+ notification = mp_client.notification_preapproval(preapproval_id)
365
+
366
+ You will get a response like this one:
367
+
368
+ Status code: 200 OK
369
+
370
+ {
371
+ "id": "preapproval_id",
372
+ "payer_id": 12345,
373
+ "payer_email": "payeremail@email.com",
374
+ "back_url": "https://www.mysite.com/afterAuth",
375
+ "collector_id": 12345,
376
+ "application_id": 10648,
377
+ "status": "authorized",
378
+ "init_point": "https://www.mercadopago.com/mlb/debits/new?preapproval_id=preapproval_id",
379
+ "sandbox_init_point": "https://www.mercadopago.com/mlb/debits/new?preapproval_id=preapproval_id",
380
+ "external_reference": "OP-1234",
381
+ "reason": "Detailed description about your service",
382
+ "auto_recurring": {
383
+ "frequency": 1,
384
+ "frequency_type": "months",
385
+ "transaction_amount": 60,
386
+ "currency_id": "BRL"
387
+ },
388
+ "date_created": "2012-08-31T11:50:26.648-04:00",
389
+ "last_modified": "2012-08-31T11:50:26.648-04:00"
390
+ }
391
+
392
+
393
+
286
394
  ### Errors
287
395
 
288
396
  Errors will also be hashes with status code, message and error key.
@@ -305,6 +413,10 @@ This gem has tests for a few methods. To check if it is working properly, just r
305
413
  Changelog
306
414
  ---------
307
415
 
416
+ 2.1.0 (thanks jamessonfaria)
417
+
418
+ Added functionality to create and get recurring payments. Also added support for recurring payments notification.
419
+
308
420
  2.0.2
309
421
 
310
422
  Request uses Faraday HTTP client instead of RestClient for better SSL support.
@@ -336,4 +448,4 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
336
448
 
337
449
  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
338
450
 
339
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
451
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -3,6 +3,7 @@ require 'mercadopago/request'
3
3
  require 'mercadopago/authentication'
4
4
  require 'mercadopago/checkout'
5
5
  require 'mercadopago/collection'
6
+ require 'mercadopago/merchant_order'
6
7
  require 'mercadopago/client'
7
8
 
8
9
  module MercadoPago
@@ -19,6 +19,14 @@ module MercadoPago
19
19
  MercadoPago::Request.wrap_post("/checkout/preferences?access_token=#{access_token}", payload, headers)
20
20
  end
21
21
 
22
+ #
23
+ # TODO
24
+ #
25
+ def self.update_preference
26
+ # TODO
27
+ end
28
+
29
+ #
22
30
  # Returns the hash with the details of certain payment preference.
23
31
  #
24
32
  # - access_token: the MercadoPago account access token
@@ -30,10 +38,26 @@ module MercadoPago
30
38
  end
31
39
 
32
40
  #
33
- # TODO
41
+ # - access_token: the MercadoPago account associated with this access_token will
42
+ # receive the money from the payment of preapproval payment.
43
+ # - data: a hash of preferences that will be trasmitted to checkout API.
34
44
  #
35
- def self.update_preference
36
- # TODO
45
+ def self.create_preapproval_payment(access_token, data)
46
+ payload = JSON.generate(data)
47
+ headers = { content_type: 'application/json', accept: 'application/json' }
48
+
49
+ MercadoPago::Request.wrap_post("/preapproval?access_token=#{access_token}", payload, headers)
50
+ end
51
+
52
+ #
53
+ # Returns the hash with the details of certain preapproval payment.
54
+ #
55
+ # - access_token: the MercadoPago account access token
56
+ # - preapproval_id: the preapproval payment ID
57
+ #
58
+ def self.get_preapproval_payment(access_token, preapproval_id)
59
+ headers = { accept: 'application/json' }
60
+ MercadoPago::Request.wrap_get("/preapproval/#{preapproval_id}?access_token=#{access_token}")
37
61
  end
38
62
 
39
63
  end
@@ -64,12 +64,53 @@ module MercadoPago
64
64
  end
65
65
 
66
66
  #
67
- # Retrieves the latest information about a payment.
67
+ # Creates a recurring payment.
68
68
  #
69
- # - payment_id: the id of the payment to be checked.
69
+ # - data: contains the data according to the recurring payment that will be created.
70
70
  #
71
- def notification(payment_id)
72
- MercadoPago::Collection.notification(@access_token, payment_id)
71
+ def create_preapproval_payment(data)
72
+ MercadoPago::Checkout.create_preapproval_payment(@access_token, data)
73
+ end
74
+
75
+ #
76
+ # Returns the recurring payment.
77
+ #
78
+ # - preapproval_id: the id of the preapproval payment preference that will be retrieved.
79
+ #
80
+ def get_preapproval_payment(preapproval_id)
81
+ MercadoPago::Checkout.get_preapproval_payment(@access_token, preapproval_id)
82
+ end
83
+
84
+ #
85
+ # Retrieves the latest information about a payment or a merchant order.
86
+ #
87
+ # - entity_id: the id of the entity (paymento or merchant order) to be checked.
88
+ #
89
+ def notification(entity_id, topic = 'payment')
90
+ case topic.to_s
91
+ when 'merchant_order'
92
+ MercadoPago::MerchantOrder.notification(@access_token, entity_id)
93
+ else # 'payment'
94
+ MercadoPago::Collection.notification(@access_token, entity_id)
95
+ end
96
+ end
97
+
98
+ #
99
+ # Retrieves the latest information about the recurring payment after authorized.
100
+ #
101
+ # - authorized_id: the id of the recurring payment authorized to be checked.
102
+ #
103
+ def notification_authorized(authorized_id)
104
+ MercadoPago::Collection.notification_authorized(@access_token, authorized_id)
105
+ end
106
+
107
+ #
108
+ # Retrieves the latest information about the recurring payment.
109
+ #
110
+ # - preapproval_id: the id of the recurring payment to be checked.
111
+ #
112
+ def notification_preapproval(preapproval_id)
113
+ MercadoPago::Collection.notification_preapproval(@access_token, preapproval_id)
73
114
  end
74
115
 
75
116
  #
@@ -104,4 +145,4 @@ module MercadoPago
104
145
 
105
146
  end
106
147
 
107
- end
148
+ end
@@ -13,6 +13,22 @@ module MercadoPago
13
13
  MercadoPago::Request.wrap_get("/collections/notifications/#{payment_id}?access_token=#{access_token}", { accept: 'application/json' })
14
14
  end
15
15
 
16
+ #
17
+ # - access_token: an access_token of the MercadoPago account associated with the payment to be checked.
18
+ # - authorized_id: the id of the authorized payment to be checked.
19
+ #
20
+ def self.notification_authorized(access_token, authorized_id)
21
+ MercadoPago::Request.wrap_get("/authorized_payments/#{authorized_id}?access_token=#{access_token}", { accept: 'application/json' })
22
+ end
23
+
24
+ #
25
+ # - access_token: an access_token of the MercadoPago account associated with the payment to be checked.
26
+ # - preapproval_id: the id of the recurring payment to be checked.
27
+ #
28
+ def self.notification_preapproval(access_token, preapproval_id)
29
+ MercadoPago::Request.wrap_get("/preapproval/#{preapproval_id}?access_token=#{access_token}", { accept: 'application/json' })
30
+ end
31
+
16
32
  #
17
33
  # Receives an access_token and a search_hash and returns matching payments, according to the search params.
18
34
  #
@@ -0,0 +1,17 @@
1
+ module MercadoPago
2
+
3
+ module MerchantOrder
4
+
5
+ #
6
+ # Receives an access_token and a merchant order id and retrieves information of the order.
7
+ #
8
+ # - access_token: an access_token of the MercadoPago account associated with the payment to be checked.
9
+ # - merchant_order_id: the id of the order to be checked.
10
+ #
11
+ def self.notification(access_token, merchant_order_id)
12
+ MercadoPago::Request.wrap_get("/merchant_orders/#{merchant_order_id}?access_token=#{access_token}", { accept: 'application/json' })
13
+ end
14
+
15
+ end
16
+
17
+ end
@@ -56,9 +56,12 @@ module MercadoPago
56
56
 
57
57
  JSON.load(response.body)
58
58
  rescue Exception => e
59
- JSON.load(e.response)
59
+ if e.respond_to?(:response)
60
+ JSON.load(e.response)
61
+ else
62
+ raise e
63
+ end
60
64
  end
61
-
62
65
  end
63
66
 
64
67
  end
@@ -1,3 +1,3 @@
1
1
  module MercadoPago
2
- VERSION = "2.0.2"
2
+ VERSION = "2.1.0"
3
3
  end
@@ -5,6 +5,7 @@ require "mercadopago/version"
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "mercadopago"
7
7
  s.version = MercadoPago::VERSION
8
+ s.licenses = ['MIT']
8
9
  s.authors = ["Kauplus Social Commerce", "Ombu Shop, Tu Tienda Online"]
9
10
  s.email = ["suporte@kauplus.com.br"]
10
11
  s.homepage = "https://github.com/kauplus/mercadopago"
@@ -20,7 +21,7 @@ Gem::Specification.new do |s|
20
21
 
21
22
  # specify any dependencies here:
22
23
  s.add_dependency 'json', '>= 1.4.6'
23
- s.add_dependency 'faraday', '0.9.0'
24
+ s.add_dependency 'faraday', '>= 0.9.0'
24
25
  s.add_development_dependency 'pry'
25
26
  s.add_development_dependency 'debugger'
26
27
  end
@@ -95,14 +95,22 @@ class TestMercadoPago < MiniTest::Unit::TestCase
95
95
  assert_equal "https://www.mercadopago.com/mlb/checkout/pay?pref_id=#{pref_id}", response['init_point']
96
96
  end
97
97
 
98
- def test_that_client_can_get_notification
99
- payment_id = 460494008
98
+ def test_that_client_can_get_payment_notification
99
+ payment_id = 849707350
100
100
  mp_client = MercadoPago::Client.new(CREDENTIALS[:client_id], CREDENTIALS[:client_secret])
101
101
 
102
102
  response = mp_client.notification(payment_id)
103
103
  assert_equal payment_id, response['collection']['id']
104
104
  end
105
105
 
106
+ def test_that_client_can_get_merchant_order_notification
107
+ payment_id = 61166827
108
+ mp_client = MercadoPago::Client.new(CREDENTIALS[:client_id], CREDENTIALS[:client_secret])
109
+
110
+ response = mp_client.notification(payment_id, 'merchant_order')
111
+ assert_equal payment_id, response['id']
112
+ end
113
+
106
114
  def test_that_client_can_search
107
115
  mp_client = MercadoPago::Client.new(CREDENTIALS[:client_id], CREDENTIALS[:client_secret])
108
116
  response = mp_client.search(status: :pending)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mercadopago
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kauplus Social Commerce
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-06-03 00:00:00.000000000 Z
12
+ date: 2014-10-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -29,14 +29,14 @@ dependencies:
29
29
  name: faraday
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - '='
32
+ - - ">="
33
33
  - !ruby/object:Gem::Version
34
34
  version: 0.9.0
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - '='
39
+ - - ">="
40
40
  - !ruby/object:Gem::Version
41
41
  version: 0.9.0
42
42
  - !ruby/object:Gem::Dependency
@@ -84,12 +84,14 @@ files:
84
84
  - lib/mercadopago/checkout.rb
85
85
  - lib/mercadopago/client.rb
86
86
  - lib/mercadopago/collection.rb
87
+ - lib/mercadopago/merchant_order.rb
87
88
  - lib/mercadopago/request.rb
88
89
  - lib/mercadopago/version.rb
89
90
  - mercadopago.gemspec
90
91
  - test/test_mercado_pago.rb
91
92
  homepage: https://github.com/kauplus/mercadopago
92
- licenses: []
93
+ licenses:
94
+ - MIT
93
95
  metadata: {}
94
96
  post_install_message:
95
97
  rdoc_options: []