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 =
'N'
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, mapping

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



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

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



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

def billing_address(params = {})
  add_street_address!(params)
  super(params.dup)
  add_phone_for!(:billing_address, params)
end

#customer(params = {}) ⇒ Object



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

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

#form_fieldsObject



94
95
96
97
98
99
# File 'lib/active_merchant/billing/integrations/direc_pay/helper.rb', line 94

def form_fields
  add_failure_url
  add_request_parameters
  
  unencoded_parameters
end

#shipping_address(params = {}) ⇒ Object



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

def shipping_address(params = {})
  add_street_address!(params)
  super(params.dup)
  add_field(mappings[:shipping_address][:name], fields[mappings[:customer][:name]]) if fields[mappings[:shipping_address][:name]].blank?
  add_phone_for!(:shipping_address, params)
end