# File lib/active_merchant/billing/integrations/direc_pay/helper.rb, line 55 55: def initialize(order, account, options = {}) 56: super 57: collaborator = ActiveMerchant::Billing::Base.integration_mode == :test || options[:test] ? 'TOML' : 'DirecPay' 58: add_field(mappings[:collaborator], collaborator) 59: add_field(mappings[:country], 'IND') 60: add_field(mappings[:operating_mode], OPERATING_MODE) 61: add_field(mappings[:other_details], OTHER_DETAILS) 62: add_field(mappings[:edit_allowed], EDIT_ALLOWED) 63: end
Need to format the amount to have 2 decimal places
# File lib/active_merchant/billing/integrations/direc_pay/helper.rb, line 72 72: def amount=(money) 73: cents = money.respond_to?(:cents) ? money.cents : money 74: if money.is_a?(String) or cents.to_i <= 0 75: raise ArgumentError, 'money amount must be either a Money object or a positive integer in cents.' 76: end 77: add_field(mappings[:amount], sprintf("%.2f", cents.to_f/100)) 78: end
# File lib/active_merchant/billing/integrations/direc_pay/helper.rb, line 84 84: def billing_address(params = {}) 85: super(update_address(:billing_address, params)) 86: end
# File lib/active_merchant/billing/integrations/direc_pay/helper.rb, line 66 66: def customer(params = {}) 67: add_field(mappings[:customer][:name], full_name(params)) 68: add_field(mappings[:customer][:email], params[:email]) 69: end
# File lib/active_merchant/billing/integrations/direc_pay/helper.rb, line 114 114: def add_failure_url 115: if fields[mappings[:failure_url]].nil? 116: add_field(mappings[:failure_url], fields[mappings[:return_url]]) 117: end 118: end
Split a single phone number into the country code, area code and local number as best as possible
# File lib/active_merchant/billing/integrations/direc_pay/helper.rb, line 138 138: def add_land_line_phone_for(address_type, params) 139: address_field = address_type == :billing_address ? 'custPhoneNo' : 'deliveryPhNo' 140: 141: if params.has_key?(:phone2) 142: phone = normalize_phone_number(params[:phone2]) 143: phone_country_code, phone_area_code, phone_number = nil 144: 145: if params[:country] == 'IN' && phone =~ /(91)? *(\d{3}) *(\d{4,})$/ 146: phone_country_code, phone_area_code, phone_number = $1, $2, $3 147: else 148: numbers = phone.split(' ') 149: case numbers.size 150: when 3 151: phone_country_code, phone_area_code, phone_number = numbers 152: when 2 153: phone_area_code, phone_number = numbers 154: else 155: phone =~ /(\d{3})(\d+)$/ 156: phone_area_code, phone_number = $1, $2 157: end 158: end 159: 160: add_field("#{address_field}1", phone_country_code || phone_code_for_country(params[:country]) || '91') 161: add_field("#{address_field}2", phone_area_code) 162: add_field("#{address_field}3", phone_number) 163: end 164: end
# File lib/active_merchant/billing/integrations/direc_pay/helper.rb, line 98 98: def add_request_parameters 99: params = ENCODED_PARAMS.map{ |param| fields[mappings[param]] } 100: encoded = encode_value(params.join('|')) 101: 102: add_field('requestparameter', encoded) 103: end
# File lib/active_merchant/billing/integrations/direc_pay/helper.rb, line 181 181: def decode_value(value) 182: decoded = ActiveSupport::Base64.decode64(value) 183: string_to_decode = decoded[0, 1] + decoded[2, decoded.length] 184: ActiveSupport::Base64.decode64(string_to_decode) 185: end
# File lib/active_merchant/billing/integrations/direc_pay/helper.rb, line 175 175: def encode_value(value) 176: encoded = ActiveSupport::Base64.encode64s(value) 177: string_to_encode = encoded[0, 1] + "T" + encoded[1, encoded.length] 178: ActiveSupport::Base64.encode64s(string_to_encode) 179: end
# File lib/active_merchant/billing/integrations/direc_pay/helper.rb, line 191 191: def full_name(params) 192: return if params[:name].blank? && params[:first_name].blank? && params[:last_name].blank? 193: 194: params[:name] || "#{params[:first_name]} #{params[:last_name]}" 195: end
# File lib/active_merchant/billing/integrations/direc_pay/helper.rb, line 166 166: def normalize_phone_number(phone) 167: phone.gsub(/[^\d ]+/, '') if phone 168: end
# File lib/active_merchant/billing/integrations/direc_pay/helper.rb, line 187 187: def phone_code_for_country(country) 188: PHONE_CODES[country] 189: end
Special characters are NOT allowed while posting transaction parameters on DirecPay system
# File lib/active_merchant/billing/integrations/direc_pay/helper.rb, line 171 171: def remove_special_characters(string) 172: string.gsub(/[~"'&#%]/, '-') 173: end
# File lib/active_merchant/billing/integrations/direc_pay/helper.rb, line 105 105: def unencoded_parameters 106: params = fields.dup 107: # remove all encoded params from exported fields 108: ENCODED_PARAMS.each{ |param| params.delete(mappings[param]) } 109: # remove all special characters from each field value 110: params = params.collect{|name, value| [name, remove_special_characters(value)] } 111: Hash[params] 112: end
# File lib/active_merchant/billing/integrations/direc_pay/helper.rb, line 120 120: def update_address(address_type, params) 121: params = params.dup 122: address = params[:address1] 123: address = "#{address} #{params[:address2]}" if params[:address2].present? 124: address = "#{params[:company]} #{address}" if params[:company].present? 125: params[:address1] = address 126: 127: params[:phone] = normalize_phone_number(params[:phone]) 128: add_land_line_phone_for(address_type, params) 129: 130: if address_type == :shipping_address 131: shipping_name = full_name(params) || fields[mappings[:customer][:name]] 132: add_field(mappings[:shipping_address][:name], shipping_name) 133: end 134: params 135: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.