Class: ActiveMerchant::Billing::Integrations::Dotpay::Notification

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

Constant Summary collapse

PAYMENT_HOOK_FIELDS =
[
  :id,
  :control,
  :t_id,
  :orginal_amount,
  :email,
  :service,
  :code,
  :username,
  :password,
  :t_status,
  :description,
  :md5,
  :p_info,
  :p_email,
  :t_date
]
PAYMENT_HOOK_SIGNATURE_FIELDS =
[
  :id,
  :control,
  :t_id,
  :amount,
  :email,
  :service,
  :code,
  :username,
  :password,
  :t_status
]

Instance Attribute Summary

Attributes inherited from Notification

#params, #raw

Instance Method Summary collapse

Methods inherited from Notification

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

Constructor Details

This class inherits a constructor from ActiveMerchant::Billing::Integrations::Notification

Instance Method Details

#acknowledgeObject



79
80
81
# File 'lib/active_merchant/billing/integrations/dotpay/notification.rb', line 79

def acknowledge      
  generate_signature.to_s == md5.to_s
end

#complete?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/active_merchant/billing/integrations/dotpay/notification.rb', line 8

def complete?
  status == 'OK' && %w(2 4 5).include?(t_status)
end

#currencyObject



12
13
14
# File 'lib/active_merchant/billing/integrations/dotpay/notification.rb', line 12

def currency
  orginal_amount.split(' ')[1]
end

#generate_signatureObject



75
76
77
# File 'lib/active_merchant/billing/integrations/dotpay/notification.rb', line 75

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

#generate_signature_stringObject



71
72
73
# File 'lib/active_merchant/billing/integrations/dotpay/notification.rb', line 71

def generate_signature_string
  "#{@options[:pin]}:" + PAYMENT_HOOK_SIGNATURE_FIELDS.map {|key| params[key.to_s]} * ":"
end

#grossObject

the money amount we received in X.2 decimal.



17
18
19
# File 'lib/active_merchant/billing/integrations/dotpay/notification.rb', line 17

def gross
  params['amount']
end

#pin=(value) ⇒ Object



21
22
23
# File 'lib/active_merchant/billing/integrations/dotpay/notification.rb', line 21

def pin=(value)
  @options[:pin] = value
end

#statusObject



25
26
27
# File 'lib/active_merchant/billing/integrations/dotpay/notification.rb', line 25

def status
  params['status']
end

#test?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/active_merchant/billing/integrations/dotpay/notification.rb', line 29

def test?
  params['t_id'].match('.*-TST\d+') ? true : false
end