mercadopago-sdk 2.1.0 → 2.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +2 -0
- data/.rubocop_todo.yml +1 -1
- data/Gemfile.lock +2 -2
- data/README.md +4 -4
- data/lib/mercadopago/config/config.rb +2 -2
- 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: db8a423302b0b645b2a78a1a5ed957ebe8cbb60aa689d6eb01673e41325e4371
|
4
|
+
data.tar.gz: 845ced4c1aca6a7543100703ff7e828c2e3ea0f98b82448198934cee1d98d6ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 727cba9089c2ea5b85cb6a7e4b41c428999f12e903bc04996ecb529f50301642a10c9dec3676e044b734f8c53091b1b9f8ac6a6ff674c869e35856055108655f
|
7
|
+
data.tar.gz: 1c420d60d2ee836b1f03a05fff2ca43fceb83c890625e1314e3beddd61066bdab4d100118db533ca5f1b7e5c6c0e9d842150577df83f887778708175d1a1baf8
|
data/.github/workflows/ruby.yml
CHANGED
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)
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
[![Gem](https://img.shields.io/gem/v/mercadopago-sdk)](https://rubygems.org/gems/mercadopago-sdk)
|
4
4
|
[![Gem](https://img.shields.io/gem/dt/mercadopago-sdk)](https://rubygems.org/gems/mercadopago-sdk)
|
5
|
-
|
5
|
+
![GitHub](https://img.shields.io/github/license/mercadopago/sdk-ruby)
|
6
6
|
|
7
7
|
This library provides developers with a simple set of bindings to help you integrate Mercado Pago API to a website and start receiving payments.
|
8
8
|
|
@@ -18,7 +18,7 @@ Run ```gem install mercadopago-sdk```
|
|
18
18
|
|
19
19
|
First time using Mercado Pago? Create your [Mercado Pago account](https://www.mercadopago.com).
|
20
20
|
|
21
|
-
Copy your `Access Token` in the [credentials panel](https://www.mercadopago.com/developers/panel/
|
21
|
+
Copy your `Access Token` in the [credentials panel](https://www.mercadopago.com/developers/panel/app) and replace the text `YOUR_ACCESS_TOKEN` with it.
|
22
22
|
|
23
23
|
### Simple usage
|
24
24
|
|
@@ -62,10 +62,10 @@ payment = result[:response]
|
|
62
62
|
## 📚 Documentation
|
63
63
|
|
64
64
|
Visit our Dev Site for further information regarding:
|
65
|
-
- [
|
65
|
+
- [Developer Docs](https://www.mercadopago.com/developers/en/docs)
|
66
|
+
- [Checkout Bricks](https://www.mercadopago.com/developers/en/docs/checkout-bricks/landing)
|
66
67
|
- [Checkout Pro](https://www.mercadopago.com/developers/en/guides/online-payments/checkout-pro/introduction)
|
67
68
|
- [Checkout API](https://www.mercadopago.com/developers/en/guides/online-payments/checkout-api/introduction)
|
68
|
-
- [Web Tokenize Checkout](https://www.mercadopago.com/developers/en/guides/online-payments/web-tokenize-checkout/introduction)
|
69
69
|
|
70
70
|
Check our official code reference to explore all available functionalities.
|
71
71
|
|
@@ -3,10 +3,10 @@
|
|
3
3
|
|
4
4
|
module Mercadopago
|
5
5
|
class Config
|
6
|
-
@@VERSION = '2.1
|
6
|
+
@@VERSION = '2.2.1'
|
7
7
|
@@USER_AGENT = "MercadoPago Ruby SDK v#{@@VERSION}"
|
8
8
|
@@PRODUCT_ID = 'bc32a7vtrpp001u8nhjg'
|
9
|
-
@@TRACKING_ID = "
|
9
|
+
@@TRACKING_ID = "platform:#{RUBY_VERSION},type:SDK#{@@VERSION},so;"
|
10
10
|
@@API_BASE_URL = 'https://api.mercadopago.com'
|
11
11
|
@@MIME_JSON = 'application/json'
|
12
12
|
@@MIME_FORM = 'application/x-www-form-urlencoded'
|
@@ -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.1
|
4
|
+
version: 2.2.1
|
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-10-25 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
|