Module: OffsitePayments::Integrations::RealexOffsite::Common
- Included in:
- Helper, Notification
- Defined in:
- lib/offsite_payments/integrations/realex_offsite.rb
Constant Summary collapse
- CURRENCY_SPECIAL_MINOR_UNITS =
{ 'BIF' => 0, 'BYR' => 0, 'CLF' => 0, 'CLP' => 0, 'CVE' => 0, 'DJF' => 0, 'GNF' => 0, 'HUF' => 0, 'ISK' => 0, 'JPY' => 0, 'KMF' => 0, 'KRW' => 0, 'PYG' => 0, 'RWF' => 0, 'UGX' => 0, 'UYI' => 0, 'VND' => 0, 'VUV' => 0, 'XAF' => 0, 'XOF' => 0, 'XPF' => 0, 'BHD' => 3, 'IQD' => 3, 'JOD' => 3, 'KWD' => 3, 'LYD' => 3, 'OMR' => 3, 'TND' => 3, 'COU' => 4 }
- CANADIAN_STATES =
{ 'AB' => 'Alberta', 'BC' => 'British Columbia', 'MB' => 'Manitoba', 'NB' => 'New Brunswick', 'NL' => 'Newfoundland', 'NS' => 'Nova Scotia', 'NU' => 'Nunavut', 'NT' => 'Northwest Territories', 'ON' => 'Ontario', 'PE' => 'Prince Edward Island', 'QC' => 'Quebec', 'SK' => 'Saskatchewan', 'YT' => 'Yukon' }
- US_STATES =
{ 'AL' => 'Alabama', 'AK' => 'Alaska', 'AS' => 'American Samoa', 'AZ' => 'Arizona', 'AR' => 'Arkansas', 'CA' => 'California', 'CO' => 'Colorado', 'CT' => 'Connecticut', 'DE' => 'Delaware', 'DC' => 'District Of Columbia', 'FM' => 'Federated States Of Micronesia', 'FL' => 'Florida', 'GA' => 'Georgia', 'GU' => 'Guam', 'HI' => 'Hawaii', 'ID' => 'Idaho', 'IL' => 'Illinois', 'IN' => 'Indiana', 'IA' => 'Iowa', 'KS' => 'Kansas', 'KY' => 'Kentucky', 'LA' => 'Louisiana', 'ME' => 'Maine', 'MH' => 'Marshall Islands', 'MD' => 'Maryland', 'MA' => 'Massachusetts', 'MI' => 'Michigan', 'MN' => 'Minnesota', 'MS' => 'Mississippi', 'MO' => 'Missouri', 'MT' => 'Montana', 'NE' => 'Nebraska', 'NV' => 'Nevada', 'NH' => 'New Hampshire', 'NJ' => 'New Jersey', 'NM' => 'New Mexico', 'NY' => 'New York', 'NC' => 'North Carolina', 'ND' => 'North Dakota', 'MP' => 'Northern Mariana Islands', 'OH' => 'Ohio', 'OK' => 'Oklahoma', 'OR' => 'Oregon', 'PW' => 'Palau', 'PA' => 'Pennsylvania', 'PR' => 'Puerto Rico', 'RI' => 'Rhode Island', 'SC' => 'South Carolina', 'SD' => 'South Dakota', 'TN' => 'Tennessee', 'TX' => 'Texas', 'UT' => 'Utah', 'VT' => 'Vermont', 'VI' => 'Virgin Islands', 'VA' => 'Virginia', 'WA' => 'Washington', 'WV' => 'West Virginia', 'WI' => 'Wisconsin', 'WY' => 'Wyoming' }
Instance Method Summary collapse
-
#copy_billing_address ⇒ Object
if HPP_ADDRESS_MATCH_INDICATOR is set to TRUE HPP requires the shipping address to be sent from the billing address.
- #create_signature(fields, secret) ⇒ Object
- #extract_address_match_indicator(value) ⇒ Object
- #extract_avs_code(params = {}) ⇒ Object
- #extract_digits(value) ⇒ Object
-
#format_amount(amount, currency) ⇒ Object
Realex accepts currency amounts as an integer in the lowest value e.g.
-
#format_amount_as_float(amount, currency) ⇒ Object
Realex returns currency amount as an integer.
-
#format_phone_number(phone_number) ⇒ Object
The home phone number provided by the Cardholder.
- #lookup_state_code(country_code, state) ⇒ Object
Instance Method Details
#copy_billing_address ⇒ Object
if HPP_ADDRESS_MATCH_INDICATOR is set to TRUE HPP requires the shipping address to be sent from the billing address
210 211 212 213 214 215 |
# File 'lib/offsite_payments/integrations/realex_offsite.rb', line 210 def copy_billing_address @fields.select { |k, _| k.start_with? 'HPP_BILLING_' } .each do |k, v| add_field("HPP_SHIPPING_#{k.split('HPP_BILLING_')[1]}", v) end end |
#create_signature(fields, secret) ⇒ Object
145 146 147 148 149 150 |
# File 'lib/offsite_payments/integrations/realex_offsite.rb', line 145 def create_signature(fields, secret) data = fields.join('.') digest = Digest::SHA1.hexdigest(data) signed = "#{digest}.#{secret}" Digest::SHA1.hexdigest(signed) end |
#extract_address_match_indicator(value) ⇒ Object
178 179 180 |
# File 'lib/offsite_payments/integrations/realex_offsite.rb', line 178 def extract_address_match_indicator(value) value ? 'TRUE' : 'FALSE' end |
#extract_avs_code(params = {}) ⇒ Object
174 175 176 |
# File 'lib/offsite_payments/integrations/realex_offsite.rb', line 174 def extract_avs_code(params={}) [extract_digits(params[:zip]), extract_digits(params[:address1])].join('|') end |
#extract_digits(value) ⇒ Object
169 170 171 172 |
# File 'lib/offsite_payments/integrations/realex_offsite.rb', line 169 def extract_digits(value) return unless value value.scan(/\d+/).join('') end |
#format_amount(amount, currency) ⇒ Object
Realex accepts currency amounts as an integer in the lowest value e.g.
format_amount(110.56, 'GBP')
=> 11056
156 157 158 159 160 |
# File 'lib/offsite_payments/integrations/realex_offsite.rb', line 156 def format_amount(amount, currency) units = CURRENCY_SPECIAL_MINOR_UNITS[currency] || 2 multiple = 10**units return ((amount || 0).to_d * multiple.to_d).to_i end |
#format_amount_as_float(amount, currency) ⇒ Object
Realex returns currency amount as an integer
163 164 165 166 167 |
# File 'lib/offsite_payments/integrations/realex_offsite.rb', line 163 def format_amount_as_float(amount, currency) units = CURRENCY_SPECIAL_MINOR_UNITS[currency] || 2 divisor = 10**units return ((amount || 0).to_d / divisor.to_d) end |
#format_phone_number(phone_number) ⇒ Object
The home phone number provided by the Cardholder. Should be In format: of ‘CountryCallingCode|Number’ for example, ‘1|123456789’.
184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/offsite_payments/integrations/realex_offsite.rb', line 184 def format_phone_number(phone_number) return nil if phone_number.nil? clean_number = phone_number.gsub(/\D/, '') return phone_number if clean_number.length < 10 country_code = clean_number[0, clean_number.length - 9] number = clean_number[clean_number.length - 9, clean_number.length] "#{country_code}|#{number}" end |
#lookup_state_code(country_code, state) ⇒ Object
197 198 199 200 201 202 203 204 205 206 |
# File 'lib/offsite_payments/integrations/realex_offsite.rb', line 197 def lookup_state_code(country_code, state) case country_code when 'CA' state_code = CANADIAN_STATES.find { |code, state_name| state_name.downcase == state.downcase} state_code ? state_code.first : state when 'US' state_code = US_STATES.find { |code, state_name| state_name.downcase == state.downcase} state_code ? state_code.first : state end end |