Class: Datatrans::Web::Transaction

Inherits:
Object
  • Object
show all
Includes:
Common
Defined in:
lib/datatrans/web/transaction.rb,
lib/datatrans/web/transaction/authorize.rb

Defined Under Namespace

Classes: AuthorizeResponse

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Common

#sign

Constructor Details

#initialize(datatrans, params) ⇒ Transaction

Returns a new instance of Transaction.



10
11
12
13
14
15
16
17
18
# File 'lib/datatrans/web/transaction.rb', line 10

def initialize(datatrans, params)
  warn "DEPRECATION WARNING: Support for the payment page is deprecated and will be removed in the next major version. Please use the JSON API instead."

  @datatrans = datatrans
  params = params.to_hash
  params.symbolize_keys!
  params.reverse_merge!(reqtype: "NOA", useAlias: "yes", hiddenMode: "yes")
  @params = params
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/datatrans/web/transaction.rb', line 33

def method_missing(method, *args, &block)
  if response.respond_to? method.to_sym
    response.send(method)
  else
    super
  end
end

Instance Attribute Details

#datatransObject (readonly)

Returns the value of attribute datatrans.



8
9
10
# File 'lib/datatrans/web/transaction.rb', line 8

def datatrans
  @datatrans
end

#paramsObject (readonly)

Returns the value of attribute params.



8
9
10
# File 'lib/datatrans/web/transaction.rb', line 8

def params
  @params
end

#requestObject

Returns the value of attribute request.



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

def request
  @request
end

#responseObject (readonly)

Returns the value of attribute response.



8
9
10
# File 'lib/datatrans/web/transaction.rb', line 8

def response
  @response
end

Instance Method Details

#authorizeObject



24
25
26
27
# File 'lib/datatrans/web/transaction.rb', line 24

def authorize
  @response = AuthorizeResponse.new(datatrans, params)
  @response.successful?
end

#respond_to_missing?(method) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/datatrans/web/transaction.rb', line 29

def respond_to_missing?(method, *)
  response.respond_to?(method.to_sym) || super
end

#signatureObject



20
21
22
# File 'lib/datatrans/web/transaction.rb', line 20

def signature
  sign(datatrans.merchant_id, params[:amount], params[:currency], params[:refno])
end