transbank-sdk 1.4.1 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0ea564f34c9caf8e849fb14c9ce61f55d2bbb7735e70d8524f21cb1b6449290a
4
- data.tar.gz: 2979766f5ed7d08b06b3e6c991f1a8482c0c6bc5c84b42ab6308629fb72b27db
3
+ metadata.gz: a655d24c2814f6a3dc1c7ef2822b33cc6d14e7406df11d7b92a75040b894fe7a
4
+ data.tar.gz: 92da17813b042422b0ddbef2a5cc0cac43d09deb28f371cd88a6f565afa66ccb
5
5
  SHA512:
6
- metadata.gz: 86d8009d2cdfd937ab5de8e5daa921c5ba291af3798baf5c9fb8d57af1b25ab6b3187e6edfb83cd0e41f20a80008941b9638bd5f2ef8d062033f195927dfd03f
7
- data.tar.gz: 610377b81766678beb1edc38a809c57b9bb9a536ae82d81376b28e742149de8fd84665466465b5da492458c6cb594889d4f53ebfbf64eca259d66afe50336c81
6
+ metadata.gz: 218214545c94021480df5a18f635bc9771b610c57fd616c6c4eef30eb09212fd756a1083e04c6c15e6554760e23a43cdef2771098cdfdb27479c71d083307717
7
+ data.tar.gz: 4408049419fcf0e0a1cc9bdba91ebbb716085e542b7061a17ae9ee8749fdbb7684c3739d85d2a61d22bc7eef8f1ffb75568cb21cbb4dbd07022d344bac7ff195
data/CHANGELOG.md CHANGED
@@ -4,6 +4,10 @@ Todos los cambios notables a este proyecto serán documentados en este archivo.
4
4
  El formato está basado en [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5
5
  y este proyecto adhiere a [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [1.5.1] - 2021-04-12
8
+ ### Added
9
+ - Se agrega captura diferida en Transacción Completa y Transacción Completa Mall
10
+
7
11
  ## [1.4.1] - 2021-03-30
8
12
  ### Fixed
9
13
  - Se agrega parámetro de estado faltante en respuesta de Commit y Status en Webpay Plus
@@ -1,7 +1,6 @@
1
1
  module Transbank
2
2
  module TransaccionCompleta
3
3
  class Base
4
-
5
4
  DEFAULT_API_KEY = '579B532A7440BB0C9079DED94D31EA1615BACEB56610332264630D42D0A36B1C'.freeze
6
5
  DEFAULT_COMMERCE_CODE = '597055555530'.freeze
7
6
 
@@ -12,19 +11,20 @@ module Transbank
12
11
  @commerce_code = DEFAULT_COMMERCE_CODE
13
12
  @integration_type = :TEST
14
13
  @integration_types = {
15
- LIVE: "https://webpay3g.transbank.cl/",
16
- TEST: "https://webpay3gint.transbank.cl/"
14
+ LIVE: 'https://webpay3g.transbank.cl/',
15
+ TEST: 'https://webpay3gint.transbank.cl/'
17
16
  }
18
17
  class << self
19
18
  attr_reader :integration_types
20
19
  attr_accessor :api_key, :integration_type, :commerce_code
21
20
 
22
-
23
21
  def integration_type_url(integration_type)
24
22
  type = integration_type.upcase.to_sym
25
23
  return @integration_types[type] unless @integration_types[type].nil?
24
+
26
25
  valid_values = @integration_types.keys.join(', ')
27
- raise Transbank::Webpay::Errors::IntegrationTypeError, "Invalid integration type, valid values are #{valid_values}"
26
+ raise Transbank::Webpay::Errors::IntegrationTypeError,
27
+ "Invalid integration type, valid values are #{valid_values}"
28
28
  end
29
29
 
30
30
  def current_integration_type_url
@@ -34,8 +34,10 @@ module Transbank
34
34
  def integration_type=(integration_type)
35
35
  type = integration_type.upcase.to_sym
36
36
  return @integration_type = type unless @integration_types[type].nil?
37
+
37
38
  valid_values = @integration_types.keys.join(', ')
38
- raise Transbank::Webpay::Errors::IntegrationTypeError, "Invalid integration type, valid values are #{valid_values}"
39
+ raise Transbank::Webpay::Errors::IntegrationTypeError,
40
+ "Invalid integration type, valid values are #{valid_values}"
39
41
  end
40
42
 
41
43
  def configure_for_testing
@@ -46,4 +48,4 @@ module Transbank
46
48
  end
47
49
  end
48
50
  end
49
- end
51
+ end
@@ -4,3 +4,4 @@ require 'transbank/sdk/transaccion_completa/errors/transaction_commit_error'
4
4
  require 'transbank/sdk/transaccion_completa/errors/transaction_installments_error'
5
5
  require 'transbank/sdk/transaccion_completa/errors/transaction_refund_error'
6
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
@@ -8,14 +8,16 @@ module Transbank
8
8
  COMMIT_TRANSACTION_ENDPOINT = 'rswebpaytransaction/api/webpay/v1.0/transactions/:token'
9
9
  TRANSACTION_STATUS_ENDPOINT = 'rswebpaytransaction/api/webpay/v1.0/transactions/:token'
10
10
  REFUND_TRANSACTION_ENDPOINT = 'rswebpaytransaction/api/webpay/v1.0/transactions/:token/refunds'
11
+ CAPTURE_TRANSACTION_ENDPOINT = 'rswebpaytransaction/api/webpay/v1.0/transactions/:token/capture'
11
12
 
12
13
  class << self
13
- def create(buy_order:, session_id:,card_number:, card_expiration_date:,
14
- details:, options:nil)
14
+ def create(
15
+ buy_order:, session_id:, card_number:, card_expiration_date:, details:, cvv: nil, options: nil
16
+ )
15
17
  api_key = options&.api_key || default_integration_params[:api_key]
16
18
  commerce_code = options&.commerce_code || default_integration_params[:commerce_code]
17
19
  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)
20
+ base_url = integration_type.nil? ? TransaccionCompleta::Base.integration_type[:TEST] : TransaccionCompleta::Base.integration_type_url(integration_type)
19
21
 
20
22
  detail = create_details(details)
21
23
  body = {
@@ -23,20 +25,22 @@ module Transbank
23
25
  card_number: card_number, card_expiration_date: card_expiration_date,
24
26
  details: detail
25
27
  }
28
+ body[:cvv] = cvv unless cvv.nil?
26
29
 
27
30
  url = base_url + CREATE_TRANSACTION_ENDPOINT
28
31
  headers = webpay_headers(commerce_code: commerce_code, api_key: api_key)
29
32
  resp = http_post(uri_string: url, body: body, headers: headers, camel_case_keys: false)
30
33
  body = JSON.parse(resp.body)
31
- return ::Transbank::TransaccionCompleta::TransactionCreateResponse.new(body) if resp.kind_of? Net::HTTPSuccess
34
+ return ::Transbank::TransaccionCompleta::TransactionCreateResponse.new(body) if resp.is_a? Net::HTTPSuccess
35
+
32
36
  raise Errors::TransactionCreateError.new(body['error_message'], resp.code)
33
37
  end
34
38
 
35
- def installments(token:, details:, options:nil)
39
+ def installments(token:, details:, options: nil)
36
40
  api_key = options&.api_key || default_integration_params[:api_key]
37
41
  base_commerce_code = options&.commerce_code || default_integration_params[:commerce_code]
38
42
  integration_type = options&.integration_type || default_integration_params[:integration_type]
39
- base_url = integration_type.nil? ? TransaccionCompleta::Base::integration_type[:TEST] : TransaccionCompleta::Base.integration_type_url(integration_type)
43
+ base_url = integration_type.nil? ? TransaccionCompleta::Base.integration_type[:TEST] : TransaccionCompleta::Base.integration_type_url(integration_type)
40
44
 
41
45
  url = base_url + TRANSACTION_INSTALLMENTS_ENDPOINT.gsub(':token', token)
42
46
  headers = webpay_headers(commerce_code: base_commerce_code, api_key: api_key)
@@ -44,15 +48,15 @@ module Transbank
44
48
  detail = installments_details(details)
45
49
 
46
50
  resp = detail.map do |det|
47
- body = {
48
- commerce_code: det[:commerce_code],
49
- buy_order: det[:buy_order],
50
- installments_number: det[:installments_number]
51
- }
52
- http_post(uri_string: url, body: body, headers: headers, camel_case_keys: false)
51
+ body = {
52
+ commerce_code: det[:commerce_code],
53
+ buy_order: det[:buy_order],
54
+ installments_number: det[:installments_number]
55
+ }
56
+ http_post(uri_string: url, body: body, headers: headers, camel_case_keys: false)
53
57
  end
54
58
 
55
- if resp.all? { |res| res.kind_of? Net::HTTPSuccess }
59
+ if resp.all? { |res| res.is_a? Net::HTTPSuccess }
56
60
  return resp.map do |res|
57
61
  body = JSON.parse(res.body)
58
62
  ::Transbank::TransaccionCompleta::TransactionInstallmentsResponse.new(body)
@@ -62,21 +66,24 @@ module Transbank
62
66
  raise Errors::TransactionInstallmentsError.new(resp, resp.code)
63
67
  end
64
68
 
65
- def commit(token:,details:, options:nil)
69
+ def commit(token:, details:, options: nil)
66
70
  api_key = options&.api_key || default_integration_params[:api_key]
67
71
  commerce_code = options&.commerce_code || default_integration_params[:commerce_code]
68
72
  integration_type = options&.integration_type || default_integration_params[:integration_type]
69
- base_url = integration_type.nil? ? TransaccionCompleta::Base::integration_type[:TEST] : TransaccionCompleta::Base.integration_type_url(integration_type)
73
+ base_url = integration_type.nil? ? TransaccionCompleta::Base.integration_type[:TEST] : TransaccionCompleta::Base.integration_type_url(integration_type)
70
74
 
71
75
  url = base_url + COMMIT_TRANSACTION_ENDPOINT.gsub(':token', token)
72
76
  headers = webpay_headers(commerce_code: commerce_code, api_key: api_key)
73
77
 
74
78
  detail = commit_details(details)
75
- body = { details: detail }
79
+ body = { details: detail }
76
80
 
77
- resp = http_put(uri_string: url, body: body, headers: headers)
81
+ resp = http_put(uri_string: url, body: body, headers: headers)
78
82
  body = JSON.parse(resp.body)
79
- return ::Transbank::TransaccionCompleta::MallTransactionCommitResponse.new(body) if resp.kind_of? Net::HTTPSuccess
83
+ if resp.is_a? Net::HTTPSuccess
84
+ return ::Transbank::TransaccionCompleta::MallTransactionCommitResponse.new(body)
85
+ end
86
+
80
87
  raise Errors::TransactionCommitError.new(body['error_message'], resp.code)
81
88
  end
82
89
 
@@ -84,21 +91,24 @@ module Transbank
84
91
  api_key = options&.api_key || default_integration_params[:api_key]
85
92
  commerce_code = options&.commerce_code || default_integration_params[:commerce_code]
86
93
  integration_type = options&.integration_type || default_integration_params[:integration_type]
87
- base_url = integration_type.nil? ? TransaccionCompleta::Base::integration_type[:TEST] : TransaccionCompleta::Base.integration_type_url(integration_type)
94
+ base_url = integration_type.nil? ? TransaccionCompleta::Base.integration_type[:TEST] : TransaccionCompleta::Base.integration_type_url(integration_type)
88
95
 
89
96
  url = base_url + TRANSACTION_STATUS_ENDPOINT.gsub(':token', token)
90
97
  headers = webpay_headers(commerce_code: commerce_code, api_key: api_key)
91
98
  resp = http_get(uri_string: url, headers: headers)
92
99
  body = JSON.parse(resp.body)
93
- return ::Transbank::TransaccionCompleta::MallTransactionStatusResponse.new(body) if resp.kind_of? Net::HTTPSuccess
100
+ if resp.is_a? Net::HTTPSuccess
101
+ return ::Transbank::TransaccionCompleta::MallTransactionStatusResponse.new(body)
102
+ end
103
+
94
104
  raise Errors::TransactionStatusError.new(body['error_message'], resp.code)
95
105
  end
96
106
 
97
- def refund(token:, child_buy_order:, child_commerce_code:, amount:, options:nil)
107
+ def refund(token:, child_buy_order:, child_commerce_code:, amount:, options: nil)
98
108
  api_key = options&.api_key || default_integration_params[:api_key]
99
109
  commerce_code = options&.commerce_code || default_integration_params[:commerce_code]
100
110
  integration_type = options&.integration_type || default_integration_params[:integration_type]
101
- base_url = integration_type.nil? ? TransaccionCompleta::Base::integration_type[:TEST] : TransaccionCompleta::Base.integration_type_url(integration_type)
111
+ base_url = integration_type.nil? ? TransaccionCompleta::Base.integration_type[:TEST] : TransaccionCompleta::Base.integration_type_url(integration_type)
102
112
 
103
113
  body = {
104
114
  buy_order: child_buy_order,
@@ -110,20 +120,46 @@ module Transbank
110
120
  headers = webpay_headers(commerce_code: commerce_code, api_key: api_key)
111
121
  resp = http_post(uri_string: url, body: body, headers: headers, camel_case_keys: false)
112
122
  body = JSON.parse(resp.body)
113
- return ::Transbank::TransaccionCompleta::TransactionRefundResponse.new(body) if resp.kind_of? Net::HTTPSuccess
123
+ return ::Transbank::TransaccionCompleta::TransactionRefundResponse.new(body) if resp.is_a? Net::HTTPSuccess
124
+
114
125
  raise Errors::TransactionRefundError.new(body['error_message'], resp.code)
115
126
  end
116
127
 
128
+ def capture(token:, commerce_code:, buy_order:, authorization_code:, capture_amount:, options: nil)
129
+ api_key = options&.api_key || default_integration_params[:api_key]
130
+ parent_commerce_code = options&.commerce_code || default_integration_params[:commerce_code]
131
+ integration_type = options&.integration_type || default_integration_params[:integration_type]
132
+ base_url = integration_type.nil? ? TransaccionCompleta::Base.integration_type[:TEST] : TransaccionCompleta::Base.integration_type_url(integration_type)
133
+
134
+ body = {
135
+ commerce_code: commerce_code,
136
+ buy_order: buy_order,
137
+ authorization_code: authorization_code,
138
+ capture_amount: capture_amount
139
+ }
140
+
141
+ url = base_url + CAPTURE_TRANSACTION_ENDPOINT.gsub(':token', token)
142
+ headers = webpay_headers(commerce_code: parent_commerce_code, api_key: api_key)
143
+ resp = http_put(uri_string: url, body: body, headers: headers)
144
+ body = JSON.parse(resp.body)
145
+ if resp.is_a? Net::HTTPSuccess
146
+ return ::Transbank::TransaccionCompleta::MallTransactionCaptureResponse.new(body)
147
+ end
148
+
149
+ raise Errors::TransactionCaptureError.new(body['error_message'], resp.code)
150
+ end
151
+
117
152
  def default_integration_params
118
153
  {
119
154
  api_key: TransaccionCompleta::Base.api_key,
120
155
  commerce_code: TransaccionCompleta::Base.commerce_code,
121
- integration_type: TransaccionCompleta::Base::integration_type,
122
- base_url: TransaccionCompleta::Base::current_integration_type_url
156
+ integration_type: TransaccionCompleta::Base.integration_type,
157
+ base_url: TransaccionCompleta::Base.current_integration_type_url
123
158
  }
124
159
  end
125
160
 
126
161
  private
162
+
127
163
  def create_details(details)
128
164
  details.map do |det|
129
165
  {
@@ -137,11 +173,11 @@ module Transbank
137
173
  def commit_details(details)
138
174
  details.map do |det|
139
175
  {
140
- commerce_code: det.fetch('commerce_code'){ det.fetch(:commerce_code) },
141
- buy_order: det.fetch('buy_order'){ det.fetch(:buy_order) },
142
- id_query_installments: det.fetch('id_query_installments'){ det.fetch(:id_query_installments) },
143
- deferred_period_index: det.fetch('deferred_period_index'){ det.fetch(:deferred_period_index) },
144
- grace_period: det.fetch('grace_period'){ det.fetch(:grace_period) }
176
+ commerce_code: det.fetch('commerce_code') { det.fetch(:commerce_code) },
177
+ buy_order: det.fetch('buy_order') { det.fetch(:buy_order) },
178
+ id_query_installments: det.fetch('id_query_installments') { det.fetch(:id_query_installments) },
179
+ deferred_period_index: det.fetch('deferred_period_index') { det.fetch(:deferred_period_index) },
180
+ grace_period: det.fetch('grace_period') { det.fetch(:grace_period) }
145
181
  }
146
182
  end
147
183
  end
@@ -155,10 +191,7 @@ module Transbank
155
191
  }
156
192
  end
157
193
  end
158
-
159
194
  end
160
195
  end
161
196
  end
162
197
  end
163
-
164
-
@@ -0,0 +1,12 @@
1
+ module Transbank
2
+ module TransaccionCompleta
3
+ class MallTransactionCaptureResponse
4
+ FIELDS = %i[token authorization_code authorization_date captured_amount response_code].freeze
5
+ attr_accessor(*FIELDS)
6
+
7
+ def initialize(json)
8
+ FIELDS.each { |field| send("#{field}=", json[field.to_s]) }
9
+ end
10
+ end
11
+ end
12
+ end
@@ -1,13 +1,14 @@
1
1
  module Transbank
2
2
  module TransaccionCompleta
3
3
  class MallTransactionCommitResponse
4
- FIELDS = %i(
5
- buy_order session_id card_detail expiration_date
6
- accounting_date transaction_date details
7
- )
8
- attr_accessor *FIELDS
4
+ FIELDS = %i[
5
+ buy_order session_id card_detail expiration_date
6
+ accounting_date transaction_date details
7
+ ]
8
+ attr_accessor(*FIELDS)
9
+
9
10
  def initialize(json)
10
- FIELDS.each { |field| send("#{field}=", json["#{field}"])}
11
+ FIELDS.each { |field| send("#{field}=", json[field.to_s]) }
11
12
  end
12
13
  end
13
14
  end
@@ -1,3 +1,4 @@
1
1
  require 'transbank/sdk/transaccion_completa/mall/responses/mall_transaction_commit_response'
2
2
  require 'transbank/sdk/transaccion_completa/mall/responses/mall_transaction_status_response'
3
3
  require 'transbank/sdk/transaccion_completa/mall/responses/mall_transaction_installments_response'
4
+ require 'transbank/sdk/transaccion_completa/mall/responses/mall_transaction_capture_response'
@@ -2,4 +2,5 @@ require 'transbank/sdk/transaccion_completa/responses/transaction_commit_respons
2
2
  require 'transbank/sdk/transaccion_completa/responses/transaction_create_response'
3
3
  require 'transbank/sdk/transaccion_completa/responses/transaction_installments_response'
4
4
  require 'transbank/sdk/transaccion_completa/responses/transaction_status_response'
5
- require 'transbank/sdk/transaccion_completa/responses/transaction_refund_response'
5
+ require 'transbank/sdk/transaccion_completa/responses/transaction_refund_response'
6
+ require 'transbank/sdk/transaccion_completa/responses/transaction_capture_response'
@@ -0,0 +1,12 @@
1
+ module Transbank
2
+ module TransaccionCompleta
3
+ class TransactionCaptureResponse
4
+ FIELDS = %i[token authorization_code authorization_date captured_amount response_code].freeze
5
+ attr_accessor(*FIELDS)
6
+
7
+ def initialize(json)
8
+ FIELDS.each { |field| send("#{field}=", json[field.to_s]) }
9
+ end
10
+ end
11
+ end
12
+ end
@@ -2,4 +2,6 @@ require 'transbank/sdk/transaccion_completa/errors/transaccion_completa_errors'
2
2
  require 'transbank/sdk/transaccion_completa/responses/transaccion_completa_responses'
3
3
  require 'transbank/sdk/transaccion_completa/options'
4
4
  require 'transbank/sdk/transaccion_completa/base'
5
- require 'transbank/sdk/transaccion_completa/transaction'
5
+ require 'transbank/sdk/transaccion_completa/transaction'
6
+ require 'transbank/sdk/transaccion_completa/mall/mall_transaction'
7
+ require 'transbank/sdk/transaccion_completa/mall/responses/mall_transaction_responses'
@@ -8,14 +8,15 @@ module Transbank
8
8
  COMMIT_TRANSACTION_ENDPOINT = 'rswebpaytransaction/api/webpay/v1.0/transactions/:token'
9
9
  TRANSACTION_STATUS_ENDPOINT = 'rswebpaytransaction/api/webpay/v1.0/transactions/:token'
10
10
  REFUND_TRANSACTION_ENDPOINT = 'rswebpaytransaction/api/webpay/v1.0/transactions/:token/refunds'
11
+ CAPTURE_TRANSACTION_ENDPOINT = 'rswebpaytransaction/api/webpay/v1.0/transactions/:token/capture'
11
12
 
12
13
  class << self
13
14
  def create(buy_order:, session_id:, amount:, card_number:, cvv:,
14
- card_expiration_date:, options:nil)
15
+ card_expiration_date:, options: nil)
15
16
  api_key = options&.api_key || default_integration_params[:api_key]
16
17
  commerce_code = options&.commerce_code || default_integration_params[:commerce_code]
17
18
  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
+ base_url = integration_type.nil? ? TransaccionCompleta::Base.integration_type[:TEST] : TransaccionCompleta::Base.integration_type_url(integration_type)
19
20
 
20
21
  body = {
21
22
  buy_order: buy_order, session_id: session_id,
@@ -27,33 +28,37 @@ module Transbank
27
28
  headers = webpay_headers(commerce_code: commerce_code, api_key: api_key)
28
29
  resp = http_post(uri_string: url, body: body, headers: headers, camel_case_keys: false)
29
30
  body = JSON.parse(resp.body)
30
- return ::Transbank::TransaccionCompleta::TransactionCreateResponse.new(body) if resp.kind_of? Net::HTTPSuccess
31
+ return ::Transbank::TransaccionCompleta::TransactionCreateResponse.new(body) if resp.is_a? Net::HTTPSuccess
32
+
31
33
  raise Errors::TransactionCreateError.new(body['error_message'], resp.code)
32
34
  end
33
35
 
34
- def installments(token:, installments_number:, options:nil)
36
+ def installments(token:, installments_number:, options: nil)
35
37
  api_key = options&.api_key || default_integration_params[:api_key]
36
38
  commerce_code = options&.commerce_code || default_integration_params[:commerce_code]
37
39
  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)
40
+ base_url = integration_type.nil? ? TransaccionCompleta::Base.integration_type[:TEST] : TransaccionCompleta::Base.integration_type_url(integration_type)
39
41
 
40
42
  url = base_url + TRANSACTION_INSTALLMENTS_ENDPOINT.gsub(':token', token)
41
43
  headers = webpay_headers(commerce_code: commerce_code, api_key: api_key)
42
44
 
43
- body = {installments_number: installments_number}
45
+ body = { installments_number: installments_number }
44
46
 
45
47
  resp = http_post(uri_string: url, body: body, headers: headers, camel_case_keys: false)
46
48
  body = JSON.parse(resp.body)
47
- return ::Transbank::TransaccionCompleta::TransactionInstallmentsResponse.new(body) if resp.kind_of? Net::HTTPSuccess
49
+ if resp.is_a? Net::HTTPSuccess
50
+ return ::Transbank::TransaccionCompleta::TransactionInstallmentsResponse.new(body)
51
+ end
52
+
48
53
  raise Errors::TransactionInstallmentsError.new(body['error_message'], resp.code)
49
54
  end
50
55
 
51
56
  def commit(token:, id_query_installments:, deferred_period_index:,
52
- grace_period:, options:nil)
57
+ grace_period:, options: nil)
53
58
  api_key = options&.api_key || default_integration_params[:api_key]
