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
@@ -0,0 +1,24 @@
1
+ # typed: true
2
+ # frozen_string_literal: true
3
+
4
+ module Mercadopago
5
+ ###
6
+ # This class will allow you to refund payments created through the Payments class.
7
+ # You can refund a payment within 180 days after it was approved.
8
+
9
+ # You must have sufficient funds in your account in order to successfully refund the payment amount. Otherwise, you will get a 400 Bad Request error.
10
+
11
+ # [Click here for more infos](https://www.mercadopago.com.br/developers/en/guides/manage-account/account/cancellations-and-refunds#bookmark_refunds)
12
+
13
+ class Refund < MPBase
14
+ def list(payment_id, request_options: nil)
15
+ _get(uri: "/v1/payments/#{payment_id}/refunds", request_options: request_options)
16
+ end
17
+
18
+ def create(payment_id, refund_data: nil, request_options: nil)
19
+ raise TypeError, 'Param refund_data must be a Hash' unless refund_data.nil? || refund_data.is_a?(Hash)
20
+
21
+ _post(uri: "/v1/payments/#{payment_id}/refunds", data: refund_data, request_options: request_options)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,13 @@
1
+ # typed: true
2
+ # frozen_string_literal: true
3
+
4
+ module Mercadopago
5
+ ###
6
+ # Access to Users
7
+
8
+ class User < MPBase
9
+ def get(request_options: nil)
10
+ _get(uri: '/users/me', request_options: request_options)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,85 @@
1
+ # typed: true
2
+ # frozen_string_literal: true
3
+
4
+ module Mercadopago
5
+ class SDK
6
+ attr_reader :access_token, :http_client
7
+
8
+ def initialize(access_token, http_client: nil, request_options: nil)
9
+ self.access_token = access_token
10
+ self.http_client = http_client.nil? ? HttpClient.new : http_client
11
+ self.request_options = request_options.nil? ? RequestOptions.new(access_token: access_token) : request_options
12
+ end
13
+
14
+ def advanced_payment
15
+ AdvancedPayment.new(request_options, http_client)
16
+ end
17
+
18
+ def card
19
+ Card.new(request_options, http_client)
20
+ end
21
+
22
+ def card_token
23
+ CardToken.new(request_options, http_client)
24
+ end
25
+
26
+ def customer
27
+ Customer.new(request_options, http_client)
28
+ end
29
+
30
+ def disbursement_refund
31
+ DisbursementRefund.new(request_options, http_client)
32
+ end
33
+
34
+ def user
35
+ User.new(request_options, http_client)
36
+ end
37
+
38
+ def identification_type
39
+ IdentificationType.new(request_options, http_client)
40
+ end
41
+
42
+ def merchant_order
43
+ MerchantOrder.new(request_options, http_client)
44
+ end
45
+
46
+ def payment
47
+ Payment.new(request_options, http_client)
48
+ end
49
+
50
+ def payment_methods
51
+ PaymentMethods.new(request_options, http_client)
52
+ end
53
+
54
+ def preference
55
+ Preference.new(request_options, http_client)
56
+ end
57
+
58
+ def refund
59
+ Refund.new(request_options, http_client)
60
+ end
61
+
62
+ def access_token=(value)
63
+ raise TypeError, 'Param access_token must be a String' unless value.is_a?(String)
64
+
65
+ @access_token = value
66
+ end
67
+
68
+ def http_client=(value)
69
+ raise TypeError, 'Param http_client must be a implementation of HttpClient' unless value.is_a?(HttpClient)
70
+
71
+ @http_client = value
72
+ end
73
+
74
+ def request_options=(value)
75
+ raise TypeError, 'Param request_options must be a RequestOptions object' unless value.is_a?(RequestOptions)
76
+
77
+ @request_options = value
78
+ end
79
+
80
+ def request_options
81
+ @request_options.access_token = @access_token if @request_options.access_token.nil?
82
+ @request_options
83
+ end
84
+ end
85
+ end
data/mercadopago.gemspec CHANGED
@@ -1,21 +1,21 @@
1
- # -*- encoding: utf-8 -*-
2
- require File.dirname(__FILE__) + '/lib/version'
1
+ # frozen_string_literal: true
3
2
 
