Class: ActiveMerchant::Billing::Integrations::DirecPay::Helper

Inherits:
Helper
  • Object
show all
Defined in:
lib/active_merchant/billing/integrations/direc_pay/helper.rb

Constant Summary collapse

OPERATING_MODE =
'DOM'
COUNTRY =
'IND'
CURRENCY =
'INR'
OTHER_DETAILS =
'NULL'
EDIT_ALLOWED =
'Y'
PHONE_CODES =
{
  'IN' => '91',
  'US' => '01',
  'CA' => '01'
}
ENCODED_PARAMS =
[ :account, :operating_mode, :country, :currency, :amount, :order, :other_details, :return_url, :failure_url, :collaborator ]

Instance Attribute Summary

Attributes inherited from Helper

#fields

Instance Method Summary collapse

Methods inherited from Helper

#add_field, #add_fields, #add_raw_html_field, #form_method, mapping, #raw_html_fields, #test?

Constructor Details

#initialize(order, account, options = {}) ⇒ Helper

Returns a new instance of Helper.



55
56
57
58
59
60
61
62
63
# File 'lib/active_merchant/billing/integrations/direc_pay/helper.rb', line 55

def initialize(order, , options = {})
  super
  collaborator = ActiveMerchant::Billing::Base.integration_mode == :test || options[:test] ? 'TOML' : 'DirecPay'
  add_field(mappings[:collaborator], collaborator)
  add_field(mappings[:country], 'IND')
  add_field(mappings[:operating_mode], OPERATING_MODE)
  add_field(mappings[:other_details], OTHER_DETAILS)
  add_field(mappings[:edit_allowed], EDIT_ALLOWED)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ActiveMerchant::Billing::Integrations::Helper

Instance Method Details

#amount=(money) ⇒ Object

Need to format the amount to have 2 decimal places



72
73
74
75
76
77
78
# File 'lib/active_merchant/billing/integrations/direc_pay/helper.rb', line 72

def amount=(money)
  cents = money.respond_to?(:cents) ? money.cents : money
  if money.is_a?(String) or cents.to_i <= 0
    raise ArgumentError, 'money amount must be either a Money object or a positive integer in cents.'
  end
  add_field(mappings[:amount], sprintf("%.2f", cents.to_f/100))
end

#billing_address(params = {}) ⇒ Object



84
85
86
# File 'lib/active_merchant/billing/integrations/direc_pay/helper.rb', line 84

def billing_address(params = {})
  super(update_address(:billing_address, params))
end

#customer(params = {}) ⇒ Object



66
67
68
69
# File 'lib/active_merchant/billing/integrations/direc_pay/helper.rb', line 66

def customer(params = {})
  add_field(mappings[:customer][:name], full_name(params))
  add_field(mappings[:customer][:email], params[:email])
end

#form_fieldsObject



88
89
90
91
92
93
# File 'lib/active_merchant/billing/integrations/direc_pay/helper.rb', line 88

def form_fields
  add_failure_url
  add_request_parameters
  
  unencoded_parameters
end

#shipping_address(params = {}) ⇒ Object



80
81
82
# File 'lib/active_merchant/billing/integrations/direc_pay/helper.rb', line 80

def shipping_address(params = {})
  super(update_address(:shipping_address, params))
end