Class: ActiveMerchant::Billing::Integrations::Quickpay::Notification

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

Constant Summary collapse

MD5_CHECK_FIELDS =
[
  :msgtype,
  :ordernumber,
  :amount,
  :currency,
  :time,
  :state,
  :qpstat,
  :qpstatmsg,
  :chstat,
  :chstatmsg,
  :merchant,
  :merchantemail,
  :transaction,
  :cardtype,
  :cardnumber,
  :cardhash,
  :cardexpire,
  :splitpayment,
  :fraudprobability,
  :fraudremarks,
  :fraudreport,
  :fee
]

Instance Attribute Summary

Attributes inherited from Notification

#params, #raw

Instance Method Summary collapse

Methods inherited from Notification

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

Constructor Details

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

Instance Method Details

#acknowledge(authcode = nil) ⇒ Object

Quickpay doesn’t do acknowledgements of callback notifications Instead it uses and MD5 hash of all parameters



104
105
106
# File 'lib/active_merchant/billing/integrations/quickpay/notification.rb', line 104

def acknowledge(authcode = nil)
  generate_md5check == params['md5check']
end

#complete?Boolean

Returns:

  • (Boolean)


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

def complete?
  status == '000'
end

#currencyObject



39
40
41
# File 'lib/active_merchant/billing/integrations/quickpay/notification.rb', line 39

def currency
  params['currency']
end

#generate_md5checkObject



98
99
100
# File 'lib/active_merchant/billing/integrations/quickpay/notification.rb', line 98

def generate_md5check
  Digest::MD5.hexdigest(generate_md5string)
end

#generate_md5stringObject



94
95
96
# File 'lib/active_merchant/billing/integrations/quickpay/notification.rb', line 94

def generate_md5string
  MD5_CHECK_FIELDS.map { |key| params[key.to_s] } * "" + @options[:credential2].to_s
end

#grossObject



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

def gross
  "%.2f" % (gross_cents / 100.0)
end

#gross_centsObject



31
32
33
# File 'lib/active_merchant/billing/integrations/quickpay/notification.rb', line 31

def gross_cents
  params['amount'].to_i
end

#item_idObject



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

def item_id
  params['ordernumber']
end

#parse(post) ⇒ Object

Take the posted data and move the relevant data into a hash



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/active_merchant/billing/integrations/quickpay/notification.rb', line 109

def parse(post)
  # 30 + 12
  #------------------------------8a827a0e6829
  #Content-Disposition: form-data; name="msgtype"
  #
  #subscribe
  #------------------------------8a827a0e6829
  #Content-Disposition: form-data; name="ordernumber"
  #
  #BILP94406

  if post =~ /-{20,40}\w{6,24}/
    @raw = post.to_s
    post.split(/-{20,40}\w{6,24}[\n\r]*/m).each do |part|
      part.scan(/([^\n\r]+)[\n\r]+([^\n\r]*)/m) do |header, value|
        if header.match(/name=["'](.*)["']/)
          params[$1] = value.strip
        end
      end
    end
  else
    super
  end
end

#received_atObject



20
21
22
23
24
25
# File 'lib/active_merchant/billing/integrations/quickpay/notification.rb', line 20

def received_at
  time = params['time']
  # If time only contains 12 integers then it's pre v5 format
  time = "20#{params['time']}" if /[0-9]{12}/.match(params['time'])
  Time.parse(time)
end

#statusObject



35
36
37
# File 'lib/active_merchant/billing/integrations/quickpay/notification.rb', line 35

def status
  params['qpstat']
end

#transaction_idObject



16
17
18
# File 'lib/active_merchant/billing/integrations/quickpay/notification.rb', line 16

def transaction_id
  params['transaction']
end