class ActiveMerchant::Billing::PaySecureGateway

Constants

SUCCESS
SUCCESS_MESSAGE
TRANSACTIONS

Currently Authorization and Capture is not implemented because capturing requires the original credit card information

Public Class Methods

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

Public Instance Methods

purchase(money, credit_card, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/pay_secure.rb, line 30
def purchase(money, credit_card, options = {})
  requires!(options, :order_id)

  post = {}
  add_amount(post, money)
  add_invoice(post, options)
  add_credit_card(post, credit_card)

  commit(:purchase, money, post)
end

Private Instance Methods

add_amount(post, money) click to toggle source
# File lib/active_merchant/billing/gateways/pay_secure.rb, line 50
def add_amount(post, money)
  post[:amount] = amount(money)
end
add_credit_card(post, credit_card) click to toggle source
# File lib/active_merchant/billing/gateways/pay_secure.rb, line 61
def add_credit_card(post, credit_card)
  post[:cardnum]  = credit_card.number
  post[:cardname] = credit_card.name
  post[:expiry]   = expdate(credit_card)
  post[:cvv2]     = credit_card.verification_value
end
add_invoice(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/pay_secure.rb, line 54
def add_invoice(post, options)
  post[:merchant_transid] = options[:order_id].to_s.slice(0, 21)
  post[:memnum]           = options[:invoice]
  post[:custnum]          = options[:customer]
  post[:clientdata]       = options[:description]
end
add_reference(post, identification) click to toggle source

Used for capturing, which is currently not supported.

# File lib/active_merchant/billing/gateways/pay_secure.rb, line 44
def add_reference(post, identification)
  auth, trans_id = identification.split(';')
  post[:authnum]    = auth
  post[:transid] = trans_id
end
authorization_from(response) click to toggle source
# File lib/active_merchant/billing/gateways/pay_secure.rb, line 81
def authorization_from(response)
  [ response[:authnum], response[:transid] ].compact.join(';')
end
commit(action, money, parameters) click to toggle source
# File lib/active_merchant/billing/gateways/pay_secure.rb, line 68
def commit(action, money, parameters)
  response = parse(ssl_post(self.live_url, post_data(action, parameters)))

  Response.new(successful?(response), message_from(response), response,
    :test => test_response?(response),
    :authorization => authorization_from(response)
  )
end
message_from(response) click to toggle source
# File lib/active_merchant/billing/gateways/pay_secure.rb, line 89
def message_from(response)
  successful?(response) ? SUCCESS_MESSAGE : response[:errorstring]
end
parse(body) click to toggle source
# File lib/active_merchant/billing/gateways/pay_secure.rb, line 93
def parse(body)
  response = {}
  body.to_s.each_line do |l|
    key, value = l.split(':', 2)
    response[key.to_s.downcase.to_sym] = value.strip
  end
  response
end
post_data(action, parameters = {}) click to toggle source
# File lib/active_merchant/billing/gateways/pay_secure.rb, line 102
def post_data(action, parameters = {})
  parameters[:request_type]     = TRANSACTIONS[action]
  parameters[:merchant_id]      = @options[:login]
  parameters[:password]         = @options[:password]

  parameters.reject { |k, v| v.blank? }.collect { |key, value| "#{key.to_s.upcase}=#{CGI.escape(value.to_s)}" }.join('&')
end
successful?(response) click to toggle source
# File lib/active_merchant/billing/gateways/pay_secure.rb, line 77
def successful?(response)
  response[:status] == SUCCESS
end
test_response?(response) click to toggle source
# File lib/active_merchant/billing/gateways/pay_secure.rb, line 85
def test_response?(response)
  !!(response[:transid] =~ /SimProxy/)
end