class ActiveMerchant::Billing::SecurePayAuGateway
Constants
- API_VERSION
- PERIODIC_ACTIONS
- PERIODIC_API_VERSION
- PERIODIC_TYPES
- SUCCESS_CODES
- TRANSACTIONS
0 Standard Payment 4 Refund 6 Client Reversal (Void) 10 Preauthorise 11 Preauth Complete (Advice)
Public Class Methods
new(options = {})
click to toggle source
Calls superclass method
ActiveMerchant::Billing::Gateway::new
# File lib/active_merchant/billing/gateways/secure_pay_au.rb, line 59 def initialize(options = {}) requires!(options, :login, :password) super end
Public Instance Methods
capture(money, reference, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/secure_pay_au.rb, line 79 def capture(money, reference, options = {}) commit :capture, build_reference_request(money, reference) end
credit(money, reference, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/secure_pay_au.rb, line 87 def credit(money, reference, options = {}) ActiveMerchant.deprecated CREDIT_DEPRECATION_MESSAGE refund(money, reference) end
purchase(money, credit_card_or_stored_id, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/secure_pay_au.rb, line 64 def purchase(money, credit_card_or_stored_id, options = {}) if credit_card_or_stored_id.respond_to?(:number) requires!(options, :order_id) commit :purchase, build_purchase_request(money, credit_card_or_stored_id, options) else options[:billing_id] = credit_card_or_stored_id.to_s commit_periodic(build_periodic_item(:trigger, money, nil, options)) end end
refund(money, reference, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/secure_pay_au.rb, line 83 def refund(money, reference, options = {}) commit :refund, build_reference_request(money, reference) end
store(creditcard, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/secure_pay_au.rb, line 96 def store(creditcard, options = {}) requires!(options, :billing_id, :amount) commit_periodic(build_periodic_item(:add_triggered, options[:amount], creditcard, options)) end
unstore(identification, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/secure_pay_au.rb, line 101 def unstore(identification, options = {}) options[:billing_id] = identification commit_periodic(build_periodic_item(:remove_triggered, options[:amount], nil, options)) end
void(reference, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/secure_pay_au.rb, line 92 def void(reference, options = {}) commit :void, build_reference_request(nil, reference) end
Private Instance Methods
build_periodic_item(action, money, credit_card, options)
click to toggle source
# File lib/active_merchant/billing/gateways/secure_pay_au.rb, line 180 def build_periodic_item(action, money, credit_card, options) xml = Builder::XmlMarkup.new xml.tag! 'actionType', PERIODIC_ACTIONS[action] xml.tag! 'clientID', options[:billing_id].to_s if credit_card xml.tag! 'CreditCardInfo' do xml.tag! 'cardNumber', credit_card.number xml.tag! 'expiryDate', expdate(credit_card) xml.tag! 'cvv', credit_card.verification_value if credit_card.verification_value? end end xml.tag! 'amount', amount(money) xml.tag! 'periodicType', PERIODIC_TYPES[action] if PERIODIC_TYPES[action] xml.target! end
build_periodic_request(body)
click to toggle source
# File lib/active_merchant/billing/gateways/secure_pay_au.rb, line 199 def build_periodic_request(body) xml = Builder::XmlMarkup.new xml.instruct! xml.tag! 'SecurePayMessage' do xml.tag! 'MessageInfo' do xml.tag! 'messageID', SecureRandom.hex(15) xml.tag! 'messageTimestamp', generate_timestamp xml.tag! 'timeoutValue', request_timeout xml.tag! 'apiVersion', PERIODIC_API_VERSION end xml.tag! 'MerchantInfo' do xml.tag! 'merchantID', @options[:login] xml.tag! 'password', @options[:password] end xml.tag! 'RequestType', 'Periodic' xml.tag! 'Periodic' do xml.tag! 'PeriodicList', "count" => 1 do xml.tag! 'PeriodicItem', "ID" => 1 do xml << body end end end end xml.target! end
build_purchase_request(money, credit_card, options)
click to toggle source
# File lib/active_merchant/billing/gateways/secure_pay_au.rb, line 108 def build_purchase_request(money, credit_card, options) xml = Builder::XmlMarkup.new currency = options[:currency] || currency(money) xml.tag! 'amount', localized_amount(money, currency) xml.tag! 'currency', currency xml.tag! 'purchaseOrderNo', options[:order_id].to_s.gsub(/[ ']/, '') xml.tag! 'CreditCardInfo' do xml.tag! 'cardNumber', credit_card.number xml.tag! 'expiryDate', expdate(credit_card) xml.tag! 'cvv', credit_card.verification_value if credit_card.verification_value? end xml.target! end
build_reference_request(money, reference)
click to toggle source
# File lib/active_merchant/billing/gateways/secure_pay_au.rb, line 126 def build_reference_request(money, reference) xml = Builder::XmlMarkup.new transaction_id, order_id, preauth_id, original_amount = reference.split('*') xml.tag! 'amount', (money ? amount(money) : original_amount) xml.tag! 'currency', options[:currency] || currency(money) xml.tag! 'txnID', transaction_id xml.tag! 'purchaseOrderNo', order_id xml.tag! 'preauthID', preauth_id xml.target! end
build_request(action, body)
click to toggle source
# File lib/active_merchant/billing/gateways/secure_pay_au.rb, line 140 def build_request(action, body) xml = Builder::XmlMarkup.new xml.instruct! xml.tag! 'SecurePayMessage' do xml.tag! 'MessageInfo' do xml.tag! 'messageID', SecureRandom.hex(15) xml.tag! 'messageTimestamp', generate_timestamp xml.tag! 'timeoutValue', request_timeout xml.tag! 'apiVersion', API_VERSION end xml.tag! 'MerchantInfo' do xml.tag! 'merchantID', @options[:login] xml.tag! 'password', @options[:password] end xml.tag! 'RequestType', 'Payment' xml.tag! 'Payment' do xml.tag! 'TxnList', "count" => 1 do xml.tag! 'Txn', "ID" => 1 do xml.tag! 'txnType', TRANSACTIONS[action] xml.tag! 'txnSource', 23 xml << body end end end end xml.target! end
commit(action, request)
click to toggle source
# File lib/active_merchant/billing/gateways/secure_pay_au.rb, line 171 def commit(action, request) response = parse(ssl_post(test? ? self.test_url : self.live_url, build_request(action, request))) Response.new(success?(response), message_from(response), response, :test => test?, :authorization => authorization_from(response) ) end
commit_periodic(request)
click to toggle source
# File lib/active_merchant/billing/gateways/secure_pay_au.rb, line 227 def commit_periodic(request) my_request = build_periodic_request(request) #puts my_request response = parse(ssl_post(test? ? self.test_periodic_url : self.live_periodic_url, my_request)) Response.new(success?(response), message_from(response), response, :test => test?, :authorization => authorization_from(response) ) end
expdate(credit_card)
click to toggle source
# File lib/active_merchant/billing/gateways/secure_pay_au.rb, line 250 def expdate(credit_card) "#{format(credit_card.month, :two_digits)}/#{format(credit_card.year, :two_digits)}" end
generate_timestamp()
click to toggle source
YYYYDDMMHHNNSSKKK000sOOO
# File lib/active_merchant/billing/gateways/secure_pay_au.rb, line 275 def generate_timestamp time = Time.now.utc time.strftime("%Y%d%m%H%M%S#{time.usec}+000") end
message_from(response)
click to toggle source
# File lib/active_merchant/billing/gateways/secure_pay_au.rb, line 246 def message_from(response) response[:response_text] || response[:status_description] end
parse(body)
click to toggle source
# File lib/active_merchant/billing/gateways/secure_pay_au.rb, line 254 def parse(body) xml = REXML::Document.new(body) response = {} xml.root.elements.to_a.each do |node| parse_element(response, node) end response end
parse_element(response, node)
click to toggle source
# File lib/active_merchant/billing/gateways/secure_pay_au.rb, line 266 def parse_element(response, node) if node.has_elements? node.elements.each{|element| parse_element(response, element) } else response[node.name.underscore.to_sym] = node.text end end
success?(response)
click to toggle source
# File lib/active_merchant/billing/gateways/secure_pay_au.rb, line 238 def success?(response) SUCCESS_CODES.include?(response[:response_code]) end