Class: Transbank::Webpay::Oneclick::MallTransaction

Inherits:
Common::BaseTransaction show all
Defined in:
lib/transbank/sdk/webpay/oneclick/mall_transaction.rb

Constant Summary collapse

DEFAULT_ENVIRONMENT =
:integration
RESOURCES_URL =
::Transbank::Common::ApiConstants::ONECLICK_ENDPOINT
AUTHORIZE_ENDPOINT =
(RESOURCES_URL + '/transactions').freeze
STATUS_ENDPOINT =
(RESOURCES_URL + '/transactions/%{token}').freeze
REFUND_ENDPOINT =
(RESOURCES_URL + '/transactions/%{token}/refunds').freeze
CAPTURE_ENDPOINT =
(RESOURCES_URL + '/transactions/capture').freeze
INCREASE_AMOUNT_ENDPOINT =
(RESOURCES_URL + '/transactions/amount').freeze
INCREASE_AUTHORIZATION_DATE_ENDPOINT =
(RESOURCES_URL + '/transactions/authorization_date').freeze
REVERSE_PRE_AUTHORIZED_AMOUNT_ENDPOINT =
(RESOURCES_URL + '/transactions/reverse/amount').freeze
DEFERRED_CAPTURE_HISTORY_ENDPOINT =
(RESOURCES_URL + '/transactions/details').freeze

Instance Method Summary collapse

Constructor Details

#initialize(commerce_code = ::Transbank::Common::IntegrationCommerceCodes::ONECLICK_MALL, api_key = ::Transbank::Common::IntegrationApiKeys::WEBPAY, environment = DEFAULT_ENVIRONMENT) ⇒ MallTransaction

Returns a new instance of MallTransaction.



16
17
18
# File 'lib/transbank/sdk/webpay/oneclick/mall_transaction.rb', line 16

def initialize(commerce_code = ::Transbank::Common::IntegrationCommerceCodes::ONECLICK_MALL, api_key = ::Transbank::Common::IntegrationApiKeys::WEBPAY, environment = DEFAULT_ENVIRONMENT)
  super(commerce_code, api_key, environment)
end

Instance Method Details

#authorize(username, tbk_user, parent_buy_order, details) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/transbank/sdk/webpay/oneclick/mall_transaction.rb', line 20

def authorize(username, tbk_user, parent_buy_order, details)

  Transbank::Common::Validation.has_text_with_max_length(username, Transbank::Common::ApiConstants::USER_NAME_LENGTH, "username")
  Transbank::Common::Validation.has_text_with_max_length(tbk_user, Transbank::Common::ApiConstants::TBK_USER_LENGTH, "tbk_user")
  Transbank::Common::Validation.has_text_with_max_length(parent_buy_order, Transbank::Common::ApiConstants::BUY_ORDER_LENGTH, "parent_buy_order")

  request_service = ::Transbank::Shared::RequestService.new(
    @environment, AUTHORIZE_ENDPOINT, @commerce_code, @api_key
  )
  request_service.post({
    username: username, tbk_user: tbk_user, buy_order: parent_buy_order, details: details
                       })
end

#capture(child_commerce_code, child_buy_order, authorization_code, amount) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/transbank/sdk/webpay/oneclick/mall_transaction.rb', line 34

def capture(child_commerce_code, child_buy_order, authorization_code, amount)
 
  Transbank::Common::Validation.has_text_with_max_length(child_commerce_code, Transbank::Common::ApiConstants::COMMERCE_CODE_LENGTH, "child_commerce_code")
  Transbank::Common::Validation.has_text_with_max_length(child_buy_order, Transbank::Common::ApiConstants::BUY_ORDER_LENGTH, "child_buy_order")
  Transbank::Common::Validation.has_text_with_max_length(authorization_code, Transbank::Common::ApiConstants::AUTHORIZATION_CODE_LENGTH, "authorization_code")

  request_service = ::Transbank::Shared::RequestService.new(
    @environment, CAPTURE_ENDPOINT, @commerce_code, @api_key
  )
  request_service.put(commerce_code: child_commerce_code, buy_order: child_buy_order, authorization_code: authorization_code, capture_amount: amount)
end

#deferred_capture_history(child_commerce_code, child_buy_order, authorization_code) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
# File 'lib/transbank/sdk/webpay/oneclick/mall_transaction.rb', line 104

def deferred_capture_history(child_commerce_code, child_buy_order, authorization_code)
  
  Transbank::Common::Validation.has_text_with_max_length(child_commerce_code, Transbank::Common::ApiConstants::COMMERCE_CODE_LENGTH, "child_commerce_code")
  Transbank::Common::Validation.has_text_with_max_length(child_buy_order, Transbank::Common::ApiConstants::BUY_ORDER_LENGTH, "child_buy_order")
  Transbank::Common::Validation.has_text_with_max_length(authorization_code, Transbank::Common::ApiConstants::AUTHORIZATION_CODE_LENGTH, "authorization_code")

  request_service = ::Transbank::Shared::RequestService.new(
    @environment, DEFERRED_CAPTURE_HISTORY_ENDPOINT, @commerce_code, @api_key
  )
  request_service.post(commerce_code: child_commerce_code, buy_order: child_buy_order, authorization_code: authorization_code)
