Skip to content

Commit

Permalink
SecurePayAu: fix credit card check
Browse files Browse the repository at this point in the history
- Some ActiveMerchant users have their own credit card object that they
  pass to ActiveMerchant so we shouldn't be checking for
ActiveMerchant::Billing::CreditCard explicitly but check that it looks
like a credit card instead (having a number method is a good check).
  • Loading branch information
John Duff committed May 22, 2012
1 parent 94eea85 commit 333cd57
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/active_merchant/billing/gateways/nab_transact.rb
Expand Up @@ -59,7 +59,7 @@ def test?
end

def purchase(money, credit_card_or_stored_id, options = {})
if credit_card_or_stored_id.is_a?(ActiveMerchant::Billing::CreditCard)
if credit_card_or_stored_id.respond_to?(:number)
#Credit card for instant payment
commit :purchase, build_purchase_request(money, credit_card_or_stored_id, options)
else
Expand Down
2 changes: 1 addition & 1 deletion lib/active_merchant/billing/gateways/secure_pay_au.rb
Expand Up @@ -64,7 +64,7 @@ def test?
end

def purchase(money, credit_card_or_stored_id, options = {})
if credit_card_or_stored_id.is_a?(ActiveMerchant::Billing::CreditCard)
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
Expand Down
14 changes: 13 additions & 1 deletion test/unit/gateways/secure_pay_au_test.rb
Expand Up @@ -58,6 +58,18 @@ def test_failed_purchase
assert_equal "CARD EXPIRED", response.message
end

def test_purchase_with_stored_id_calls_commit_periodic
@gateway.expects(:commit_periodic)

@gateway.purchase(@amount, "123", @options)
end

def test_purchase_with_creditcard_calls_commit_with_purchase
@gateway.expects(:commit).with(:purchase, anything)

@gateway.purchase(@amount, @credit_card, @options)
end

def test_successful_authorization
@gateway.expects(:ssl_post).returns(successful_authorization_response)

Expand Down Expand Up @@ -454,4 +466,4 @@ def successful_refund_response
def failed_refund_response
%(<?xml version="1.0" encoding="UTF-8" standalone="no"?><SecurePayMessage><MessageInfo><messageID>6bacab2b7ae1200d8099e0873e25bc</messageID><messageTimestamp>20102807071248484000+600</messageTimestamp><apiVersion>xml-4.2</apiVersion></MessageInfo><RequestType>Payment</RequestType><MerchantInfo><merchantID>CAX0001</merchantID></MerchantInfo><Status><statusCode>000</statusCode><statusDescription>Normal</statusDescription></Status><Payment><TxnList count="1"><Txn ID="1"><txnType>4</txnType><txnSource>23</txnSource><amount>101</amount><currency>AUD</currency><purchaseOrderNo>269061</purchaseOrderNo><approved>No</approved><responseCode>134</responseCode><responseText>Only $1.00 available for refund</responseText><thinlinkResponseCode>300</thinlinkResponseCode><thinlinkResponseText>000</thinlinkResponseText><thinlinkEventStatusCode>999</thinlinkEventStatusCode><thinlinkEventStatusText>Error - Transaction Already Fully Refunded/Only $x.xx Available for Refund</thinlinkEventStatusText><settlementDate/><txnID/><CreditCardInfo><pan>444433...111</pan><expiryDate>09/11</expiryDate><cardType>6</cardType><cardDescription>Visa</cardDescription></CreditCardInfo></Txn></TxnList></Payment></SecurePayMessage>)
end
end
end

0 comments on commit 333cd57

Please sign in to comment.