class ActiveMerchant::Billing::MerchantOneGateway

Constants

BASE_URL

Public Class Methods

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

Public Instance Methods

authorize(money, creditcard, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/merchant_one.rb, line 27
def authorize(money, creditcard, options = {})
  post = {}
  add_customer_data(post, options)
  add_creditcard(post, creditcard)
  add_address(post, creditcard, options)
  add_customer_data(post, options)
  add_amount(post, money, options)
  commit('auth', money, post)
end
capture(money, authorization, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/merchant_one.rb, line 47
def capture(money, authorization, options = {})
  post = {}
  post[:transactionid] = authorization
  add_amount(post, money, options)
  commit('capture', money, post)
end
new_connection(endpoint) click to toggle source
# File lib/active_merchant/billing/gateways/merchant_one.rb, line 54
def new_connection(endpoint)
  MerchantOneSslConnection.new(endpoint)
end
purchase(money, creditcard, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/merchant_one.rb, line 37
def purchase(money, creditcard, options = {})
  post = {}
  add_customer_data(post, options)
  add_creditcard(post, creditcard)
  add_address(post, creditcard, options)
  add_customer_data(post, options)
  add_amount(post, money, options)
  commit('sale', money, post)
end

Private Instance Methods

add_address(post, creditcard, options) click to toggle source
# File lib/active_merchant/billing/gateways/merchant_one.rb, line 69
def add_address(post, creditcard, options)
  post['address1'] = options[:billing_address][:address1]
  post['city'] = options[:billing_address][:city]
  post['state'] = options[:billing_address][:state]
  post['zip'] = options[:billing_address][:zip]
  post['country'] = options[:billing_address][:country]
end
add_amount(post, money, options) click to toggle source
# File lib/active_merchant/billing/gateways/merchant_one.rb, line 65
def add_amount(post, money, options)
  post['amount'] = amount(money)
end
add_creditcard(post, creditcard) click to toggle source
# File lib/active_merchant/billing/gateways/merchant_one.rb, line 77
def add_creditcard(post, creditcard)
  post['cvv'] = creditcard.verification_value
  post['ccnumber'] = creditcard.number
  post['ccexp'] = "#{sprintf("%02d", creditcard.month)}#{creditcard.year.to_s[-2, 2]}"
end
add_customer_data(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/merchant_one.rb, line 60
def add_customer_data(post, options)
  post['firstname'] = options[:billing_address][:first_name]
  post['lastname'] = options[:billing_address][:last_name]
end
commit(action, money, parameters={}) click to toggle source
# File lib/active_merchant/billing/gateways/merchant_one.rb, line 83
def commit(action, money, parameters={})
  parameters['username'] = @options[:username]
  parameters['password'] = @options[:password]
  parse(ssl_post(BASE_URL, post_data(action, parameters)))
end
parse(data) click to toggle source
# File lib/active_merchant/billing/gateways/merchant_one.rb, line 101
def parse(data)
  responses =  CGI.parse(data).inject({}) { |h, (k, v)| h[k] = v.first; h }
  Response.new(
    (responses['response'].to_i == 1),
    responses['responsetext'],
    responses,
    :test => test?,
    :authorization => responses['transactionid']
  )
end
post_data(action, parameters = {}) click to toggle source
# File lib/active_merchant/billing/gateways/merchant_one.rb, line 89
def post_data(action, parameters = {})
  parameters[:type] = action
  ret = ''
  for key in parameters.keys
    ret += "#{key}=#{CGI.escape(parameters[key].to_s)}"
    if key != parameters.keys.last
      ret += '&'
    end
  end
  ret.to_s
end