54
59
  commerce_code = options&.commerce_code || default_integration_params[:commerce_code]
55
60
  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)
61
+ base_url = integration_type.nil? ? TransaccionCompleta::Base.integration_type[:TEST] : TransaccionCompleta::Base.integration_type_url(integration_type)
57
62
 
58
63
  url = base_url + COMMIT_TRANSACTION_ENDPOINT.gsub(':token', token)
59
64
  headers = webpay_headers(commerce_code: commerce_code, api_key: api_key)
@@ -63,9 +68,10 @@ module Transbank
63
68
  grace_period: grace_period
64
69
  }
65
70
 
66
- resp = http_put(uri_string: url, body: body, headers: headers)
71
+ resp = http_put(uri_string: url, body: body, headers: headers)
67
72
  body = JSON.parse(resp.body)
68
- return ::Transbank::TransaccionCompleta::TransactionCommitResponse.new(body) if resp.kind_of? Net::HTTPSuccess
73
+ return ::Transbank::TransaccionCompleta::TransactionCommitResponse.new(body) if resp.is_a? Net::HTTPSuccess
74
+
69
75
  raise Errors::TransactionCommitError.new(body['error_message'], resp.code)
70
76
  end
71
77
 
@@ -73,21 +79,22 @@ module Transbank
73
79
  api_key = options&.api_key || default_integration_params[:api_key]
