Class: ActiveMerchant::Billing::Integrations::Nochex::Notification
- Inherits:
-
ActiveMerchant::Billing::Integrations::Notification
- Object
- ActiveMerchant::Billing::Integrations::Notification
- ActiveMerchant::Billing::Integrations::Nochex::Notification
- Includes:
- PostsData
- Defined in:
- lib/active_merchant/billing/integrations/nochex/notification.rb
Overview
Parser and handler for incoming Automatic Payment Confirmations from Nochex.
Instance Attribute Summary
Attributes inherited from ActiveMerchant::Billing::Integrations::Notification
Instance Method Summary collapse
-
#acknowledge ⇒ Object
Acknowledge the transaction to Nochex.
- #complete? ⇒ Boolean
- #currency ⇒ Object
-
#gross ⇒ Object
the money amount we received in X.2 decimal.
-
#item_id ⇒ Object
Id of the order we passed to Nochex.
- #payer_email ⇒ Object
-
#received_at ⇒ Object
When was this payment received by the client.
- #receiver_email ⇒ Object
- #security_key ⇒ Object
- #status ⇒ Object
-
#test? ⇒ Boolean
Was this a test transaction?.
- #transaction_id ⇒ Object
Methods included from PostsData
Methods inherited from ActiveMerchant::Billing::Integrations::Notification
#amount, #empty!, #gross_cents, #initialize
Constructor Details
This class inherits a constructor from ActiveMerchant::Billing::Integrations::Notification
Instance Method Details
#acknowledge ⇒ 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
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/active_merchant/billing/integrations/nochex/notification.rb', line 77 def acknowledge payload = raw uri = URI.parse(Nochex.notification_confirmation_url) request = Net::HTTP::Post.new(uri.path) request['Content-Length'] = "#{payload.size}" request['User-Agent'] = "Active Merchant -- http://home.leetsoft.com/am" request['Content-Type'] = "application/x-www-form-urlencoded" http = Net::HTTP.new(uri.host, uri.port) http.verify_mode = OpenSSL::SSL::VERIFY_NONE unless @ssl_strict http.use_ssl = true response = http.request(request, payload) raise StandardError.new("Faulty Nochex result: #{response.body}") unless ["AUTHORISED", "DECLINED"].include?(response.body) response.body == "AUTHORISED" end |
#complete? ⇒ Boolean
12 13 14 |
# File 'lib/active_merchant/billing/integrations/nochex/notification.rb', line 12 def complete? status == 'Completed' end |
#currency ⇒ Object
25 26 27 |
# File 'lib/active_merchant/billing/integrations/nochex/notification.rb', line 25 def currency 'GBP' end |
#gross ⇒ Object
the money amount we received in X.2 decimal.
50 51 52 |
# File 'lib/active_merchant/billing/integrations/nochex/notification.rb', line 50 def gross params['amount'] end |
#item_id ⇒ Object
Id of the order we passed to Nochex
17 18 19 |
# File 'lib/active_merchant/billing/integrations/nochex/notification.rb', line 17 def item_id params['order_id'] end |
#payer_email ⇒ Object
37 38 39 |
# File 'lib/active_merchant/billing/integrations/nochex/notification.rb', line 37 def payer_email params['from_email'] end |
#received_at ⇒ Object
When was this payment received by the client.
30 31 32 33 34 35 |
# File 'lib/active_merchant/billing/integrations/nochex/notification.rb', line 30 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_email ⇒ Object
41 42 43 |
# File 'lib/active_merchant/billing/integrations/nochex/notification.rb', line 41 def receiver_email params['to_email'] end |
#security_key ⇒ Object
45 46 47 |
# File 'lib/active_merchant/billing/integrations/nochex/notification.rb', line 45 def security_key params['security_key'] end |
#status ⇒ Object
59 60 61 |
# File 'lib/active_merchant/billing/integrations/nochex/notification.rb', line 59 def status 'Completed' end |
#test? ⇒ Boolean
Was this a test transaction?
55 56 57 |
# File 'lib/active_merchant/billing/integrations/nochex/notification.rb', line 55 def test? params['status'] == 'test' end |
#transaction_id ⇒ Object
21 22 23 |
# File 'lib/active_merchant/billing/integrations/nochex/notification.rb', line 21 def transaction_id params['transaction_id'] end |