class ActiveMerchant::Billing::SecurePayTechGateway

Constants

PAYMENT_GATEWAY_RESPONSES

Public Class Methods

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

Public Instance Methods

purchase(money, creditcard, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/secure_pay_tech.rb, line 33
def purchase(money, creditcard, options = {})
  post = SecurePayTechPostData.new

  add_invoice(post, money, options)
  add_creditcard(post, creditcard)

  commit(:purchase, post)
end

Private Instance Methods

add_creditcard(post, creditcard) click to toggle source
# File lib/active_merchant/billing/gateways/secure_pay_tech.rb, line 51
def add_creditcard(post, creditcard)
  post[:CardNumber] = creditcard.number
  post[:CardExpiry] = expdate(creditcard)
  post[:CardHolderName] = creditcard.name

  if creditcard.verification_value?
    post[:EnableCSC] = true
    post[:CSC] = creditcard.verification_value
  end

  # SPT will autodetect this
  post[:CardType] = 0
end
add_invoice(post, money, options) click to toggle source
# File lib/active_merchant/billing/gateways/secure_pay_tech.rb, line 44
def add_invoice(post, money, options)
  post[:Amount] = amount(money)
  post[:Currency] = options[:currency] || currency(money)

  post[:OrderReference] = options[:order_id]
end
commit(action, post) click to toggle source
# File lib/active_merchant/billing/gateways/secure_pay_tech.rb, line 84
def commit(action, post)
  response = parse( ssl_post(self.live_url, post_data(action, post) ) )

  Response.new(response[:result_code] == 1, message_from(response), response,
    :test => test?,
    :authorization => response[:merchant_transaction_reference]
  )
end
message_from(result) click to toggle source
# File lib/active_merchant/billing/gateways/secure_pay_tech.rb, line 93
def message_from(result)
  PAYMENT_GATEWAY_RESPONSES[result[:result_code]]
end
parse(body) click to toggle source
# File lib/active_merchant/billing/gateways/secure_pay_tech.rb, line 65
def parse(body)
  response = CGI.unescape(body).split(',')

  result = {}
  result[:result_code] = response[0].to_i

  if response.length == 2
    result[:fail_reason] = response[1]
  else
    result[:merchant_transaction_reference] = response[1]
    result[:receipt_number] = response[2]
    result[:transaction_number] = response[3]
    result[:authorisation_id] = response[4]
    result[:batch_number] = response[5]
  end

  result
end
post_data(action, post) click to toggle source
# File lib/active_merchant/billing/gateways/secure_pay_tech.rb, line 97
def post_data(action, post)
  post[:MerchantID] = @options[:login]
  post[:MerchantKey] = @options[:password]
  post.to_s
end