class ActiveMerchant::Billing::TransactProGateway
For more information visit Transact Pro Services
This gateway was formerly associated with www.1stpayments.net
Written by Piers Chambers (Varyonic.com)
Public Class Methods
new(options = {})
click to toggle source
Calls superclass method
ActiveMerchant::Billing::Gateway::new
# File lib/active_merchant/billing/gateways/transact_pro.rb, line 20 def initialize(options = {}) requires!(options, :guid, :password, :terminal) super end
Public Instance Methods
capture(amount, authorization, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/transact_pro.rb, line 69 def capture(amount, authorization, options = {}) identifier, original_amount = split_authorization(authorization) raise ArgumentError.new("Partial capture is not supported, and #{amount.inspect} != #{original_amount.inspect}") if amount && (amount != original_amount) post = PostData.new add_credentials(post) post[:init_transaction_id] = identifier post[:f_extended] = '4' commit('charge_hold', post, original_amount) end
purchase(amount, payment, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/transact_pro.rb, line 25 def purchase(amount, payment, options = {}) post = PostData.new add_invoice(post, amount, options) add_payment(post, payment) add_address(post, payment, options) add_customer_data(post, options) add_credentials(post) post[:rs] = @options[:terminal] MultiResponse.run do |r| r.process { commit('init', post) } r.process do post = PostData.new post[:init_transaction_id] = r.authorization add_payment_cc(post, payment) post[:f_extended] = '4' commit('charge', post, amount) end end end
refund(amount, authorization, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/transact_pro.rb, line 81 def refund(amount, authorization, options = {}) identifier, original_amount = split_authorization(authorization) post = PostData.new add_credentials(post, :account_guid) post[:init_transaction_id] = identifier post[:amount_to_refund] = amount(amount || original_amount) commit('refund', post) end
verify(credit_card, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/transact_pro.rb, line 102 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/transact_pro.rb, line 92 def void(authorization, options = {}) identifier, amount = split_authorization(authorization) post = PostData.new add_credentials(post, :account_guid) post[:init_transaction_id] = identifier post[:amount_to_refund] = amount(amount) commit('cancel_dms', post) end
Private Instance Methods
add_address(post, creditcard, options)
click to toggle source
# File lib/active_merchant/billing/gateways/transact_pro.rb, line 116 def add_address(post, creditcard, options) if address = options[:billing_address] post[:street] = address[:address1].to_s post[:city] = address[:city].to_s post[:state] = (address[:state].blank? ? 'NA' : address[:state].to_s) post[:zip] = address[:zip].to_s post[:country] = address[:country].to_s post[:phone] = (address[:phone].to_s.gsub(/[^0-9]/, '') || '0000000') end if address = options[:shipping_address] post[:shipping_name] = "#{address.first_name} #{address.last_name}" post[:shipping_street] = address[:address1].to_s post[:shipping_phone] = address[:phone].to_s post[:shipping_zip] = address[:zip].to_s post[:shipping_city] = address[:city].to_s post[:shipping_country] = address[:country].to_s post[:shipping_state] = (address[:state].blank? ? 'NA' : address[:state].to_s) post[:shipping_email] = (options[:email] || 'noone@example.com') end end
add_credentials(post, key = :guid)
click to toggle source
# File lib/active_merchant/billing/gateways/transact_pro.rb, line 159 def add_credentials(post, key = :guid) post[key] = @options[:guid] post[:pwd] = Digest::SHA1.hexdigest(@options[:password]) end
add_customer_data(post, options)
click to toggle source
# File lib/active_merchant/billing/gateways/transact_pro.rb, line 111 def add_customer_data(post, options) post[:email] = (options[:email] || 'noone@example.com') post[:user_ip] = (options[:ip] || '127.0.0.1') end
add_invoice(post, money, options)
click to toggle source
# File lib/active_merchant/billing/gateways/transact_pro.rb, line 138 def add_invoice(post, money, options) post[:merchant_transaction_id] = options[:order_id] if options[:order_id] post[:amount] = amount(money) post[:currency] = (options[:currency] || currency(money)) post[:description] = options[:description] post[:merchant_site_url] = options[:merchant] end
add_payment(post, payment)
click to toggle source
# File lib/active_merchant/billing/gateways/transact_pro.rb, line 146 def add_payment(post, payment) post[:name_on_card] = "#{payment.first_name} #{payment.last_name}" post[:card_bin] = payment.first_digits end
add_payment_cc(post, credit_card)
click to toggle source
# File lib/active_merchant/billing/gateways/transact_pro.rb, line 151 def add_payment_cc(post, credit_card) post[:cc] = credit_card.number post[:cvv] = credit_card.verification_value if credit_card.verification_value? year = sprintf('%.4i', credit_card.year) month = sprintf('%.2i', credit_card.month) post[:expire] = "#{month}/#{year[2..3]}" end
commit(action, parameters, amount = nil)
click to toggle source
# File lib/active_merchant/billing/gateways/transact_pro.rb, line 179 def commit(action, parameters, amount = nil) url = (test? ? test_url : live_url) response = parse(ssl_post(url, post_data(action, parameters))) Response.new( success_from(response), message_from(response), response, authorization: authorization_from(parameters, response, amount), test: test? ) end
message_from(response)
click to toggle source
# File lib/active_merchant/billing/gateways/transact_pro.rb, line 212 def message_from(response) (response[:message] || response[:status]) end
parse(body)
click to toggle source
# File lib/active_merchant/billing/gateways/transact_pro.rb, line 164 def parse(body) if /^ID:/.match?(body) body.split('~').reduce(Hash.new) { |h, v| m = v.match('(.*?):(.*)') h.merge!(m[1].underscore.to_sym => m[2]) } elsif (m = body.match('(.*?):(.*)')) m[1] == 'OK' ? { status: 'success', id: m[2] } : { status: 'failure', message: m[2] } else { status: body } end end
post_data(action, parameters = {})
click to toggle source
# File lib/active_merchant/billing/gateways/transact_pro.rb, line 216 def post_data(action, parameters = {}) parameters[:a] = action parameters.to_s end
success_from(response)
click to toggle source
# File lib/active_merchant/billing/gateways/transact_pro.rb, line 208 def success_from(response) (response[:status] =~ /success/i || response[:status] =~ /ok/i) end