class ActiveMerchant::Billing::JetpayGateway

Constants

ACTION_CODE_MESSAGES

Public Class Methods

new(options = {}) click to toggle source
Calls superclass method ActiveMerchant::Billing::Gateway::new
# File lib/active_merchant/billing/gateways/jetpay.rb, line 65
def initialize(options = {})
  requires!(options, :login)
  super
end

Public Instance Methods

authorize(money, credit_card, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/jetpay.rb, line 74
def authorize(money, credit_card, options = {})
  commit(money, build_authonly_request(money, credit_card, options))
end
capture(money, reference, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/jetpay.rb, line 78
def capture(money, reference, options = {})
  commit(money, build_capture_request('CAPT', reference.split(";").first))
end
credit(money, transaction_id_or_card, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/jetpay.rb, line 87
def credit(money, transaction_id_or_card, options = {})
  if transaction_id_or_card.is_a?(String)
    ActiveMerchant.deprecated CREDIT_DEPRECATION_MESSAGE
    refund(money, transaction_id_or_card, options)
  else
    commit(money, build_credit_request('CREDIT', money, nil, transaction_id_or_card))
  end
end
purchase(money, credit_card, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/jetpay.rb, line 70
def purchase(money, credit_card, options = {})
  commit(money, build_sale_request(money, credit_card, options))
end
refund(money, reference, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/jetpay.rb, line 96
def refund(money, reference, options = {})
  transaction_id = reference.split(";").first
  credit_card = options[:credit_card]
  commit(money, build_credit_request('CREDIT', money, transaction_id, credit_card))
end
void(reference, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/jetpay.rb, line 82
def void(reference, options = {})
  transaction_id, approval, amount = reference.split(";")
  commit(amount.to_i, build_void_request(amount.to_i, transaction_id, approval))
end

Private Instance Methods

add_addresses(xml, options) click to toggle source
# File lib/active_merchant/billing/gateways/jetpay.rb, line 233
def add_addresses(xml, options)
  if billing_address = options[:billing_address] || options[:address]
    xml.tag! 'BillingAddress', [billing_address[:address1], billing_address[:address2]].compact.join(" ")
    xml.tag! 'BillingCity', billing_address[:city]
    xml.tag! 'BillingStateProv', billing_address[:state]
    xml.tag! 'BillingPostalCode', billing_address[:zip]
    xml.tag! 'BillingCountry', lookup_country_code(billing_address[:country])
    xml.tag! 'BillingPhone', billing_address[:phone]
  end

  if shipping_address = options[:shipping_address]
    xml.tag! 'ShippingInfo' do
      xml.tag! 'ShippingName', shipping_address[:name]

      xml.tag! 'ShippingAddr' do
        xml.tag! 'Address', [shipping_address[:address1], shipping_address[:address2]].compact.join(" ")
        xml.tag! 'City', shipping_address[:city]
        xml.tag! 'StateProv', shipping_address[:state]
        xml.tag! 'PostalCode', shipping_address[:zip]
        xml.tag! 'Country', lookup_country_code(shipping_address[:country])
      end
    end
  end
end
add_credit_card(xml, credit_card) click to toggle source
# File lib/active_merchant/billing/gateways/jetpay.rb, line 219
def add_credit_card(xml, credit_card)
  xml.tag! 'CardNum', credit_card.number
  xml.tag! 'CardExpMonth', format_exp(credit_card.month)
  xml.tag! 'CardExpYear', format_exp(credit_card.year)

  if credit_card.first_name || credit_card.last_name
    xml.tag! 'CardName', [credit_card.first_name,credit_card.last_name].compact.join(' ')
  end

  unless credit_card.verification_value.nil? || (credit_card.verification_value.length == 0)
    xml.tag! 'CVV2', credit_card.verification_value
  end
end
add_customer_data(xml, options) click to toggle source
# File lib/active_merchant/billing/gateways/jetpay.rb, line 258
def add_customer_data(xml, options)
  xml.tag! 'Email', options[:email] if options[:email]
  xml.tag! 'UserIPAddress', options[:ip] if options[:ip]
end
add_invoice_data(xml, options) click to toggle source
# File lib/active_merchant/billing/gateways/jetpay.rb, line 263
def add_invoice_data(xml, options)
  xml.tag! 'OrderNumber', options[:order_id] if options[:order_id]
  xml.tag! 'TaxAmount', amount(options[:tax]) if options[:tax]
end
authorization_from(response, money) click to toggle source
# File lib/active_merchant/billing/gateways/jetpay.rb, line 214
def authorization_from(response, money)
  original_amount = amount(money) if money
  [ response[:transaction_id], response[:approval], original_amount ].join(";")
end
build_authonly_request(money, credit_card, options) click to toggle source
# File lib/active_merchant/billing/gateways/jetpay.rb, line 133
def build_authonly_request(money, credit_card, options)
  build_xml_request('AUTHONLY') do |xml|
    add_credit_card(xml, credit_card)
    add_addresses(xml, options)
    add_customer_data(xml, options)
    add_invoice_data(xml, options)
    xml.tag! 'TotalAmount', amount(money)

    xml.target!
  end
end
build_capture_request(transaction_type, transaction_id) click to toggle source
# File lib/active_merchant/billing/gateways/jetpay.rb, line 145
def build_capture_request(transaction_type, transaction_id)
  build_xml_request(transaction_type, transaction_id)
end
build_credit_request(transaction_type, money, transaction_id, card) click to toggle source

‘transaction_id` may be nil for unlinked credit transactions.

# File lib/active_merchant/billing/gateways/jetpay.rb, line 159
def build_credit_request(transaction_type, money, transaction_id, card)
  build_xml_request(transaction_type, transaction_id) do |xml|
    add_credit_card(xml, card) if card
    xml.tag! 'TotalAmount', amount(money)

    xml.target!
  end
end
build_sale_request(money, credit_card, options) click to toggle source
# File lib/active_merchant/billing/gateways/jetpay.rb, line 121
def build_sale_request(money, credit_card, options)
  build_xml_request('SALE') do |xml|
    add_credit_card(xml, credit_card)
    add_addresses(xml, options)
    add_customer_data(xml, options)
    add_invoice_data(xml, options)
    xml.tag! 'TotalAmount', amount(money)

    xml.target!
  end
end
build_void_request(money, transaction_id, approval) click to toggle source
# File lib/active_merchant/billing/gateways/jetpay.rb, line 149
def build_void_request(money, transaction_id, approval)
  build_xml_request('VOID', transaction_id) do |xml|
    xml.tag! 'Approval', approval
    xml.tag! 'TotalAmount', amount(money)

    xml.target!
  end
end
build_xml_request(transaction_type, transaction_id = nil) { |xml| ... } click to toggle source
# File lib/active_merchant/billing/gateways/jetpay.rb, line 105
def build_xml_request(transaction_type, transaction_id = nil, &block)
  xml = Builder::XmlMarkup.new
  xml.tag! 'JetPay' do
    # The basic values needed for any request
    xml.tag! 'TerminalID', @options[:login]
    xml.tag! 'TransactionType', transaction_type
    xml.tag! 'TransactionID', transaction_id.nil? ? generate_unique_id.slice(0, 18) : transaction_id

    if block_given?
      yield xml
    else
      xml.target!
    end
  end
end
commit(money, request) click to toggle source
# File lib/active_merchant/billing/gateways/jetpay.rb, line 168
def commit(money, request)
  response = parse(ssl_post(test? ? self.test_url : self.live_url, request))

  success = success?(response)
  Response.new(success,
    success ? 'APPROVED' : message_from(response),
    response,
    :test => test?,
    :authorization => authorization_from(response, money),
    :avs_result => { :code => response[:avs] },
    :cvv_result => response[:cvv2]
  )
end
format_exp(value) click to toggle source
# File lib/active_merchant/billing/gateways/jetpay.rb, line 202
def format_exp(value)
  format(value, :two_digits)
end
lookup_country_code(code) click to toggle source
# File lib/active_merchant/billing/gateways/jetpay.rb, line 268
def lookup_country_code(code)
  country = Country.find(code) rescue nil
  country && country.code(:alpha3)
end
message_from(response) click to toggle source
# File lib/active_merchant/billing/gateways/jetpay.rb, line 210
def message_from(response)
  ACTION_CODE_MESSAGES[response[:action_code]]
end
parse(body) click to toggle source
# File lib/active_merchant/billing/gateways/jetpay.rb, line 182
def parse(body)
  return {} if body.blank?

  xml = REXML::Document.new(body)

  response = {}
  xml.root.elements.to_a.each do |node|
    parse_element(response, node)
  end
  response
end
parse_element(response, node) click to toggle source
# File lib/active_merchant/billing/gateways/jetpay.rb, line 194
def parse_element(response, node)
  if node.has_elements?
    node.elements.each{|element| parse_element(response, element) }
  else
    response[node.name.underscore.to_sym] = node.text
  end
end
success?(response) click to toggle source
# File lib/active_merchant/billing/gateways/jetpay.rb, line 206
def success?(response)
  response[:action_code] == "000"
end