4
3
  Gem::Specification.new do |gem|
5
- gem.name = 'mercadopago-sdk'
6
- gem.version = MERCADO_PAGO_VERSION
7
- gem.authors = %w(maticompiano)
8
- gem.email = %w(matias.compiano@mercadolibre.com)
9
- gem.description = %q{MercadoPago Ruby SDK}
10
- gem.summary = %q{MercadoPago Ruby SDK}
11
- gem.homepage = 'http://github.com/mercadopago/sdk-ruby'
4
+ gem.name = 'mercadopago-sdk'
5
+ gem.version = '2.0.2'
6
+ gem.required_ruby_version = '>= 2.3.0'
7
+ gem.author = 'Mercado Pago'
8
+ gem.description = 'Mercado Pago Ruby SDK'
9
+ gem.summary = 'Mercado Pago Ruby SDK'
10
+ gem.homepage = 'http://github.com/mercadopago/sdk-ruby'
11
+ gem.license = 'MIT'
12
12
 
13
- gem.files = `git ls-files`.split($/)
13
+ gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
14
14
  gem.test_files = gem.files.grep(%r{^(tests)/})
15
- gem.require_paths = %w(lib)
15
+ gem.require_paths = ['lib']
16
16
 
17
- gem.add_dependency 'json'
18
-
19
- gem.add_development_dependency 'pry'
20
- gem.add_development_dependency 'rake'
17
+ gem.add_dependency 'json', '~>2.5'
18
+ gem.add_dependency 'rest-client', '~>2.1'
19
+ gem.add_development_dependency 'pry', '~>0.14'
20
+ gem.add_development_dependency 'rake', '~>13.0'
21
21
  end
