Class Index [+]

Quicksearch

ActiveMerchant::Billing::QuantumGateway

ActiveMerchant Implementation for Quantum Gateway XML Requester Service Based on API Doc from 8/6/2009

Important Notes

Constants

LIVE_URL

Public Class Methods

new(options = {}) click to toggle source

These are the options that can be used when creating a new Quantum Gateway object.

:login => Your Quantum Gateway Gateway ID

:password => Your Quantum Gateway Vault Key or Restrict Key

NOTE: For testing supply your test GatewayLogin and GatewayKey

:email_receipt => true if you want a receipt sent to the customer (false be default)

:merchant_receipt => true if you want to override receiving the merchant receipt

:ignore_avs => true ignore both AVS and CVV verification :ignore_cvv => true don’t want to use CVV so continue processing even if CVV would have failed

    # File lib/active_merchant/billing/gateways/quantum.rb, line 38
38:       def initialize(options = {})
39:         requires!(options, :login, :password)
40:         @options = options
41:         super
42:       end

Public Instance Methods

authorize(money, creditcard, options = {}) click to toggle source

Request an authorization for an amount from CyberSource

    # File lib/active_merchant/billing/gateways/quantum.rb, line 51
51:       def authorize(money, creditcard, options = {})
52:         setup_address_hash(options)
53:         commit(build_auth_request(money, creditcard, options), options )
54:       end
capture(money, authorization, options = {}) click to toggle source

Capture an authorization that has previously been requested

    # File lib/active_merchant/billing/gateways/quantum.rb, line 57
57:       def capture(money, authorization, options = {})
58:         setup_address_hash(options)
59:         commit(build_capture_request(money, authorization, options), options)
60:       end
credit(money, identification, options = {}) click to toggle source
    # File lib/active_merchant/billing/gateways/quantum.rb, line 77
77:       def credit(money, identification, options = {})
78:         deprecated CREDIT_DEPRECATION_MESSAGE
79:         refund(money, identification, options)
80:       end
purchase(money, creditcard, options = {}) click to toggle source

Purchase is an auth followed by a capture You must supply an order_id in the options hash

    # File lib/active_merchant/billing/gateways/quantum.rb, line 64
64:       def purchase(money, creditcard, options = {})
65:         setup_address_hash(options)
66:         commit(build_purchase_request(money, creditcard, options), options)
67:       end
refund(money, identification, options = {}) click to toggle source
    # File lib/active_merchant/billing/gateways/quantum.rb, line 73
73:       def refund(money, identification, options = {})
74:         commit(build_credit_request(money, identification, options), options)
75:       end
test?() click to toggle source

Should run against the test servers or not?

    # File lib/active_merchant/billing/gateways/quantum.rb, line 45
45:       def test?
46:         @options[:test] || Base.gateway_mode == :test
47:       end
void(identification, options = {}) click to toggle source
    # File lib/active_merchant/billing/gateways/quantum.rb, line 69
69:       def void(identification, options = {})
70:         commit(build_void_request(identification, options), options)
71:       end

Private Instance Methods

add_address(xml, creditcard, address, options, shipTo = false) click to toggle source
     # File lib/active_merchant/billing/gateways/quantum.rb, line 174
174:       def add_address(xml, creditcard, address, options, shipTo = false)
175:         xml.tag! 'FirstName', creditcard.first_name
176:         xml.tag! 'LastName', creditcard.last_name
177:         xml.tag! 'Address', address[:address1] # => there is no support for address2 in quantum
178:         xml.tag! 'City', address[:city]
179:         xml.tag! 'State', address[:state]
180:         xml.tag! 'ZipCode', address[:zip]
181:         xml.tag! 'Country', address[:country]
182:         xml.tag! 'EmailAddress', options[:email]
183:         xml.tag! 'IPAddress', options[:ip]
184:       end
add_business_rules_data(xml) click to toggle source
     # File lib/active_merchant/billing/gateways/quantum.rb, line 147
147:       def add_business_rules_data(xml)
148:         xml.tag!('CustomerEmail', @options[:email_receipt] ? 'Y' : 'N')
149:         xml.tag!('MerchantEmail', @options[:merchant_receipt] ? 'Y' : 'N')
150:       end
add_common_credit_card_info(xml, process_type) click to toggle source
     # File lib/active_merchant/billing/gateways/quantum.rb, line 140
