Class: OffsitePayments::Helper
- Inherits:
-
Object
- Object
- OffsitePayments::Helper
- Includes:
- MoneyCompatibility
- Defined in:
- lib/offsite_payments/helper.rb
Overview
:nodoc:
Direct Known Subclasses
Integrations::A1agregator::Helper, Integrations::AuthorizeNetSim::Helper, Integrations::BitPay::Helper, Integrations::Bogus::Helper, Integrations::CheckoutFinland::Helper, Integrations::Chronopay::Helper, Integrations::Citrus::Helper, Integrations::Coinbase::Helper, Integrations::DirecPay::Helper, Integrations::Directebanking::Helper, Integrations::Doku::Helper, Integrations::Dotpay::Helper, Integrations::Dwolla::Helper, Integrations::EPaymentPlans::Helper, Integrations::EasyPay::Helper, Integrations::Epay::Helper, Integrations::Gestpay::Helper, Integrations::HiTrust::Helper, Integrations::Ipay88::Helper, Integrations::Klarna::Helper, Integrations::Liqpay::Helper, Integrations::Maksuturva::Helper, Integrations::Mollie::Helper, Integrations::Molpay::Helper, Integrations::Moneybookers::Helper, Integrations::Nochex::Helper, Integrations::PagSeguro::Helper, Integrations::Paxum::Helper, Integrations::PayFast::Helper, Integrations::Paydollar::Helper, Integrations::PayflowLink::Helper, Integrations::Paypal::Helper, Integrations::Paysbuy::Helper, Integrations::Paytm::Helper, Integrations::PayuIn::Helper, Integrations::Platron::Helper, Integrations::Pxpay::Helper, Integrations::Quickpay::Helper, Integrations::QuickpayV10::Helper, Integrations::Rbkmoney::Helper, Integrations::RealexOffsite::Helper, Integrations::Robokassa::Helper, Integrations::SagePayForm::Helper, Integrations::TwoCheckout::Helper, Integrations::Universal::Helper, Integrations::Valitor::Helper, Integrations::Verkkomaksut::Helper, Integrations::WebPay::Helper, Integrations::Webmoney::Helper, Integrations::WirecardCheckoutPage::Helper, Integrations::WorldPay::Helper
Instance Attribute Summary collapse
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
Class Method Summary collapse
- .inherited(subclass) ⇒ Object
-
.mapping(attribute, options = {}) ⇒ Object
Add a mapping between attribute name and gateway specific field name.
Instance Method Summary collapse
-
#add_field(name, value) ⇒ Object
Add an input in the form.
- #add_fields(subkey, params = {}) ⇒ Object
-
#add_raw_html_field(name, value) ⇒ Object
Add a field that has characters that CGI::escape would mangle.
- #billing_address(params = {}) ⇒ Object
- #form_fields ⇒ Object
-
#form_method ⇒ String
Specifies the HTTP method used in form submmition.
-
#initialize(order, account, options = {}) ⇒ Helper
constructor
-
amount * currency * credential2 * credential3 * credential4 * notify_url * return_url * redirect_param.
-
- #raw_html_fields ⇒ Object
- #shipping_address(params = {}) ⇒ Object
-
#test? ⇒ Boolean
Whether in test mode.
Methods included from MoneyCompatibility
Constructor Details
#initialize(order, account, options = {}) ⇒ Helper
-
amount
-
currency
-
credential2
-
credential3
-
credential4
-
notify_url
-
return_url
-
redirect_param
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/offsite_payments/helper.rb', line 37 def initialize(order, account, = {}) .assert_valid_keys([:amount, :currency, :test, :credential2, :credential3, :credential4, :country, :account_name, :description, :transaction_type, :authcode, :notify_url, :return_url, :redirect_param, :forward_url, :checkout_token]) @fields = {} @raw_html_fields = [] @test = [:test] self.order = order self.account = account self.amount = [:amount] self.currency = [:currency] self.credential2 = [:credential2] self.credential3 = [:credential3] self.credential4 = [:credential4] self.notify_url = [:notify_url] self.return_url = [:return_url] self.redirect_param = [:redirect_param] self.checkout_token = [:checkout_token] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_id, *args) ⇒ Object (private)
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/offsite_payments/helper.rb', line 166 def method_missing(method_id, *args) method_id = method_id.to_s.gsub(/=$/, '').to_sym # Return and do nothing if the mapping was not found. This allows # for easy substitution of the different integrations return if mappings[method_id].nil? mapping = mappings[method_id] case mapping when Array mapping.each{ |field| add_field(field, args.last) } when Hash = args.last.is_a?(Hash) ? args.pop : {} mapping.each{ |key, field| add_field(field, [key]) } else add_field(mapping, args.last) end end |
Instance Attribute Details
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
11 12 13 |
# File 'lib/offsite_payments/helper.rb', line 11 def fields @fields end |
Class Method Details
.inherited(subclass) ⇒ Object
22 23 24 |
# File 'lib/offsite_payments/helper.rb', line 22 def self.inherited(subclass) subclass.mappings ||= {} end |
.mapping(attribute, options = {}) ⇒ Object
Add a mapping between attribute name and gateway specific field name. This mapping can then be used in form helper to assign values to each attributes. For example, a ‘mapping :height, “HEIGHT”` means user can write `f.height 182` in ’payment_service_for’ form helper, and an input tag with the name “HEIGHT” and value of 182 will be generated. This is an abstraction over the ‘add_field` method.
String: Name of generated input
Array: Names of generated inputs, for creating synonym inputs. Each generated input will have the same value.
Hash: Keys as attribute name and values as generated input names. Used to group related fields together, such as different segments of an address, for example:
mapping :address, :region => ‘REGION’, :city => ‘CITY’, :address => ‘ADD’
80 81 82 |
# File 'lib/offsite_payments/helper.rb', line 80 def self.mapping(attribute, = {}) self.mappings[attribute] = end |
Instance Method Details
#add_field(name, value) ⇒ Object
Add an input in the form. Useful when gateway requires some uncommon fields not provided by the gem.
# inside ‘payment_service_for do |service|` block service.add_field(’c_id’,‘_xclick’)
Gateway implementor can also use this to add default fields in the form:
# in a subclass of ActiveMerchant::Billing::Integrations::Helper def initialize(order, account, options = {}) super # mandatory fields add_field(‘Rvg2c’, 1) end
101 102 103 104 |
# File 'lib/offsite_payments/helper.rb', line 101 def add_field(name, value) return if name.blank? || value.blank? @fields[name.to_s] = value.to_s end |
#add_fields(subkey, params = {}) ⇒ Object
106 107 108 109 110 111 |
# File 'lib/offsite_payments/helper.rb', line 106 def add_fields(subkey, params = {}) params.each do |k, v| field = mappings[subkey][k] add_field(field, v) unless field.blank? end end |
#add_raw_html_field(name, value) ⇒ Object
Add a field that has characters that CGI::escape would mangle. Allows for multiple fields with the same name (e.g., to support line items).
115 116 117 118 |
# File 'lib/offsite_payments/helper.rb', line 115 def add_raw_html_field(name, value) return if name.blank? || value.blank? @raw_html_fields << [name, value] end |
#billing_address(params = {}) ⇒ Object
124 125 126 |
# File 'lib/offsite_payments/helper.rb', line 124 def billing_address(params = {}) add_address(:billing_address, params) end |
#form_fields ⇒ Object
132 133 134 |
# File 'lib/offsite_payments/helper.rb', line 132 def form_fields @fields end |
#form_method ⇒ String
Specifies the HTTP method used in form submmition. Set to POST which gateway implementor can override if other http method is desired (e.g. PUT).
145 146 147 |
# File 'lib/offsite_payments/helper.rb', line 145 def form_method "POST" end |
#raw_html_fields ⇒ Object
120 121 122 |
# File 'lib/offsite_payments/helper.rb', line 120 def raw_html_fields @raw_html_fields end |
#shipping_address(params = {}) ⇒ Object
128 129 130 |
# File 'lib/offsite_payments/helper.rb', line 128 def shipping_address(params = {}) add_address(:shipping_address, params) end |
#test? ⇒ Boolean
Returns whether in test mode.
137 138 139 |
# File 'lib/offsite_payments/helper.rb', line 137 def test? @test_mode ||= OffsitePayments.mode == :test || !!@test end |