transbank-sdk 1.1.0 → 1.2.0
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 +4 -4
- data/.github/ISSUE_TEMPLATE/reporte-de-error.md +40 -0
- data/.gitignore +3 -1
- data/.travis.yml +2 -0
- data/CHANGELOG.md +4 -0
- data/Makefile +1 -1
- data/lib/transbank/sdk.rb +5 -5
- 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/base.rb +51 -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 +3 -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 +5 -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 +3 -0
- data/lib/transbank/sdk/oneclick/oneclick.rb +3 -0
- data/lib/transbank/sdk/onepay/models/item.rb +1 -1
- data/lib/transbank/sdk/onepay/models/refund.rb +4 -5
- data/lib/transbank/sdk/onepay/models/shopping_cart.rb +1 -1
- data/lib/transbank/sdk/onepay/models/transaction.rb +11 -9
- data/lib/transbank/sdk/onepay/requests/request.rb +1 -1
- data/lib/transbank/sdk/onepay/responses/response.rb +1 -1
- data/lib/transbank/sdk/transaccion_completa/base.rb +49 -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 +6 -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/options.rb +7 -0
- data/lib/transbank/sdk/transaccion_completa/responses/transaccion_completa_responses.rb +5 -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 +5 -0
- data/lib/transbank/sdk/transaccion_completa/transaction.rb +117 -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/{onepay/utils → utils}/request_builder.rb +0 -0
- data/lib/transbank/sdk/{onepay/utils → utils}/signature_utils.rb +0 -0
- data/lib/transbank/sdk/utils/utils.rb +9 -0
- data/lib/transbank/sdk/version.rb +1 -1
- data/lib/transbank/sdk/webpay/errors/integration_type_error.rb +8 -0
- data/lib/transbank/sdk/webpay/errors/webpay_error.rb +14 -0
- data/transbank-sdk.gemspec +1 -1
- metadata +56 -10
- data/lib/transbank/sdk/onepay/utils/json_utils.rb +0 -77
- data/lib/transbank/sdk/onepay/utils/net_helper.rb +0 -38
- data/lib/transbank/sdk/onepay/utils/utils.rb +0 -9
@@ -0,0 +1,5 @@
|
|
1
|
+
require 'transbank/sdk/oneclick/mall/errors/oneclick_mall_errors'
|
2
|
+
require 'transbank/sdk/oneclick/mall/responses/oneclick_mall_responses'
|
3
|
+
require 'transbank/sdk/oneclick/mall/base'
|
4
|
+
require 'transbank/sdk/oneclick/mall/mall_inscription'
|
5
|
+
require 'transbank/sdk/oneclick/mall/mall_transaction'
|
@@ -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
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Transbank
|
2
2
|
module Onepay
|
3
3
|
class Refund
|
4
|
-
extend Utils::NetHelper, Utils::RequestBuilder
|
4
|
+
extend Transbank::Utils::NetHelper, Utils::RequestBuilder
|
5
5
|
# Manages Refunds
|
6
6
|
REFUND_TRANSACTION = 'nullifytransaction'.freeze
|
7
7
|
TRANSACTION_BASE_PATH = '/ewallet-plugin-api-services/services/transactionservice/'.freeze
|
@@ -24,13 +24,12 @@ module Transbank
|
|
24
24
|
external_unique_number: external_unique_number,
|
25
25
|
authorization_code: authorization_code,
|
26
26
|
options: options)
|
27
|
-
response = http_post(refund_path, refund_request.to_h)
|
28
|
-
|
29
|
-
if response.nil? || !response['responseCode']
|
27
|
+
response = http_post(uri_string: refund_path, body: refund_request.to_h)
|
28
|
+
if response.nil? || !JSON.parse(response.body)['responseCode']
|
30
29
|
raise Errors::RefundCreateError, 'Could not obtain a response from the service.'
|
31
30
|
end
|
32
31
|
|
33
|
-
refund_create_response = RefundCreateResponse.new(response)
|
32
|
+
refund_create_response = RefundCreateResponse.new(JSON.parse(response.body))
|
34
33
|
|
35
34
|
unless refund_create_response.response_ok?
|
36
35
|
raise Errors::RefundCreateError, refund_create_response.full_description
|
@@ -2,7 +2,7 @@ module Transbank
|
|
2
2
|
module Onepay
|
3
3
|
# Represents a Shopping Cart, which contains [Item]s that the user wants to buy
|
4
4
|
class ShoppingCart
|
5
|
-
include Utils::JSONUtils
|
5
|
+
include Transbank::Utils::JSONUtils
|
6
6
|
|
7
7
|
# @return [Array<Item>] An [Array<Item>] with the [ShoppingCart] contents
|
8
8
|
attr_reader :items
|
@@ -3,7 +3,7 @@ module Transbank
|
|
3
3
|
## Class Transaction
|
4
4
|
# This class creates or commits a Transaction (that is, a purchase)
|
5
5
|
class Transaction
|
6
|
-
extend Utils::NetHelper, Utils::RequestBuilder
|
6
|
+
extend Transbank::Utils::NetHelper, Utils::RequestBuilder
|
7
7
|
|
8
8
|
SEND_TRANSACTION = 'sendtransaction'.freeze
|
9
9
|
COMMIT_TRANSACTION = 'gettransactionnumber'.freeze
|
@@ -40,9 +40,9 @@ module Transbank
|
|
40
40
|
channel: channel,
|
41
41
|
external_unique_number: external_unique_number,
|
42
42
|
options: options)
|
43
|
-
response = http_post(transaction_create_path, create_request.to_h)
|
43
|
+
response = http_post(uri_string: transaction_create_path, body: create_request.to_h)
|
44
44
|
validate_create_response!(response)
|
45
|
-
transaction_create_response = TransactionCreateResponse.new response
|
45
|
+
transaction_create_response = TransactionCreateResponse.new JSON.parse(response.body)
|
46
46
|
signature_is_valid = transaction_create_response.valid_signature?(options.fetch(:shared_secret))
|
47
47
|
unless signature_is_valid
|
48
48
|
raise Errors::SignatureError, "The response's signature is not valid."
|
@@ -62,9 +62,9 @@ module Transbank
|
|
62
62
|
commit_request = commit_transaction(occ: occ,
|
63
63
|
external_unique_number: external_unique_number,
|
64
64
|
options: options)
|
65
|
-
response = http_post(transaction_commit_path, commit_request.to_h)
|
65
|
+
response = http_post(uri_string: transaction_commit_path, body: commit_request.to_h)
|
66
66
|
validate_commit_response!(response)
|
67
|
-
transaction_commit_response = TransactionCommitResponse.new(response)
|
67
|
+
transaction_commit_response = TransactionCommitResponse.new(JSON.parse(response.body))
|
68
68
|
signature_is_valid = transaction_commit_response.valid_signature?(options.fetch(:shared_secret))
|
69
69
|
unless signature_is_valid
|
70
70
|
raise Errors::SignatureError, "The response's signature is not valid."
|
@@ -101,8 +101,9 @@ module Transbank
|
|
101
101
|
raise Errors::TransactionCommitError, 'Could not obtain a response from the service.'
|
102
102
|
end
|
103
103
|
|
104
|
-
unless response.fetch('responseCode') == 'OK'
|
105
|
-
|
104
|
+
unless JSON.parse(response.body).fetch('responseCode') == 'OK'
|
105
|
+
body = JSON.parse(response.body)
|
106
|
+
msg = "#{body.fetch('responseCode')} : #{body.fetch('description')}"
|
106
107
|
raise Errors::TransactionCommitError, msg
|
107
108
|
end
|
108
109
|
response
|
@@ -113,8 +114,9 @@ module Transbank
|
|
113
114
|
raise Errors::TransactionCreateError, 'Could not obtain a response from the service.'
|
114
115
|
end
|
115
116
|
|
116
|
-
unless response.fetch('responseCode') == 'OK'
|
117
|
-
|
117
|
+
unless JSON.parse(response.body).fetch('responseCode') == 'OK'
|
118
|
+
body = JSON.parse(response.body)
|
119
|
+
msg = "#{body.fetch('responseCode')} : #{body['description']}"
|
118
120
|
raise Errors::TransactionCreateError, msg
|
119
121
|
end
|
120
122
|
response
|
@@ -2,7 +2,7 @@ module Transbank
|
|
2
2
|
module Onepay
|
3
3
|
# Base module with methods & attributes common to Requests
|
4
4
|
module Request
|
5
|
-
include Utils::JSONUtils, Utils::SignatureUtils
|
5
|
+
include Transbank::Utils::JSONUtils, Utils::SignatureUtils
|
6
6
|
attr_accessor :api_key
|
7
7
|
attr_accessor :app_key
|
8
8
|
|
@@ -2,7 +2,7 @@ module Transbank
|
|
2
2
|
module Onepay
|
3
3
|
# Shared methods and attributes between all types of Responses
|
4
4
|
module Response
|
5
|
-
include Utils::SignatureUtils, Utils::JSONUtils
|
5
|
+
include Utils::SignatureUtils, Transbank::Utils::JSONUtils
|
6
6
|
attr_accessor :response_code
|
7
7
|
attr_accessor :description
|
8
8
|
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Transbank
|
2
|
+
module TransaccionCompleta
|
3
|
+
class Base
|
4
|
+
|
5
|
+
DEFAULT_API_KEY = '579B532A7440BB0C9079DED94D31EA1615BACEB56610332264630D42D0A36B1C'.freeze
|
6
|
+
DEFAULT_COMMERCE_CODE = '597055555530'.freeze
|
7
|
+
|
8
|
+
DEFAULT_MALL_COMMERCE_CODE = '597055555551'.freeze
|
9
|
+
DEFAULT_MALL_CHILD_COMMERCE_CODES = ['597055555552'.freeze, '597055555553'.freeze].freeze
|
10
|
+
|
11
|
+
@api_key = DEFAULT_API_KEY
|
12
|
+
@commerce_code = DEFAULT_COMMERCE_CODE
|
13
|
+
@integration_type = :TEST
|
14
|
+
@integration_types = {
|
15
|
+
LIVE: "https://webpay3g.transbank.cl/",
|
16
|
+
TEST: "https://webpay3gint.transbank.cl/"
|
17
|
+
}
|
18
|
+
class << self
|
19
|
+
attr_reader :integration_types
|
20
|
+
attr_accessor :api_key, :integration_type, :commerce_code
|
21
|
+
|
22
|
+
|
23
|
+
def integration_type_url(integration_type)
|
24
|
+
type = integration_type.upcase.to_sym
|
25
|
+
return @integration_types[type] unless @integration_types[type].nil?
|
26
|
+
valid_values = @integration_types.keys.join(', ')
|
27
|
+
raise Transbank::Webpay::Errors::IntegrationTypeError, "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
|
+
valid_values = @integration_types.keys.join(', ')
|
38
|
+
raise Transbank::Webpay::Errors::IntegrationTypeError, "Invalid integration type, valid values are #{valid_values}"
|
39
|
+
end
|
40
|
+
|
41
|
+
def configure_for_testing
|
42
|
+
@api_key = DEFAULT_API_KEY
|
43
|
+
@commerce_code = DEFAULT_COMMERCE_CODE
|
44
|
+
self.integration_type = :TEST
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
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,6 @@
|
|
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'
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Transbank
|
2
|
+
module TransaccionCompleta
|
3
|
+
module Errors
|
4
|
+
class TransactionCommitError < 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
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Transbank
|
2
|
+
module TransaccionCompleta
|
3
|
+
module Errors
|
4
|
+
class TransactionCreateError < 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
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Transbank
|
2
|
+
module TransaccionCompleta
|
3
|
+
module Errors
|
4
|
+
class TransactionInstallmentsError < 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
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Transbank
|
2
|
+
module TransaccionCompleta
|
3
|
+
module Errors
|
4
|
+
class TransactionRefundError < 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
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Transbank
|
2
|
+
module TransaccionCompleta
|
3
|
+
module Errors
|
4
|
+
class TransactionStatusError < 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
|
@@ -0,0 +1,5 @@
|
|
1
|
+
require 'transbank/sdk/transaccion_completa/responses/transaction_commit_response'
|
2
|
+
require 'transbank/sdk/transaccion_completa/responses/transaction_create_response'
|
3
|
+
require 'transbank/sdk/transaccion_completa/responses/transaction_installments_response'
|
4
|
+
require 'transbank/sdk/transaccion_completa/responses/transaction_status_response'
|
5
|
+
require 'transbank/sdk/transaccion_completa/responses/transaction_refund_response'
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Transbank
|
2
|
+
module TransaccionCompleta
|
3
|
+
class TransactionCommitResponse
|
4
|
+
FIELDS = %i(
|
5
|
+
vci amount status buy_order session_id card_number
|
6
|
+
accounting_date transaction_date authorization_code
|
7
|
+
payment_type_code response_code installments_number
|
8
|
+
installments_amount balance
|
9
|
+
)
|
10
|
+
attr_accessor *FIELDS
|
11
|
+
def initialize(json)
|
12
|
+
FIELDS.each { |field| send("#{field}=", json["#{field}"])}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Transbank
|
2
|
+
module TransaccionCompleta
|
3
|
+
class TransactionInstallmentsResponse
|
4
|
+
attr_accessor :installments_amount, :id_query_installments,
|
5
|
+
:deferred_periods
|
6
|
+
def initialize(json)
|
7
|
+
@installments_amount = json['installments_amount']
|
8
|
+
@id_query_installments = json['id_query_installments']
|
9
|
+
@deferred_periods = json['deferred_periods']
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Transbank
|
2
|
+
module TransaccionCompleta
|
3
|
+
class TransactionRefundResponse
|
4
|
+
FIELDS = %i(
|
5
|
+
type authorization_code authorization_date
|
6
|
+
nullified_amount balance response_code
|
7
|
+
)
|
8
|
+
attr_accessor *FIELDS
|
9
|
+
def initialize(json)
|
10
|
+
FIELDS.each { |field| send("#{field}=", json["#{field}"])}
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Transbank
|
2
|
+
module TransaccionCompleta
|
3
|
+
class TransactionStatusResponse
|
4
|
+
FIELDS = %i(
|
5
|
+
vci amount status buy_order session_id card_number
|
6
|
+
accounting_date transaction_date authorization_code
|
7
|
+
payment_type_code response_code installments_number
|
8
|
+
installments_amount balance
|
9
|
+
)
|
10
|
+
attr_accessor *FIELDS
|
11
|
+
def initialize(json)
|
12
|
+
FIELDS.each { |field| send("#{field}=", json["#{field}"])}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,5 @@
|
|
1
|
+
require 'transbank/sdk/transaccion_completa/errors/transaccion_completa_errors'
|
2
|
+
require 'transbank/sdk/transaccion_completa/responses/transaccion_completa_responses'
|
3
|
+
require 'transbank/sdk/transaccion_completa/options'
|
4
|
+
require 'transbank/sdk/transaccion_completa/base'
|
5
|
+
require 'transbank/sdk/transaccion_completa/transaction'
|
@@ -0,0 +1,117 @@
|
|
1
|
+
module Transbank
|
2
|
+
module TransaccionCompleta
|
3
|
+
class Transaction
|
4
|
+
extend Utils::NetHelper
|
5
|
+
|
6
|
+
CREATE_TRANSACTION_ENDPOINT = 'rswebpaytransaction/api/webpay/v1.0/transactions'
|
7
|
+
TRANSACTION_INSTALLMENTS_ENDPOINT = 'rswebpaytransaction/api/webpay/v1.0/transactions/:token/installments'
|
8
|
+
COMMIT_TRANSACTION_ENDPOINT = 'rswebpaytransaction/api/webpay/v1.0/transactions/:token'
|
9
|
+
TRANSACTION_STATUS_ENDPOINT = 'rswebpaytransaction/api/webpay/v1.0/transactions/:token'
|
10
|
+
REFUND_TRANSACTION_ENDPOINT = 'rswebpaytransaction/api/webpay/v1.0/transactions/:token/refunds'
|
11
|
+
|
12
|
+
class << self
|
13
|
+
def create(buy_order:, session_id:, amount:, card_number:, cvv:,
|
14
|
+
card_expiration_date:, 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? ? TransaccionCompleta::Base::integration_type[:TEST] : TransaccionCompleta::Base.integration_type_url(integration_type)
|
19
|
+
|
20
|
+
body = {
|
21
|
+
buy_order: buy_order, session_id: session_id,
|
22
|
+
amount: amount, card_number: card_number, cvv: cvv,
|
23
|
+
card_expiration_date: card_expiration_date
|
24
|
+
}
|
25
|
+
|
26
|
+
url = base_url + CREATE_TRANSACTION_ENDPOINT
|
27
|
+
headers = webpay_headers(commerce_code: commerce_code, api_key: api_key)
|
28
|
+
resp = http_post(uri_string: url, body: body, headers: headers, camel_case_keys: false)
|
29
|
+
body = JSON.parse(resp.body)
|
30
|
+
return ::Transbank::TransaccionCompleta::TransactionCreateResponse.new(body) if resp.kind_of? Net::HTTPSuccess
|
31
|
+
raise Errors::TransactionCreateError.new(body['error_message'], resp.code)
|
32
|
+
end
|
33
|
+
|
34
|
+
def installments(token:, installments_number:, options:nil)
|
35
|
+
api_key = options&.api_key || default_integration_params[:api_key]
|
36
|
+
commerce_code = options&.commerce_code || default_integration_params[:commerce_code]
|
37
|
+
integration_type = options&.integration_type || default_integration_params[:integration_type]
|
38
|
+
base_url = integration_type.nil? ? TransaccionCompleta::Base::integration_type[:TEST] : TransaccionCompleta::Base.integration_type_url(integration_type)
|
39
|
+
|
40
|
+
url = base_url + TRANSACTION_INSTALLMENTS_ENDPOINT.gsub(':token', token)
|
41
|
+
headers = webpay_headers(commerce_code: commerce_code, api_key: api_key)
|
42
|
+
|
43
|
+
body = {installments_number: installments_number}
|
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::TransaccionCompleta::TransactionInstallmentsResponse.new(body) if resp.kind_of? Net::HTTPSuccess
|
48
|
+
raise Errors::TransactionInstallmentsError.new(body['error_message'], resp.code)
|
49
|
+
end
|
50
|
+
|
51
|
+
def commit(token:, id_query_installments:, deferred_period_index:,
|
52
|
+
grace_period:, 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
|
+
integration_type = options&.integration_type || default_integration_params[:integration_type]
|
56
|
+
base_url = integration_type.nil? ? TransaccionCompleta::Base::integration_type[:TEST] : TransaccionCompleta::Base.integration_type_url(integration_type)
|
57
|
+
|
58
|
+
url = base_url + COMMIT_TRANSACTION_ENDPOINT.gsub(':token', token)
|
59
|
+
headers = webpay_headers(commerce_code: commerce_code, api_key: api_key)
|
60
|
+
body = {
|
61
|
+
id_query_installments: id_query_installments,
|
62
|
+
deferred_period_index: deferred_period_index,
|
63
|
+
grace_period: grace_period
|
64
|
+
}
|
65
|
+
|
66
|
+
resp = http_put(uri_string: url, body: body, headers: headers)
|
67
|
+
body = JSON.parse(resp.body)
|
68
|
+
return ::Transbank::TransaccionCompleta::TransactionCommitResponse.new(body) if resp.kind_of? Net::HTTPSuccess
|
69
|
+
raise Errors::TransactionCommitError.new(body['error_message'], resp.code)
|
70
|
+
end
|
71
|
+
|
72
|
+
def status(token:, options: nil)
|
73
|
+
api_key = options&.api_key || default_integration_params[:api_key]
|
74
|
+
commerce_code = options&.commerce_code || default_integration_params[:commerce_code]
|
75
|
+
integration_type = options&.integration_type || default_integration_params[:integration_type]
|
76
|
+
base_url = integration_type.nil? ? TransaccionCompleta::Base::integration_type[:TEST] : TransaccionCompleta::Base.integration_type_url(integration_type)
|
77
|
+
|
78
|
+
url = base_url + TRANSACTION_STATUS_ENDPOINT.gsub(':token', token)
|
79
|
+
headers = webpay_headers(commerce_code: commerce_code, api_key: api_key)
|
80
|
+
resp = http_get(uri_string: url, headers: headers)
|
81
|
+
body = JSON.parse(resp.body)
|
82
|
+
return ::Transbank::TransaccionCompleta::TransactionStatusResponse.new(body) if resp.kind_of? Net::HTTPSuccess
|
83
|
+
raise Errors::TransactionStatusError.new(body['error_message'], resp.code)
|
84
|
+
end
|
85
|
+
|
86
|
+
def refund(token:, amount:, options:nil)
|
87
|
+
api_key = options&.api_key || default_integration_params[:api_key]
|
88
|
+
commerce_code = options&.commerce_code || default_integration_params[:commerce_code]
|
89
|
+
integration_type = options&.integration_type || default_integration_params[:integration_type]
|
90
|
+
base_url = integration_type.nil? ? TransaccionCompleta::Base::integration_type[:TEST] : TransaccionCompleta::Base.integration_type_url(integration_type)
|
91
|
+
|
92
|
+
body = {
|
93
|
+
amount: amount
|
94
|
+
}
|
95
|
+
|
96
|
+
url = base_url + REFUND_TRANSACTION_ENDPOINT.gsub(':token', token)
|
97
|
+
headers = webpay_headers(commerce_code: commerce_code, api_key: api_key)
|
98
|
+
resp = http_post(uri_string: url, body: body, headers: headers, camel_case_keys: false)
|
99
|
+
body = JSON.parse(resp.body)
|
100
|
+
return ::Transbank::TransaccionCompleta::TransactionRefundResponse.new(body) if resp.kind_of? Net::HTTPSuccess
|
101
|
+
raise Errors::TransactionRefundError.new(body['error_message'], resp.code)
|
102
|
+
end
|
103
|
+
|
104
|
+
def default_integration_params
|
105
|
+
{
|
106
|
+
api_key: TransaccionCompleta::Base::DEFAULT_API_KEY,
|
107
|
+
commerce_code: TransaccionCompleta::Base::DEFAULT_COMMERCE_CODE,
|
108
|
+
integration_type: TransaccionCompleta::Base::integration_type,
|
109
|
+
base_url: TransaccionCompleta::Base::current_integration_type_url
|
110
|
+
}
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
|