Class: ActiveMerchant::Billing::Integrations::Directebanking::Notification

Inherits:
Notification
  • Object
show all
Defined in:
lib/active_merchant/billing/integrations/directebanking/notification.rb

Constant Summary collapse

PAYMENT_HOOK_SIGNATURE_FIELDS =

for verifying the signature of the URL parameters

[
  :transaction,
  :user_id,
  :project_id,
  :sender_holder,
  :sender_account_number,
  :sender_bank_code,
  :sender_bank_name,
  :sender_bank_bic,
  :sender_iban,
  :sender_country_id,
  :recipient_holder,
  :recipient_account_number,
  :recipient_bank_code,
  :recipient_bank_name,
  :recipient_bank_bic,
  :recipient_iban,
  :recipient_country_id,
  :international_transaction,
  :amount,
  :currency_id,
  :reason_1,
  :reason_2,
  :security_criteria,
  :user_variable_0,
  :user_variable_1,
  :user_variable_2,
  :user_variable_3,
  :user_variable_4,
  :user_variable_5,
  :created
]
PAYMENT_HOOK_IGNORE_AT_METHOD_CREATION_FIELDS =
[
  :transaction,
  :amount,
  :currency_id,
  :user_variable_0,
  :user_variable_1,
  :user_variable_2,
  :user_variable_3,
  :created
]

Instance Attribute Summary

Attributes inherited from Notification

#params, #raw

Instance Method Summary collapse

Methods inherited from Notification

#amount, #empty!, #gross_cents, #valid_sender?

Constructor Details

#initialize(data, options) ⇒ Notification

Returns a new instance of Notification.



7
8
9
10
11
12
# File 'lib/active_merchant/billing/integrations/directebanking/notification.rb', line 7

def initialize(data, options)
  if options[:credential4].nil?
    raise ArgumentError, "You need to provide the notification password (SH1) as the option :credential4 to verify that the notification originated from Directebanking (Payment Networks AG)"
  end
  super
end

Instance Method Details

#acknowledge(authcode = nil) ⇒ Object



111
112
113
114
# File 'lib/active_merchant/billing/integrations/directebanking/notification.rb', line 111

def acknowledge(authcode = nil)
  # signature_is_valid?
  generate_signature.to_s == params['hash'].to_s
end

#complete?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/active_merchant/billing/integrations/directebanking/notification.rb', line 14

def complete?
  status == 'Completed'
end

#currencyObject



40
41
42
# File 'lib/active_merchant/billing/integrations/directebanking/notification.rb', line 40

def currency
  params['currency_id']
end

#generate_signatureObject



107
108
109
# File 'lib/active_merchant/billing/integrations/directebanking/notification.rb', line 107

def generate_signature
  Digest::SHA1.hexdigest(generate_signature_string)
end

#generate_signature_stringObject



102
103
104
105
# File 'lib/active_merchant/billing/integrations/directebanking/notification.rb', line 102

def generate_signature_string
  #format is: transaction|user_id|project_id|sender_holder|sender_account_number|sender_bank_code|sender_bank_name|sender_bank_bic|sender_iban|sender_country_id|recipient_holder|recipient_account_number|recipient_bank_code|recipient_bank_name|recipient_bank_bic|recipient_iban|recipient_country_id|international_transaction|amount|currency_id|reason_1|reason_2|security_criteria|user_variable_0|user_variable_1|user_variable_2|user_variable_3|user_variable_4|user_variable_5|created|notification_password
  PAYMENT_HOOK_SIGNATURE_FIELDS.map {|key| params[key.to_s]} * "|" + "|#{@options[:credential4]}"
end

#grossObject

the money amount we received in X.2 decimal.



32
33
34
# File 'lib/active_merchant/billing/integrations/directebanking/notification.rb', line 32

def gross
  "%.2f" % params['amount'].to_f
end

#item_idObject



18
19
20
# File 'lib/active_merchant/billing/integrations/directebanking/notification.rb', line 18

def item_id
  params['user_variable_0']
end

#received_atObject

When was this payment received by the client.



27
28
29
# File 'lib/active_merchant/billing/integrations/directebanking/notification.rb', line 27

def received_at
  Time.parse(params['created']) if params['created']
end

#statusObject



36
37
38
# File 'lib/active_merchant/billing/integrations/directebanking/notification.rb', line 36

def status
  'Completed'
end

#test?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/active_merchant/billing/integrations/directebanking/notification.rb', line 44

def test?
  params['sender_bank_name'] == 'Testbank'
end

#transaction_idObject



22
23
24
# File 'lib/active_merchant/billing/integrations/directebanking/notification.rb', line 22

def transaction_id
  params['transaction']
end