class ActiveMerchant::Billing::PlugnpayGateway

Constants

AVS_ERRORS
AVS_MESSAGES
CARD_CODE_ERRORS
CARD_CODE_MESSAGES
FAILURE_CODES
PAYMENT_GATEWAY_RESPONSES
SUCCESS_CODES
TRANSACTIONS

Public Class Methods

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

Public Instance Methods

authorize(money, creditcard, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/plugnpay.rb, line 118
def authorize(money, creditcard, options = {})
  post = PlugnpayPostData.new

  add_amount(post, money, options)
  add_creditcard(post, creditcard)
  add_addresses(post, options)
  add_invoice_data(post, options)
  add_customer_data(post, options)

  post[:authtype] = 'authonly'
  commit(:authorization, post)
end
capture(money, authorization, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/plugnpay.rb, line 131
def capture(money, authorization, options = {})
  post = PlugnpayPostData.new

  post[:orderID] = authorization

  add_amount(post, money, options)
  add_customer_data(post, options)

  commit(:capture, post)
end
credit(money, identification_or_creditcard, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/plugnpay.rb, line 151
def credit(money, identification_or_creditcard, options = {})
  post = PlugnpayPostData.new
  add_amount(post, money, options)

  if identification_or_creditcard.is_a?(String)
    ActiveMerchant.deprecated CREDIT_DEPRECATION_MESSAGE
    refund(money, identification_or_creditcard, options)
  else
    add_creditcard(post, identification_or_creditcard)
    add_addresses(post, options)
    add_customer_data(post, options)

    commit(:credit, post)
  end
end
purchase(money, creditcard, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/plugnpay.rb, line 105
def purchase(money, creditcard, options = {})
  post = PlugnpayPostData.new

  add_amount(post, money, options)
  add_creditcard(post, creditcard)
  add_addresses(post, options)
  add_invoice_data(post, options)
  add_customer_data(post, options)

  post[:authtype] = 'authpostauth'
  commit(:authorization, post)
end
refund(money, reference, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/plugnpay.rb, line 167
def refund(money, reference, options = {})
  post = PlugnpayPostData.new
  add_amount(post, money, options)
  post[:orderID] = reference
  commit(:refund, post)
end
void(authorization, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/plugnpay.rb, line 142
def void(authorization, options = {})
  post = PlugnpayPostData.new

  post[:orderID] = authorization
  post[:txn_type] = 'auth'

  commit(:void, post)
end

Private Instance Methods

add_addresses(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/plugnpay.rb, line 231
def add_addresses(post, options)
  if address = options[:billing_address] || options[:address]
    post[:card_address1] = address[:address1]
    post[:card_zip]      = address[:zip]
    post[:card_city]     = address[:city]
    post[:card_country]  = address[:country]
    post[:phone]         = address[:phone]

    case address[:country]
    when 'US', 'CA'
      post[:card_state] = address[:state]
    else
      post[:card_state] = 'ZZ'
      post[:card_prov]  = address[:state]
    end
  end

  if shipping_address = options[:shipping_address] || address
    post[:shipname] = shipping_address[:name]
    post[:address1] = shipping_address[:address1]
    post[:address2] = shipping_address[:address2]
    post[:city] = shipping_address[:city]

    case shipping_address[:country]
    when 'US', 'CA'
      post[:state] = shipping_address[:state]
    else
      post[:state] = 'ZZ'
      post[:province]  = shipping_address[:state]
    end

    post[:country] = shipping_address[:country]
    post[:zip] = shipping_address[:zip]
  end
end
add_amount(post, money, options) click to toggle source
# File lib/active_merchant/billing/gateways/plugnpay.rb, line 267
def add_amount(post, money, options)
  post[:card_amount] = amount(money)
  post[:currency] = options[:currency] || currency(money)
end
add_creditcard(post, creditcard) click to toggle source
# File lib/active_merchant/billing/gateways/plugnpay.rb, line 213
def add_creditcard(post, creditcard)
  post[:card_number]  = creditcard.number
  post[:card_cvv]     = creditcard.verification_value
  post[:card_exp]     = expdate(creditcard)
  post[:card_name]    = creditcard.name.slice(0..38)
end
add_customer_data(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/plugnpay.rb, line 220
def add_customer_data(post, options)
  post[:email] = options[:email]
  post[:dontsndmail]        = 'yes' unless options[:send_email_confirmation]
  post[:ipaddress] = options[:ip]
end
add_invoice_data(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/plugnpay.rb, line 226
def add_invoice_data(post, options)
  post[:shipping] = amount(options[:shipping]) unless options[:shipping].blank?
  post[:tax] = amount(options[:tax]) unless options[:tax].blank?
end
commit(action, post) click to toggle source
# File lib/active_merchant/billing/gateways/plugnpay.rb, line 176
def commit(action, post)
  response = parse(ssl_post(self.live_url, post_data(action, post)))
  success = SUCCESS_CODES.include?(response[:finalstatus])
  message = success ? 'Success' : message_from(response)

  Response.new(success, message, response,
    :test => test?,
    :authorization => response[:orderid],
    :avs_result => { :code => response[:avs_code] },
    :cvv_result => response[:cvvresp]
  )
end
expdate(creditcard) click to toggle source
# File lib/active_merchant/billing/gateways/plugnpay.rb, line 276
def expdate(creditcard)
  year  = sprintf('%.4i', creditcard.year)
  month = sprintf('%.2i', creditcard.month)

  "#{month}/#{year[-2..-1]}"
end
message_from(results) click to toggle source
# File lib/active_merchant/billing/gateways/plugnpay.rb, line 272
def message_from(results)
  PAYMENT_GATEWAY_RESPONSES[results[:resp_code]]
end
parse(body) click to toggle source
# File lib/active_merchant/billing/gateways/plugnpay.rb, line 189
def parse(body)
  body = CGI.unescape(body)
  results = {}
  body.split('&').collect { |e| e.split('=') }.each do |key, value|
    results[key.downcase.to_sym] = normalize(value.to_s.strip)
  end

  results.delete(:publisher_password)
  results[:avs_message] = AVS_MESSAGES[results[:avs_code]] if results[:avs_code]
  results[:card_code_message] = CARD_CODE_MESSAGES[results[:cvvresp]] if results[:cvvresp]

  results
end
post_data(action, post) click to toggle source
# File lib/active_merchant/billing/gateways/plugnpay.rb, line 203
def post_data(action, post)
  post[:mode]               = TRANSACTIONS[action]
  post[:convert]            = 'underscores'
  post[:app_level]          = 0
  post[:publisher_name]     = @options[:login]
  post[:publisher_password] = @options[:password]

  post.to_s
end