class ActiveMerchant::Billing::PayConexGateway

Public Class Methods

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

Public Instance Methods

authorize(money, payment_method, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/pay_conex.rb, line 27
def authorize(money, payment_method, options={})
  post = {}
  add_auth_purchase_params(post, money, payment_method, options)
  commit("AUTHORIZATION", post)
end
capture(money, authorization, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/pay_conex.rb, line 33
def capture(money, authorization, options={})
  post = {}
  add_reference_params(post, authorization, options)
  add_amount(post, money, options)
  commit("CAPTURE", post)
end
credit(money, payment_method, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/pay_conex.rb, line 53
def credit(money, payment_method, options={})
  if payment_method.is_a?(String)
    raise ArgumentError, "Reference credits are not supported. Please supply the original credit card or use the #refund method."
  end

  post = {}
  add_auth_purchase_params(post, money, payment_method, options)
  commit("CREDIT", post)
end
purchase(money, payment_method, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/pay_conex.rb, line 21
def purchase(money, payment_method, options={})
  post = {}
  add_auth_purchase_params(post, money, payment_method, options)
  commit("SALE", post)
end
refund(money, authorization, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/pay_conex.rb, line 40
def refund(money, authorization, options={})
  post = {}
  add_reference_params(post, authorization, options)
  add_amount(post, money, options)
  commit("REFUND", post)
end
scrub(transcript) click to toggle source
# File lib/active_merchant/billing/gateways/pay_conex.rb, line 80
def scrub(transcript)
  force_utf8(transcript).
    gsub(%r((api_accesskey=)\w+), '\1[FILTERED]').
    gsub(%r((card_number=)\w+), '\1[FILTERED]').
    gsub(%r((card_verification=)\w+), '\1[FILTERED]')
end
store(payment_method, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/pay_conex.rb, line 67
def store(payment_method, options={})
  post = {}
  add_credentials(post)
  add_payment_method(post, payment_method)
  add_address(post, options)
  add_common_options(post, options)
  commit("STORE", post)
end
supports_scrubbing?() click to toggle source
# File lib/active_merchant/billing/gateways/pay_conex.rb, line 76
def supports_scrubbing?
  true
end
verify(payment_method, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/pay_conex.rb, line 63
def verify(payment_method, options={})
  authorize(0, payment_method, options)
end
void(authorization, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/pay_conex.rb, line 47
def void(authorization, options = {})
  post = {}
  add_reference_params(post, authorization, options)
  commit("REVERSAL", post)
end

Private Instance Methods

add_address(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/pay_conex.rb, line 166
def add_address(post, options)
  address = options[:billing_address]
  return unless address

  add_if_present(post, :street_address1, address[:address1])
  add_if_present(post, :street_address2, address[:address2])
  add_if_present(post, :city, address[:city])
  add_if_present(post, :state, address[:state])
  add_if_present(post, :zip, address[:zip])
  add_if_present(post, :country, address[:country])
  add_if_present(post, :phone, address[:phone])
end
add_amount(post, money, options) click to toggle source
# File lib/active_merchant/billing/gateways/pay_conex.rb, line 115
def add_amount(post, money, options)
  post[:transaction_amount] = amount(money)
  currency_code = (options[:currency] || currency(money))
  add_if_present(post, :currency, currency_code)
end
add_auth_purchase_params(post, money, payment_method, options) click to toggle source
# File lib/active_merchant/billing/gateways/pay_conex.rb, line 100
def add_auth_purchase_params(post, money, payment_method, options)
  add_credentials(post)
  add_payment_method(post, payment_method)
  add_address(post, options)
  add_common_options(post, options)
  add_amount(post, money, options)
  add_if_present(post, :email, options[:email])
end
add_card_present_payment_method(post, payment_method) click to toggle source
# File lib/active_merchant/billing/gateways/pay_conex.rb, line 151
def add_card_present_payment_method(post, payment_method)
  post[:tender_type] = "CARD"
  post[:card_tracks] = payment_method.track_data
end
add_check(post, payment_method) click to toggle source
# File lib/active_merchant/billing/gateways/pay_conex.rb, line 156
def add_check(post, payment_method)
  post[:tender_type] = "ACH"
  post[:first_name] = payment_method.first_name
  post[:last_name] = payment_method.last_name
  post[:bank_account_number] = payment_method.account_number
  post[:bank_routing_number] = payment_method.routing_number
  post[:check_number] = payment_method.number
  add_if_present(post, :ach_account_type, payment_method.account_type)
end
add_common_options(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/pay_conex.rb, line 179
def add_common_options(post, options)
  add_if_present(post, :transaction_description, options[:description])
  add_if_present(post, :custom_id, options[:custom_id])
  add_if_present(post, :custom_data, options[:custom_data])
  add_if_present(post, :ip_address, options[:ip])
  add_if_present(post, :payment_type, options[:payment_type])
  add_if_present(post, :cashier, options[:cashier])

  post[:disable_cvv] = options[:disable_cvv] unless options[:disable_cvv].nil?
  post[:response_format] = 'JSON'
end
add_credentials(post) click to toggle source
# File lib/active_merchant/billing/gateways/pay_conex.rb, line 95
def add_credentials(post)
  post[:account_id] = @options[:account_id]
  post[:api_accesskey] = @options[:api_accesskey]
end
add_credit_card(post, payment_method) click to toggle source
# File lib/active_merchant/billing/gateways/pay_conex.rb, line 136
def add_credit_card(post, payment_method)
  post[:tender_type] = "CARD"
  post[:card_number] = payment_method.number
  post[:card_expiration] = expdate(payment_method)
  post[:card_verification] = payment_method.verification_value
  post[:first_name] = payment_method.first_name
  post[:last_name] = payment_method.last_name
end
add_if_present(post, key, value) click to toggle source
# File lib/active_merchant/billing/gateways/pay_conex.rb, line 191
def add_if_present(post, key, value)
  post[key] = value unless empty?(value)
end
add_payment_method(post, payment_method) click to toggle source
# File lib/active_merchant/billing/gateways/pay_conex.rb, line 121
def add_payment_method(post, payment_method)
  case payment_method
  when String
    add_token_payment_method(post, payment_method)
  when Check
    add_check(post, payment_method)
  else
    if payment_method.respond_to?(:track_data) && payment_method.track_data.present?
      add_card_present_payment_method(post, payment_method)
    else
      add_credit_card(post, payment_method)
    end
  end
end
add_reference_params(post, authorization, options) click to toggle source
# File lib/active_merchant/billing/gateways/pay_conex.rb, line 109
def add_reference_params(post, authorization, options)
  add_credentials(post)
  add_common_options(post, options)
  add_token_id(post, authorization)
end
add_token_id(post, authorization) click to toggle source
# File lib/active_merchant/billing/gateways/pay_conex.rb, line 195
def add_token_id(post, authorization)
  post[:token_id] = authorization
end
add_token_payment_method(post, payment_method) click to toggle source
# File lib/active_merchant/billing/gateways/pay_conex.rb, line 145
def add_token_payment_method(post, payment_method)
  post[:tender_type] = "CARD"
  post[:token_id] = payment_method
  post[:reissue] = true
end
commit(action, params) click to toggle source
# File lib/active_merchant/billing/gateways/pay_conex.rb, line 203
def commit(action, params)
  raw_response = ssl_post(url, post_data(action, params))
  response = parse(raw_response)

  Response.new(
    success_from(response),
    message_from(response),
    response,
    authorization: response["transaction_id"],
    :avs_result => AVSResult.new(code: response["avs_response"]),
    :cvv_result => CVVResult.new(response["cvv2_response"]),
    test: test?
  )

rescue JSON::ParserError
  unparsable_response(raw_response)
end
force_utf8(string) click to toggle source
# File lib/active_merchant/billing/gateways/pay_conex.rb, line 89
def force_utf8(string)
  return nil unless string
  binary = string.encode("BINARY", invalid: :replace, undef: :replace, replace: "?")   # Needed for Ruby 2.0 since #encode is a no-op if the string is already UTF-8. It's not needed for Ruby 2.1 and up since it's not a no-op there.
  binary.encode("UTF-8", invalid: :replace, undef: :replace, replace: "?")
end
message_from(response) click to toggle source
# File lib/active_merchant/billing/gateways/pay_conex.rb, line 229
def message_from(response)
  success_from(response) ? response["authorization_message"] : response["error_message"]
end
parse(body) click to toggle source
# File lib/active_merchant/billing/gateways/pay_conex.rb, line 199
def parse(body)
  JSON.parse(body)
end
post_data(action, params) click to toggle source
# File lib/active_merchant/billing/gateways/pay_conex.rb, line 233
def post_data(action, params)
  params[:transaction_type] = action
  params.map {|k, v| "#{k}=#{CGI.escape(v.to_s)}"}.join('&')
end
success_from(response) click to toggle source
# File lib/active_merchant/billing/gateways/pay_conex.rb, line 225
def success_from(response)
  response["transaction_approved"] || !response["error"]
end
unparsable_response(raw_response) click to toggle source
# File lib/active_merchant/billing/gateways/pay_conex.rb, line 238
def unparsable_response(raw_response)
  message = "Invalid JSON response received from PayConex. Please contact PayConex if you continue to receive this message."
  message += " (The raw response returned by the API was #{raw_response.inspect})"
  return Response.new(false, message)
end
url() click to toggle source
# File lib/active_merchant/billing/gateways/pay_conex.rb, line 221
def url
  test? ? test_url : live_url
end