tbk-sdk 1.5.0.pre.ruby2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.built +0 -0
- data/.bundled +0 -0
- data/.github/ISSUE_TEMPLATE/reporte-de-error.md +40 -0
- data/.gitignore +16 -0
- data/.rakeTasks +7 -0
- data/.travis.yml +10 -0
- data/CHANGELOG.md +63 -0
- data/Dockerfile +5 -0
- data/Gemfile +6 -0
- data/LICENSE.md +11 -0
- data/Makefile +24 -0
- data/README.md +87 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/docker-compose.yml +20 -0
- data/lib/transbank/sdk/oneclick/base.rb +64 -0
- data/lib/transbank/sdk/oneclick/errors/oneclick_error.rb +16 -0
- data/lib/transbank/sdk/oneclick/inscription/errors/mall_inscription_delete_error.rb +16 -0
- data/lib/transbank/sdk/oneclick/inscription/errors/mall_inscription_finish_error.rb +16 -0
- data/lib/transbank/sdk/oneclick/inscription/errors/mall_inscription_start_error.rb +16 -0
- data/lib/transbank/sdk/oneclick/inscription/errors/oneclick_mall_inscription_errors.rb +3 -0
- data/lib/transbank/sdk/oneclick/inscription/inscription.rb +3 -0
- data/lib/transbank/sdk/oneclick/inscription/responses/mall_inscription_delete_response.rb +18 -0
- data/lib/transbank/sdk/oneclick/inscription/responses/mall_inscription_finish_response.rb +15 -0
- data/lib/transbank/sdk/oneclick/inscription/responses/mall_inscription_start_response.rb +14 -0
- data/lib/transbank/sdk/oneclick/inscription/responses/oneclick_mall_inscription_responses.rb +3 -0
- data/lib/transbank/sdk/oneclick/mall/errors/mall_transaction_authorize_error.rb +16 -0
- data/lib/transbank/sdk/oneclick/mall/errors/mall_transaction_refund_error.rb +16 -0
- data/lib/transbank/sdk/oneclick/mall/errors/mall_transaction_status_error.rb +16 -0
- data/lib/transbank/sdk/oneclick/mall/errors/oneclick_mall_errors.rb +4 -0
- data/lib/transbank/sdk/oneclick/mall/mall_inscription.rb +73 -0
- data/lib/transbank/sdk/oneclick/mall/mall_transaction.rb +97 -0
- data/lib/transbank/sdk/oneclick/mall/oneclick_mall.rb +4 -0
- data/lib/transbank/sdk/oneclick/mall/responses/mall_transaction_authorize_response.rb +16 -0
- data/lib/transbank/sdk/oneclick/mall/responses/mall_transaction_refund_response.rb +16 -0
- data/lib/transbank/sdk/oneclick/mall/responses/mall_transaction_status_response.rb +15 -0
- data/lib/transbank/sdk/oneclick/mall/responses/oneclick_mall_responses.rb +4 -0
- data/lib/transbank/sdk/oneclick/mall_deferred/errors/mall_deferred_transaction_capture_error.rb +16 -0
- data/lib/transbank/sdk/oneclick/mall_deferred/mall_deferred_inscription.rb +20 -0
- data/lib/transbank/sdk/oneclick/mall_deferred/mall_deferred_transaction.rb +42 -0
- data/lib/transbank/sdk/oneclick/mall_deferred/responses/mall_deferred_transaction_capture_response.rb +16 -0
- data/lib/transbank/sdk/oneclick/oneclick.rb +12 -0
- data/lib/transbank/sdk/onepay/base.rb +125 -0
- data/lib/transbank/sdk/onepay/errors/errors.rb +17 -0
- data/lib/transbank/sdk/onepay/errors/integration_type_error.rb +8 -0
- data/lib/transbank/sdk/onepay/errors/invalid_options_error.rb +8 -0
- data/lib/transbank/sdk/onepay/errors/item_error.rb +8 -0
- data/lib/transbank/sdk/onepay/errors/refund_create_error.rb +8 -0
- data/lib/transbank/sdk/onepay/errors/response_error.rb +8 -0
- data/lib/transbank/sdk/onepay/errors/shopping_cart_error.rb +8 -0
- data/lib/transbank/sdk/onepay/errors/signature_error.rb +8 -0
- data/lib/transbank/sdk/onepay/errors/transaction_commit_error.rb +8 -0
- data/lib/transbank/sdk/onepay/errors/transaction_create_error.rb +8 -0
- data/lib/transbank/sdk/onepay/errors/transbank_error.rb +9 -0
- data/lib/transbank/sdk/onepay/models/channels.rb +15 -0
- data/lib/transbank/sdk/onepay/models/item.rb +103 -0
- data/lib/transbank/sdk/onepay/models/models.rb +10 -0
- data/lib/transbank/sdk/onepay/models/refund.rb +50 -0
- data/lib/transbank/sdk/onepay/models/shopping_cart.rb +65 -0
- data/lib/transbank/sdk/onepay/models/transaction.rb +143 -0
- data/lib/transbank/sdk/onepay/requests/refund_create_request.rb +45 -0
- data/lib/transbank/sdk/onepay/requests/request.rb +18 -0
- data/lib/transbank/sdk/onepay/requests/requests.rb +9 -0
- data/lib/transbank/sdk/onepay/requests/transaction_commit_request.rb +48 -0
- data/lib/transbank/sdk/onepay/requests/transaction_create_request.rb +85 -0
- data/lib/transbank/sdk/onepay/responses/refund_create_response.rb +24 -0
- data/lib/transbank/sdk/onepay/responses/response.rb +18 -0
- data/lib/transbank/sdk/onepay/responses/responses.rb +9 -0
- data/lib/transbank/sdk/onepay/responses/transaction_commit_response.rb +39 -0
- data/lib/transbank/sdk/onepay/responses/transaction_create_response.rb +32 -0
- data/lib/transbank/sdk/patpass/errors/integration_type_error.rb +8 -0
- data/lib/transbank/sdk/patpass/errors/patpass_error.rb +15 -0
- data/lib/transbank/sdk/patpass/patpass_by_webpay/base.rb +47 -0
- data/lib/transbank/sdk/patpass/patpass_by_webpay/errors/patpass_by_webpay_errors.rb +12 -0
- data/lib/transbank/sdk/patpass/patpass_by_webpay/errors/transaction_commit_error.rb +15 -0
- data/lib/transbank/sdk/patpass/patpass_by_webpay/errors/transaction_create_error.rb +15 -0
- data/lib/transbank/sdk/patpass/patpass_by_webpay/errors/transaction_status_error.rb +15 -0
- data/lib/transbank/sdk/patpass/patpass_by_webpay/options.rb +9 -0
- data/lib/transbank/sdk/patpass/patpass_by_webpay/patpass_by_webpay.rb +16 -0
- data/lib/transbank/sdk/patpass/patpass_by_webpay/responses/patpass_by_webpay_responses.rb +3 -0
- data/lib/transbank/sdk/patpass/patpass_by_webpay/responses/transaction_commit_response.rb +20 -0
- data/lib/transbank/sdk/patpass/patpass_by_webpay/responses/transaction_create_response.rb +15 -0
- data/lib/transbank/sdk/patpass/patpass_by_webpay/responses/transaction_status_response.rb +21 -0
- data/lib/transbank/sdk/patpass/patpass_by_webpay/transaction.rb +93 -0
- data/lib/transbank/sdk/patpass/patpass_comercio/base.rb +47 -0
- data/lib/transbank/sdk/patpass/patpass_comercio/errors/inscription_start_error.rb +15 -0
- data/lib/transbank/sdk/patpass/patpass_comercio/errors/inscription_status_error.rb +15 -0
- data/lib/transbank/sdk/patpass/patpass_comercio/errors/patpass_comercio_errors.rb +2 -0
- data/lib/transbank/sdk/patpass/patpass_comercio/inscription.rb +79 -0
- data/lib/transbank/sdk/patpass/patpass_comercio/options.rb +9 -0
- data/lib/transbank/sdk/patpass/patpass_comercio/patpass_comercio.rb +5 -0
- data/lib/transbank/sdk/patpass/patpass_comercio/responses/inscription_start_response.rb +13 -0
- data/lib/transbank/sdk/patpass/patpass_comercio/responses/inscription_status_response.rb +13 -0
- data/lib/transbank/sdk/patpass/patpass_comercio/responses/patpass_comercio_responses.rb +2 -0
- data/lib/transbank/sdk/transaccion_completa/base.rb +51 -0
- data/lib/transbank/sdk/transaccion_completa/errors/transaccion_completa_error.rb +16 -0
- data/lib/transbank/sdk/transaccion_completa/errors/transaccion_completa_errors.rb +7 -0
- data/lib/transbank/sdk/transaccion_completa/errors/transaction_capture_error.rb +14 -0
- data/lib/transbank/sdk/transaccion_completa/errors/transaction_commit_error.rb +14 -0
- data/lib/transbank/sdk/transaccion_completa/errors/transaction_create_error.rb +14 -0
- data/lib/transbank/sdk/transaccion_completa/errors/transaction_installments_error.rb +14 -0
- data/lib/transbank/sdk/transaccion_completa/errors/transaction_refund_error.rb +14 -0
- data/lib/transbank/sdk/transaccion_completa/errors/transaction_status_error.rb +14 -0
- data/lib/transbank/sdk/transaccion_completa/mall/mall_transaction.rb +197 -0
- data/lib/transbank/sdk/transaccion_completa/mall/responses/mall_transaction_capture_response.rb +12 -0
- data/lib/transbank/sdk/transaccion_completa/mall/responses/mall_transaction_commit_response.rb +15 -0
- data/lib/transbank/sdk/transaccion_completa/mall/responses/mall_transaction_installments_response.rb +11 -0
- data/lib/transbank/sdk/transaccion_completa/mall/responses/mall_transaction_responses.rb +4 -0
- data/lib/transbank/sdk/transaccion_completa/mall/responses/mall_transaction_status_response.rb +14 -0
- data/lib/transbank/sdk/transaccion_completa/options.rb +7 -0
- data/lib/transbank/sdk/transaccion_completa/responses/transaccion_completa_responses.rb +6 -0
- data/lib/transbank/sdk/transaccion_completa/responses/transaction_capture_response.rb +12 -0
- data/lib/transbank/sdk/transaccion_completa/responses/transaction_commit_response.rb +16 -0
- data/lib/transbank/sdk/transaccion_completa/responses/transaction_create_response.rb +10 -0
- data/lib/transbank/sdk/transaccion_completa/responses/transaction_installments_response.rb +13 -0
- data/lib/transbank/sdk/transaccion_completa/responses/transaction_refund_response.rb +14 -0
- data/lib/transbank/sdk/transaccion_completa/responses/transaction_status_response.rb +16 -0
- data/lib/transbank/sdk/transaccion_completa/transaccion_completa.rb +7 -0
- data/lib/transbank/sdk/transaccion_completa/transaction.rb +144 -0
- data/lib/transbank/sdk/transbank_error.rb +6 -0
- data/lib/transbank/sdk/utils/json_utils.rb +75 -0
- data/lib/transbank/sdk/utils/net_helper.rb +82 -0
- data/lib/transbank/sdk/utils/request_builder.rb +96 -0
- data/lib/transbank/sdk/utils/signature_utils.rb +49 -0
- data/lib/transbank/sdk/utils/utils.rb +9 -0
- data/lib/transbank/sdk/version.rb +5 -0
- data/lib/transbank/sdk/webpay/errors/integration_type_error.rb +8 -0
- data/lib/transbank/sdk/webpay/errors/webpay_error.rb +14 -0
- data/lib/transbank/sdk/webpay/webpay_plus/base.rb +74 -0
- data/lib/transbank/sdk/webpay/webpay_plus/deferred/deferred_transaction.rb +108 -0
- data/lib/transbank/sdk/webpay/webpay_plus/deferred/errors/transaction_capture_error.rb +16 -0
- data/lib/transbank/sdk/webpay/webpay_plus/deferred/errors/webpay_plus_deferred_errors.rb +1 -0
- data/lib/transbank/sdk/webpay/webpay_plus/deferred/responses/transaction_capture_response.rb +22 -0
- data/lib/transbank/sdk/webpay/webpay_plus/deferred/responses/webpay_plus_deferred_responses.rb +1 -0
- data/lib/transbank/sdk/webpay/webpay_plus/errors/transaction_commit_error.rb +17 -0
- data/lib/transbank/sdk/webpay/webpay_plus/errors/transaction_create_error.rb +16 -0
- data/lib/transbank/sdk/webpay/webpay_plus/errors/transaction_refund_error.rb +16 -0
- data/lib/transbank/sdk/webpay/webpay_plus/errors/transaction_status_error.rb +16 -0
- data/lib/transbank/sdk/webpay/webpay_plus/errors/webpay_plus_errors.rb +13 -0
- data/lib/transbank/sdk/webpay/webpay_plus/mall/mall_transaction.rb +88 -0
- data/lib/transbank/sdk/webpay/webpay_plus/mall/responses/mall_transaction_commit_response.rb +23 -0
- data/lib/transbank/sdk/webpay/webpay_plus/mall/responses/mall_transaction_status_response.rb +21 -0
- data/lib/transbank/sdk/webpay/webpay_plus/mall/responses/webpay_plus_mall_responses.rb +2 -0
- data/lib/transbank/sdk/webpay/webpay_plus/mall_deferred/mall_deferred_transaction.rb +109 -0
- data/lib/transbank/sdk/webpay/webpay_plus/options.rb +9 -0
- data/lib/transbank/sdk/webpay/webpay_plus/responses/transaction_commit_response.rb +20 -0
- data/lib/transbank/sdk/webpay/webpay_plus/responses/transaction_create_response.rb +15 -0
- data/lib/transbank/sdk/webpay/webpay_plus/responses/transaction_refund_response.rb +19 -0
- data/lib/transbank/sdk/webpay/webpay_plus/responses/transaction_status_response.rb +21 -0
- data/lib/transbank/sdk/webpay/webpay_plus/responses/webpay_plus_responses.rb +4 -0
- data/lib/transbank/sdk/webpay/webpay_plus/transaction.rb +89 -0
- data/lib/transbank/sdk/webpay/webpay_plus/webpay_plus.rb +24 -0
- data/lib/transbank/sdk.rb +27 -0
- data/sdk_test.sh +2 -0
- data/transbank-sdk.gemspec +35 -0
- metadata +340 -0
@@ -0,0 +1,73 @@
|
|
1
|
+
module Transbank
|
2
|
+
module Webpay
|
3
|
+
module Oneclick
|
4
|
+
class MallInscription
|
5
|
+
extend Transbank::Utils::NetHelper
|
6
|
+
|
7
|
+
INSCRIPTION_START_ENDPOINT = 'rswebpaytransaction/api/oneclick/v1.0/inscriptions'.freeze
|
8
|
+
INSCRIPTION_FINISH_ENDPOINT = 'rswebpaytransaction/api/oneclick/v1.0/inscriptions/:token'.freeze
|
9
|
+
INSCRIPTION_DELETE_ENDPOINT = 'rswebpaytransaction/api/oneclick/v1.0/inscriptions'.freeze
|
10
|
+
class << self
|
11
|
+
def start(user_name:, email:, response_url:, options: nil)
|
12
|
+
api_key = options&.api_key || default_integration_params[:api_key]
|
13
|
+
commerce_code = options&.commerce_code || default_integration_params[:commerce_code]
|
14
|
+
integration_type = options&.integration_type || default_integration_params[:integration_type]
|
15
|
+
base_url = integration_type.nil? ? Oneclick::Base::integration_type[:TEST] : Oneclick::Base.integration_type_url(integration_type)
|
16
|
+
|
17
|
+
url = base_url + INSCRIPTION_START_ENDPOINT
|
18
|
+
headers = webpay_headers(commerce_code: commerce_code, api_key: api_key)
|
19
|
+
|
20
|
+
body = {
|
21
|
+
username: user_name,
|
22
|
+
email: email,
|
23
|
+
response_url: response_url
|
24
|
+
}
|
25
|
+
resp = http_post(uri_string: url, body: body, headers: headers, camel_case_keys: false)
|
26
|
+
body = JSON.parse(resp.body)
|
27
|
+
return ::Transbank::Webpay::Oneclick::MallInscriptionStartResponse.new(body) if resp.kind_of? Net::HTTPSuccess
|
28
|
+
raise Oneclick::Errors::MallInscriptionStartError.new(body['error_message'], resp.code)
|
29
|
+
end
|
30
|
+
|
31
|
+
def finish(token:, options: nil)
|
32
|
+
api_key = options&.api_key || default_integration_params[:api_key]
|
33
|
+
commerce_code = options&.commerce_code || default_integration_params[:commerce_code]
|
34
|
+
integration_type = options&.integration_type || default_integration_params[:integration_type]
|
35
|
+
base_url = integration_type.nil? ? Oneclick::Base::integration_type[:TEST] : Oneclick::Base.integration_type_url(integration_type)
|
36
|
+
|
37
|
+
url = base_url + INSCRIPTION_FINISH_ENDPOINT.gsub(':token', token)
|
38
|
+
headers = webpay_headers(commerce_code: commerce_code, api_key: api_key)
|
39
|
+
|
40
|
+
resp = http_put(uri_string: url, headers: headers)
|
41
|
+
body = JSON.parse(resp.body)
|
42
|
+
return ::Transbank::Webpay::Oneclick::MallInscriptionFinishResponse.new(body) if resp.kind_of? Net::HTTPSuccess
|
43
|
+
raise Oneclick::Errors::MallInscriptionFinishError.new(body['error_message'], resp.code)
|
44
|
+
end
|
45
|
+
|
46
|
+
def delete(tbk_user:, user_name:, options: nil)
|
47
|
+
api_key = options&.api_key || default_integration_params[:api_key]
|
48
|
+
commerce_code = options&.commerce_code || default_integration_params[:commerce_code]
|
49
|
+
integration_type = options&.integration_type || default_integration_params[:integration_type]
|
50
|
+
base_url = integration_type.nil? ? Oneclick::Base::integration_type[:TEST] : Oneclick::Base.integration_type_url(integration_type)
|
51
|
+
|
52
|
+
url = base_url + INSCRIPTION_DELETE_ENDPOINT
|
53
|
+
headers = webpay_headers(commerce_code: commerce_code, api_key: api_key)
|
54
|
+
body = {tbk_user: tbk_user, username: user_name}
|
55
|
+
resp = http_delete(uri_string: url, body: body, headers: headers)
|
56
|
+
code = resp.code
|
57
|
+
return ::Transbank::Webpay::Oneclick::MallInscriptionDeleteResponse.new(code) if resp.kind_of? Net::HTTPSuccess
|
58
|
+
raise Oneclick::Errors::MallInscriptionDeleteError.new(body['error_message'], resp.code)
|
59
|
+
end
|
60
|
+
|
61
|
+
def default_integration_params
|
62
|
+
{
|
63
|
+
api_key: Oneclick::Base.api_key,
|
64
|
+
commerce_code: Oneclick::Base.commerce_code,
|
65
|
+
integration_type: Oneclick::Base::integration_type,
|
66
|
+
base_url: Oneclick::Base::current_integration_type_url
|
67
|
+
}
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
module Transbank
|
2
|
+
module Webpay
|
3
|
+
module Oneclick
|
4
|
+
class MallTransaction
|
5
|
+
extend Transbank::Utils::NetHelper
|
6
|
+
|
7
|
+
AUTHORIZE_TRANSACTION_ENDPOINT = 'rswebpaytransaction/api/oneclick/v1.0/transactions'.freeze
|
8
|
+
TRANSACTION_STATUS_ENDPOINT = 'rswebpaytransaction/api/oneclick/v1.0/transactions/:buy_order'.freeze
|
9
|
+
TRANSACTION_REFUND_ENDPOINT = 'rswebpaytransaction/api/oneclick/v1.0/transactions/:buy_order/refunds'.freeze
|
10
|
+
|
11
|
+
class << self
|
12
|
+
|
13
|
+
def authorize(username:, tbk_user:, parent_buy_order:, details:,
|
14
|
+
options: nil)
|
15
|
+
api_key = options&.api_key || default_integration_params[:api_key]
|
16
|
+
commerce_code = options&.commerce_code || default_integration_params[:commerce_code]
|
17
|
+
integration_type = options&.integration_type || default_integration_params[:integration_type]
|
18
|
+
base_url = integration_type.nil? ? Oneclick::Base::integration_type[:TEST] : Oneclick::Base.integration_type_url(integration_type)
|
19
|
+
|
20
|
+
url = base_url + AUTHORIZE_TRANSACTION_ENDPOINT
|
21
|
+
headers = webpay_headers(commerce_code: commerce_code, api_key: api_key)
|
22
|
+
|
23
|
+
details_array = details.map do |det|
|
24
|
+
hash = det.reduce({}) do |acc, (k, v)|
|
25
|
+
acc[k.to_s] = v
|
26
|
+
acc
|
27
|
+
end
|
28
|
+
# We need to make sure the hash's keys are strings (or symbols)
|
29
|
+
# since Ruby doesnt have hahes with indifferent access
|
30
|
+
# I chose to make them strings
|
31
|
+
details_hash = {}
|
32
|
+
details_hash[:amount] = hash.fetch('amount')
|
33
|
+
details_hash[:buy_order] = hash.fetch('buy_order')
|
34
|
+
details_hash[:commerce_code] = hash.fetch('commerce_code')
|
35
|
+
details_hash[:installments_number] = hash.fetch('installments_number')
|
36
|
+
details_hash
|
37
|
+
end
|
38
|
+
|
39
|
+
body = {
|
40
|
+
username: username,
|
41
|
+
tbk_user: tbk_user,
|
42
|
+
buy_order: parent_buy_order,
|
43
|
+
details: details_array
|
44
|
+
}
|
45
|
+
resp = http_post(uri_string: url, body: body, headers: headers, camel_case_keys: false)
|
46
|
+
body = JSON.parse(resp.body)
|
47
|
+
return ::Transbank::Webpay::Oneclick::MallTransactionAuthorizeResponse.new(body) if resp.kind_of? Net::HTTPSuccess
|
48
|
+
raise Oneclick::Errors::MallTransactionAuthorizeError.new(body['error_message'], resp.code)
|
49
|
+
end
|
50
|
+
|
51
|
+
def status(buy_order:, options: nil)
|
52
|
+
api_key = options&.api_key || default_integration_params[:api_key]
|
53
|
+
commerce_code = options&.commerce_code || default_integration_params[:commerce_code]
|
54
|
+
integration_type = options&.integration_type || default_integration_params[:integration_type]
|
55
|
+
base_url = integration_type.nil? ? Oneclick::Base::integration_type[:TEST] : Oneclick::Base.integration_type_url(integration_type)
|
56
|
+
|
57
|
+
url = base_url + TRANSACTION_STATUS_ENDPOINT.gsub(':buy_order', buy_order)
|
58
|
+
headers = webpay_headers(commerce_code: commerce_code, api_key: api_key)
|
59
|
+
resp = http_get(uri_string: url, headers: headers)
|
60
|
+
body = JSON.parse(resp.body)
|
61
|
+
return ::Transbank::Webpay::Oneclick::MallTransactionStatusResponse.new(body) if resp.kind_of? Net::HTTPSuccess
|
62
|
+
raise Oneclick::Errors::MallTransactionStatusError.new(body['error_message'], resp.code)
|
63
|
+
end
|
64
|
+
|
65
|
+
def refund(buy_order:, child_commerce_code:, child_buy_order:, amount:,
|
66
|
+
options: nil)
|
67
|
+
api_key = options&.api_key || default_integration_params[:api_key]
|
68
|
+
commerce_code = options&.commerce_code || default_integration_params[:commerce_code]
|
69
|
+
integration_type = options&.integration_type || default_integration_params[:integration_type]
|
70
|
+
base_url = integration_type.nil? ? Oneclick::Base::integration_type[:TEST] : Oneclick::Base.integration_type_url(integration_type)
|
71
|
+
|
72
|
+
url = base_url + TRANSACTION_REFUND_ENDPOINT.gsub(':buy_order', buy_order)
|
73
|
+
headers = webpay_headers(commerce_code: commerce_code, api_key: api_key)
|
74
|
+
body = {
|
75
|
+
detail_buy_order: child_buy_order,
|
76
|
+
commerce_code: child_commerce_code,
|
77
|
+
amount: amount
|
78
|
+
}
|
79
|
+
resp = http_post(uri_string: url, body: body, headers: headers, camel_case_keys: false)
|
80
|
+
body = JSON.parse(resp.body)
|
81
|
+
return ::Transbank::Webpay::Oneclick::MallTransactionRefundResponse.new(body) if resp.kind_of? Net::HTTPSuccess
|
82
|
+
raise Oneclick::Errors::MallTransactionRefundError.new(body['error_message'], resp.code)
|
83
|
+
end
|
84
|
+
|
85
|
+
def default_integration_params
|
86
|
+
{
|
87
|
+
api_key: Oneclick::Base.api_key,
|
88
|
+
commerce_code: Oneclick::Base.commerce_code,
|
89
|
+
integration_type: Oneclick::Base::integration_type,
|
90
|
+
base_url: Oneclick::Base::current_integration_type_url
|
91
|
+
}
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Transbank
|
2
|
+
module Webpay
|
3
|
+
module Oneclick
|
4
|
+
class MallTransactionAuthorizeResponse
|
5
|
+
FIELDS = [:buy_order, :session_id, :card_detail, :expiration_date,
|
6
|
+
:accounting_date, :transaction_date, :details]
|
7
|
+
|
8
|
+
attr_accessor *FIELDS
|
9
|
+
|
10
|
+
def initialize(json)
|
11
|
+
FIELDS.each {|field| send("#{field}=", json["#{field}"]) }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Transbank
|
2
|
+
module Webpay
|
3
|
+
module Oneclick
|
4
|
+
class MallTransactionRefundResponse
|
5
|
+
FIELDS = [:type, :authorization_code, :authorization_date,
|
6
|
+
:nullified_amount, :balance, :response_code]
|
7
|
+
|
8
|
+
attr_accessor *FIELDS
|
9
|
+
|
10
|
+
def initialize(json)
|
11
|
+
FIELDS.each {|field| send("#{field}=", json["#{field}"]) }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Transbank
|
2
|
+
module Webpay
|
3
|
+
module Oneclick
|
4
|
+
class MallTransactionStatusResponse
|
5
|
+
FIELDS = [:buy_order, :session_id, :card_detail, :expiration_date,
|
6
|
+
:accounting_date, :transaction_date, :details]
|
7
|
+
attr_accessor *FIELDS
|
8
|
+
|
9
|
+
def initialize(json)
|
10
|
+
FIELDS.each {|field| send("#{field}=", json["#{field}"]) }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,4 @@
|
|
1
|
+
require 'transbank/sdk/oneclick/mall/responses/mall_transaction_authorize_response'
|
2
|
+
require 'transbank/sdk/oneclick/mall/responses/mall_transaction_status_response'
|
3
|
+
require 'transbank/sdk/oneclick/mall/responses/mall_transaction_refund_response'
|
4
|
+
require 'transbank/sdk/oneclick/mall_deferred/responses/mall_deferred_transaction_capture_response'
|
data/lib/transbank/sdk/oneclick/mall_deferred/errors/mall_deferred_transaction_capture_error.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
module Transbank
|
2
|
+
module Webpay
|
3
|
+
module Oneclick
|
4
|
+
module Errors
|
5
|
+
class MallDeferredTransactionCaptureError < OneclickError
|
6
|
+
attr_accessor :code, :message
|
7
|
+
def initialize(message, code)
|
8
|
+
@code = code
|
9
|
+
@message = message
|
10
|
+
super(message, code)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Transbank
|
2
|
+
module Webpay
|
3
|
+
module Oneclick
|
4
|
+
class MallDeferredInscription < Transbank::Webpay::Oneclick::MallInscription
|
5
|
+
extend Transbank::Utils::NetHelper
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def default_integration_params
|
9
|
+
{
|
10
|
+
api_key: Oneclick::Base.api_key,
|
11
|
+
commerce_code: Oneclick::Base.commerce_code,
|
12
|
+
integration_type: Oneclick::Base::integration_type,
|
13
|
+
base_url: Oneclick::Base::current_integration_type_url
|
14
|
+
}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Transbank
|
2
|
+
module Webpay
|
3
|
+
module Oneclick
|
4
|
+
class MallDeferredTransaction < Transbank::Webpay::Oneclick::MallTransaction
|
5
|
+
extend Transbank::Utils::NetHelper
|
6
|
+
TRANSACTION_CAPTURE_ENDPOINT = 'rswebpaytransaction/api/oneclick/v1.0/transactions/capture'.freeze
|
7
|
+
|
8
|
+
class << self
|
9
|
+
|
10
|
+
def capture(child_commerce_code:, child_buy_order:, authorization_code:, amount:, options: nil)
|
11
|
+
api_key = options&.api_key || default_integration_params[:api_key]
|
12
|
+
commerce_code = options&.commerce_code || default_integration_params[:commerce_code]
|
13
|
+
integration_type = options&.integration_type || default_integration_params[:integration_type]
|
14
|
+
base_url = integration_type.nil? ? Oneclick::Base::integration_type[:TEST] : Oneclick::Base.integration_type_url(integration_type)
|
15
|
+
|
16
|
+
url = base_url + TRANSACTION_CAPTURE_ENDPOINT
|
17
|
+
headers = webpay_headers(commerce_code: commerce_code, api_key: api_key)
|
18
|
+
body = {
|
19
|
+
commerce_code: child_commerce_code,
|
20
|
+
buy_order: child_buy_order,
|
21
|
+
authorization_code: authorization_code,
|
22
|
+
capture_amount: amount
|
23
|
+
}
|
24
|
+
resp = http_put(uri_string: url, headers: headers, body: body)
|
25
|
+
body = JSON.parse(resp.body)
|
26
|
+
return ::Transbank::Webpay::Oneclick::MallDeferredTransactionCaptureResponse.new(body) if resp.kind_of? Net::HTTPSuccess
|
27
|
+
raise Oneclick::Errors::MallDeferredTransactionCaptureError.new(body['error_message'], resp.code)
|
28
|
+
end
|
29
|
+
|
30
|
+
def default_integration_params
|
31
|
+
{
|
32
|
+
api_key: Oneclick::Base.api_key,
|
33
|
+
commerce_code: Oneclick::Base.commerce_code,
|
34
|
+
integration_type: Oneclick::Base::integration_type,
|
35
|
+
base_url: Oneclick::Base::current_integration_type_url
|
36
|
+
}
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Transbank
|
2
|
+
module Webpay
|
3
|
+
module Oneclick
|
4
|
+
class MallDeferredTransactionCaptureResponse
|
5
|
+
|
6
|
+
FIELDS = %i[authorization_code authorization_date captured_amount response_code]
|
7
|
+
attr_accessor *FIELDS
|
8
|
+
|
9
|
+
def initialize(json)
|
10
|
+
FIELDS.each {|field| send("#{field}=", json["#{field}"]) }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'transbank/sdk/oneclick/base'
|
2
|
+
require 'transbank/sdk/oneclick/errors/oneclick_error'
|
3
|
+
require 'transbank/sdk/oneclick/inscription/inscription'
|
4
|
+
require 'transbank/sdk/oneclick/mall/oneclick_mall'
|
5
|
+
require 'transbank/sdk/oneclick/mall_deferred/mall_deferred_transaction'
|
6
|
+
require 'transbank/sdk/oneclick/mall_deferred/mall_deferred_inscription'
|
7
|
+
|
8
|
+
module Transbank
|
9
|
+
module Webpay
|
10
|
+
module Oneclick; end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
module Transbank
|
2
|
+
module Onepay
|
3
|
+
class Base
|
4
|
+
# The base class for Transbank Onepay
|
5
|
+
DEFAULT_CALLBACK = "http://no.callback.has/been.set".freeze
|
6
|
+
DEFAULT_API_KEY = 'dKVhq1WGt_XapIYirTXNyUKoWTDFfxaEV63-O5jcsdw'.freeze
|
7
|
+
DEFAULT_SHARED_SECRET = '?XW#WOLG##FBAGEAYSNQ5APD#JF@$AYZ'.freeze
|
8
|
+
|
9
|
+
@app_keys = {TEST: '1a0c0639-bd2f-4846-8d26-81f43187e797',
|
10
|
+
LIVE: '2B571C49-C1B6-4AD1-9806-592AC68023B7',
|
11
|
+
MOCK: '04533c31-fe7e-43ed-bbc4-1c8ab1538afp'}.freeze
|
12
|
+
@integration_types = {TEST: 'https://onepay.ionix.cl'.freeze,
|
13
|
+
LIVE: 'https://www.onepay.cl'.freeze,
|
14
|
+
MOCK: 'https://transbank-onepay-ewallet-mock.herokuapp.com'.freeze}.freeze
|
15
|
+
@callback_url = self::DEFAULT_CALLBACK
|
16
|
+
@api_key = ENV['ONEPAY_API_KEY'].nil? ? DEFAULT_API_KEY : ENV['ONEPAY_API_KEY']
|
17
|
+
@shared_secret = ENV['ONEPAY_SHARED_SECRET'].nil? ? DEFAULT_SHARED_SECRET : ENV['ONEPAY_SHARED_SECRET']
|
18
|
+
|
19
|
+
@integration_type = :TEST
|
20
|
+
@app_scheme = nil
|
21
|
+
@default_channel = Transbank::Onepay::Channel::WEB
|
22
|
+
|
23
|
+
class << self
|
24
|
+
# Contains all valid integration types
|
25
|
+
# @return [Hash<String, String>]
|
26
|
+
attr_reader :integration_types
|
27
|
+
|
28
|
+
# Your Api key, given by Transbank
|
29
|
+
# @return [String]
|
30
|
+
attr_writer :api_key
|
31
|
+
|
32
|
+
# Your callback URL, used to resume the payment process after validating with
|
33
|
+
# Transbank when paying on Channel::MOBILE
|
34
|
+
# @param [String]
|
35
|
+
# @return [String]
|
36
|
+
attr_accessor :callback_url
|
37
|
+
|
38
|
+
# Your shared secret, given by Transbank
|
39
|
+
# @param [String]
|
40
|
+
# @return [String]
|
41
|
+
attr_writer :shared_secret
|
42
|
+
|
43
|
+
# The current integration type
|
44
|
+
# @param [String, Symbol]
|
45
|
+
# @return [Symbol]
|
46
|
+
attr_reader :integration_type
|
47
|
+
|
48
|
+
# The URI for the app (eg the Android Intent that starts the app/the iOS
|
49
|
+
# equivalent)
|
50
|
+
# @param [String]
|
51
|
+
# @return [String]
|
52
|
+
attr_writer :app_scheme
|
53
|
+
|
54
|
+
# The default channel. Value must be in Channel.values
|
55
|
+
# @return [String] One of the values from Channel.values
|
56
|
+
attr_reader :default_channel
|
57
|
+
|
58
|
+
# The width and height in pixels for the returned QR.
|
59
|
+
# @param [Integer]
|
60
|
+
# @return [Integer]
|
61
|
+
attr_accessor :qr_width_height
|
62
|
+
|
63
|
+
# The url of the commerce logo to be displayed in the Onepay mobile app.
|
64
|
+
# @param [String]
|
65
|
+
# @return [String]
|
66
|
+
attr_accessor :commerce_logo_url
|
67
|
+
|
68
|
+
# @return [String] the URL that is used by the current integration type
|
69
|
+
def current_integration_type_url
|
70
|
+
@integration_types[@integration_type]
|
71
|
+
end
|
72
|
+
|
73
|
+
# @return [String] the app key used by the current integration type
|
74
|
+
def current_integration_type_app_key
|
75
|
+
@app_keys[@integration_type]
|
76
|
+
end
|
77
|
+
|
78
|
+
# Sets the current integration type
|
79
|
+
# @param type [String] Type of integration to be set. Must be included one
|
80
|
+
# of the keys of self.integration_types
|
81
|
+
# @raise [IntegrationTypeError] if the given type is not valid
|
82
|
+
def integration_type=(type)
|
83
|
+
return @integration_type = type.to_sym unless @integration_types[type.to_sym].nil?
|
84
|
+
valid_values = @integration_types.keys.join(', ')
|
85
|
+
raise Transbank::Onepay::Errors::IntegrationTypeError, "Invalid integration type, valid values are #{valid_values}"
|
86
|
+
end
|
87
|
+
|
88
|
+
# Returns the app_scheme
|
89
|
+
# @return [String] the app scheme, either the one set on @app_scheme or,
|
90
|
+
# failing that, the value of ENV['ONEPAY_APP_SCHEME'] (your env variable)
|
91
|
+
def app_scheme
|
92
|
+
return ENV['ONEPAY_APP_SCHEME'] unless @app_scheme
|
93
|
+
@app_scheme
|
94
|
+
end
|
95
|
+
|
96
|
+
def api_key
|
97
|
+
return ENV['ONEPAY_API_KEY'] if @api_key.nil?
|
98
|
+
@api_key
|
99
|
+
end
|
100
|
+
|
101
|
+
# Returns the 'ONEPAY_API_KEY' env variable, or, if ONEPAY_API_KEY
|
102
|
+
# doesn't exist, returns a default api key
|
103
|
+
# @return [String] ENV['ONEPAY_API_KEY] or DEFAULT_API_KEY
|
104
|
+
def default_api_key
|
105
|
+
env_api_key = ENV['ONEPAY_API_KEY']
|
106
|
+
env_api_key.nil? ? DEFAULT_API_KEY : env_api_key
|
107
|
+
end
|
108
|
+
|
109
|
+
def shared_secret
|
110
|
+
return ENV['ONEPAY_SHARED_SECRET'] if @shared_secret.nil?
|
111
|
+
@shared_secret
|
112
|
+
end
|
113
|
+
|
114
|
+
# Returns the 'ONEPAY_SHARED_SECRET' env variable, or, if ONEPAY_SHARED_SECRET
|
115
|
+
# doesn't exist, returns a default shared secret
|
116
|
+
# @return [String] ENV['ONEPAY_SHARED_SECRET'] or DEFAULT_SHARED_SECRET
|
117
|
+
def default_shared_secret
|
118
|
+
env_shared_secret = ENV['ONEPAY_SHARED_SECRET']
|
119
|
+
env_shared_secret.nil? ? DEFAULT_SHARED_SECRET : env_shared_secret
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'transbank/sdk/onepay/errors/transbank_error'
|
2
|
+
require 'transbank/sdk/onepay/errors/integration_type_error'
|
3
|
+
require 'transbank/sdk/onepay/errors/invalid_options_error'
|
4
|
+
require 'transbank/sdk/onepay/errors/item_error'
|
5
|
+
require 'transbank/sdk/onepay/errors/refund_create_error'
|
6
|
+
require 'transbank/sdk/onepay/errors/response_error'
|
7
|
+
require 'transbank/sdk/onepay/errors/shopping_cart_error'
|
8
|
+
require 'transbank/sdk/onepay/errors/signature_error'
|
9
|
+
require 'transbank/sdk/onepay/errors/transaction_commit_error'
|
10
|
+
require 'transbank/sdk/onepay/errors/transaction_create_error'
|
11
|
+
|
12
|
+
module Transbank
|
13
|
+
module Onepay
|
14
|
+
module Errors
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Transbank
|
2
|
+
module Onepay
|
3
|
+
class Channel
|
4
|
+
## Contains static values for all possible channel values
|
5
|
+
|
6
|
+
WEB = 'WEB'.freeze
|
7
|
+
MOBILE = 'MOBILE'.freeze
|
8
|
+
APP = 'APP'.freeze
|
9
|
+
|
10
|
+
def self.values
|
11
|
+
constants.map { |const| const_get const }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|