Class: OffsitePayments::Integrations::Paytm::Helper
- Inherits:
-
Helper
- Object
- Helper
- OffsitePayments::Integrations::Paytm::Helper
show all
- Defined in:
- lib/offsite_payments/integrations/paytm.rb
Constant Summary
collapse
- CHECKSUM_FIELDS =
%w(MID ORDER_ID CALLBACK_URL CUST_ID TXN_AMOUNT CHANNEL_ID INDUSTRY_TYPE_ID WEBSITE MERC_UNQ_REF).freeze
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?
#to_cents
Constructor Details
#initialize(order, account, options = {}) ⇒ Helper
Returns a new instance of Helper.
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/offsite_payments/integrations/paytm.rb', line 63
def initialize(order, account, options = {})
super
@options = options
@timestamp = Time.now.strftime('%Y%m%d%H%M%S')
add_field(mappings[:channel_id], "WEB")
add_field 'ORDER_ID', "#{order}-#{@timestamp.to_i}"
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
#customer(options = {}) ⇒ Object
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/offsite_payments/integrations/paytm.rb', line 74
def customer(options = {})
customer_id =
if options[:email].present?
sanitize_field(options[:email])
else
sanitize_field(options[:phone])
end
add_field('CUST_ID', customer_id)
end
|
#encrypt_checksum ⇒ Object
90
91
92
93
94
95
96
97
98
|
# File 'lib/offsite_payments/integrations/paytm.rb', line 90
def encrypt_checksum
payload_items = {}
CHECKSUM_FIELDS.each do |field|
payload_items[field] = @fields[field]
end
Paytm.encrypt(Paytm.checksum(payload_items), @options[:credential2])
end
|
85
86
87
88
|
# File 'lib/offsite_payments/integrations/paytm.rb', line 85
def form_fields
sanitize_fields
@fields.merge(mappings[:checksum] => encrypt_checksum)
end
|
#sanitize_field(field) ⇒ Object
106
107
108
|
# File 'lib/offsite_payments/integrations/paytm.rb', line 106
def sanitize_field(field)
field.gsub(/[^a-zA-Z0-9\-_@\/\s.]/, '') if field
end
|
#sanitize_fields ⇒ Object
100
101
102
103
104
|
# File 'lib/offsite_payments/integrations/paytm.rb', line 100
def sanitize_fields
%w(email phone).each do |field|
@fields[field] = sanitize_field(@fields[field])
end
end
|