class ActiveMerchant::Billing::TransFirstGateway
Constants
- DECLINED
- UNUSED_FIELDS
Public Class Methods
new(options = {})
click to toggle source
Calls superclass method
ActiveMerchant::Billing::Gateway::new
# File lib/active_merchant/billing/gateways/trans_first.rb, line 15 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/trans_first.rb, line 20 def purchase(money, credit_card, options = {}) post = {} add_amount(post, money) add_invoice(post, options) add_credit_card(post, credit_card) add_address(post, options) commit(post) end
Private Instance Methods
add_address(post, options)
click to toggle source
# File lib/active_merchant/billing/gateways/trans_first.rb, line 36 def add_address(post, options) address = options[:billing_address] || options[:address] if address add_pair(post, :Address, address[:address1]) add_pair(post, :ZipCode, address[:zip]) end end
add_amount(post, money)
click to toggle source
# File lib/active_merchant/billing/gateways/trans_first.rb, line 32 def add_amount(post, money) add_pair(post, :Amount, amount(money), :required => true) end
add_credit_card(post, credit_card)
click to toggle source
# File lib/active_merchant/billing/gateways/trans_first.rb, line 53 def add_credit_card(post, credit_card) add_pair(post, :CardHolderName, credit_card.name, :required => true) add_pair(post, :CardNumber, credit_card.number, :required => true) add_pair(post, :Expiration, expdate(credit_card), :required => true) add_pair(post, :CVV2, credit_card.verification_value) end
add_invoice(post, options)
click to toggle source
# File lib/active_merchant/billing/gateways/trans_first.rb, line 45 def add_invoice(post, options) add_pair(post, :RefID, options[:order_id], :required => true) add_pair(post, :PONumber, options[:invoice], :required => true) add_pair(post, :SaleTaxAmount, amount(options[:tax] || 0)) add_pair(post, :PaymentDesc, options[:description], :required => true) add_pair(post, :TaxIndicator, 0) end
add_pair(post, key, value, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/trans_first.rb, line 120 def add_pair(post, key, value, options = {}) post[key] = value if !value.blank? || options[:required] end
add_unused_fields(post)
click to toggle source
# File lib/active_merchant/billing/gateways/trans_first.rb, line 61 def add_unused_fields(post) UNUSED_FIELDS.each do |f| post[f] = "" end end
commit(params)
click to toggle source
# File lib/active_merchant/billing/gateways/trans_first.rb, line 91 def commit(params) response = parse( ssl_post(self.live_url, post_data(params)) ) Response.new(response[:status] == "Authorized", message_from(response), response, :test => test?, :authorization => response[:trans_id], :avs_result => { :code => response[:avs_code] }, :cvv_result => response[:cvv2_code] ) end
expdate(credit_card)
click to toggle source
# File lib/active_merchant/billing/gateways/trans_first.rb, line 67 def expdate(credit_card) year = format(credit_card.year, :two_digits) month = format(credit_card.month, :two_digits) "#{month}#{year}" end
message_from(response)
click to toggle source
# File lib/active_merchant/billing/gateways/trans_first.rb, line 102 def message_from(response) case response[:message] when 'Call Voice Center' DECLINED else response[:message] end end
parse(data)
click to toggle source
# File lib/active_merchant/billing/gateways/trans_first.rb, line 74 def parse(data) response = {} xml = REXML::Document.new(data) root = REXML::XPath.first(xml, "//CCSaleDebitResponse") if root.nil? response[:message] = data.to_s.strip else root.elements.to_a.each do |node| response[node.name.underscore.to_sym] = node.text end end response end
post_data(params = {})
click to toggle source
# File lib/active_merchant/billing/gateways/trans_first.rb, line 111 def post_data(params = {}) add_unused_fields(params) params[:MerchantID] = @options[:login] params[:RegKey] = @options[:password] request = params.collect { |key, value| "#{key}=#{CGI.escape(value.to_s)}" }.join("&") request end