class ActiveMerchant::Billing::EzicGateway

Public Class Methods

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

Public Instance Methods

authorize(money, payment, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/ezic.rb, line 29
def authorize(money, payment, options = {})
  post = {}

  add_account_id(post)
  add_invoice(post, money, options)
  add_payment(post, payment)
  add_customer_data(post, options)

  commit('A', post)
end
capture(money, authorization, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/ezic.rb, line 40
def capture(money, authorization, options = {})
  post = {}

  add_account_id(post)
  add_invoice(post, money, options)
  add_authorization(post, authorization)
  add_pay_type(post)

  commit('D', post)
end
purchase(money, payment, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/ezic.rb, line 18
def purchase(money, payment, options = {})
  post = {}

  add_account_id(post)
  add_invoice(post, money, options)
  add_payment(post, payment)
  add_customer_data(post, options)

  commit('S', post)
end
refund(money, authorization, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/ezic.rb, line 51
def refund(money, authorization, options = {})
  post = {}

  add_account_id(post)
  add_invoice(post, money, options)
  add_authorization(post, authorization)
  add_pay_type(post)

  commit('R', post)
end
scrub(transcript) click to toggle source
# File lib/active_merchant/billing/gateways/ezic.rb, line 83
def scrub(transcript)
  transcript.
    gsub(%r((card_number=)\w+), '\1[FILTERED]').
    gsub(%r((card_cvv2=)\w+), '\1[FILTERED]')
end
supports_scrubbing?() click to toggle source
# File lib/active_merchant/billing/gateways/ezic.rb, line 79
def supports_scrubbing?
  true
end
verify(credit_card, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/ezic.rb, line 72
def verify(credit_card, options = {})
  MultiResponse.run(:use_first_response) do |r|
    r.process { authorize(100, credit_card, options) }
    r.process(:ignore_result) { void(r.authorization, options) }
  end
end
void(authorization, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/ezic.rb, line 62
def void(authorization, options = {})
  post = {}

  add_account_id(post)
  add_authorization(post, authorization)
  add_pay_type(post)

  commit('U', post)
end

Private Instance Methods

add_account_id(post) click to toggle source
# File lib/active_merchant/billing/gateways/ezic.rb, line 91
def add_account_id(post)
  post[:account_id] = @options[:account_id]
end
add_addresses(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/ezic.rb, line 95
def add_addresses(post, options)
  add_billing_address(post, options)
  add_shipping_address(post, options)
end
add_authorization(post, authorization) click to toggle source
# File lib/active_merchant/billing/gateways/ezic.rb, line 141
def add_authorization(post, authorization)
  post[:orig_id] = authorization
end
add_billing_address(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/ezic.rb, line 100
def add_billing_address(post, options)
  address = options[:billing_address] || {}

  post[:bill_name1], post[:bill_name2] = split_names(address[:name])
  post[:bill_street] = address[:address1] if address[:address1]
  post[:bill_city] = address[:city] if address[:city]
  post[:bill_state] = address[:state] if address[:state]
  post[:bill_zip] = address[:zip] if address[:zip]
  post[:bill_country] = address[:country] if address[:country]
  post[:cust_phone] = address[:phone] if address[:phone]
end
add_customer_data(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/ezic.rb, line 123
def add_customer_data(post, options)
  post[:cust_ip] = options[:ip] if options[:ip]
  post[:cust_email] = options[:email] if options[:email]
  add_addresses(post, options)
end
add_invoice(post, money, options) click to toggle source
# File lib/active_merchant/billing/gateways/ezic.rb, line 129
def add_invoice(post, money, options)
  post[:amount] = amount(money)
  post[:description] = options[:description] if options[:description]
end
add_pay_type(post) click to toggle source
# File lib/active_merchant/billing/gateways/ezic.rb, line 145
def add_pay_type(post)
  post[:pay_type] = 'C'
end
add_payment(post, payment) click to toggle source
# File lib/active_merchant/billing/gateways/ezic.rb, line 134
def add_payment(post, payment)
  add_pay_type(post)
  post[:card_number] = payment.number
  post[:card_cvv2] = payment.verification_value
  post[:card_expire] = expdate(payment)
end
add_shipping_address(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/ezic.rb, line 112
def add_shipping_address(post, options)
  address = options[:shipping_address] || {}

  post[:ship_name1], post[:ship_name2] = split_names(address[:name])
  post[:ship_street] = address[:address1] if address[:address1]
  post[:ship_city] = address[:city] if address[:city]
  post[:ship_state] = address[:state] if address[:state]
  post[:ship_zip] = address[:zip] if address[:zip]
  post[:ship_country] = address[:country] if address[:country]
end
authorization_from(response) click to toggle source
# File lib/active_merchant/billing/gateways/ezic.rb, line 180
def authorization_from(response)
  response['trans_id']
end
commit(transaction_type, parameters) click to toggle source
# File lib/active_merchant/billing/gateways/ezic.rb, line 153
def commit(transaction_type, parameters)
  parameters[:tran_type] = transaction_type

  begin
    response = parse(ssl_post(live_url, post_data(parameters), headers))
    Response.new(
      success_from(response),
      message_from(response),
      response,
      authorization: authorization_from(response),
      avs_result: AVSResult.new(code: response['avs_code']),
      cvv_result: CVVResult.new(response['cvv2_code']),
      test: test?
    )
  rescue ResponseError => e
    Response.new(false, e.response.message)
  end
end
headers() click to toggle source
# File lib/active_merchant/billing/gateways/ezic.rb, line 188
def headers
  {
    'User-Agent' => "ActiveMerchantBindings/#{ActiveMerchant::VERSION}"
  }
end
message_from(response) click to toggle source
# File lib/active_merchant/billing/gateways/ezic.rb, line 176
def message_from(response)
  response['auth_msg']
end
parse(body) click to toggle source
# File lib/active_merchant/billing/gateways/ezic.rb, line 149
def parse(body)
  CGI::parse(body).inject({}) { |hash, (key, value)| hash[key] = value.first; hash }
end
post_data(parameters = {}) click to toggle source
# File lib/active_merchant/billing/gateways/ezic.rb, line 184
def post_data(parameters = {})
  parameters.collect { |key, value| "#{key}=#{CGI.escape(value.to_s)}" }.join('&')
end
success_from(response) click to toggle source
# File lib/active_merchant/billing/gateways/ezic.rb, line 172
def success_from(response)
  response['status_code'] == '1' || response['status_code'] == 'T'
end