mercadopago-sdk 2.1.0 → 2.2.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
  SHA256:
3
- metadata.gz: 495f4405c4f5218162702e1b5dc89fb0272011a7fbf6087be65af587e26b7b69
4
- data.tar.gz: 46a6aecbdaf9d33e966c49316d694150e6bacbac165d18a5759cf8459e61e47b
3
+ metadata.gz: 41c1d87f633a6f99580d5aa53ff476e1c39ab6cde50f2cd6b5972c2fd46efdce
4
+ data.tar.gz: f894cf94fb149964f837cc2ea2863ac4b573f8d6842207b36dc3cc1745289db2
5
5
  SHA512:
6
- metadata.gz: 0e929b0bfd4d9bf9f88e103484624adea240491b27c669943ecb7498570cfe775fdb894b7bed6343d250fe27794cbb16e89be8b62373585d1d1ec1dbcf33d29d
7
- data.tar.gz: 14a3aa78706c87948ed259d300548b9d01e69b00be87276ad14f12ab464b3c30ced5ebaacd731fd9034d930ec498c4342f1ab85df1c14f2d83f7fd9af5b476ca
6
+ metadata.gz: fded9ebc44f76799bfbc0bfdb984ad9de475b064bfb86b40592caece6eec1dfcb78e9e70a05eaeeeacb82b0ac6144075f393a710daad181e8efb6f3a40977341
7
+ data.tar.gz: 4080de6c39418743845166d9bbb06bc481cc511a676f46ad6ea170d6746a2a74283294553770f250974d87595c7827478af25246d04b98b9994b2cfbce53e368
data/.rubocop_todo.yml CHANGED
@@ -14,7 +14,7 @@ Gemspec/RequiredRubyVersion:
14
14
  - 'mercadopago.gemspec'
15
15
 
16
16
  # Offense count: 8
17
- Lint/SelfAssignment:
17
+ Style/SelfAssignment:
18
18
  Exclude:
19
19
  - 'lib/mercadopago/core/mp_base.rb'
20
20
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mercadopago-sdk (2.0.3)
4
+ mercadopago-sdk (2.1.0)
5
5
  json (~> 2.5)
6
6
  rest-client (~> 2.1)
7
7
 
@@ -20,7 +20,7 @@ GEM
20
20
  method_source (1.0.0)
21
21
  mime-types (3.4.1)
22
22
  mime-types-data (~> 3.2015)
23
- mime-types-data (3.2021.1115)
23
+ mime-types-data (3.2022.0105)
24
24
  minitest (5.14.4)
25
25
  netrc (0.11.0)
26
26
  parallel (1.19.2)