74
80
  commerce_code = options&.commerce_code || default_integration_params[:commerce_code]
75
81
  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)
82
+ base_url = integration_type.nil? ? TransaccionCompleta::Base.integration_type[:TEST] : TransaccionCompleta::Base.integration_type_url(integration_type)
77
83
 
78
84
  url = base_url + TRANSACTION_STATUS_ENDPOINT.gsub(':token', token)
79
85
  headers = webpay_headers(commerce_code: commerce_code, api_key: api_key)
80
86
  resp = http_get(uri_string: url, headers: headers)
81
87
  body = JSON.parse(resp.body)
82
- return ::Transbank::TransaccionCompleta::TransactionStatusResponse.new(body) if resp.kind_of? Net::HTTPSuccess
88
+ return ::Transbank::TransaccionCompleta::TransactionStatusResponse.new(body) if resp.is_a? Net::HTTPSuccess
89
+
83
90
  raise Errors::TransactionStatusError.new(body['error_message'], resp.code)
84
91
  end
85
92
 
86
- def refund(token:, amount:, options:nil)
93
+ def refund(token:, amount:, options: nil)
87
94
  api_key = options&.api_key || default_integration_params[:api_key]
88
95
  commerce_code = options&.commerce_code || default_integration_params[:commerce_code]
