Class: Transbank::Webpay::WebpayPlus::Transaction

Inherits:
Common::BaseTransaction show all
Defined in:
lib/transbank/sdk/webpay/webpay_plus/transaction.rb

Constant Summary collapse

DEFAULT_ENVIRONMENT =
:integration
RESOURCES_URL =
::Transbank::Common::ApiConstants::WEBPAY_ENDPOINT
CREATE_ENDPOINT =
(RESOURCES_URL + '/transactions/').freeze
COMMIT_ENDPOINT =
(RESOURCES_URL + '/transactions/%{token}').freeze
STATUS_ENDPOINT =
(RESOURCES_URL + '/transactions/%{token}').freeze
REFUND_ENDPOINT =
(RESOURCES_URL + '/transactions/%{token}/refunds').freeze
CAPTURE_ENDPOINT =
(RESOURCES_URL + '/transactions/%{token}/capture').freeze

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Transaction.



13
14
15
# File 'lib/transbank/sdk/webpay/webpay_plus/transaction.rb', line 13

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

Instance Method Details

#capture(token, buy_order, authorization_code, amount) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/transbank/sdk/webpay/webpay_plus/transaction.rb', line 61

def capture(token, buy_order, authorization_code, amount)
  
  Transbank::Common::Validation.has_text_with_max_length(token, Transbank::Common::ApiConstants::TOKEN_LENGTH, "token")
  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(authorization_code, Transbank::Common::ApiConstants::AUTHORIZATION_CODE_LENGTH, "authorization_code")

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

#commit(token) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/transbank/sdk/webpay/webpay_plus/transaction.rb', line 31

def commit(token)

  Transbank::Common::Validation.has_text_with_max_length(token, Transbank::Common::ApiConstants::TOKEN_LENGTH, "token")

  request_service = ::Transbank::Shared::RequestService.new(
    @environment, format(COMMIT_ENDPOINT, token: token), @commerce_code, @api_key
  )
  request_service.put({})
end

#create(buy_order, session_id, amount, return_url) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/transbank/sdk/webpay/webpay_plus/transaction.rb', line 17

def create(buy_order, session_id, amount, return_url)

  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(session_id, Transbank::Common::ApiConstants::SESSION_ID_LENGTH, "session_id")
  Transbank::Common::Validation.has_text_with_max_length(return_url, Transbank::Common::ApiConstants::RETURN_URL_LENGTH, "return_url")

  request_service = ::Transbank::Shared::RequestService.new(
    @environment, CREATE_ENDPOINT, @commerce_code, @api_key
  )
  request_service.post({
                         buy_order: buy_order, session_id: session_id, amount: amount, return_url: return_url
                       })
end

#refund(token, amount) ⇒ Object



51
52
53
54
55
56
57
58
59
# File 'lib/transbank/sdk/webpay/webpay_plus/transaction.rb', line 51

def refund(token, amount)

  Transbank::Common::Validation.has_text_with_max_length(token, Transbank::Common::ApiConstants::TOKEN_LENGTH, "token")

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

#status(token) ⇒ Object



41
42
43
44
45
46
47
48
49
# File 'lib/transbank/sdk/webpay/webpay_plus/transaction.rb', line 41

def status(token)

  Transbank::Common::Validation.has_text_with_max_length(token, Transbank::Common::ApiConstants::TOKEN_LENGTH, "token")

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