@@ -0,0 +1,36 @@
1
+ # typed: true
2
+ # frozen_string_literal: true
3
+
4
+ module Mercadopago
5
+ ###
6
+ # This class provides the methods to access the API
7
+ # that will allow you to create your own subscription experience on your website.
8
+
9
+ # From basic to advanced configurations, you control the whole experience.
10
+
11
+ # [Click here for more infos](https://www.mercadopago.com.ar/developers/es/reference/subscriptions/_preapproval/post)
12
+
13
+ class Preapproval < MPBase
14
+ def search(filters: nil, request_options: nil)
15
+ raise TypeError, 'Param filters must be a Hash' unless filters.nil? || filters.is_a?(Hash)
16
+
17
+ _get(uri: '/preapproval/search', filters: filters, request_options: request_options)
18
+ end
19
+
20
+ def get(preapproval_id, request_options: nil)
21
+ _get(uri: "/preapproval/#{preapproval_id}", request_options: request_options)
22
+ end
23
+
24
+ def create(preapproval_data, request_options: nil)
25
+ raise TypeError, 'Param preapproval_data must be a Hash' unless preapproval_data.is_a?(Hash)
26
+
27
+ _post(uri: '/preapproval/', data: preapproval_data, request_options: request_options)
28
+ end
29
+
30
+ def update(preapproval_id, preapproval_data, request_options: nil)
31
+ raise TypeError, 'Param preapproval_data must be a Hash' unless preapproval_data.is_a?(Hash)
32
+
33
+ _put(uri: "/preapproval/#{preapproval_id}", data: preapproval_data, request_options: request_options)
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,36 @@
1
+ # typed: true
2
+ # frozen_string_literal: true
3
+
4
+ module Mercadopago
5
+ ###
6
+ # This class provides the methods to access the API
7
+ # that will allow you to create your own plan of subscription experience on your website.
8
+
9
+ # From basic to advanced configurations, you control the whole experience.
10
+
11
+ # [Click here for more infos](https://www.mercadopago.com.ar/developers/es/reference/subscriptions/_preapproval_plan/post)
12
+
13
+ class PreapprovalPlan < MPBase
14
+ def search(filters: nil, request_options: nil)
15
+ raise TypeError, 'Param filters must be a Hash' unless filters.nil? || filters.is_a?(Hash)
16
+
17
+ _get(uri: '/preapproval_plan/search', filters: filters, request_options: request_options)
18
+ end
19
+
20
+ def get(preapproval_plan_id, request_options: nil)
21
+ _get(uri: "/preapproval_plan/#{preapproval_plan_id}", request_options: request_options)
22
+ end
23
+
24
+ def create(preapproval_plan_data, request_options: nil)
25
+ raise TypeError, 'Param preapproval_plan_data must be a Hash' unless preapproval_plan_data.is_a?(Hash)
26
+
27
+ _post(uri: '/preapproval_plan/', data: preapproval_plan_data, request_options: request_options)
28
+ end
29
+
30
+ def update(preapproval_plan_id, preapproval_plan_data, request_options: nil)
31
+ raise TypeError, 'Param preapproval_plan_data must be a Hash' unless preapproval_plan_data.is_a?(Hash)
32
+
33
+ _put(uri: "/preapproval_plan/#{preapproval_plan_id}", data: preapproval_plan_data, request_options: request_options)
34
+ end
35
+ end
36
+ end
@@ -59,6 +59,14 @@ module Mercadopago
59
59
  Refund.new(request_options, http_client)
60
60
  end
61
61
 
62
+ def preapproval
63
+ Preapproval.new(request_options, http_client)
64
+ end
65
+
66
+ def preapproval_plan
67
+ PreapprovalPlan.new(request_options, http_client)
68
+ end
69
+
62
70
  def access_token=(value)
63
71
  raise TypeError, 'Param access_token must be a String' unless value.is_a?(String)
64
72
 
data/lib/mercadopago.rb CHANGED
@@ -20,5 +20,7 @@ require_relative './mercadopago/resources/merchant_order'
20
20
  require_relative './mercadopago/resources/payment_methods'
21
21
  require_relative './mercadopago/resources/advanced_payment'
22
22
  require_relative './mercadopago/resources/disbursement_refund'
23
+ require_relative './mercadopago/resources/preapproval'
24
+ require_relative './mercadopago/resources/preapproval_plan'
23
25
 
24
26
  require_relative './mercadopago/sdk'
data/mercadopago.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |gem|
4
4
  gem.name = 'mercadopago-sdk'
5
- gem.version = '2.1.0'
5
+ gem.version = '2.2.0'
6
6
  gem.required_ruby_version = '>= 2.3.0'
7
7
  gem.author = 'Mercado Pago'
8
8
  gem.description = 'Mercado Pago Ruby SDK'