140:       def add_common_credit_card_info(xml, process_type)
141:         xml.tag! 'RequestType', 'ProcessSingleTransaction'
142:         xml.tag! 'TransactionType', 'CREDIT'
143:         xml.tag! 'PaymentType', 'CC'
144:         xml.tag! 'ProcessType', process_type
145:       end
add_creditcard(xml, creditcard) click to toggle source
     # File lib/active_merchant/billing/gateways/quantum.rb, line 186
186:       def add_creditcard(xml, creditcard)
187:         xml.tag! 'PaymentType', 'CC'
188:         xml.tag! 'CreditCardNumber', creditcard.number
189:         xml.tag! 'ExpireMonth', format(creditcard.month, :two_digits)
190:         xml.tag! 'ExpireYear', format(creditcard.year, :four_digits)
191:         xml.tag!('CVV2', creditcard.verification_value) unless (@options[:ignore_cvv] || creditcard.verification_value.blank? )
192:       end
add_customer_details(xml, options) click to toggle source
     # File lib/active_merchant/billing/gateways/quantum.rb, line 157
157:       def add_customer_details(xml, options)
158:         xml.tag! 'CustomerID', options[:customer]
159:       end
add_invoice_details(xml, options) click to toggle source
     # File lib/active_merchant/billing/gateways/quantum.rb, line 152
152:       def add_invoice_details(xml, options)
153:         xml.tag! 'InvoiceNumber', options[:invoice]
154:         xml.tag! 'InvoiceDescription', options[:merchant]
155:       end
add_memo(xml, options) click to toggle source
     # File lib/active_merchant/billing/gateways/quantum.rb, line 165
165:       def add_memo(xml, options)
166:         xml.tag! 'Memo', options[:description]
167:       end
add_purchase_data(xml, money = 0) click to toggle source
     # File lib/active_merchant/billing/gateways/quantum.rb, line 169
169:       def add_purchase_data(xml, money = 0)
170:         xml.tag! 'Amount', amount(money)
171:         xml.tag! 'TransactionDate', Time.now
172:       end
add_transaction_id(xml, transaction_id) click to toggle source
     # File lib/active_merchant/billing/gateways/quantum.rb, line 161
161:       def add_transaction_id(xml, transaction_id)
162:         xml.tag! 'TransactionID', transaction_id
163:       end
authorization_for(reply) click to toggle source
     # File lib/active_merchant/billing/gateways/quantum.rb, line 272
272:       def authorization_for(reply)
273:         "#{reply[:TransactionID]};#{reply[:CreditCardNumber]}"
274:       end
authorization_parts_from(authorization) click to toggle source
     # File lib/active_merchant/billing/gateways/quantum.rb, line 276
276:       def authorization_parts_from(authorization)
277:         authorization.split(/;/)
278:       end
build_auth_request(money, creditcard, options) click to toggle source
    # File lib/active_merchant/billing/gateways/quantum.rb, line 88
88:       def build_auth_request(money, creditcard, options)
89:         xml = Builder::XmlMarkup.new
90:         add_common_credit_card_info(xml,'AUTH_ONLY')
91:         add_purchase_data(xml, money)
92:         add_creditcard(xml, creditcard)
93:         add_address(xml, creditcard, options[:billing_address], options)
94:         add_invoice_details(xml, options)
95:         add_customer_details(xml, options)
96:         add_memo(xml, options)
97:         add_business_rules_data(xml)
98:         xml.target!
99:       end
build_capture_request(money, authorization, options) click to toggle source
     # File lib/active_merchant/billing/gateways/quantum.rb, line 101
101:       def build_capture_request(money, authorization, options)
102:         xml = Builder::XmlMarkup.new
103:         add_common_credit_card_info(xml,'PREVIOUS_SALE')
104:         transaction_id, _ = authorization_parts_from(authorization)
105:         add_transaction_id(xml, transaction_id)
106:         xml.target!
107:       end
build_credit_request(money, authorization, options) click to toggle source
     # File lib/active_merchant/billing/gateways/quantum.rb, line 130
130:       def build_credit_request(money, authorization, options)
131:         xml = Builder::XmlMarkup.new
132:         add_common_credit_card_info(xml,'RETURN')
133:         add_purchase_data(xml, money)
134:         transaction_id, cc = authorization_parts_from(authorization)
135:         add_transaction_id(xml, transaction_id)
136:         xml.tag! 'CreditCardNumber', cc
137:         xml.target!
138:       end
build_purchase_request(money, creditcard, options) click to toggle source
     # File lib/active_merchant/billing/gateways/quantum.rb, line 109
