Class: AbnAmro::Internetkassa::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/abn-amro/internetkassa/response.rb,
lib/abn-amro/internetkassa/response_codes.rb

Defined Under Namespace

Modules: Codes Classes: SignatureInvalidError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Response

Returns a new instance of Response.



10
11
12
13
14
15
16
# File 'lib/abn-amro/internetkassa/response.rb', line 10

def initialize(params)
  @params = params
  
  unless valid?
    raise SignatureInvalidError, "signature `#{signature}' does not match the signature calculated for this message `#{calculated_signature}'"
  end
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



8
9
10
# File 'lib/abn-amro/internetkassa/response.rb', line 8

def params
  @params
end

Instance Method Details

#acceptanceObject



23
# File 'lib/abn-amro/internetkassa/response.rb', line 23

def acceptance;           @params['ACCEPTANCE']                           end

#amountObject



33
34
35
# File 'lib/abn-amro/internetkassa/response.rb', line 33

def amount
  @amount ||= (@params['amount'].to_f * 100).to_i
end

#authorized?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/abn-amro/internetkassa/response.rb', line 51

def authorized?
  status_code == '5'
end

#captured?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/abn-amro/internetkassa/response.rb', line 55

def captured?
  status_code == '9'
end

#card_brandObject



29
# File 'lib/abn-amro/internetkassa/response.rb', line 29

def card_brand;           @params['BRAND']                                end

#card_expiration_dateObject



31
# File 'lib/abn-amro/internetkassa/response.rb', line 31

def card_expiration_date; @params['ED']                                   end

#card_numberObject



30
# File 'lib/abn-amro/internetkassa/response.rb', line 30

def card_number;          @params['CARDNO']                               end

#currencyObject



24
# File 'lib/abn-amro/internetkassa/response.rb', line 24

def currency;             @params['currency']                             end

#customer_nameObject



28
# File 'lib/abn-amro/internetkassa/response.rb', line 28

def customer_name;        @params['CN']                                   end

#error_codeObject



26
# File 'lib/abn-amro/internetkassa/response.rb', line 26

def error_code;           @params['NCERROR'] if @params['NCERROR'] != '0' end

#error_messageObject



67
68
69
# File 'lib/abn-amro/internetkassa/response.rb', line 67

def error_message
  Codes::ERROR_CODES[error_code][:explanation] if error_code
end

#order_idObject

attributes



20
# File 'lib/abn-amro/internetkassa/response.rb', line 20

def order_id;             @params['orderID']                              end

#payment_idObject



21
# File 'lib/abn-amro/internetkassa/response.rb', line 21

def payment_id;           @params['PAYID']                                end

#payment_methodObject



22
# File 'lib/abn-amro/internetkassa/response.rb', line 22

def payment_method;       @params['PM']                                   end

#retry?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/abn-amro/internetkassa/response.rb', line 59

def retry?
  Codes::ERROR_CODES[error_code][:retry] if error_code
end

#signatureObject



27
# File 'lib/abn-amro/internetkassa/response.rb', line 27

def signature;            @params['SHASIGN']                              end

#status_codeObject



25
# File 'lib/abn-amro/internetkassa/response.rb', line 25

def status_code;          @params['STATUS']                               end

#status_messageObject



63
64
65
# File 'lib/abn-amro/internetkassa/response.rb', line 63

def status_message
  Codes::STATUS_CODES[status_code]
end

#success?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/abn-amro/internetkassa/response.rb', line 47

def success?
  error_code.nil? && (authorized? || captured?)
end

#transaction_dateObject



37
38
39
# File 'lib/abn-amro/internetkassa/response.rb', line 37

def transaction_date
  @transaction_date ||= Date.parse(@params['TRXDATE'], true)
end

#valid?Boolean

methods

Returns:

  • (Boolean)


43
44
45
# File 'lib/abn-amro/internetkassa/response.rb', line 43

def valid?
  signature == calculated_signature
end