@@ -0,0 +1,93 @@
1
+ # typed: true
2
+ # frozen_string_literal: true
3
+
4
+ require_relative '../lib/mercadopago'
5
+
6
+ require 'minitest/autorun'
7
+
8
+ class TestPreapproval < Minitest::Test
9
+ def setup
10
+ @card_token_object = {
11
+ card_number: '5031433215406351',
12
+ expiration_year: 2025,
13
+ expiration_month: 11,
14
+ security_code: '123',
15
+ cardholder: {
16
+ name: 'APRO'
17
+ }
18
+ }
19
+ end
20
+
21
+ def test_method_search
22
+ sdk = Mercadopago::SDK.new(ENV['ACCESS_TOKEN'])
23
+
24
+ create_response = create_preapproval(sdk)
25
+ assert_equal 201, create_response[:status]
26
+
27
+ result = sdk.preapproval.search(filters: { id: create_response[:response]['id'] })
28
+ assert_equal 200, result[:status]
29
+ end
30
+
31
+ def test_method_get_id
32
+ sdk = Mercadopago::SDK.new(ENV['ACCESS_TOKEN'])
33
+
34
+ create_response = create_preapproval(sdk)
35
+ assert_equal 201, create_response[:status]
36
+
37
+ result = sdk.preapproval.get(create_response[:response]['id'])
38
+ assert_equal 200, result[:status]
39
+ end
40
+
41
+ def test_method_post
42
+ sdk = Mercadopago::SDK.new(ENV['ACCESS_TOKEN'])
43
+
44
+ result = create_preapproval(sdk)
45
+ assert_equal 201, result[:status]
46
+ end
47
+
48
+ def test_method_put
49
+ sdk = Mercadopago::SDK.new(ENV['ACCESS_TOKEN'])
50
+
51
+ create_response = create_preapproval(sdk)
52
+ assert_equal 201, create_response[:status]
53
+
54
+ update_data = {
55
+ reason: 'Yoga classes',
56
+ external_reference: 'YG-12345',
57
+ payer_email: 'test_user@testuser.com',
58
+ auto_recurring: {
59
+ frequency: 2,
60
+ frequency_type: 'months',
61
+ transaction_amount: 15,
62
+ currency_id: 'BRL'
63
+ },
64
+ back_url: 'https://www.mercadopago.com.ar',
65
+ status: 'authorized'
66
+ }
67
+ result = sdk.preapproval.update(create_response[:response]['id'], update_data)
68
+ assert_equal 200, result[:status]
69
+ end
70
+
71
+ def create_preapproval(sdk)
72
+ result_card_token = sdk.card_token.create(@card_token_object)
73
+
74
+ preapproval_data = {
75
+ reason: 'Yoga classes',
76
+ external_reference: 'YG-1234',
77
+ payer_email: 'test_user@testuser.com',
78
+ card_token_id: result_card_token[:response]['id'],
79
+ auto_recurring: {
80
+ frequency: 1,
81
+ frequency_type: 'months',
82
+ start_date: '2023-06-02T13:07:14.260Z',
83
+ end_date: "2023-07-20T15:59:52.581Z",
84
+ transaction_amount: 10,
85
+ currency_id: 'BRL'
86
+ },
87
+ back_url: 'https://www.mercadopago.com.ar',
88
+ status: 'authorized'
89
+ }
90
+
91
+ sdk.preapproval.create(preapproval_data)
92
+ end
93
+ end
@@ -0,0 +1,98 @@
1
+ # typed: true
2
+ # frozen_string_literal: true
3
+
4
+ require_relative '../lib/mercadopago'
5
+
6
+ require 'minitest/autorun'
7
+
8
+ class TestPreapprovalPlan < Minitest::Test
9
+ def setup
10
+ @preapproval_plan_data = {
11
+ reason: 'Yoga classes',
12
+ auto_recurring: {
13
+ frequency: 1,
14
+ frequency_type: 'months',
15
+ repetitions: 12,
16
+ billing_day: 10,
17
+ billing_day_proportional: true,
18
+ free_trial: {
19
+ frequency: 1,
20
+ frequency_type: 'months'
21
+ },
22
+ transaction_amount: 10,
23
+ currency_id: 'BRL'
24
+ },
25
+ payment_methods_allowed: {
26
+ payment_types: [
27
+ {}
28
+ ],
29
+ payment_methods: [
30
+ {}
31
+ ]
32
+ },
33
+ back_url: 'https://www.yoursite.com'
34
+ }
35
+ end
36
+
37
+ def test_method_search
38
+ sdk = Mercadopago::SDK.new(ENV['ACCESS_TOKEN'])
39
+ result = sdk.preapproval_plan.create(@preapproval_plan_data)
40
+ assert_equal 201, result[:status]
41
+
42
+ result = sdk.preapproval_plan.search(filters: { id: result[:response]['id'] })
43
+ assert_equal 200, result[:status]
44
+ end
45
+
46
+ def test_method_get_id
47
+ sdk = Mercadopago::SDK.new(ENV['ACCESS_TOKEN'])
48
+
49
+ result = sdk.preapproval_plan.create(@preapproval_plan_data)
50
+ assert_equal 201, result[:status]
51
+
52
+ result = sdk.preapproval_plan.get(result[:response]['id'])
53
+ assert_equal 200, result[:status]
54
+ end
55
+
56
+ def test_method_post
57
+ sdk = Mercadopago::SDK.new(ENV['ACCESS_TOKEN'])
58
+
59
+ result = sdk.preapproval_plan.create(@preapproval_plan_data)
60
+ assert_equal 201, result[:status]
61
+ end
62
+
63
+ def test_method_put
64
+ sdk = Mercadopago::SDK.new(ENV['ACCESS_TOKEN'])
65
+
66
+ update_data = {
67
+ reason: 'Pilates classes',
68
+ auto_recurring: {
69
+ frequency: 1,
70
+ frequency_type: 'months',
71
+ repetitions: 20,
72
+ billing_day: 15,
73
+ billing_day_proportional: true,
74
+ free_trial: {
75
+ frequency: 1,
76
+ frequency_type: 'months'
77
+ },
78
+ transaction_amount: 10,
79
+ currency_id: 'BRL'
80
+ },
81
+ payment_methods_allowed: {
82
+ payment_types: [
83
+ {}
84
+ ],
85
+ payment_methods: [
86
+ {}
87
+ ]
88
+ },
89
+ back_url: 'https://www.yoursite.com'
90
+ }
91
+
92
+ result = sdk.preapproval_plan.create(@preapproval_plan_data)
93
+ assert_equal 201, result[:status]
94
+
95
+ result = sdk.preapproval_plan.update(result[:response]['id'], update_data)
96
+ assert_equal 200, result[:status]
97
+ end
98
+ end
data/tests/tests.rb CHANGED
@@ -11,3 +11,5 @@ require_relative './test_preference'
11
11
  require_relative './test_refund_with_custom_headers'
