Class: Datatrans::JSON::Transaction::MerchantAuthorize

Inherits:
Object
  • Object
show all
Defined in:
lib/datatrans/json/transaction/merchant_authorize.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(datatrans, params) ⇒ MerchantAuthorize

Returns a new instance of MerchantAuthorize.



9
10
11
12
# File 'lib/datatrans/json/transaction/merchant_authorize.rb', line 9

def initialize(datatrans, params)
  @datatrans = datatrans
  @params = params
end

Instance Attribute Details

#datatransObject

class to authorize a transaction without user interaction api-reference.datatrans.ch/#tag/v1transactions/operation/authorize



7
8
9
# File 'lib/datatrans/json/transaction/merchant_authorize.rb', line 7

def datatrans
  @datatrans
end

#paramsObject

class to authorize a transaction without user interaction api-reference.datatrans.ch/#tag/v1transactions/operation/authorize



7
8
9
# File 'lib/datatrans/json/transaction/merchant_authorize.rb', line 7

def params
  @params
end

Instance Method Details

#post(url, options = {}) ⇒ Object



14
15
16
17
18
19
# File 'lib/datatrans/json/transaction/merchant_authorize.rb', line 14

def post(url, options = {})
  options = options
    .merge(datatrans.proxy)
    .merge(basic_auth: {username: datatrans.merchant_id, password: datatrans.password})
  HTTParty.post(url, **options)
end

#processObject



21
22
23
24
25
# File 'lib/datatrans/json/transaction/merchant_authorize.rb', line 21

def process
  post(datatrans.url(:authorize_transaction),
    headers: {"Content-Type" => "application/json"},
    body: request_body.to_json).parsed_response
end

#request_bodyObject



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/datatrans/json/transaction/merchant_authorize.rb', line 27

def request_body
  auto_settle = params[:auto_settle].nil? ? true : params[:auto_settle]

  {
    currency: params[:currency],
    refno: params[:refno],
    amount: params[:amount],
    card: params[:card],
    autoSettle: auto_settle
  }
end