@@ -0,0 +1,79 @@
1
+ # typed: true
2
+ # frozen_string_literal: true
3
+
4
+ require_relative '../lib/mercadopago'
5
+
6
+ require 'minitest/autorun'
7
+
8
+ class TestCard < Minitest::Test
9
+ def test_all
10
+ sdk = Mercadopago::SDK.new('TEST-783169576377080-082620-395ee7f82e0d55b1db606c118686c1db-464842924')
11
+
12
+ customer_object = {
13
+ email: 'test_payer_999944@testuser.com',
14
+ first_name: 'Rafa',
15
+ last_name: 'Williner',
16
+ phone: {
17
+ area_code: '03492',
18
+ number: '432334'
19
+ },
20
+ identification: {
21
+ type: 'DNI',
22
+ number: '29804555'
23
+ },
24
+ address: {
25
+ zip_code: '2300',
26
+ street_name: 'some street'
27
+ },
28
+ description: 'customer description'
29
+ }
30
+
31
+ customer_saved = sdk.customer.create(customer_object)
32
+ assert_equal 201, customer_saved[:status]
33
+ customer_id = customer_saved[:response]['id']
34
+ sleep(1)
35
+
36
+ card_token_object = {
37
+ card_number: '5031433215406351',
38
+ expiration_year: 2025,
39
+ expiration_month: 11,
40
+ security_code: '123',
41
+ cardholder: {
42
+ name: 'APRO'
43
+ }
44
+ }
45
+
46
+ begin
47
+ card_token = sdk.card_token.create(card_token_object)
48
+
49
+ card_object = {
50
+ token: card_token[:response]['id']
51
+ }
52
+
53
+ card_saved = sdk.card.create(customer_id, card_object)
54
+ assert !card_saved.nil?
55
+ assert !card_saved[:response].nil?
56
+ assert !card_saved[:response]['id'].nil?
57
+ sleep(1)
58
+
59
+ cards = sdk.card.list(customer_id)
60
+ assert !cards.nil?
61
+ assert !cards[:response].nil?
62
+ assert !cards[:response].empty?
63
+ sleep(1)
64
+
65
+ card_get = sdk.card.get(customer_id, card_saved[:response]['id'])
66
+ assert_equal 200, card_get[:status]
67
+ sleep(1)
68
+
69
+ card_deleted = sdk.card.delete(customer_id, card_saved[:response]['id'])
70
+ assert_equal 200, card_deleted[:status]
71
+ sleep(1)
72
+ ensure
73
+ if customer_saved.key?(:response) && customer_saved[:response].key?('id')
74
+ customer_deleted = sdk.customer.delete(customer_saved[:response]['id'])
75
+ assert_equal 200, customer_deleted[:status]
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,39 @@
1
+ # typed: true
2
+ # frozen_string_literal: true
3
+
4
+ require_relative '../lib/mercadopago'
5
+
6
+ require 'minitest/autorun'
7
+
8
+ class CardToken < Minitest::Test
9
+ def test_method_get_id
10
+ sdk = Mercadopago::SDK.new('APP_USR-558881221729581-091712-44fdc612e60e3e638775d8b4003edd51-471763966')
11
+ card_token_object = {
12
+ card_number: '5031433215406351',
13
+ expiration_year: 2025,
14
+ expiration_month: 11,
15
+ security_code: '123',
16
+ cardholder: {
17
+ name: 'APRO'
18
+ }
19
+ }
20
+ result_card_token = sdk.card_token.create(card_token_object)
21
+ result = sdk.card_token.get(result_card_token[:response]['id'])
22
+ assert_equal 200, result[:status]
23
+ end
24
+
25
+ def test_method_post
26
+ sdk = Mercadopago::SDK.new('APP_USR-558881221729581-091712-44fdc612e60e3e638775d8b4003edd51-471763966')
27
+ card_token_object = {
28
+ card_number: '5031433215406351',
29
+ expiration_year: 2025,
30
+ expiration_month: 11,
31
+ security_code: '123',
32
+ cardholder: {
33
+ name: 'APRO'
34
+ }
35
+ }
36
+ result = sdk.card_token.create(card_token_object)
37
+ assert_equal 201, result[:status]
38
+ end
39
+ end
@@ -0,0 +1,54 @@
1
+ # typed: true
2
+ # frozen_string_literal: true
3
+
4
+ require_relative '../lib/mercadopago'
5
+
6
+ require 'minitest/autorun'
7
+
8
+ class TestCustomer < Minitest::Test
9
+ def test_all
10
+ sdk = Mercadopago::SDK.new('TEST-783169576377080-082620-395ee7f82e0d55b1db606c118686c1db-464842924')
11
+
12
+ customer_object = {
13
+ email: 'test_payer_999922@testuser.com',
14
+ first_name: 'Rafa',
15
+ last_name: 'Williner',
16
+ phone: {
17
+ area_code: '03492',
18
+ number: '432334'
19
+ },
20
+ identification: {
21
+ type: 'DNI',
22
+ number: '29804555'
23
+ },
24
+ address: {
25
+ zip_code: '2300',
26
+ street_name: 'some street'
27
+ },
28
+ description: 'customer description'
29
+ }
30
+
31
+ begin
32
+ customer_saved = sdk.customer.create(customer_object)
33
+ assert_equal 201, customer_saved[:status]
34
+ sleep(1)
35
+
36
+ customers = sdk.customer.search(filters: { email: 'test_payer_999922@testuser.com' })
37
+ assert_equal 200, customers[:status]
38
+ sleep(1)
39
+
40
+ customer_update = sdk.customer.update(customer_saved[:response]['id'], { last_name: 'Payer' })
41
+ assert_equal 200, customer_update[:status]
42
+ sleep(1)
43
+
44
+ customer_updated = sdk.customer.get(customer_saved[:response]['id'])
45
+ assert_equal 'Payer', customer_updated[:response]['last_name']
46
+ sleep(1)
47
+ ensure
48
+ if customer_saved.key?(:response) && customer_saved[:response].key?('id')
49
+ customer_deleted = sdk.customer.delete(customer_saved[:response]['id'])
50
+ assert_equal 200, customer_deleted[:status]
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,16 @@
1
+ # typed: true
2
+ # frozen_string_literal: true
3
+
4
+ require_relative '../lib/mercadopago'
5
+
6
+ require 'minitest/autorun'
7
+
8
+ class TestIdentificationType < Minitest::Test
9
+ def test_method_get
10
+ sdk = Mercadopago::SDK.new('APP_USR-558881221729581-091712-44fdc612e60e3e638775d8b4003edd51-471763966')
11
+ sdk.request_options = Mercadopago::RequestOptions.new(corporation_id: 'abc')
12
+ result = sdk.identification_type.get
13
+
14
+ assert_equal 200, result[:status]
15
+ end
16
+ end
@@ -0,0 +1,94 @@
1
+ # typed: true
2
+ # frozen_string_literal: true
3
+
4
+ require_relative '../lib/mercadopago'
5
+
6
+ require 'minitest/autorun'
7
+
8
+ class TestMerchantOrden < Minitest::Test
9
+ def test_method_search
10
+ sdk = Mercadopago::SDK.new('TEST-6130770563612470-121314-d27bbd7363e64c3853f058251cf8fc6e-537031659')
11
+ result = sdk.merchant_order.search(filters: { id: 123_187_219_6 })
12
+ assert_equal 200, result[:status]
13
+ end
14
+
15
+ def test_method_post
16
+ sdk = Mercadopago::SDK.new('APP_USR-558881221729581-091712-44fdc612e60e3e638775d8b4003edd51-471763966')
17
+ data = {
18
+ items: [
19
+ {
20
+ title: 'Dummy Item',
21
+ description: 'Multicolor Item',
22
+ quantity: 1,
23
+ currency_id: '',
24
+ unit_price: 10.0
25
+ }
26
+ ]
27
+ }
28
+ result_prefence = sdk.preference.create(data)
29
+ merchant_orden_object = {
30
+ preference_id: result_prefence[:response]['id'],
31
+ site_id: 'MLB',
32
+ notification_url: 'https://seller/notification',
33
+ additional_info: 'Aditional info',
34
+ external_reference: 1,
35
+ marketplace: 'NONE',
36
+ items: [{
37
+ description: 'Test Update Success',
38
+ id: '5678',
39
+ picture_url: 'http://product1.image.png',
40
+ quantity: 1,
41
+ title: 'Item 1',
42
+ currency_id: 'BRL',
43
+ unit_price: 20.5
44
+ }]
45
+ }
46
+ result_merchant_order = sdk.merchant_order.create(merchant_orden_object)
47
+ assert_equal 201, result_merchant_order[:status]
48
+ end
49
+
50
+ def test_method_get_id
51
+ sdk = Mercadopago::SDK.new('APP_USR-558881221729581-091712-44fdc612e60e3e638775d8b4003edd51-471763966')
52
+ result = sdk.merchant_order.get('2112122225')
53
+ assert_equal 200, result[:status]
54
+ end
55
+
56
+ def test_method_put
57
+ sdk = Mercadopago::SDK.new('APP_USR-558881221729581-091712-44fdc612e60e3e638775d8b4003edd51-471763966')
58
+ data = {
59
+ items: [
60
+ {
61
+ title: 'Dummy Item',
62
+ description: 'Multicolor Item',
63
+ quantity: 1,
64
+ currency_id: '',
65
+ unit_price: 10.0
66
+ }
67
+ ]
68
+ }
69
+ result_prefence = sdk.preference.create(data)
70
+ merchant_orden_object = {
71
+ preference_id: result_prefence[:response]['id'],
72
+ site_id: 'MLB',
73
+ notification_url: 'https://seller/notification',
74
+ additional_info: 'Aditional info',
75
+ external_reference: 1,
76
+ marketplace: 'NONE',
77
+ items: [
78
+ {
79
+ description: 'Test Update Success',
80
+ id: '5678',
81
+ picture_url: 'http://product1.image.png',
82
+ quantity: 1,
83
+ title: 'Item 1',
84
+ currency_id: 'BRL',
85
+ unit_price: 20.5
86
+ }
87
+ ]
88
+ }
89
+ result_merchant_order = sdk.merchant_order.create(merchant_orden_object)
90
+ merchant_order_update = { additional_info: 'Info 3' }
91
+ result = sdk.merchant_order.update(result_merchant_order[:response]['id'], merchant_order_update)
92
+ assert_equal 200, result[:status]
93
+ end
94
+ end