class ActiveMerchant::Billing::MerchantPartnersGateway

Constants

ACTIONS
STORE_TX_TYPES

Public Class Methods

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

Public Instance Methods

authorize(amount, payment_method, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/merchant_partners.rb, line 30
def authorize(amount, payment_method, options={})
  post = {}
  add_invoice(post, amount, options)
  add_payment_method(post, payment_method)
  add_customer_data(post, options)

  commit(:authorize, post)
end
capture(amount, authorization, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/merchant_partners.rb, line 39
def capture(amount, authorization, options={})
  post = {}
  add_invoice(post, amount, options)
  add_reference(post, authorization)
  add_customer_data(post, options)

  commit(:capture, post)
end
credit(amount, payment_method, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/merchant_partners.rb, line 64
def credit(amount, payment_method, options={})
  post = {}
  add_invoice(post, amount, options)
  add_payment_method(post, payment_method)

  commit(payment_method.is_a?(String) ? :stored_credit : :credit, post)
end
purchase(amount, payment_method, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/merchant_partners.rb, line 21
def purchase(amount, payment_method, options={})
  post = {}
  add_invoice(post, amount, options)
  add_payment_method(post, payment_method)
  add_customer_data(post, options)

  commit(payment_method.is_a?(String) ? :stored_purchase : :purchase, post)
end
refund(amount, authorization, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/merchant_partners.rb, line 55
def refund(amount, authorization, options={})
  post = {}
  add_invoice(post, amount, options)
  add_reference(post, authorization)
  add_customer_data(post, options)

  commit(:refund, post)
end
scrub(transcript) click to toggle source
# File lib/active_merchant/billing/gateways/merchant_partners.rb, line 93
def scrub(transcript)
  transcript.
    gsub(%r((<ccnum>)[^<]+(<))i, '\1[FILTERED]\2').
    gsub(%r((<cvv2>)[^<]+(<))i, '\1[FILTERED]\2').
    gsub(%r((<merchantpin>)[^<]+(<))i, '\1[FILTERED]\2')
end
store(payment_method, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/merchant_partners.rb, line 79
def store(payment_method, options = {})
  post = {}
  add_payment_method(post, payment_method)
  add_customer_data(post, options)

  post[:profileactiontype] = options[:profileactiontype] || STORE_TX_TYPES[:store_only]

  commit(:store, post)
end
supports_scrubbing?() click to toggle source
# File lib/active_merchant/billing/gateways/merchant_partners.rb, line 89
def supports_scrubbing?
  true
end
test?() click to toggle source
# File lib/active_merchant/billing/gateways/merchant_partners.rb, line 100
def test?
  @options[:account_id].eql?('TEST0')
end
verify(credit_card, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/merchant_partners.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/merchant_partners.rb, line 48
def void(authorization, options={})
  post = {}
  add_reference(post, authorization)

  commit(:void, post)
end

Private Instance Methods

add_customer_data(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/merchant_partners.rb, line 127
def add_customer_data(post, options)
  post[:email] = options[:email] if options[:email]
  post[:ipaddress] = options[:ip] if options[:ip]
  if(billing_address = options[:billing_address])
    post[:billaddr1] = billing_address[:address1]
    post[:billaddr2] = billing_address[:address2]
    post[:billcity] = billing_address[:city]
    post[:billstate] = billing_address[:state]
    post[:billcountry] = billing_address[:country]
    post[:bilzip]    = billing_address[:zip]
    post[:phone] = billing_address[:phone]
  end
end
add_invoice(post, money, options) click to toggle source
# File lib/active_merchant/billing/gateways/merchant_partners.rb, line 106
def add_invoice(post, money, options)
  post[:amount] = amount(money)
  post[:merchantordernumber] = options[:order_id]
  post[:currency] = options[:currency] || currency(money)
end
add_payment_method(post, payment_method) click to toggle source
# File lib/active_merchant/billing/gateways/merchant_partners.rb, line 112
def add_payment_method(post, payment_method)
  if(payment_method.is_a?(String))
    user_profile_id, last_4 = split_authorization(payment_method)
    post[:userprofileid] = user_profile_id
    post[:last4digits] = last_4
  else
    post[:ccname] = payment_method.name
    post[:ccnum] = payment_method.number
    post[:cvv2] = payment_method.verification_value
    post[:expmon] = format(payment_method.month, :two_digits)
    post[:expyear] = format(payment_method.year, :four_digits)
    post[:swipedata] = payment_method.track_data if payment_method.track_data
  end
end
add_reference(post, authorization) click to toggle source
# File lib/active_merchant/billing/gateways/merchant_partners.rb, line 141
def add_reference(post, authorization)
  post[:historykeyid] = authorization
end
authorization_from(request, response) click to toggle source
# File lib/active_merchant/billing/gateways/merchant_partners.rb, line 227
def authorization_from(request, response)
  request[:service] == ACTIONS[:store] ?
    "#{response[:userprofileid]}|#{response[:last4digits]}" :
    response[:historyid]
end
build_request(post) click to toggle source
# File lib/active_merchant/billing/gateways/merchant_partners.rb, line 187
def build_request(post)
  Nokogiri::XML::Builder.new(:encoding => 'utf-8') do |xml|
    xml.interface_driver {
      xml.trans_catalog {
        xml.transaction(name: "creditcard") {
          xml.inputs {
            post.each do |field, value|
              xml.send(field, value)
            end
          }
        }
      }
    }
  end.to_xml
end
commit(action, post) click to toggle source
# File lib/active_merchant/billing/gateways/merchant_partners.rb, line 161
def commit(action, post)
  post[:acctid] = @options[:account_id]
  post[:merchantpin] = @options[:merchant_pin]
  post[:service] = ACTIONS[action] if ACTIONS[action]

  data = build_request(post)
  response_data = parse(ssl_post(live_url, data, headers))
  succeeded = success_from(response_data)

  Response.new(
    succeeded,
    message_from(succeeded, response_data),
    response_data,
    authorization: authorization_from(post, response_data),
    :avs_result => AVSResult.new(code: response_data["avs_response"]),
    :cvv_result => CVVResult.new(response_data["cvv2_response"]),
    test: test?
  )
end
error_message_from(response) click to toggle source
# File lib/active_merchant/billing/gateways/merchant_partners.rb, line 237
def error_message_from(response)
  if(response[:status] == "Declined")
    match = response[:result].match(/DECLINED:\d{10}:(.+):/)
    match[1] if match
  end
end
headers() click to toggle source
# File lib/active_merchant/billing/gateways/merchant_partners.rb, line 181
def headers
  {
    "Content-Type"  => "application/xml"
  }
end
message_from(succeeded, response) click to toggle source
# File lib/active_merchant/billing/gateways/merchant_partners.rb, line 223
def message_from(succeeded, response)
  succeeded ? "Succeeded" : error_message_from(response)
end
parse(body) click to toggle source
# File lib/active_merchant/billing/gateways/merchant_partners.rb, line 203
def parse(body)
  response = {}
  Nokogiri::XML(CGI.unescapeHTML(body)).xpath("//trans_catalog/transaction/outputs").children.each do |node|
    parse_element(response, node)
  end
  response
end
parse_element(response, node) click to toggle source
# File lib/active_merchant/billing/gateways/merchant_partners.rb, line 211
def parse_element(response, node)
  if node.elements.size == 0
    response[node.name.downcase.underscore.to_sym] = node.text
  else
    node.elements.each{|element| parse_element(response, element) }
  end
end
split_authorization(authorization) click to toggle source
# File lib/active_merchant/billing/gateways/merchant_partners.rb, line 233
def split_authorization(authorization)
  authorization.split("|")
end
success_from(response) click to toggle source
# File lib/active_merchant/billing/gateways/merchant_partners.rb, line 219
def success_from(response)
  response[:status] == "Approved"
end