class AmexEnhancedAuthorization::OnlinePurchasePayload

Attributes

amount[RW]
billing_address[RW]
billing_first_name[RW]
billing_last_name[RW]
billing_phone_number[RW]
billing_postal_code[RW]
card_acceptor_id[RW]
card_number[RW]
currency_code[RW]
customer_email[RW]
device_ip[RW]
shipto_address[RW]
shipto_country_code[RW]
shipto_first_name[RW]
shipto_last_name[RW]
shipto_phone_number[RW]
shipto_postal_code[RW]
timestamp[RW]

Public Class Methods

new(params) click to toggle source
# File lib/amex_enhanced_authorization/online_purchase_payload.rb, line 11
def initialize(params)
  params.each_pair { |k, v| send "#{k}=", v }
end

Public Instance Methods

to_json() click to toggle source
# File lib/amex_enhanced_authorization/online_purchase_payload.rb, line 15
def to_json
  payload = {
    timestamp: strftime(Time.now),
    transaction_data: {
      card_acceptor_id: card_acceptor_id.to_s, # aka. SE10 or Merchant code
      card_number: card_number,
      amount: amount.to_s,
      currency_code: currency_code,
      transaction_timestamp: strftime(timestamp),
      additional_information: { risk_score: true },
    }
  }
  payload[:purchaser_information] = purchaser_information if purchaser_information.any?
  payload.to_json
end

Protected Instance Methods

ascify(s) click to toggle source
# File lib/amex_enhanced_authorization/online_purchase_payload.rb, line 55
    def ascify(s)
      s && s.tr( 
"ÀÁÂÃÄÅàáâãäåĀāĂ㥹ÇçĆćĈĉĊċČčÐðĎďĐđÈÉÊËèéêëĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħÌÍÎÏìíîïĨĩĪīĬĭĮįİıĴĵĶķĸĹĺĻļĽľĿŀŁłÑñŃńŅņŇňʼnŊŋÒÓÔÕÖØòóôõöøŌōŎŏŐőŔŕŖŗŘřŚśŜŝŞşŠšſŢţŤťŦŧÙÚÛÜùúûüŨũŪūŬŭŮůŰűŲųŴŵÝýÿŶŷŸŹźŻżŽž", 
"AAAAAAaaaaaaAaAaAaCcCcCcCcCcDdDdDdEEEEeeeeEeEeEeEeEeGgGgGgGgHhHhIIIIiiiiIiIiIiIiIiJjKkkLlLlLlLlLlNnNnNnNnnNnOOOOOOooooooOoOoOoRrRrRrSsSsSsSssTtTtTtUUUUuuuuUuUuUuUuUuUuWwYyyYyYZzZzZz")
    end
munge(s, exp, length) click to toggle source
# File lib/amex_enhanced_authorization/online_purchase_payload.rb, line 51
def munge(s, exp, length)
  s && ascify(s).gsub(exp, ' ')[0..(length-1)]
end
purchaser_information() click to toggle source
# File lib/amex_enhanced_authorization/online_purchase_payload.rb, line 33
def purchaser_information
  @purchaser_information ||= {
    customer_email: customer_email,
    billing_address: munge(billing_address, /[^A-Za-z0-9 ]/, 70),
    billing_postal_code: munge(billing_postal_code, /[^A-Za-z0-9\- ]/, 9),
    billing_first_name: munge(billing_first_name, /[^A-Za-z0-9 ]/, 30),
    billing_last_name: munge(billing_last_name, /[^A-Za-z0-9 ]/,  30),
    billing_phone_number: billing_phone_number,
    shipto_address: munge(shipto_address, /[^A-Za-z0-9 ]/, 50),
    shipto_postal_code: shipto_postal_code,
    shipto_first_name: shipto_first_name,
    shipto_last_name: munge(shipto_last_name, /[^A-Za-z0-9 ]/, 30),
    shipto_phone_number: shipto_phone_number,
    shipto_country_code: shipto_country_code,
    device_ip: device_ip,
  }.compact
end
strftime(timestamp) click to toggle source
# File lib/amex_enhanced_authorization/online_purchase_payload.rb, line 61
def strftime(timestamp)
  timestamp.utc.strftime('%Y-%m-%dT%H:%M:%S.%L%:z')
end