Module: MerbMerchant::Billing::Integrations::Nochex

Defined in:
lib/merb_merchant/billing/integrations/nochex.rb,
lib/merb_merchant/billing/integrations/nochex/helper.rb,
lib/merb_merchant/billing/integrations/nochex/return.rb,
lib/merb_merchant/billing/integrations/nochex/notification.rb

Overview

To start with Nochex, follow the instructions for installing MerbMerchant as a plugin, as described on www.activemerchant.org/.

The plugin will automatically add the ActionView helper for MerbMerchant, which will allow you to make the Nochex payments.

The idea behind the helper is that it generates an invisible forwarding screen that will automatically redirect the user.

So you would collect all the information about the order and then simply render the hidden form, which redirects the user to Nochex.

The syntax of the helper is as follows:

<% payment_service_for 'order id', 'nochex_user_id',
                              :amount => 50.00,
                              :service => :nochex,
                              :html => { :id => 'nochex-form' } do |service| %>

   <% service.customer :first_name => 'Cody',
                      :last_name => 'Fauser',
                      :phone => '(555)555-5555',
                      :email => '[email protected]' %>

   <% service.billing_address :city => 'Ottawa',
                             :address1 => '21 Snowy Brook Lane',
                             :address2 => 'Apt. 36',
                             :state => 'ON',
                             :country => 'CA',
                             :zip => 'K1J1E5' %>

   <% service.invoice '#1000' %>
   <% service.shipping '0.00' %>
   <% service.tax '0.00' %>

   <% service.notify_url url_for(:action => 'notify', :only_path => false) %>
   <% service.return_url url_for(:action => 'done', :only_path => false) %>
   <% service.cancel_return_url 'http://mystore.com' %>
 <% end %>

The notify_url is the URL that the Nochex IPN will be sent. You can handle the notification in your controller action as follows:

class NotificationController < ApplicationController
  include MerbMerchant::Billing::Integrations

  def notify
    notification =  Nochex::Notification.new(request.raw_post)

    begin
      # Acknowledge notification with Nochex
      raise StandardError, 'Illegal Notification' unless notification.acknowledge
        # Process the payment  
    rescue => e
        logger.warn("Illegal notification received: #{e.message}")
    ensure
        head(:ok)
    end
  end
end

Defined Under Namespace

Classes: Helper, Notification, Return

Class Method Summary collapse

Class Method Details

.notification(post) ⇒ Object

Simply a convenience method that returns a new MerbMerchant::Billing::Integrations::Nochex::Notification



91
92
93
# File 'lib/merb_merchant/billing/integrations/nochex.rb', line 91

def self.notification(post)
  Notification.new(post)
end

.notification_confirmation_urlObject



79
80
81
# File 'lib/merb_merchant/billing/integrations/nochex.rb', line 79

def self.notification_confirmation_url
  @@notification_confirmation_url
end

.notification_confirmation_url=(notification_confirmation_url) ⇒ Object



83
84
85
# File 'lib/merb_merchant/billing/integrations/nochex.rb', line 83

def self.notification_confirmation_url=(notification_confirmation_url)
  @@notification_confirmation_url = notification_confirmation_url
end

.return(query_string) ⇒ Object



95
96
97
# File 'lib/merb_merchant/billing/integrations/nochex.rb', line 95

def self.return(query_string)
  Return.new(query_string)
end

.service_urlObject



69
70
71
# File 'lib/merb_merchant/billing/integrations/nochex.rb', line 69

def self.service_url
  @@service_url
end

.service_url=(service_url) ⇒ Object



73
74
75
# File 'lib/merb_merchant/billing/integrations/nochex.rb', line 73

def self.service_url=(service_url)
  @@service_url = service_url
end