# File lib/active_merchant/billing/integrations/sage_pay_form/helper.rb, line 44 44: def form_fields 45: fields['DeliveryFirstnames'] ||= fields['BillingFirstnames'] 46: fields['DeliverySurname'] ||= fields['BillingSurname'] 47: 48: fields['FailureURL'] ||= fields['SuccessURL'] 49: 50: crypt_skip = ['Vendor', 'EncryptKey', 'SendEmail'] 51: crypt_skip << 'BillingState' unless fields['BillingCountry'] == 'US' 52: crypt_skip << 'DeliveryState' unless fields['DeliveryCountry'] == 'US' 53: crypt_skip << 'CustomerEMail' unless fields['SendEmail'] 54: 55: key = fields['EncryptKey'] 56: @crypt ||= create_crypt_field(fields.except(*crypt_skip), key) 57: 58: { 59: 'VPSProtocol' => '2.23', 60: 'TxType' => 'PAYMENT', 61: 'Vendor' => @fields['Vendor'], 62: 'Crypt' => @crypt 63: } 64: end
# File lib/active_merchant/billing/integrations/sage_pay_form/helper.rb, line 68 68: def create_crypt_field(fields, key) 69: parts = fields.map { |k, v| "#{k}=#{sanitize(k, v)}" unless v.nil? }.compact.shuffle 70: parts.unshift(sage_encrypt_salt(key.length, key.length * 2)) 71: sage_encrypt(parts.join('&'), key) 72: end
# File lib/active_merchant/billing/integrations/sage_pay_form/helper.rb, line 74 74: def sanitize(key, value) 75: reject = exact = nil 76: 77: case key 78: when /URL$/ 79: # allow all 80: when 'VendorTxCode' 81: reject = /[^A-Za-z0-9{}._-]+/ 82: when /[Nn]ames?$/ 83: reject = %{[^[:alpha:] /\\.'-]+} 84: when /(?:Address[12]|City)$/ 85: reject = %{[^[:alnum:] +'/\\:,.\n()-]+} 86: when /PostCode$/ 87: reject = /[^A-Za-z0-9 -]+/ 88: when /Phone$/ 89: reject = /[^0-9A-Za-z+ ()-]+/ 90: when 'Currency' 91: exact = /^[A-Z]{3}$/ 92: when /State$/ 93: exact = /^[A-Z]{2}$/ 94: else 95: reject = /&+/ 96: end 97: 98: if exact 99: raise ArgumentError, "Invalid value for #{key}: #{value.inspect}" unless value =~ exact 100: value 101: elsif reject 102: value.gsub(reject, ' ') 103: else 104: value 105: end 106: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.