mercadopago-sdk 2.0.3 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +1 -1
- data/Gemfile.lock +2 -2
- data/lib/mercadopago/config/config.rb +1 -1
- data/lib/mercadopago/config/request_options.rb +1 -0
- data/lib/mercadopago/resources/preapproval.rb +36 -0
- data/lib/mercadopago/resources/preapproval_plan.rb +36 -0
- data/lib/mercadopago/sdk.rb +8 -0
- data/lib/mercadopago.rb +2 -0
- data/mercadopago.gemspec +1 -1
- data/tests/test_preapproval.rb +93 -0
- data/tests/test_preapproval_plan.rb +98 -0
- data/tests/tests.rb +2 -0
- metadata +9 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 41c1d87f633a6f99580d5aa53ff476e1c39ab6cde50f2cd6b5972c2fd46efdce
|
4
|
+
data.tar.gz: f894cf94fb149964f837cc2ea2863ac4b573f8d6842207b36dc3cc1745289db2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fded9ebc44f76799bfbc0bfdb984ad9de475b064bfb86b40592caece6eec1dfcb78e9e70a05eaeeeacb82b0ac6144075f393a710daad181e8efb6f3a40977341
|
7
|
+
data.tar.gz: 4080de6c39418743845166d9bbb06bc481cc511a676f46ad6ea170d6746a2a74283294553770f250974d87595c7827478af25246d04b98b9994b2cfbce53e368
|
data/.rubocop_todo.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
mercadopago-sdk (2.0
|
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.
|
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)
|
@@ -28,6 +28,7 @@ module Mercadopago
|
|
28
28
|
headers = { 'Authorization': "Bearer #{@access_token}",
|
29
29
|
'x-product-id' => @config.product_id,
|
30
30
|
'x-tracking-id' => @config.tracking_id,
|
31
|
+
'x-idempotency-key' => SecureRandom.uuid,
|
31
32
|
'User-Agent' => @config.user_agent,
|
32
33
|
'Accept': @config.mime_json }
|
33
34
|
|
@@ -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
|
data/lib/mercadopago/sdk.rb
CHANGED
@@ -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
@@ -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
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.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:
|
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.
|
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
|