tbk-sdk 1.5.0.pre.ruby2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,32 @@
|
|
|
1
|
+
module Transbank
|
|
2
|
+
module Onepay
|
|
3
|
+
# Serializes the response to a TransactionCreateRequest
|
|
4
|
+
class TransactionCreateResponse
|
|
5
|
+
include Response
|
|
6
|
+
|
|
7
|
+
attr_accessor :occ, :ott, :external_unique_number, :qr_code_as_base64,
|
|
8
|
+
:issued_at, :signature
|
|
9
|
+
|
|
10
|
+
SIGNATURE_PARAMS = [:occ,
|
|
11
|
+
:external_unique_number,
|
|
12
|
+
:issued_at].freeze
|
|
13
|
+
# @raise [KeyError] upon trying to fetch a missing key from the response
|
|
14
|
+
def initialize(json)
|
|
15
|
+
result = json.fetch('result')
|
|
16
|
+
@response_code = json.fetch('responseCode')
|
|
17
|
+
@description = json.fetch('description')
|
|
18
|
+
@occ = result.fetch('occ')
|
|
19
|
+
@ott = result.fetch('ott')
|
|
20
|
+
@external_unique_number = result.fetch('externalUniqueNumber')
|
|
21
|
+
@qr_code_as_base64 = result.fetch('qrCodeAsBase64')
|
|
22
|
+
@issued_at = result.fetch('issuedAt')
|
|
23
|
+
@signature = result.fetch('signature')
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def sign(secret)
|
|
27
|
+
@signature = signature_for(to_data, secret)
|
|
28
|
+
self
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module Transbank
|
|
2
|
+
module Patpass
|
|
3
|
+
module Errors
|
|
4
|
+
class PatpassError < ::Transbank::Errors::TransbankError
|
|
5
|
+
attr_accessor :message, :code
|
|
6
|
+
def initialize(message, code)
|
|
7
|
+
self.message = message
|
|
8
|
+
self.code = code
|
|
9
|
+
super(message)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
module Transbank
|
|
2
|
+
module Patpass
|
|
3
|
+
module PatpassByWebpay
|
|
4
|
+
class Base
|
|
5
|
+
|
|
6
|
+
DEFAULT_API_KEY = '579B532A7440BB0C9079DED94D31EA1615BACEB56610332264630D42D0A36B1C'.freeze
|
|
7
|
+
DEFAULT_COMMERCE_CODE = '597055555550'.freeze
|
|
8
|
+
|
|
9
|
+
@api_key = DEFAULT_API_KEY
|
|
10
|
+
@commerce_code = DEFAULT_COMMERCE_CODE
|
|
11
|
+
@integration_type = :TEST
|
|
12
|
+
@integration_types = {
|
|
13
|
+
LIVE: "https://webpay3g.transbank.cl/",
|
|
14
|
+
TEST: "https://webpay3gint.transbank.cl/"
|
|
15
|
+
}
|
|
16
|
+
class << self
|
|
17
|
+
attr_reader :integration_types
|
|
18
|
+
attr_accessor :api_key, :integration_type, :commerce_code
|
|
19
|
+
|
|
20
|
+
def integration_type_url(integration_type)
|
|
21
|
+
type = integration_type.upcase.to_sym
|
|
22
|
+
return @integration_types[type] unless @integration_types[type].nil?
|
|
23
|
+
valid_values = @integration_types.keys.join(', ')
|
|
24
|
+
raise Transbank::Patpass::Errors::IntegrationTypeError, "Invalid integration type, valid values are #{valid_values}"
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def current_integration_type_url
|
|
28
|
+
@integration_types[@integration_type]
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def integration_type=(integration_type)
|
|
32
|
+
type = integration_type.upcase.to_sym
|
|
33
|
+
return @integration_type = type unless @integration_types[type].nil?
|
|
34
|
+
valid_values = @integration_types.keys.join(', ')
|
|
35
|
+
raise Transbank::Patpass::Errors::IntegrationTypeError, "Invalid integration type, valid values are #{valid_values}"
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def configure_for_testing
|
|
39
|
+
@api_key = DEFAULT_API_KEY
|
|
40
|
+
@commerce_code = DEFAULT_COMMERCE_CODE
|
|
41
|
+
self.integration_type = :TEST
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
require 'transbank/sdk/patpass/patpass_by_webpay/errors/transaction_create_error'
|
|
2
|
+
require 'transbank/sdk/patpass/patpass_by_webpay/errors/transaction_commit_error'
|
|
3
|
+
require 'transbank/sdk/patpass/patpass_by_webpay/errors/transaction_status_error'
|
|
4
|
+
|
|
5
|
+
module Transbank
|
|
6
|
+
module Patpass
|
|
7
|
+
module PatpassByWebpay
|
|
8
|
+
module Errors
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module Transbank
|
|
2
|
+
module Patpass
|
|
3
|
+
module PatpassByWebpay
|
|
4
|
+
module Errors
|
|
5
|
+
class TransactionCommitError < ::Transbank::Patpass::Errors::PatpassError
|
|
6
|
+
attr_reader :code
|
|
7
|
+
def initialize(message, code)
|
|
8
|
+
@code = code
|
|
9
|
+
super(message, code)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module Transbank
|
|
2
|
+
module Patpass
|
|
3
|
+
module PatpassByWebpay
|
|
4
|
+
module Errors
|
|
5
|
+
class TransactionCreateError < ::Transbank::Patpass::Errors::PatpassError
|
|
6
|
+
attr_reader :code
|
|
7
|
+
def initialize(message, code)
|
|
8
|
+
@code = code
|
|
9
|
+
super(message, code)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module Transbank
|
|
2
|
+
module Patpass
|
|
3
|
+
module PatpassByWebpay
|
|
4
|
+
module Errors
|
|
5
|
+
class TransactionStatusError < ::Transbank::Patpass::Errors::PatpassError
|
|
6
|
+
attr_reader :code
|
|
7
|
+
def initialize(message, code)
|
|
8
|
+
@code = code
|
|
9
|
+
super(message, code)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require 'transbank/sdk/patpass/errors/patpass_error'
|
|
2
|
+
require 'transbank/sdk/patpass/errors/integration_type_error'
|
|
3
|
+
require 'transbank/sdk/patpass/patpass_by_webpay/errors/patpass_by_webpay_errors'
|
|
4
|
+
require 'transbank/sdk/patpass/patpass_by_webpay/responses/patpass_by_webpay_responses'
|
|
5
|
+
|
|
6
|
+
require 'transbank/sdk/patpass/patpass_by_webpay/base'
|
|
7
|
+
require 'transbank/sdk/patpass/patpass_by_webpay/options'
|
|
8
|
+
require 'transbank/sdk/patpass/patpass_by_webpay/transaction'
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
module Transbank
|
|
12
|
+
module Patpass
|
|
13
|
+
module PatpassByWebpay
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module Transbank
|
|
2
|
+
module Patpass
|
|
3
|
+
module PatpassByWebpay
|
|
4
|
+
class TransactionCommitResponse
|
|
5
|
+
|
|
6
|
+
FIELDS =
|
|
7
|
+
[:vci, :amount, :buy_order, :session_id,
|
|
8
|
+
:card_detail, :accounting_date, :transaction_date,
|
|
9
|
+
:authorization_code, :payment_type_code, :response_code,
|
|
10
|
+
:installments_amount, :installments_number, :balance]
|
|
11
|
+
|
|
12
|
+
attr_accessor *FIELDS
|
|
13
|
+
|
|
14
|
+
def initialize(json)
|
|
15
|
+
FIELDS.each {|field| send("#{field}=", json["#{field}"]) }
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module Transbank
|
|
2
|
+
module Patpass
|
|
3
|
+
module PatpassByWebpay
|
|
4
|
+
class TransactionStatusResponse
|
|
5
|
+
|
|
6
|
+
FIELDS =
|
|
7
|
+
[:vci, :amount, :buy_order, :session_id,
|
|
8
|
+
:card_detail, :accounting_date, :transaction_date,
|
|
9
|
+
:authorization_code, :payment_type_code, :response_code,
|
|
10
|
+
:installments_amount, :installments_number, :balance]
|
|
11
|
+
|
|
12
|
+
attr_accessor *FIELDS
|
|
13
|
+
|
|
14
|
+
def initialize(json)
|
|
15
|
+
FIELDS.each {|field| send("#{field}=", json["#{field}"]) }
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
module Transbank
|
|
2
|
+
module Patpass
|
|
3
|
+
module PatpassByWebpay
|
|
4
|
+
class Transaction
|
|
5
|
+
extend Transbank::Utils::NetHelper
|
|
6
|
+
CREATE_TRANSACTION_ENDPOINT = 'rswebpaytransaction/api/webpay/v1.0/transactions'
|
|
7
|
+
COMMIT_TRANSACTION_ENDPOINT = 'rswebpaytransaction/api/webpay/v1.0/transactions'
|
|
8
|
+
TRANSACTION_STATUS_ENDPOINT = 'rswebpaytransaction/api/webpay/v1.0/transactions'
|
|
9
|
+
|
|
10
|
+
class << self
|
|
11
|
+
|
|
12
|
+
def create(buy_order:, session_id:, amount:, return_url:, details: ,options: nil)
|
|
13
|
+
|
|
14
|
+
api_key = options&.api_key || default_integration_params[:api_key]
|
|
15
|
+
commerce_code = options&.commerce_code || default_integration_params[:commerce_code]
|
|
16
|
+
integration_type = options&.integration_type || default_integration_params[:integration_type]
|
|
17
|
+
base_url = integration_type.nil? ? PatpassByWebpay::Base::integration_types[:TEST] : PatpassByWebpay::Base.integration_type_url(integration_type)
|
|
18
|
+
|
|
19
|
+
wpm_detail = wpm_details(details)
|
|
20
|
+
body = {
|
|
21
|
+
buy_order: buy_order,
|
|
22
|
+
session_id: session_id,
|
|
23
|
+
amount: amount,
|
|
24
|
+
return_url: return_url,
|
|
25
|
+
wpm_detail: wpm_detail
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
url = base_url + CREATE_TRANSACTION_ENDPOINT
|
|
29
|
+
headers = webpay_headers(commerce_code: commerce_code, api_key: api_key)
|
|
30
|
+
resp = http_post(uri_string: url, body: body, headers: headers, camel_case_keys: false)
|
|
31
|
+
body = JSON.parse(resp.body)
|
|
32
|
+
|
|
33
|
+
return ::Transbank::Patpass::PatpassByWebpay::TransactionCreateResponse.new(body) if resp.kind_of? Net::HTTPSuccess
|
|
34
|
+
raise Errors::TransactionCreateError.new(body['error_message'], resp.code)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def commit(token:, options: nil)
|
|
38
|
+
|
|
39
|
+
api_key = options&.api_key || default_integration_params[:api_key]
|
|
40
|
+
commerce_code = options&.commerce_code || default_integration_params[:commerce_code]
|
|
41
|
+
base_url = PatpassByWebpay::Base.integration_types[options&.integration_type] || default_integration_params[:base_url]
|
|
42
|
+
|
|
43
|
+
url = base_url + COMMIT_TRANSACTION_ENDPOINT + "/#{token}"
|
|
44
|
+
headers = webpay_headers(commerce_code: commerce_code, api_key: api_key)
|
|
45
|
+
|
|
46
|
+
resp = http_put(uri_string: url, body: nil, headers: headers)
|
|
47
|
+
body = JSON.parse(resp.body)
|
|
48
|
+
return ::Transbank::Patpass::PatpassByWebpay::TransactionCommitResponse.new(body) if resp.kind_of? Net::HTTPSuccess
|
|
49
|
+
raise Errors::TransactionCommitError.new(body['error_message'], resp.code)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def status(token:, options: nil)
|
|
53
|
+
api_key = options&.api_key || default_integration_params[:api_key]
|
|
54
|
+
commerce_code = options&.commerce_code || default_integration_params[:commerce_code]
|
|
55
|
+
base_url = PatpassByWebpay::Base.integration_types[options&.integration_type] || default_integration_params[:base_url]
|
|
56
|
+
|
|
57
|
+
url = base_url + "#{TRANSACTION_STATUS_ENDPOINT}/#{token}"
|
|
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::Patpass::PatpassByWebpay::TransactionStatusResponse.new(body) if resp.kind_of? Net::HTTPSuccess
|
|
62
|
+
raise Errors::TransactionStatusError.new(body['error_message'], resp.code)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def default_integration_params
|
|
66
|
+
{
|
|
67
|
+
api_key: PatpassByWebpay::Base.api_key,
|
|
68
|
+
commerce_code: PatpassByWebpay::Base.commerce_code,
|
|
69
|
+
base_url: PatpassByWebpay::Base::current_integration_type_url
|
|
70
|
+
}
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
private
|
|
74
|
+
def wpm_details(details)
|
|
75
|
+
# Check against the wpm_detail_fields
|
|
76
|
+
# If one is missing, KeyError will be raised
|
|
77
|
+
wpm_detail_fields.reduce({}) do |acc, field|
|
|
78
|
+
acc[field] = details.fetch(field) { details.fetch(field.to_s) }
|
|
79
|
+
acc
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def wpm_detail_fields
|
|
84
|
+
%i(service_id card_holder_id card_holder_name card_holder_last_name1
|
|
85
|
+
card_holder_last_name2 card_holder_mail cellphone_number expiration_date
|
|
86
|
+
commerce_mail uf_flag)
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
module Transbank
|
|
2
|
+
module Patpass
|
|
3
|
+
module PatpassComercio
|
|
4
|
+
class Base
|
|
5
|
+
|
|
6
|
+
DEFAULT_API_KEY = 'cxxXQgGD9vrVe4M41FIt'.freeze
|
|
7
|
+
DEFAULT_COMMERCE_CODE = '28299257'.freeze
|
|
8
|
+
|
|
9
|
+
@api_key = DEFAULT_API_KEY
|
|
10
|
+
@commerce_code = DEFAULT_COMMERCE_CODE
|
|
11
|
+
@integration_type = :TEST
|
|
12
|
+
@integration_types = {
|
|
13
|
+
LIVE: "https://www.pagoautomaticocontarjetas.cl/",
|
|
14
|
+
TEST: "https://pagoautomaticocontarjetasint.transbank.cl/"
|
|
15
|
+
}
|
|
16
|
+
class << self
|
|
17
|
+
attr_reader :integration_types
|
|
18
|
+
attr_accessor :api_key, :integration_type, :commerce_code
|
|
19
|
+
|
|
20
|
+
def integration_type_url(integration_type)
|
|
21
|
+
type = integration_type.upcase.to_sym
|
|
22
|
+
return @integration_types[type] unless @integration_types[type].nil?
|
|
23
|
+
valid_values = @integration_types.keys.join(', ')
|
|
24
|
+
raise Transbank::Patpass::Errors::IntegrationTypeError, "Invalid integration type, valid values are #{valid_values}"
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def current_integration_type_url
|
|
28
|
+
@integration_types[@integration_type]
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def integration_type=(integration_type)
|
|
32
|
+
type = integration_type.upcase.to_sym
|
|
33
|
+
return @integration_type = type unless @integration_types[type].nil?
|
|
34
|
+
valid_values = @integration_types.keys.join(', ')
|
|
35
|
+
raise Transbank::Patpass::Errors::IntegrationTypeError, "Invalid integration type, valid values are #{valid_values}"
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def configure_for_testing
|
|
39
|
+
@api_key = DEFAULT_API_KEY
|
|
40
|
+
@commerce_code = DEFAULT_COMMERCE_CODE
|
|
41
|
+
self.integration_type = :TEST
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module Transbank
|
|
2
|
+
module Patpass
|
|
3
|
+
module PatpassComercio
|
|
4
|
+
module Errors
|
|
5
|
+
class InscriptionStartError < ::Transbank::Patpass::Errors::PatpassError
|
|
6
|
+
attr_reader :code
|
|
7
|
+
def initialize(message, code)
|
|
8
|
+
@code = code
|
|
9
|
+
super(message, code)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module Transbank
|
|
2
|
+
module Patpass
|
|
3
|
+
module PatpassComercio
|
|
4
|
+
module Errors
|
|
5
|
+
class InscriptionStatusError < ::Transbank::Patpass::Errors::PatpassError
|
|
6
|
+
attr_reader :code
|
|
7
|
+
def initialize(message, code)
|
|
8
|
+
@code = code
|
|
9
|
+
super(message, code)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
module Transbank
|
|
2
|
+
module Patpass
|
|
3
|
+
module PatpassComercio
|
|
4
|
+
class Inscription
|
|
5
|
+
extend Utils::NetHelper
|
|
6
|
+
|
|
7
|
+
START_INSCRIPTION_ENDPOINT = 'restpatpass/v1/services/patInscription'.freeze
|
|
8
|
+
INSCRIPTION_STATUS_ENDPOINT = 'restpatpass/v1/services/status'.freeze
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
FIELDS = %i(
|
|
12
|
+
url name first_last_name second_last_name rut service_id final_url max_amount
|
|
13
|
+
phone_number mobile_number patpass_name person_email commerce_email address city
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
class << self
|
|
17
|
+
def start(url:, name:, first_last_name:, second_last_name:, rut:, service_id:, final_url:, max_amount:,
|
|
18
|
+
phone_number:, mobile_number:, patpass_name:, person_email:, commerce_email:, address:, city:, options: nil)
|
|
19
|
+
api_key = options&.api_key || default_integration_params[:api_key]
|
|
20
|
+
commerce_code = options&.commerce_code || default_integration_params[:commerce_code]
|
|
21
|
+
integration_type = options&.integration_type || default_integration_params[:integration_type]
|
|
22
|
+
base_url = integration_type.nil? ? PatpassComercio::Base::integration_types[:TEST] : PatpassComercio::Base.integration_type_url(integration_type)
|
|
23
|
+
|
|
24
|
+
body = {
|
|
25
|
+
url: url,
|
|
26
|
+
nombre: name,
|
|
27
|
+
pApellido: first_last_name,
|
|
28
|
+
sApellido: second_last_name,
|
|
29
|
+
rut: rut,
|
|
30
|
+
serviceId: service_id,
|
|
31
|
+
finalUrl: final_url,
|
|
32
|
+
commerceCode: commerce_code,
|
|
33
|
+
montoMaximo: max_amount,
|
|
34
|
+
telefonoFijo: phone_number,
|
|
35
|
+
telefonoCelular: mobile_number,
|
|
36
|
+
nombrePatPass: patpass_name,
|
|
37
|
+
correoPersona: person_email,
|
|
38
|
+
correoComercio: commerce_email,
|
|
39
|
+
direccion: address,
|
|
40
|
+
ciudad: city
|
|
41
|
+
}
|
|
42
|
+
url = base_url + START_INSCRIPTION_ENDPOINT
|
|
43
|
+
headers = patpass_comercio_headers(commerce_code: commerce_code, api_key: api_key)
|
|
44
|
+
resp = http_post(uri_string: url, body: body, headers: headers, camel_case_keys: false)
|
|
45
|
+
resp_body = JSON.parse(resp.body)
|
|
46
|
+
return ::Transbank::Patpass::PatpassComercio::InscriptionStartResponse.new(resp_body) if resp.kind_of? Net::HTTPSuccess
|
|
47
|
+
raise Errors::InscriptionStartError.new(resp_body['description'], resp.code)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def status(token: ,options: nil)
|
|
51
|
+
api_key = options&.api_key || default_integration_params[:api_key]
|
|
52
|
+
commerce_code = options&.commerce_code || default_integration_params[:commerce_code]
|
|
53
|
+
integration_type = options&.integration_type || default_integration_params[:integration_type]
|
|
54
|
+
base_url = integration_type.nil? ? PatpassComercio::Base::integration_types[:TEST] : PatpassComercio::Base.integration_type_url(integration_type)
|
|
55
|
+
|
|
56
|
+
body = {
|
|
57
|
+
token: token
|
|
58
|
+
}
|
|
59
|
+
url = base_url + INSCRIPTION_STATUS_ENDPOINT
|
|
60
|
+
headers = patpass_comercio_headers(commerce_code: commerce_code, api_key: api_key)
|
|
61
|
+
resp = http_post(uri_string: url, body: body, headers: headers, camel_case_keys: false)
|
|
62
|
+
resp_body = JSON.parse(resp.body)
|
|
63
|
+
return ::Transbank::Patpass::PatpassComercio::InscriptionStatusResponse.new(resp_body) if resp.kind_of? Net::HTTPSuccess
|
|
64
|
+
raise Errors::InscriptionStatusError.new(resp_body['description'], resp.code)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def default_integration_params
|
|
68
|
+
{
|
|
69
|
+
api_key: Patpass::PatpassComercio::Base.api_key,
|
|
70
|
+
commerce_code: Patpass::PatpassComercio::Base.commerce_code,
|
|
71
|
+
integration_type: Patpass::PatpassComercio::Base::integration_type,
|
|
72
|
+
base_url: Patpass::PatpassComercio::Base::current_integration_type_url
|
|
73
|
+
}
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
require 'transbank/sdk/patpass/patpass_comercio/errors/patpass_comercio_errors'
|
|
2
|
+
require 'transbank/sdk/patpass/patpass_comercio/responses/patpass_comercio_responses'
|
|
3
|
+
require 'transbank/sdk/patpass/patpass_comercio/base'
|
|
4
|
+
require 'transbank/sdk/patpass/patpass_comercio/options'
|
|
5
|
+
require 'transbank/sdk/patpass/patpass_comercio/inscription'
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module Transbank
|
|
2
|
+
module Patpass
|
|
3
|
+
module PatpassComercio
|
|
4
|
+
class InscriptionStatusResponse
|
|
5
|
+
attr_accessor :authorized, :voucher_url
|
|
6
|
+
def initialize(json)
|
|
7
|
+
self.authorized = json['authorized']
|
|
8
|
+
self.voucher_url = json['voucherUrl']
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
module Transbank
|
|
2
|
+
module TransaccionCompleta
|
|
3
|
+
class Base
|
|
4
|
+
DEFAULT_API_KEY = '579B532A7440BB0C9079DED94D31EA1615BACEB56610332264630D42D0A36B1C'.freeze
|
|
5
|
+
DEFAULT_COMMERCE_CODE = '597055555530'.freeze
|
|
6
|
+
|
|
7
|
+
DEFAULT_MALL_COMMERCE_CODE = '597055555551'.freeze
|
|
8
|
+
DEFAULT_MALL_CHILD_COMMERCE_CODES = ['597055555552'.freeze, '597055555553'.freeze].freeze
|
|
9
|
+
|
|
10
|
+
@api_key = DEFAULT_API_KEY
|
|
11
|
+
@commerce_code = DEFAULT_COMMERCE_CODE
|
|
12
|
+
@integration_type = :TEST
|
|
13
|
+
@integration_types = {
|
|
14
|
+
LIVE: 'https://webpay3g.transbank.cl/',
|
|
15
|
+
TEST: 'https://webpay3gint.transbank.cl/'
|
|
16
|
+
}
|
|
17
|
+
class << self
|
|
18
|
+
attr_reader :integration_types
|
|
19
|
+
attr_accessor :api_key, :integration_type, :commerce_code
|
|
20
|
+
|
|
21
|
+
def integration_type_url(integration_type)
|
|
22
|
+
type = integration_type.upcase.to_sym
|
|
23
|
+
return @integration_types[type] unless @integration_types[type].nil?
|
|
24
|
+
|
|
25
|
+
valid_values = @integration_types.keys.join(', ')
|
|
26
|
+
raise Transbank::Webpay::Errors::IntegrationTypeError,
|
|
27
|
+
"Invalid integration type, valid values are #{valid_values}"
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def current_integration_type_url
|
|
31
|
+
@integration_types[@integration_type]
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def integration_type=(integration_type)
|
|
35
|
+
type = integration_type.upcase.to_sym
|
|
36
|
+
return @integration_type = type unless @integration_types[type].nil?
|
|
37
|
+
|
|
38
|
+
valid_values = @integration_types.keys.join(', ')
|
|
39
|
+
raise Transbank::Webpay::Errors::IntegrationTypeError,
|
|
40
|
+
"Invalid integration type, valid values are #{valid_values}"
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def configure_for_testing
|
|
44
|
+
@api_key = DEFAULT_API_KEY
|
|
45
|
+
@commerce_code = DEFAULT_COMMERCE_CODE
|
|
46
|
+
self.integration_type = :TEST
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module Transbank
|
|
2
|
+
module TransaccionCompleta
|
|
3
|
+
module Errors
|
|
4
|
+
class TransaccionCompletaError < ::Transbank::Errors::TransbankError
|
|
5
|
+
attr_accessor :code, :message
|
|
6
|
+
|
|
7
|
+
def initialize(message, code = nil)
|
|
8
|
+
@message = message
|
|
9
|
+
@code = code
|
|
10
|
+
super(message)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
require 'transbank/sdk/transaccion_completa/errors/transaccion_completa_error'
|
|
2
|
+
require 'transbank/sdk/transaccion_completa/errors/transaction_create_error'
|
|
3
|
+
require 'transbank/sdk/transaccion_completa/errors/transaction_commit_error'
|
|
4
|
+
require 'transbank/sdk/transaccion_completa/errors/transaction_installments_error'
|
|
5
|
+
require 'transbank/sdk/transaccion_completa/errors/transaction_refund_error'
|
|
6
|
+
require 'transbank/sdk/transaccion_completa/errors/transaction_status_error'
|
|
7
|
+
require 'transbank/sdk/transaccion_completa/errors/transaction_capture_error'
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
module Transbank
|
|
2
|
+
module TransaccionCompleta
|
|
3
|
+
module Errors
|
|
4
|
+
class TransactionCaptureError < TransaccionCompletaError
|
|
5
|
+
attr_accessor :message, :code
|
|
6
|
+
def initialize(message, code = nil)
|
|
7
|
+
self.message = message
|
|
8
|
+
self.code = code
|
|
9
|
+
super(message)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|