lib/active_merchant/billing/gateways/paymentech_orbital.rb in johnideal-activemerchant-1.4.4 vs lib/active_merchant/billing/gateways/paymentech_orbital.rb in johnideal-activemerchant-1.4.5
- old
+ new
@@ -1,12 +1,20 @@
+require File.dirname(__FILE__) + '/paymentech_orbital/paymentech_orbital_request'
+
+require File.dirname(__FILE__) + '/paymentech_orbital/end_of_day_request'
+require File.dirname(__FILE__) + '/paymentech_orbital/new_order_request'
+require File.dirname(__FILE__) + '/paymentech_orbital/profile_management_request'
+require File.dirname(__FILE__) + '/paymentech_orbital/void_request'
+
require File.dirname(__FILE__) + '/paymentech_orbital/paymentech_orbital_response'
module ActiveMerchant #:nodoc:
module Billing #:nodoc:
class PaymentechOrbitalGateway < Gateway
cattr_accessor :enable_profile_management, :urls,
- :currency_code, :currency_exponent
+ :currency_code, :currency_exponent,
+ :headers
self.urls = {
:test => [
'https://orbitalvar1.paymentech.net/authorize',
'https://orbitalvar2.paymentech.net/authorize'
@@ -37,131 +45,80 @@
self.display_name = 'Paymentect Orbital Gateway'
# Enable profile management?
self.enable_profile_management = true
+ # Headers
+ self.headers = {
+ "MIME-Version" => "1.0",
+ "Content-Type" => "Application/PTI46",
+ "Content-transfer-encoding" => "text",
+ "Request-number" => "1",
+ "Document-type" => "Request"
+ }
+
def initialize(options = {})
requires!(options, :login, :password, :merchant_id, :bin, :terminal_id)
- @options = options
+ @options = options.merge({
+ :currency_code => self.class.currency_code,
+ :currency_exponent => self.class.currency_exponent
+ })
super
end
-
- [:login, :password, :merchant_id,
- :bin, :terminal_id].each do |attr|
- define_method(:"#{attr}") do
- @options[:"#{attr}"]
- end
- end
-
- def authorize(money, creditcard, options = {})
- request = build_request("NewOrder", money, options) do |xml|
- add_credentials(xml, "A")
- add_credit_card(xml, credit_card)
- add_billing_address(xml, options[:billing_address]) if options[:billing_address]
- add_profile_management(xml, options[:customer_ref_num]) if enable_profile_management?
- end
+ def authorize(money, credit_card=nil, options = {})
+ request = NewOrderRequest.new("A", money, credit_card, options.merge(@options))
+
commit('authonly', request)
end
def purchase(money, credit_card=nil, options = {})
- request = build_request("NewOrder", money, options) do |xml|
- add_credentials(xml, "AC")
- add_credit_card(xml, credit_card)
- add_billing_address(xml, options[:billing_address]) if options[:billing_address]
- add_profile_management(xml, options[:customer_ref_num]) if enable_profile_management?
- end
+ request = NewOrderRequest.new("AC", money, credit_card, options.merge(@options))
commit('sale', request)
end
+
+ def refund(money, credit_card=nil, options={})
+ request = NewOrderRequest.new("R", money, credit_card, options.merge(@options))
- def capture(money, authorization, options = {})
- commit('capture', money, post)
+ commit('refund', request)
end
- private
- def build_request(request_type, money, options)
- xml = Builder::XmlMarkup.new(:indent => 2)
-
- xml.instruct!(:xml, :version => '1.0', :encoding => 'UTF-8')
- xml.tag! "Request" do
- xml.tag! request_type do
- yield xml if block_given?
+ def profile(action, credit_card=nil, options={})
+ request = ProfileManagementRequest.new(action, credit_card, options.merge(@options))
- xml.tag! "OrderID", options[:order_id]
- xml.tag! "Amount", money
- end
- end
-
- xml.target!
+ commit("profile-#{action}", request)
end
- def add_credentials(xml, message_type)
- xml.tag! "OrbitalConnectionUsername", login
- xml.tag! "OrbitalConnectionPassword", password
- xml.tag! "IndustryType", "EC"
- xml.tag! "MessageType", message_type
- xml.tag! "BIN", bin
- xml.tag! "MerchantID", merchant_id
- xml.tag! "TerminalID", terminal_id
+ def void(tx_ref_num, tx_ref_idx, money=nil, options={})
+ request = VoidRequest.new(tx_ref_num, tx_ref_idx, money, options.merge(@options))
+
+ commit('void', request)
end
-
- def add_credit_card(xml, credit_card=nil)
- if credit_card
- xml.tag! "CardBrand", card_brand(credit_card)
- xml.tag! "AccountNum", credit_card.number
- xml.tag! "Exp", "#{credit_card.month}#{credit_card.year}"
- add_currency(xml)
- xml.tag! "CardSecVal", credit_card.verification_value
- else
- xml.tag! "AccountNum", nil
- add_currency(xml)
- end
+
+ def end_of_day(options={})
+ request = EndOfDayRequest.new(options.merge(@options))
+
+ commit('end of day', request)
end
-
- def add_currency(xml)
- xml.tag! "CurrencyCode", self.class.currency_code
- xml.tag! "CurrencyExponent", self.class.currency_exponent
- end
-
- def add_billing_address(xml, address)
- xml.tag! "AVSzip", address[:zip]
- xml.tag! "AVSaddress1", address[:address1]
- xml.tag! "AVSaddress2", address[:address2]
- xml.tag! "AVScity", address[:city]
- xml.tag! "AVSstate", address[:state]
- xml.tag! "AVSphoneNum" , address[:phone]
- xml.tag! "AVSname", address[:name]
- xml.tag! "AVScountryCode", address[:country]
- end
-
- def add_profile_management(xml, customer_ref_num=nil)
- if customer_ref_num
- xml.tag! "CustomerRefNum", customer_ref_num
- else
- xml.tag! "CustomerProfileFromOrderInd", "A"
- xml.tag! "CustomerProfileOrderOverrideInd", "NO"
- end
- end
-
+
+ private
def commit(action, request)
- resp = ssl_post(endpoint_url, request, {
- "MIME-Version" => "1.0",
- "Content-Type" => "Application/PTI46",
- "Content-transfer-encoding" => "text",
- "Request-number" => "1",
- "Document-type" => "Request"
- })
+ resp = ssl_post(endpoint_url, request.to_xml, headers)
- @response ||= PaymentechOrbitalResponse.new(resp, {
+ @response ||= PaymentechOrbitalResponse.new(resp, request.request_type, {
:test => test?
})
end
-
+
+ def headers
+ self.class.headers
+ end
+
def endpoint_url
self.class.urls[Base.gateway_mode][0]
end
-
+
def enable_profile_management?
self.class.enable_profile_management
end
end
end