Module ActiveMerchant::Billing::Integrations::ActionViewHelper
In: lib/active_merchant/billing/integrations/action_view_helper.rb

Methods

Public Instance methods

This helper allows the usage of different payment integrations through a single form helper. Payment integrations are the type of service where the user is redirected to the secure site of the service, like Paypal or Chronopay.

The helper creates a scope around a payment service helper which provides the specific mapping for that service.

 <% payment_service_for 1000, 'paypalemail@mystore.com',
                              :amount => 50.00,
                              :currency => 'CAD',
                              :service => :paypal,
                              :html => { :id => 'payment-form' } do |service| %>

   <% service.customer :first_name => 'Cody',
                      :last_name => 'Fauser',
                      :phone => '(555)555-5555',
                      :email => 'codyfauser@gmail.com' %>

   <% 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(:only_path => false, :action => 'notify') %>
   <% service.return_url url_for(:only_path => false, :action => 'done') %>
   <% service.cancel_return_url 'http://mystore.com' %>
 <% end %>

[Source]

    # File lib/active_merchant/billing/integrations/action_view_helper.rb, line 42
42:         def payment_service_for(order, account, options = {}, &proc)          
43:           raise ArgumentError, "Missing block" unless block_given?
44: 
45:           integration_module = ActiveMerchant::Billing::Integrations.const_get(options.delete(:service).to_s.classify)
46: 
47:           if ignore_binding?
48:             concat(form_tag(integration_module.service_url, options.delete(:html) || {}))
49:           else
50:             concat(form_tag(integration_module.service_url, options.delete(:html) || {}), proc.binding)
51:           end
52:           result = "\n"
53:           
54:           service_class = integration_module.const_get('Helper')
55:           service = service_class.new(order, account, options)
56:           yield service
57:           
58:           result << service.form_fields.collect do |field, value|
59:             hidden_field_tag(field, value)
60:           end.join("\n")
61: 
62:           result << "\n"
63:           result << '</form>' 
64: 
65:           if ignore_binding?
66:             concat(result)
67:           else
68:             concat(result, proc.binding)
69:           end
70:         end

[Validate]