mercadopago-sdk 1.3.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.editorconfig +10 -0
- data/.github/ISSUE_TEMPLATE/bug_report.md +28 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +19 -0
- data/.github/workflows/ruby.yml +35 -0
- data/.rubocop.yml +1 -0
- data/.rubocop_todo.yml +104 -0
- data/.ruby-version +1 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/CODING_GUIDELINES.md +70 -0
- data/CONTRIBUTING.md +57 -0
- data/Gemfile +6 -1
- data/Gemfile.lock +45 -17
- data/LICENSE.txt +21 -0
- data/README.md +51 -27
- data/Rakefile +3 -1
- data/docs/CODE_OF_CONDUCT_md.html +154 -0
- data/docs/CODING_GUIDELINES_md.html +188 -0
- data/docs/CONTRIBUTING_md.html +165 -0
- data/docs/LICENSE_txt.html +96 -0
- data/docs/Mercadopago.html +123 -0
- data/docs/Mercadopago/AdvancedPayment.html +279 -0
- data/docs/Mercadopago/Card.html +204 -0
- data/docs/Mercadopago/CardToken.html +160 -0
- data/docs/Mercadopago/Config.html +266 -0
- data/docs/Mercadopago/Customer.html +228 -0
- data/docs/Mercadopago/DisbursementRefund.html +183 -0
- data/docs/Mercadopago/HttpClient.html +249 -0
- data/docs/Mercadopago/IdentificationType.html +136 -0
- data/docs/Mercadopago/MPBase.html +316 -0
- data/docs/Mercadopago/MerchantOrder.html +209 -0
- data/docs/Mercadopago/Payment.html +208 -0
- data/docs/Mercadopago/PaymentMethods.html +136 -0
- data/docs/Mercadopago/Preference.html +184 -0
- data/docs/Mercadopago/Refund.html +160 -0
- data/docs/Mercadopago/RequestOptions.html +433 -0
- data/docs/Mercadopago/SDK.html +528 -0
- data/docs/Mercadopago/User.html +136 -0
- data/docs/README_md.html +181 -0
- data/docs/created.rid +25 -0
- data/docs/css/fonts.css +167 -0
- data/docs/css/rdoc.css +619 -0
- data/docs/fonts/Lato-Light.ttf +0 -0
- data/docs/fonts/Lato-LightItalic.ttf +0 -0
- data/docs/fonts/Lato-Regular.ttf +0 -0
- data/docs/fonts/Lato-RegularItalic.ttf +0 -0
- data/docs/fonts/SourceCodePro-Bold.ttf +0 -0
- data/docs/fonts/SourceCodePro-Regular.ttf +0 -0
- data/docs/images/add.png +0 -0
- data/docs/images/arrow_up.png +0 -0
- data/docs/images/brick.png +0 -0
- data/docs/images/brick_link.png +0 -0
- data/docs/images/bug.png +0 -0
- data/docs/images/bullet_black.png +0 -0
- data/docs/images/bullet_toggle_minus.png +0 -0
- data/docs/images/bullet_toggle_plus.png +0 -0
- data/docs/images/date.png +0 -0
- data/docs/images/delete.png +0 -0
- data/docs/images/find.png +0 -0
- data/docs/images/loadingAnimation.gif +0 -0
- data/docs/images/macFFBgHack.png +0 -0
- data/docs/images/package.png +0 -0
- data/docs/images/page_green.png +0 -0
- data/docs/images/page_white_text.png +0 -0
- data/docs/images/page_white_width.png +0 -0
- data/docs/images/plugin.png +0 -0
- data/docs/images/ruby.png +0 -0
- data/docs/images/tag_blue.png +0 -0
- data/docs/images/tag_green.png +0 -0
- data/docs/images/transparent.png +0 -0
- data/docs/images/wrench.png +0 -0
- data/docs/images/wrench_orange.png +0 -0
- data/docs/images/zoom.png +0 -0
- data/docs/index.html +109 -0
- data/docs/js/darkfish.js +84 -0
- data/docs/js/navigation.js +105 -0
- data/docs/js/navigation.js.gz +0 -0
- data/docs/js/search.js +110 -0
- data/docs/js/search_index.js +1 -0
- data/docs/js/search_index.js.gz +0 -0
- data/docs/js/searcher.js +229 -0
- data/docs/js/searcher.js.gz +0 -0
- data/docs/table_of_contents.html +562 -0
- data/lib/mercadopago.rb +24 -295
- data/lib/mercadopago/config/config.rb +42 -0
- data/lib/mercadopago/config/request_options.rb +85 -0
- data/lib/mercadopago/core/mp_base.rb +77 -0
- data/lib/mercadopago/http/http_client.rb +74 -0
- data/lib/mercadopago/resources/advanced_payment.rb +48 -0
- data/lib/mercadopago/resources/card.rb +31 -0
- data/lib/mercadopago/resources/card_token.rb +19 -0
- data/lib/mercadopago/resources/customer.rb +36 -0
- data/lib/mercadopago/resources/disbursement_refund.rb +24 -0
- data/lib/mercadopago/resources/identification_type.rb +13 -0
- data/lib/mercadopago/resources/merchant_order.rb +32 -0
- data/lib/mercadopago/resources/payment.rb +35 -0
- data/lib/mercadopago/resources/payment_methods.rb +13 -0
- data/lib/mercadopago/resources/preference.rb +26 -0
- data/lib/mercadopago/resources/refund.rb +24 -0
- data/lib/mercadopago/resources/user.rb +13 -0
- data/lib/mercadopago/sdk.rb +85 -0
- data/mercadopago.gemspec +11 -11
- data/tests/test_card.rb +79 -0
- data/tests/test_card_token.rb +39 -0
- data/tests/test_customer.rb +54 -0
- data/tests/test_identification_type.rb +16 -0
- data/tests/test_merchant_order.rb +94 -0
- data/tests/test_payment.rb +102 -0
- data/tests/test_payment_methods.rb +14 -0
- data/tests/test_preference.rb +49 -0
- data/tests/test_refund.rb +88 -0
- data/tests/test_user.rb +17 -0
- data/tests/tests.rb +12 -56
- metadata +127 -24
- data/.travis.yml +0 -14
- data/examples/checkout-buttons/basic_preference/button.rb +0 -28
- data/examples/instant-payment-notifications/receive-ipn.rb +0 -25
- data/examples/payment-search/search-approved-payments.rb +0 -23
- data/examples/payment-search/search-creditcard-payments.rb +0 -23
- data/examples/payment-search/search-funded-payments-by-name.rb +0 -23
- data/examples/payment-search/search-payments-from-email-and-date.rb +0 -23
- data/examples/payment-search/search-payments.rb +0 -23
- data/examples/preapproval-payments/button.rb +0 -42
- data/lib/ssl_options_patch.rb +0 -15
- data/lib/version.rb +0 -2
- data/travis_Gemfile +0 -4
@@ -0,0 +1,74 @@
|
|
1
|
+
# typed: false
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'rest-client'
|
5
|
+
require 'json'
|
6
|
+
|
7
|
+
module Mercadopago
|
8
|
+
class HttpClient
|
9
|
+
def get(url:, headers:, params: nil, timeout: nil, maxretries: nil)
|
10
|
+
try = 0
|
11
|
+
headers = {} if headers.nil?
|
12
|
+
headers[:params] = params unless params.nil?
|
13
|
+
|
14
|
+
begin
|
15
|
+
result = RestClient::Request.execute(method: :get, url: url, headers: headers, timeout: timeout)
|
16
|
+
{
|
17
|
+
status: result.code,
|
18
|
+
response: JSON.parse(result.body)
|
19
|
+
}
|
20
|
+
rescue RestClient::Exception => e
|
21
|
+
try += 1
|
22
|
+
if [429, 500, 502, 503, 504].include?(e.http_code) && (try < maxretries)
|
23
|
+
sleep(1)
|
24
|
+
retry
|
25
|
+
end
|
26
|
+
{
|
27
|
+
status: e.http_code,
|
28
|
+
response: JSON.parse(e.response.body)
|
29
|
+
}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def post(url:, data:, headers:, timeout: nil)
|
34
|
+
result = RestClient::Request.execute(method: :post, url: url, payload: data, headers: headers,
|
35
|
+
timeout: timeout)
|
36
|
+
{
|
37
|
+
status: result.code,
|
38
|
+
response: JSON.parse(result.body)
|
39
|
+
}
|
40
|
+
rescue RestClient::Exception => e
|
41
|
+
{
|
42
|
+
status: e.http_code,
|
43
|
+
response: JSON.parse(e.response.body)
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
47
|
+
def put(url:, data:, headers:, timeout: nil)
|
48
|
+
result = RestClient::Request.execute(method: :put, url: url, payload: data, headers: headers,
|
49
|
+
timeout: timeout)
|
50
|
+
{
|
51
|
+
status: result.code,
|
52
|
+
response: JSON.parse(result.body)
|
53
|
+
}
|
54
|
+
rescue RestClient::Exception => e
|
55
|
+
{
|
56
|
+
status: e.http_code,
|
57
|
+
response: JSON.parse(e.response.body)
|
58
|
+
}
|
59
|
+
end
|
60
|
+
|
61
|
+
def delete(url:, headers:, timeout: nil)
|
62
|
+
result = RestClient::Request.execute(method: 'delete', url: url, headers: headers, timeout: timeout)
|
63
|
+
{
|
64
|
+
status: result.code,
|
65
|
+
response: JSON.parse(result.body)
|
66
|
+
}
|
67
|
+
rescue RestClient::Exception => e
|
68
|
+
{
|
69
|
+
status: e.http_code,
|
70
|
+
response: JSON.parse(e.response.body)
|
71
|
+
}
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# typed: false
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module Mercadopago
|
5
|
+
###
|
6
|
+
# Access to Advanced Payments
|
7
|
+
|
8
|
+
class AdvancedPayment < MPBase
|
9
|
+
def search(filters: nil, request_options: nil)
|
10
|
+
raise TypeError, 'Param filters must be a Hash' unless filters.nil? || filters.is_a?(Hash)
|
11
|
+
|
12
|
+
_get(uri: '/v1/advanced_payments/search', filters: filters, request_options: request_options)
|
13
|
+
end
|
14
|
+
|
15
|
+
def get(advanced_payment_id, request_options: nil)
|
16
|
+
_get(uri: "/v1/advanced_payments/#{advanced_payment_id}", request_options: request_options)
|
17
|
+
end
|
18
|
+
|
19
|
+
def create(advanced_payment_data, request_options: nil)
|
20
|
+
raise TypeError, 'Param advanced_payment_data must be a Hash' unless advanced_payment_data.is_a?(Hash)
|
21
|
+
|
22
|
+
_post(uri: '/v1/advanced_payments', data: advanced_payment_data, request_options: request_options)
|
23
|
+
end
|
24
|
+
|
25
|
+
def capture(advanced_payment_id, request_options: nil)
|
26
|
+
capture_data = { capture: true }
|
27
|
+
_put(uri: "/v1/advanced_payments/#{advanced_payment_id}", data: capture_data, request_options: request_options)
|
28
|
+
end
|
29
|
+
|
30
|
+
def update(advanced_payment_id, advanced_payment_data, request_options: nil)
|
31
|
+
raise TypeError, 'Param advanced_payment_data must be a Hash' unless advanced_payment_data.is_a?(Hash)
|
32
|
+
|
33
|
+
_put(uri: "/v1/advanced_payments/#{advanced_payment_id}", data: advanced_payment_data,
|
34
|
+
request_options: request_options)
|
35
|
+
end
|
36
|
+
|
37
|
+
def cancel(advanced_payment_id, request_options: nil)
|
38
|
+
cancel_data = { status: 'cancelled' }
|
39
|
+
_put(uri: "/v1/advanced_payments/#{advanced_payment_id}", data: cancel_data, request_options: request_options)
|
40
|
+
end
|
41
|
+
|
42
|
+
def update_release_date(advanced_payment_id, release_date, request_options: nil)
|
43
|
+
disbursement_data = { money_release_date: release_date.strftime('%Y-%m-%d %H:%M:%S.%f') }
|
44
|
+
_post(uri: "/v1/advanced_payments/#{advanced_payment_id}/disburses", data: disbursement_data,
|
45
|
+
request_options: request_options)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# typed: true
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module Mercadopago
|
5
|
+
###
|
6
|
+
# The cards class is the way to store card data of your customers safely to improve the shopping experience.
|
7
|
+
# This will allow your customers to complete their purchases much faster and easily, since they will not have to complete their card data again.
|
8
|
+
|
9
|
+
# This class must be used in conjunction with the Customer class.
|
10
|
+
# [Click here for more infos](https://www.mercadopago.com/developers/en/guides/online-payments/web-tokenize-checkout/customers-and-cards)
|
11
|
+
|
12
|
+
class Card < MPBase
|
13
|
+
def get(customer_id, card_id, request_options: nil)
|
14
|
+
_get(uri: "/v1/customers/#{customer_id}/cards/#{card_id}", request_options: request_options)
|
15
|
+
end
|
16
|
+
|
17
|
+
def create(customer_id, card_data, request_options: nil)
|
18
|
+
raise TypeError, 'Param card_data must be a Hash' if card_data.nil? || !card_data.is_a?(Hash)
|
19
|
+
|
20
|
+
_post(uri: "/v1/customers/#{customer_id}/cards/", data: card_data, request_options: request_options)
|
21
|
+
end
|
22
|
+
|
23
|
+
def delete(customer_id, card_id, request_options: nil)
|
24
|
+
_delete(uri: "/v1/customers/#{customer_id}/cards/#{card_id}", request_options: request_options)
|
25
|
+
end
|
26
|
+
|
27
|
+
def list(customer_id, request_options: nil)
|
28
|
+
_get(uri: "/v1/customers/#{customer_id}/cards", request_options: request_options)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# typed: true
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module Mercadopago
|
5
|
+
##
|
6
|
+
# This class will allow you to send your customers card data for Mercado Pago server and receive a token to complete the payments transactions.
|
7
|
+
|
8
|
+
class CardToken < MPBase
|
9
|
+
def get(card_token_id, request_options: nil)
|
10
|
+
_get(uri: "/v1/card_tokens/#{card_token_id}", request_options: request_options)
|
11
|
+
end
|
12
|
+
|
13
|
+
def create(card_token_data, request_options: nil)
|
14
|
+
raise TypeError, 'Param card_token_data must be a Hash' unless card_token_data.is_a?(Hash)
|
15
|
+
|
16
|
+
_post(uri: '/v1/card_tokens', data: card_token_data, request_options: request_options)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# typed: true
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module Mercadopago
|
5
|
+
###
|
6
|
+
# This class allows you to store customers data safely to improve the shopping experience.
|
7
|
+
|
8
|
+
# This will allow your customer to complete their purchases much faster and easily when used in conjunction with the Cards class.
|
9
|
+
# [Click here for more infos](https://mercadopago.com.br/developers/en/guides/online-payments/web-tokenize-checkout/customers-and-cards)
|
10
|
+
|
11
|
+
class Customer < MPBase
|
12
|
+
def search(filters: nil, request_options: nil)
|
13
|
+
_get(uri: '/v1/customers/search', filters: filters, request_options: request_options)
|
14
|
+
end
|
15
|
+
|
16
|
+
def get(customer_id, request_options: nil)
|
17
|
+
_get(uri: "/v1/customers/#{customer_id}", request_options: request_options)
|
18
|
+
end
|
19
|
+
|
20
|
+
def create(customer_data, request_options: nil)
|
21
|
+
raise TypeError, 'Param customer_data must be a Hash' unless customer_data.is_a?(Hash)
|
22
|
+
|
23
|
+
_post(uri: '/v1/customers', data: customer_data, request_options: request_options)
|
24
|
+
end
|
25
|
+
|
26
|
+
def update(customer_id, customer_data, request_options: nil)
|
27
|
+
raise TypeError, 'Param customer_data must be a Hash' unless customer_data.is_a?(Hash)
|
28
|
+
|
29
|
+
_put(uri: "/v1/customers/#{customer_id}", data: customer_data, request_options: request_options)
|
30
|
+
end
|
31
|
+
|
32
|
+
def delete(customer_id, request_options: nil)
|
33
|
+
_delete(uri: "/v1/customers/#{customer_id}", request_options: request_options)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# typed: false
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module Mercadopago
|
5
|
+
# ###
|
6
|
+
# #Access to Advanced Payments Refunds
|
7
|
+
|
8
|
+
class DisbursementRefund < MPBase
|
9
|
+
def list(advanced_payment_id, request_options: nil)
|
10
|
+
_get(uri: "/v1/advanced_payments/#{advanced_payment_id}/refunds", request_options: nil)
|
11
|
+
end
|
12
|
+
|
13
|
+
def create_all(advanced_payment_id, request_options: nil)
|
14
|
+
_post(uri: "/v1/advanced_payments/#{advanced_payment_id}/refunds", request_options: request_options)
|
15
|
+
end
|
16
|
+
|
17
|
+
def create(advanced_payment_id, disbursement_id, amount: nil, request_options: nil)
|
18
|
+
disbursement_refund_data = amount.nil? ? nil : { amount: amount }
|
19
|
+
|
20
|
+
_post(uri: "/v1/advanced_payments/#{advanced_payment_id}/disbursements/#{disbursement_id}/refunds",
|
21
|
+
data: disbursement_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 Identification Types
|
7
|
+
|
8
|
+
class IdentificationType < MPBase
|
9
|
+
def get(request_options: nil)
|
10
|
+
_get(uri: '/v1/identification_types', request_options: request_options)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# typed: true
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module Mercadopago
|
5
|
+
###
|
6
|
+
# This class will allow you to create and manage your orders. You can attach one or more payments in your merchant order.
|
7
|
+
|
8
|
+
class MerchantOrder < MPBase
|
9
|
+
def search(filters: nil, request_options: nil)
|
10
|
+
raise TypeError, 'Param filters must be a Hash' unless filters.nil? || filters.is_a?(Hash)
|
11
|
+
|
12
|
+
_get(uri: '/merchant_orders/search', filters: filters, request_options: request_options)
|
13
|
+
end
|
14
|
+
|
15
|
+
def get(merchant_order_id, request_options: nil)
|
16
|
+
_get(uri: "/merchant_orders/#{merchant_order_id}", request_options: request_options)
|
17
|
+
end
|
18
|
+
|
19
|
+
def create(merchant_order_data, request_options: nil)
|
20
|
+
raise TypeError, 'Param merchant_orders_object must be a Hash' unless merchant_order_data.is_a?(Hash)
|
21
|
+
|
22
|
+
_post(uri: '/merchant_orders', data: merchant_order_data, request_options: request_options)
|
23
|
+
end
|
24
|
+
|
25
|
+
def update(merchant_order_id, merchant_order_data, request_options: nil)
|
26
|
+
raise TypeError, 'Param merchant_orders_object must be a Hash' unless merchant_order_data.is_a?(Hash)
|
27
|
+
|
28
|
+
_put(uri: "/merchant_orders/#{merchant_order_id}", data: merchant_order_data,
|
29
|
+
request_options: request_options)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# typed: true
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module Mercadopago
|
5
|
+
###
|
6
|
+
# This class provides the methods to access the API that will allow you to create your own payment experience on your website.
|
7
|
+
|
8
|
+
# From basic to advanced configurations, you control the whole experience.
|
9
|
+
|
10
|
+
# [Click here for more infos](https://www.mercadopago.com.br/developers/en/guides/online-payments/checkout-api/introduction/)
|
11
|
+
|
12
|
+
class Payment < MPBase
|
13
|
+
def search(filters: nil, request_options: nil)
|
14
|
+
raise TypeError, 'Param filters must be a Hash' unless filters.nil? || filters.is_a?(Hash)
|
15
|
+
|
16
|
+
_get(uri: '/v1/payments/search', filters: filters, request_options: request_options)
|
17
|
+
end
|
18
|
+
|
19
|
+
def get(payment_id, request_options: nil)
|
20
|
+
_get(uri: "/v1/payments/#{payment_id}", request_options: request_options)
|
21
|
+
end
|
22
|
+
|
23
|
+
def create(payment_data, request_options: nil)
|
24
|
+
raise TypeError, 'Param payment_data must be a Hash' unless payment_data.is_a?(Hash)
|
25
|
+
|
26
|
+
_post(uri: '/v1/payments/', data: payment_data, request_options: request_options)
|
27
|
+
end
|
28
|
+
|
29
|
+
def update(payment_id, payment_data, request_options: nil)
|
30
|
+
raise TypeError, 'Param payment_data must be a Hash' unless payment_data.is_a?(Hash)
|
31
|
+
|
32
|
+
_put(uri: "/v1/payments/#{payment_id}", data: payment_data, request_options: request_options)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# typed: true
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module Mercadopago
|
5
|
+
###
|
6
|
+
# Access to Payment Methods
|
7
|
+
|
8
|
+
class PaymentMethods < MPBase
|
9
|
+
def get(request_options: nil)
|
10
|
+
_get(uri: '/v1/payment_methods', request_options: request_options)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# typed: true
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module Mercadopago
|
5
|
+
##
|
6
|
+
# This class will allow you to charge your customers through our web form from any device in a simple, fast and secure way.
|
7
|
+
# [Click here for more infos](https://www.mercadopago.com.br/developers/en/guides/online-payments/checkout-pro/introduction)
|
8
|
+
|
9
|
+
class Preference < MPBase
|
10
|
+
def get(preference_id, request_options: nil)
|
11
|
+
_get(uri: "/checkout/preferences/#{preference_id}", request_options: request_options)
|
12
|
+
end
|
13
|
+
|
14
|
+
def create(preference_data, request_options: nil)
|
15
|
+
raise TypeError, 'Param preference_data must be a Hash' unless preference_data.is_a?(Hash)
|
16
|
+
|
17
|
+
_post(uri: '/checkout/preferences', data: preference_data, request_options: request_options)
|
18
|
+
end
|
19
|
+
|
20
|
+
def update(preference_id, preference_data, request_options: nil)
|
21
|
+
raise TypeError, 'Param preference_data must be a Hash' unless preference_data.is_a?(Hash)
|
22
|
+
|
23
|
+
_put(uri: "/checkout/preferences/#{preference_id}", data: preference_data, request_options: request_options)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -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,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
|