Class: Transbank::Onepay::TransactionCreateRequest

Inherits:
Object
  • Object
show all
Includes:
Request
Defined in:
lib/transbank/sdk/onepay/requests/transaction_create_request.rb

Overview

Create a payload to create [Transaction] on Transbank

Constant Summary collapse

SIGNATURE_PARAMS =
[:external_unique_number,
:total,
:items_quantity,
:issued_at,
:callback_url].freeze

Instance Attribute Summary collapse

Attributes included from Request

#api_key, #app_key

Instance Method Summary collapse

Methods included from Request

#set_keys_from_options

Methods included from Utils::JSONUtils

included, #jsonify, #transform_hash_keys, #underscore

Methods included from Utils::SignatureUtils

#hmac_sha256, #signature_for, #to_data, #valid_signature?

Constructor Details

#initialize(opts = {}) ⇒ TransactionCreateRequest

are on the [Channel] class

Parameters:

  • opts (Hash) (defaults to: {})

    options hash with params needed to initialize this

  • external_unique_number (String)

    Unique identifier (per Merchant) of the [Transaction] that

  • total (Numeric)

    the total amount to pay for the items

  • items_quantity (Numeric)

    the quantity of items on the shopping cart

  • items (Array<Item] the items on the shopping cart)

    tems [Array<Item] the items on the shopping cart

  • issued_at (Numeric)

    timestamp at the moment the transaction is created

  • callback_url (String)

    used when the channel is mobile, to be able to finish the [Transaction]

  • channel (String)

    The channel the operation is made on. Valid values

  • app_scheme (String)

    identificator for the Merchant’s app

  • signature (String, nil)

    a hashstring created for verification purposes

  • commerce_logo_url (String)

    The URL pointing to the Merchant’s logo

  • width_height (Numeric)

    qr width and height used by the frontend JS SDK.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/transbank/sdk/onepay/requests/transaction_create_request.rb', line 30

def initialize(opts = {})
  self.external_unique_number = opts.fetch(:external_unique_number)
  self.total = opts.fetch(:total)
  self.items_quantity = opts.fetch(:items_quantity)
  self.items = opts.fetch(:items)
  self.issued_at = opts.fetch(:issued_at)
  self.callback_url = opts.fetch(:callback_url)
  channel = opts.fetch(:channel, Channel::WEB)
  self.channel = channel
  self.app_scheme = opts.fetch(:app_scheme, '')
  self.signature = nil
  self.commerce_logo_url = opts.fetch(:commerce_logo_url)
  self.width_height = opts.fetch(:width_height)
  # This is never anything but true, but it is required by the server
  @generate_ott_qr_code = true
end

Instance Attribute Details

#app_schemeObject

Returns the value of attribute app_scheme.



7
8
9
# File 'lib/transbank/sdk/onepay/requests/transaction_create_request.rb', line 7

def app_scheme
  @app_scheme
end

#callback_urlObject

Returns the value of attribute callback_url.



7
8
9
# File 'lib/transbank/sdk/onepay/requests/transaction_create_request.rb', line 7

def callback_url
  @callback_url
end

#channelObject

Returns the value of attribute channel.



7
8
9
# File 'lib/transbank/sdk/onepay/requests/transaction_create_request.rb', line 7

def channel
  @channel
end

#commerce_logo_urlObject

Returns the value of attribute commerce_logo_url.



7
8
9
# File 'lib/transbank/sdk/onepay/requests/transaction_create_request.rb', line 7

def commerce_logo_url
  @commerce_logo_url
end

#external_unique_numberObject

Returns the value of attribute external_unique_number.



7
8
9
# File 'lib/transbank/sdk/onepay/requests/transaction_create_request.rb', line 7

def external_unique_number
  @external_unique_number
end

#generate_ott_qr_codeObject (readonly)

Returns the value of attribute generate_ott_qr_code.



10
11
12
# File 'lib/transbank/sdk/onepay/requests/transaction_create_request.rb', line 10

def generate_ott_qr_code
  @generate_ott_qr_code
end

#issued_atObject

Returns the value of attribute issued_at.



7
8
9
# File 'lib/transbank/sdk/onepay/requests/transaction_create_request.rb', line 7

def issued_at
  @issued_at
end

#itemsObject

Returns the value of attribute items.



7
8
9
# File 'lib/transbank/sdk/onepay/requests/transaction_create_request.rb', line 7

def items
  @items
end

#items_quantityObject

Returns the value of attribute items_quantity.



7
8
9
# File 'lib/transbank/sdk/onepay/requests/transaction_create_request.rb', line 7

def items_quantity
  @items_quantity
end

#signatureObject

Returns the value of attribute signature.



7
8
9
# File 'lib/transbank/sdk/onepay/requests/transaction_create_request.rb', line 7

def signature
  @signature
end

#totalObject

Returns the value of attribute total.



7
8
9
# File 'lib/transbank/sdk/onepay/requests/transaction_create_request.rb', line 7

def total
  @total
end

#width_heightObject

Returns the value of attribute width_height.



7
8
9
# File 'lib/transbank/sdk/onepay/requests/transaction_create_request.rb', line 7

def width_height
  @width_height
end

Instance Method Details

#sign(secret) ⇒ Object



79
80
81
82
# File 'lib/transbank/sdk/onepay/requests/transaction_create_request.rb', line 79

def sign(secret)
  @signature = signature_for(to_data, secret)
  self
end