89
96
  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)
97
+ base_url = integration_type.nil? ? TransaccionCompleta::Base.integration_type[:TEST] : TransaccionCompleta::Base.integration_type_url(integration_type)
91
98
 
92
99
  body = {
93
100
  amount: amount
@@ -97,21 +104,41 @@ module Transbank
97
104
  headers = webpay_headers(commerce_code: commerce_code, api_key: api_key)
98
105
  resp = http_post(uri_string: url, body: body, headers: headers, camel_case_keys: false)
99
106
  body = JSON.parse(resp.body)
100
- return ::Transbank::TransaccionCompleta::TransactionRefundResponse.new(body) if resp.kind_of? Net::HTTPSuccess
107
+ return ::Transbank::TransaccionCompleta::TransactionRefundResponse.new(body) if resp.is_a? Net::HTTPSuccess
108
+
101
109
  raise Errors::TransactionRefundError.new(body['error_message'], resp.code)
102
110
  end
103
111
 
112
+ def capture(token:, buy_order:, authorization_code:, capture_amount:, options: nil)
113
+ api_key = options&.api_key || default_integration_params[:api_key]
114
+ commerce_code = options&.commerce_code || default_integration_params[:commerce_code]
115
+ integration_type = options&.integration_type || default_integration_params[:integration_type]
116
+ base_url = integration_type.nil? ? TransaccionCompleta::Base.integration_type[:TEST] : TransaccionCompleta::Base.integration_type_url(integration_type)
117
+
118
+ body = {
119
+ buy_order: buy_order,
120
+ authorization_code: authorization_code,
121
+ capture_amount: capture_amount
122
+ }
123
+
124
+ url = base_url + CAPTURE_TRANSACTION_ENDPOINT.gsub(':token', token)
125
+ headers = webpay_headers(commerce_code: commerce_code, api_key: api_key)
126
+ resp = http_put(uri_string: url, body: body, headers: headers)
127
+ body = JSON.parse(resp.body)
128
+ return ::Transbank::TransaccionCompleta::TransactionCaptureResponse.new(body) if resp.is_a? Net::HTTPSuccess
129
+
130
+ raise Errors::TransactionCaptureError.new(body['error_message'], resp.code)
131
+ end
132
+
104
133
  def default_integration_params
105
134
  {
106
135
  api_key: TransaccionCompleta::Base.api_key,
107
136
  commerce_code: TransaccionCompleta::Base.commerce_code,
108
- integration_type: TransaccionCompleta::Base::integration_type,
109
- base_url: TransaccionCompleta::Base::current_integration_type_url
137
+ integration_type: TransaccionCompleta::Base.integration_type,
138
+ base_url: TransaccionCompleta::Base.current_integration_type_url
110
139
  }
111
140
  end
112
141
  end
113
142
  end
114
143
  end
115
144
  end
116
-
117
-
@@ -1,5 +1,5 @@
1
1
  module Transbank
2
2
  module Sdk
3
- VERSION = "1.4.1"
3
+ VERSION = '1.5.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: transbank-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Transbank Developers
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-30 00:00:00.000000000 Z
11
+ date: 2021-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -256,18 +256,21 @@ files:
256
256
  - lib/transbank/sdk/transaccion_completa/base.rb
257
257
  - lib/transbank/sdk/transaccion_completa/errors/transaccion_completa_error.rb
258
258
  - lib/transbank/sdk/transaccion_completa/errors/transaccion_completa_errors.rb
259
+ - lib/transbank/sdk/transaccion_completa/errors/transaction_capture_error.rb
259
260
  - lib/transbank/sdk/transaccion_completa/errors/transaction_commit_error.rb
260
261
  - lib/transbank/sdk/transaccion_completa/errors/transaction_create_error.rb
261
262
  - lib/transbank/sdk/transaccion_completa/errors/transaction_installments_error.rb
262
263
  - lib/transbank/sdk/transaccion_completa/errors/transaction_refund_error.rb
263
264
  - lib/transbank/sdk/transaccion_completa/errors/transaction_status_error.rb
264
265
  - lib/transbank/sdk/transaccion_completa/mall/mall_transaction.rb
266
+ - lib/transbank/sdk/transaccion_completa/mall/responses/mall_transaction_capture_response.rb
265
267
  - lib/transbank/sdk/transaccion_completa/mall/responses/mall_transaction_commit_response.rb
266
268
  - lib/transbank/sdk/transaccion_completa/mall/responses/mall_transaction_installments_response.rb
267
269
  - lib/transbank/sdk/transaccion_completa/mall/responses/mall_transaction_responses.rb
268
270
  - lib/transbank/sdk/transaccion_completa/mall/responses/mall_transaction_status_response.rb
269
271
  - lib/transbank/sdk/transaccion_completa/options.rb
270
272
  - lib/transbank/sdk/transaccion_completa/responses/transaccion_completa_responses.rb
273
+ - lib/transbank/sdk/transaccion_completa/responses/transaction_capture_response.rb
271
274
  - lib/transbank/sdk/transaccion_completa/responses/transaction_commit_response.rb
272
275
  - lib/transbank/sdk/transaccion_completa/responses/transaction_create_response.rb
273
276
  - lib/transbank/sdk/transaccion_completa/responses/transaction_installments_response.rb