Class: OffsitePayments::Integrations::Nochex::Notification

Inherits:
Notification
  • Object
show all
Includes:
ActiveMerchant::PostsData
Defined in:
lib/offsite_payments/integrations/nochex.rb

Overview

Parser and handler for incoming Automatic Payment Confirmations from Nochex.

Instance Attribute Summary

Attributes inherited from Notification

#params, #raw

Instance Method Summary collapse

Methods inherited from Notification

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

Constructor Details

This class inherits a constructor from OffsitePayments::Notification

Instance Method Details

#acknowledge(authcode = nil) ⇒ Object

Acknowledge the transaction to Nochex. This method has to be called after a new apc arrives. Nochex will verify that all the information we received are correct and will return a ok or a fail. This is very similar to the PayPal IPN scheme.

Example:

def nochex_ipn
  notify = NochexNotification.new(request.raw_post)

  if notify.acknowledge
    ... process order ... if notify.complete?
  else
    ... log possible hacking attempt ...
  end

Raises:

  • (StandardError)

209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/offsite_payments/integrations/nochex.rb', line 209

def acknowledge(authcode = nil)
   payload =  raw

   response = ssl_post(Nochex.notification_confirmation_url, payload,
     'Content-Length' => "#{payload.size}",
     'User-Agent'     => "Active Merchant -- http://activemerchant.org",
     'Content-Type'   => "application/x-www-form-urlencoded"
   )

   raise StandardError.new("Faulty Nochex result: #{response}") unless ["AUTHORISED", "DECLINED"].include?(response)

   response == "AUTHORISED"
end

#complete?Boolean


144
145
146
# File 'lib/offsite_payments/integrations/nochex.rb', line 144

def complete?
  status == 'Completed'
end

#currencyObject


157
158
159
# File 'lib/offsite_payments/integrations/nochex.rb', line 157

def currency
  'GBP'
end

#grossObject

the money amount we received in X.2 decimal.


182
183
184
# File 'lib/offsite_payments/integrations/nochex.rb', line 182

def gross
  sprintf("%.2f", params['amount'].to_f)
end

#item_idObject

Id of the order we passed to Nochex


149
150
151
# File 'lib/offsite_payments/integrations/nochex.rb', line 149

def item_id
  params['order_id']
end

#payer_emailObject


169
170
171
# File 'lib/offsite_payments/integrations/nochex.rb', line 169

def payer_email
  params['from_email']
end

#received_atObject

When was this payment received by the client.


162
163
164
165
166
167
# File 'lib/offsite_payments/integrations/nochex.rb', line 162

def received_at
  # U.K. Format: 27/09/2006 22:30:54
  return if params['transaction_date'].blank?
  time = params['transaction_date'].scan(/\d+/)
  Time.utc(time[2], time[1], time[0], time[3], time[4], time[5])
end

#receiver_emailObject


173
174
175
# File 'lib/offsite_payments/integrations/nochex.rb', line 173

def receiver_email
  params['to_email']
end

#security_keyObject


177
178
179
# File 'lib/offsite_payments/integrations/nochex.rb', line 177

def security_key
  params['security_key']
end

#statusObject


191
192
193
# File 'lib/offsite_payments/integrations/nochex.rb', line 191

def status
  'Completed'
end

#test?Boolean

Was this a test transaction?


187
188
189
# File 'lib/offsite_payments/integrations/nochex.rb', line 187

def test?
  params['status'] == 'test'
end

#transaction_idObject


153
154
155
# File 'lib/offsite_payments/integrations/nochex.rb', line 153

def transaction_id
  params['transaction_id']
end