class OffsitePayments::Integrations::PayflowLink::Helper
Public Class Methods
new(order, account, options = {})
click to toggle source
Calls superclass method
# File lib/offsite_payments/integrations/payflow_link.rb, line 18 def initialize(order, account, options = {}) super add_field('login', account) add_field('echodata', 'True') add_field('user2', self.test?) add_field('invoice', order) add_field('vendor', account) add_field('user', options[:credential4].presence || account) add_field('trxtype', options[:transaction_type] || 'S') end
Public Instance Methods
billing_address(params = {})
click to toggle source
# File lib/offsite_payments/integrations/payflow_link.rb, line 56 def billing_address(params = {}) # Get the country code in the correct format # Use what we were given if we can't find anything country_code = lookup_country_code(params.delete(:country)) add_field(mappings[:billing_address][:country], country_code) add_field(mappings[:billing_address][:address], [params.delete(:address1), params.delete(:address2)].compact.join(' ')) province_code = params.delete(:state) add_field(mappings[:billing_address][:state], province_code.blank? ? 'N/A' : province_code.upcase) # Everything else params.each do |k, v| field = mappings[:billing_address][k] add_field(field, v) unless field.nil? end end
customer(params = {})
click to toggle source
# File lib/offsite_payments/integrations/payflow_link.rb, line 51 def customer(params = {}) add_field(mappings[:customer][:first_name], params[:first_name]) add_field(mappings[:customer][:last_name], params[:last_name]) end
description(value)
click to toggle source
# File lib/offsite_payments/integrations/payflow_link.rb, line 47 def description(value) add_field('description', normalize("#{value}").delete("#")) end
form_fields()
click to toggle source
# File lib/offsite_payments/integrations/payflow_link.rb, line 74 def form_fields token, token_id = request_secure_token {"securetoken" => token, "securetokenid" => token_id, "mode" => test? ? "test" : "live"} end
Private Instance Methods
normalize(text)
click to toggle source
# File lib/offsite_payments/integrations/payflow_link.rb, line 111 def normalize(text) return unless text if ActiveSupport::Inflector.method(:transliterate).arity == -2 ActiveSupport::Inflector.transliterate(text,'') elsif RUBY_VERSION >= '1.9' text.gsub(/[^\x00-\x7F]+/, '') else ActiveSupport::Inflector.transliterate(text).to_s end end
parse_response(response)
click to toggle source
# File lib/offsite_payments/integrations/payflow_link.rb, line 101 def parse_response(response) response = response.split("&").inject({}) do |hash, param| key, value = param.split("=") hash[key] = value hash end [response['SECURETOKEN'], response['SECURETOKENID']] if response['RESPMSG'] && response['RESPMSG'].downcase == "approved" end
request_secure_token()
click to toggle source
# File lib/offsite_payments/integrations/payflow_link.rb, line 90 def request_secure_token @fields["securetokenid"] = secure_token_id @fields["createsecuretoken"] = "Y" fields = @fields.collect {|key, value| "#{key}[#{value.length}]=#{value}" }.join("&") response = ssl_post(secure_token_url, fields) parse_response(response) end
secure_token_id()
click to toggle source
# File lib/offsite_payments/integrations/payflow_link.rb, line 82 def secure_token_id @secure_token_id ||= SecureRandom.hex(16) end
secure_token_url()
click to toggle source
# File lib/offsite_payments/integrations/payflow_link.rb, line 86 def secure_token_url test? ? "https://pilot-payflowpro.paypal.com" : "https://payflowpro.paypal.com" end