Class: OffsitePayments::Integrations::PayuIn::Helper

Inherits:
Helper
  • Object
show all
Defined in:
lib/offsite_payments/integrations/payu_in.rb

Constant Summary collapse

CHECKSUM_FIELDS =
[ 'txnid', 'amount', 'productinfo', 'firstname', 'email', 'udf1', 'udf2', 'udf3', 'udf4',
'udf5', 'udf6', 'udf7', 'udf8', 'udf9', 'udf10']

Instance Attribute Summary

Attributes inherited from Helper

#fields

Instance Method Summary collapse

Methods inherited from Helper

#add_field, #add_fields, #add_raw_html_field, #billing_address, #form_method, inherited, mapping, #raw_html_fields, #shipping_address, #test?

Constructor Details

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

Returns a new instance of Helper



69
70
71
72
73
# File 'lib/offsite_payments/integrations/payu_in.rb', line 69

def initialize(order, , options = {})
  super
  @options = options
  self.pg = 'CC'
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class OffsitePayments::Helper

Instance Method Details

#form_fieldsObject



75
76
77
78
# File 'lib/offsite_payments/integrations/payu_in.rb', line 75

def form_fields
  sanitize_fields
  @fields.merge(mappings[:checksum] => generate_checksum)
end

#generate_checksumObject



80
81
82
83
84
# File 'lib/offsite_payments/integrations/payu_in.rb', line 80

def generate_checksum
  checksum_payload_items = CHECKSUM_FIELDS.map { |field| @fields[field] }

  PayuIn.checksum(@fields["key"], @options[:credential2], checksum_payload_items )
end

#sanitize_fieldsObject



86
87
88
89
90
# File 'lib/offsite_payments/integrations/payu_in.rb', line 86

def sanitize_fields
  ['address1', 'address2', 'city', 'state', 'country', 'productinfo', 'email', 'phone'].each do |field|
    @fields[field].gsub!(/[^a-zA-Z0-9\-_@\/\s.]/, '') if @fields[field]
  end
end