end

#increase_amount(child_commerce_code, child_buy_order, authorization_code, amount) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
# File 'lib/transbank/sdk/webpay/oneclick/mall_transaction.rb', line 68

def increase_amount(child_commerce_code, child_buy_order, authorization_code, amount)
  
  Transbank::Common::Validation.has_text_with_max_length(child_commerce_code, Transbank::Common::ApiConstants::COMMERCE_CODE_LENGTH, "child_commerce_code")
  Transbank::Common::Validation.has_text_with_max_length(child_buy_order, Transbank::Common::ApiConstants::BUY_ORDER_LENGTH, "child_buy_order")
  Transbank::Common::Validation.has_text_with_max_length(authorization_code, Transbank::Common::ApiConstants::AUTHORIZATION_CODE_LENGTH, "authorization_code")

  request_service = ::Transbank::Shared::RequestService.new(
    @environment, INCREASE_AMOUNT_ENDPOINT, @commerce_code, @api_key
  )
  request_service.put(commerce_code: child_commerce_code, buy_order: child_buy_order, authorization_code: authorization_code, amount: amount)
end

#increase_authorization_date(child_commerce_code, child_buy_order, authorization_code) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
# File 'lib/transbank/sdk/webpay/oneclick/mall_transaction.rb', line 80

def increase_authorization_date(child_commerce_code, child_buy_order, authorization_code)
  
  Transbank::Common::Validation.has_text_with_max_length(child_commerce_code, Transbank::Common::ApiConstants::COMMERCE_CODE_LENGTH, "child_commerce_code")
  Transbank::Common::Validation.has_text_with_max_length(child_buy_order, Transbank::Common::ApiConstants::BUY_ORDER_LENGTH, "child_buy_order")
  Transbank::Common::Validation.has_text_with_max_length(authorization_code, Transbank::Common::ApiConstants::AUTHORIZATION_CODE_LENGTH, "authorization_code")

  request_service = ::Transbank::Shared::RequestService.new(
    @environment, INCREASE_AUTHORIZATION_DATE_ENDPOINT, @commerce_code, @api_key
  )
  request_service.put(commerce_code: child_commerce_code, buy_order: child_buy_order, authorization_code: authorization_code)
end

#refund(buy_order, child_commerce_code, child_buy_order, amount) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/transbank/sdk/webpay/oneclick/mall_transaction.rb', line 56

def refund(buy_order, child_commerce_code, child_buy_order, amount)

  Transbank::Common::Validation.has_text_with_max_length(buy_order, Transbank::Common::ApiConstants::BUY_ORDER_LENGTH, "buy_order")
  Transbank::Common::Validation.has_text_with_max_length(child_commerce_code, Transbank::Common::ApiConstants::COMMERCE_CODE_LENGTH, "child_commerce_code")
  Transbank::Common::Validation.has_text_with_max_length(child_buy_order, Transbank::Common::ApiConstants::BUY_ORDER_LENGTH, "child_buy_order")

  request_service = ::Transbank::Shared::RequestService.new(
    @environment, format(REFUND_ENDPOINT, token: buy_order), @commerce_code, @api_key
  )
  request_service.post(detail_buy_order: child_buy_order, commerce_code: child_commerce_code, amount: amount)
end

#reverse_pre_authorized_amount(child_commerce_code, child_buy_order, authorization_code, amount) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
# File 'lib/transbank/sdk/webpay/oneclick/mall_transaction.rb', line 92

def reverse_pre_authorized_amount(child_commerce_code, child_buy_order, authorization_code, amount)
  
  Transbank::Common::Validation.has_text_with_max_length(child_commerce_code, Transbank::Common::ApiConstants::COMMERCE_CODE_LENGTH, "child_commerce_code")
  Transbank::Common::Validation.has_text_with_max_length(child_buy_order, Transbank::Common::ApiConstants::BUY_ORDER_LENGTH, "child_buy_order")
  Transbank::Common::Validation.has_text_with_max_length(authorization_code, Transbank::Common::ApiConstants::AUTHORIZATION_CODE_LENGTH, "authorization_code")

  request_service = ::Transbank::Shared::RequestService.new(
    @environment, REVERSE_PRE_AUTHORIZED_AMOUNT_ENDPOINT, @commerce_code, @api_key
  )
  request_service.put(commerce_code: child_commerce_code, buy_order: child_buy_order, authorization_code: authorization_code, amount: amount)
end

#status(buy_order) ⇒ Object



46
47
48
49
50
51
52
53
54
# File 'lib/transbank/sdk/webpay/oneclick/mall_transaction.rb', line 46

def status(buy_order)

  Transbank::Common::Validation.has_text_with_max_length(buy_order, Transbank::Common::ApiConstants::BUY_ORDER_LENGTH, "buy_order")

  request_service = ::Transbank::Shared::RequestService.new(
    @environment, format(STATUS_ENDPOINT, token: buy_order), @commerce_code, @api_key
  )
  request_service.get
end