109:       def build_purchase_request(money, creditcard, options)
110:         xml = Builder::XmlMarkup.new
111:         add_common_credit_card_info(xml, @options[:ignore_avs] ||  @options[:ignore_cvv] ? 'SALES' : 'AUTH_CAPTURE')
112:         add_address(xml, creditcard, options[:billing_address], options)
113:         add_purchase_data(xml, money)
114:         add_creditcard(xml, creditcard)
115:         add_invoice_details(xml, options)
116:         add_customer_details(xml, options)
117:         add_memo(xml, options)
118:         add_business_rules_data(xml)
119:         xml.target!
120:       end
build_request(body, options) click to toggle source

Where we actually build the full SOAP request using builder

     # File lib/active_merchant/billing/gateways/quantum.rb, line 195
195:       def build_request(body, options)
196:         xml = Builder::XmlMarkup.new
197:         xml.instruct!
198:         xml.tag! 'QGWRequest' do
199:           xml.tag! 'Authentication' do
200:             xml.tag! 'GatewayLogin', @options[:login]
201:             xml.tag! 'GatewayKey', @options[:password]
202:           end
203:           xml.tag! 'Request' do
204:             xml << body
205:           end
206:         end
207:         xml.target!
208:       end
build_void_request(authorization, options) click to toggle source
     # File lib/active_merchant/billing/gateways/quantum.rb, line 122
122:       def build_void_request(authorization, options)
123:         xml = Builder::XmlMarkup.new
124:         add_common_credit_card_info(xml,'VOID')
125:         transaction_id, _ = authorization_parts_from(authorization)
126:         add_transaction_id(xml, transaction_id)
127:         xml.target!
128:       end
commit(request, options) click to toggle source

Contact CyberSource, make the SOAP request, and parse the reply into a Response object

     # File lib/active_merchant/billing/gateways/quantum.rb, line 211
211:       def commit(request, options)
212:         headers = { 'Content-Type' => 'text/xml' }
213:         response = parse(ssl_post(LIVE_URL, build_request(request, options), headers))
214: 
215:         success = response[:request_status] == "Success"
216:         message = response[:request_message]
217: 
218:         if success # => checking for connectivity success first
219:           success = %(APPROVED FORCED VOIDED).include?(response[:Status])
220:           message = response[:StatusDescription]
221:           authorization = success ? authorization_for(response) : nil
222:         end
223: 
224:         Response.new(success, message, response,
225:         :test => test?,
226:         :authorization => authorization,
227:         :avs_result => { :code => response[:AVSResponseCode] },
228:         :cvv_result => response[:CVV2ResponseCode]
229:         )
230:       end
parse(xml) click to toggle source

Parse the SOAP response Technique inspired by the Paypal Gateway

     # File lib/active_merchant/billing/gateways/quantum.rb, line 234
234:       def parse(xml)
235:         reply = {}
236: 
237:         begin
238:           xml = REXML::Document.new(xml)
239: 
240:           root = REXML::XPath.first(xml, "//QGWRequest/ResponseSummary")
241:           parse_element(reply, root)
242:           reply[:request_status] = reply[:Status]
243:           reply[:request_message] = "#{reply[:Status]}: #{reply[:StatusDescription]}"
244: 
245:           if root = REXML::XPath.first(xml, "//QGWRequest/Result")
246:             root.elements.to_a.each do |node|
247:               parse_element(reply, node)
248:             end
249:           end
250:         rescue Exception => e
251:           reply[:request_status] = 'Failure'
252:           reply[:request_message] = "Failure: There was a problem parsing the response XML"
253:         end
254: 
255:         return reply
256:       end
parse_element(reply, node) click to toggle source
     # File lib/active_merchant/billing/gateways/quantum.rb, line 258
258:       def parse_element(reply, node)
259:         if node.has_elements?
260:           node.elements.each{|e| parse_element(reply, e) }
261:         else
262:           if node.parent.name =~ /item/
263:             parent = node.parent.name + (node.parent.attributes["id"] ? "_" + node.parent.attributes["id"] : '')
264:             reply[(parent + '_' + node.name).to_sym] = node.text
265:           else
266:             reply[node.name.to_sym] = node.text
267:           end
268:         end
269:         return reply
270:       end
setup_address_hash(options) click to toggle source
    # File lib/active_merchant/billing/gateways/quantum.rb, line 84
84:       def setup_address_hash(options)
85:         options[:billing_address] = options[:billing_address] || options[:address] || {}
86:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.