12
12
  require_relative './test_refund'
13
13
  require_relative './test_user'
14
+ require_relative './test_preapproval'
15
+ require_relative './test_preapproval_plan'
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: 2.1.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mercado Pago
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-11 00:00:00.000000000 Z
11
+ date: 2023-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -169,6 +169,8 @@ files:
169
169
  - lib/mercadopago/resources/merchant_order.rb
170
170
  - lib/mercadopago/resources/payment.rb
171
171
  - lib/mercadopago/resources/payment_methods.rb
172
+ - lib/mercadopago/resources/preapproval.rb
173
+ - lib/mercadopago/resources/preapproval_plan.rb
172
174
  - lib/mercadopago/resources/preference.rb
173
175
  - lib/mercadopago/resources/refund.rb
174
176
  - lib/mercadopago/resources/user.rb
@@ -181,6 +183,8 @@ files:
181
183
  - tests/test_merchant_order.rb
182
184
  - tests/test_payment.rb
183
185
  - tests/test_payment_methods.rb
186
+ - tests/test_preapproval.rb
187
+ - tests/test_preapproval_plan.rb
184
188
  - tests/test_preference.rb
185
189
  - tests/test_refund.rb
186
190
  - tests/test_refund_with_custom_headers.rb
@@ -205,7 +209,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
205
209
  - !ruby/object:Gem::Version
206
210
  version: '0'
207
211
  requirements: []
208
- rubygems_version: 3.2.22
212
+ rubygems_version: 3.1.6
209
213
  signing_key:
210
214
  specification_version: 4
211
215
  summary: Mercado Pago Ruby SDK
@@ -217,6 +221,8 @@ test_files:
217
221
  - tests/test_merchant_order.rb
218
222
  - tests/test_payment.rb
219
223
  - tests/test_payment_methods.rb
224
+ - tests/test_preapproval.rb
225
+ - tests/test_preapproval_plan.rb
220
226
  - tests/test_preference.rb
221
227
  - tests/test_refund.rb
222
228
  - tests/test_refund_with_custom_headers.rb