Class: Transbank::Webpay::Oneclick::MallDeferredTransaction

Inherits:
MallTransaction
  • Object
show all
Extended by:
Utils::NetHelper
Defined in:
lib/transbank/sdk/oneclick/mall_deferred/mall_deferred_transaction.rb

Constant Summary collapse

TRANSACTION_CAPTURE_ENDPOINT =
'rswebpaytransaction/api/oneclick/v1.0/transactions/capture'.freeze

Constants inherited from MallTransaction

Transbank::Webpay::Oneclick::MallTransaction::AUTHORIZE_TRANSACTION_ENDPOINT, Transbank::Webpay::Oneclick::MallTransaction::TRANSACTION_REFUND_ENDPOINT, Transbank::Webpay::Oneclick::MallTransaction::TRANSACTION_STATUS_ENDPOINT

Class Method Summary collapse

Methods included from Utils::NetHelper

http_delete, http_get, http_post, http_put, keys_to_camel_case, patpass_comercio_headers, snake_to_camel_case, webpay_headers

Methods inherited from MallTransaction

authorize, refund, status

Class Method Details

.capture(child_commerce_code:, child_buy_order:, authorization_code:, amount:, options: nil) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/transbank/sdk/oneclick/mall_deferred/mall_deferred_transaction.rb', line 10

def capture(child_commerce_code:, child_buy_order:, authorization_code:, amount:, options: nil)
  api_key = options&.api_key || default_integration_params[:api_key]
  commerce_code = options&.commerce_code || default_integration_params[:commerce_code]
  integration_type = options&.integration_type || default_integration_params[:integration_type]
  base_url = integration_type.nil? ? Oneclick::Base::integration_type[:TEST] : Oneclick::Base.integration_type_url(integration_type)

  url = base_url + TRANSACTION_CAPTURE_ENDPOINT
  headers = webpay_headers(commerce_code: commerce_code, api_key: api_key)
  body = {
    commerce_code: child_commerce_code,
    buy_order: child_buy_order,
    authorization_code: authorization_code,
    capture_amount: amount
  }
  resp = http_put(uri_string: url, headers: headers, body: body)
  body = JSON.parse(resp.body)
  return ::Transbank::Webpay::Oneclick::MallDeferredTransactionCaptureResponse.new(body) if resp.kind_of? Net::HTTPSuccess
  raise Oneclick::Errors::MallDeferredTransactionCaptureError.new(body['error_message'], resp.code)
end

.default_integration_paramsObject



30
31
32
33
34
35
36
37
# File 'lib/transbank/sdk/oneclick/mall_deferred/mall_deferred_transaction.rb', line 30

def default_integration_params
  {
    api_key: Oneclick::Base.api_key,
    commerce_code: Oneclick::Base.commerce_code,
    integration_type: Oneclick::Base::integration_type,
    base_url: Oneclick::Base::current_integration_type_url
  }
end