Class: OffsitePayments::Integrations::DirecPay::Helper

Inherits:
Helper
  • Object
show all
Defined in:
lib/offsite_payments/integrations/direc_pay.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, inherited, mapping, #raw_html_fields, #test?

Methods included from MoneyCompatibility

#to_cents

Constructor Details

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

Returns a new instance of Helper.



82
83
84
85
86
87
88
89
90
# File 'lib/offsite_payments/integrations/direc_pay.rb', line 82

def initialize(order, , options = {})
  super
  collaborator = OffsitePayments.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 OffsitePayments::Helper

Instance Method Details

#amount=(money) ⇒ Object

Need to format the amount to have 2 decimal places

Raises:

  • (ArgumentError)


99
100
101
102
103
104
105
# File 'lib/offsite_payments/integrations/direc_pay.rb', line 99

def amount=(money)
  cents = to_cents(money)
  raise ArgumentError, "amount must be a Money object or an integer" if money.is_a?(String)
  raise ActionViewHelperError, "amount must be greater than $0.00" if cents.to_i <= 0

  add_field(mappings[:amount], sprintf("%.2f", cents.to_f/100))
end

#billing_address(params = {}) ⇒ Object



111
112
113
# File 'lib/offsite_payments/integrations/direc_pay.rb', line 111

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

#customer(params = {}) ⇒ Object



93
94
95
96
# File 'lib/offsite_payments/integrations/direc_pay.rb', line 93

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

#form_fieldsObject



115
116
117
118
119
120
# File 'lib/offsite_payments/integrations/direc_pay.rb', line 115

def form_fields
  add_failure_url
  add_request_parameters

  unencoded_parameters
end

#shipping_address(params = {}) ⇒ Object



107
108
109
# File 'lib/offsite_payments/integrations/direc_pay.rb', line 107

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