class ActiveMerchant::Billing::AxcessmsGateway
Constants
- API_VERSION
- PAYMENT_CODE_CAPTURE
- PAYMENT_CODE_DEBIT
- PAYMENT_CODE_PREAUTHORIZATION
- PAYMENT_CODE_REBILL
- PAYMENT_CODE_REFUND
- PAYMENT_CODE_REVERSAL
Public Class Methods
new(options = {})
click to toggle source
Calls superclass method
ActiveMerchant::Billing::Gateway::new
# File lib/active_merchant/billing/gateways/axcessms.rb, line 26 def initialize(options = {}) requires!(options, :sender, :login, :password, :channel) super end
Public Instance Methods
capture(money, authorization, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/axcessms.rb, line 40 def capture(money, authorization, options = {}) commit(PAYMENT_CODE_CAPTURE, money, authorization, options) end
purchase(money, payment, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/axcessms.rb, line 31 def purchase(money, payment, options = {}) payment_code = payment.respond_to?(:number) ? PAYMENT_CODE_DEBIT : PAYMENT_CODE_REBILL commit(payment_code, money, payment, options) end
refund(money, authorization, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/axcessms.rb, line 44 def refund(money, authorization, options = {}) commit(PAYMENT_CODE_REFUND, money, authorization, options) end
verify(credit_card, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/axcessms.rb, line 52 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/axcessms.rb, line 48 def void(authorization, options = {}) commit(PAYMENT_CODE_REVERSAL, nil, authorization, options) end
Private Instance Methods
add_address(xml, address)
click to toggle source
# File lib/active_merchant/billing/gateways/axcessms.rb, line 170 def add_address(xml, address) raise ArgumentError.new('Address is required') unless address xml.tag! 'Address' do xml.tag! 'Street', "#{address[:address1]} #{address[:address2]}".strip xml.tag! 'City', address[:city] xml.tag! 'State', address[:state] xml.tag! 'Zip', address[:zip] xml.tag! 'Country', address[:country] end end
add_contact(xml, options)
click to toggle source
# File lib/active_merchant/billing/gateways/axcessms.rb, line 146 def add_contact(xml, options) xml.tag! 'Contact' do xml.tag! 'Email', (options[:email] || 'unknown@example.com') xml.tag! 'Ip', (options[:ip] || '127.0.0.1') end end
add_customer_name(xml, payment)
click to toggle source
# File lib/active_merchant/billing/gateways/axcessms.rb, line 153 def add_customer_name(xml, payment) xml.tag! 'Name' do xml.tag! 'Given', payment.first_name xml.tag! 'Family', payment.last_name end end
add_payment(xml, payment)
click to toggle source
# File lib/active_merchant/billing/gateways/axcessms.rb, line 160 def add_payment(xml, payment) xml.tag! 'Account' do xml.tag! 'Number', payment.number xml.tag! 'Holder', payment.name xml.tag! 'Brand', payment.brand xml.tag! 'Expiry', 'month' => payment.month, 'year' => payment.year xml.tag! 'Verification', payment.verification_value end end
build_request(payment_code, money, payment, options)
click to toggle source
# File lib/active_merchant/billing/gateways/axcessms.rb, line 108 def build_request(payment_code, money, payment, options) xml = Builder::XmlMarkup.new indent: 2 xml.instruct! xml.tag! 'Request', 'version' => API_VERSION do xml.tag! 'Header' do xml.tag! 'Security', 'sender' => @options[:sender] end xml.tag! 'Transaction', 'mode' => options[:mode], 'channel' => @options[:channel], 'response' => 'SYNC' do xml.tag! 'User', 'login' => @options[:login], 'pwd' => @options[:password] xml.tag! 'Identification' do xml.tag! 'TransactionID', options[:order_id] || generate_unique_id xml.tag! 'ReferenceID', payment unless payment.respond_to?(:number) end xml.tag! 'Payment', 'code' => payment_code do xml.tag! 'Memo', options[:memo] unless options[:memo].blank? xml.tag! 'Presentation' do xml.tag! 'Amount', amount(money) xml.tag! 'Currency', (options[:currency] || currency(money)) xml.tag! 'Usage', options[:description] end end if payment.respond_to?(:number) add_payment(xml, payment) xml.tag! 'Customer' do add_customer_name(xml, payment) add_address(xml, options[:billing_address] || options[:address]) add_contact(xml, options) end end end end xml.target! end
commit(paymentcode, money, payment, options)
click to toggle source
# File lib/active_merchant/billing/gateways/axcessms.rb, line 61 def commit(paymentcode, money, payment, options) options[:mode] ||= (test? ? 'INTEGRATOR_TEST' : 'LIVE') request = build_request(paymentcode, money, payment, options) headers = { 'Content-Type' => 'application/x-www-form-urlencoded;charset=UTF-8' } response = parse(ssl_post((test? ? test_url : live_url), "load=#{CGI.escape(request)}", headers)) success = (response[:result] == 'ACK') message = "#{response[:reason]} - #{response[:return]}" authorization = response[:unique_id] Response.new( success, message, response, authorization: authorization, test: (response[:mode] != 'LIVE') ) end
parse(body)
click to toggle source
# File lib/active_merchant/billing/gateways/axcessms.rb, line 83 def parse(body) return {} if body.blank? xml = REXML::Document.new(body) response = {} xml.root.elements.to_a.each do |node| parse_element(response, node) end response[:mode] = REXML::XPath.first(xml, '//Transaction').attributes['mode'] response end
parse_element(response, node)
click to toggle source
# File lib/active_merchant/billing/gateways/axcessms.rb, line 98 def parse_element(response, node) node.attributes.each { |name, value| response["#{node.name}_#{name}".underscore.to_sym] = value } if node.has_attributes? if node.has_elements? node.elements.each { |element| parse_element(response, element) } else response[node.name.underscore.to_sym] = node.text end end