Permalink
Browse files

eWAY gateway: Update docs. Require address.

Docs:

* Remove old copy & paste about TrustCommerce.
* Add info about transaction results.
* Add test credit card number, provided by eway docs
  (http://www.eway.com.au/developers/sandbox/direct-payments.html)

Code:

* :order_id is not a required parameter, so remove it
* Add :address and :billing_address to required parameters, because if
  you don't pass address to gateway, you'll get:

    Error: Required XML tag(s) missing, or incorrect case used. Required tag Name(s): ewayCustomerAddress, ewayCustomerPostcode

* Remove tests for invalid expiration date and verification value.
  Seems like the Test eWay Gateway doesn't care about the validity of
  them and always returns a success code.

Closes #378.
  • Loading branch information...
1 parent e8879be commit 1b0ef23a6ad7f335363a2dfed49924b4bfbb013a @maxprokopiev maxprokopiev committed with shayfrendt Jun 16, 2012
View
@@ -10,6 +10,7 @@
[Soleone]
* Deprecate CreditCard#type method in favor of CreditCard#brand [jduff]
* Cybersource gateway: Add subscriptions support [fabiokr, jaredmoody]
+* eWay gateway: Improved docs, and more accurate required parameters [juggler]
== Version 1.23.0 (May 23, 2012)
@@ -11,14 +11,18 @@ module Billing #:nodoc:
#
# tendollar = 1000
#
- # Next, create a credit card object using a TC approved test card.
+ # The transaction result is based on the cent value of the transaction. $10.15 will return a failed transaction
+ # with a response code of "15 – No Issuer", while $10.00 will return "00 – Transaction Approved."
+ #
+ # Next, create a credit card object using a eWay approved test card number (4444333322221111).
#
# creditcard = ActiveMerchant::Billing::CreditCard.new(
- # :number => '4111111111111111',
+ # :number => '4444333322221111',
# :month => 8,
# :year => 2006,
# :first_name => 'Longbob',
- # :last_name => 'Longsen'
+ # :last_name => 'Longsen',
+ # :verification_value => '123'
# )
# options = {
# :order_id => '1230123',
@@ -28,20 +32,20 @@ module Billing #:nodoc:
# :state => 'WA',
# :country => 'Australia',
# :zip => '2000'
- # }
+ # },
# :description => 'purchased items'
# }
#
# To finish setting up, create the active_merchant object you will be using, with the eWay gateway. If you have a
- # functional eWay account, replace :login with your account info.
+ # functional eWay account, replace :login with your Customer ID.
#
# gateway = ActiveMerchant::Billing::Base.gateway(:eway).new(:login => '87654321')
#
# Now we are ready to process our transaction
#
# response = gateway.purchase(tendollar, creditcard, options)
#
- # Sending a transaction to TrustCommerce with active_merchant returns a Response object, which consistently allows you to:
+ # Sending a transaction to eWay with active_merchant returns a Response object, which consistently allows you to:
#
# 1) Check whether the transaction was successful
#
@@ -143,7 +147,7 @@ def initialize(options = {})
# ewayCustomerEmail, ewayCustomerAddress, ewayCustomerPostcode
def purchase(money, creditcard, options = {})
- requires!(options, :order_id)
+ requires_address!(options)
post = {}
add_creditcard(post, creditcard)
@@ -161,6 +165,11 @@ def test?
end
private
+
+ def requires_address!(options)
+ raise ArgumentError.new("Missing eWay required parameters: address or billing_address") unless (options.has_key?(:address) or options.has_key?(:billing_address))
+ end
+
def add_creditcard(post, creditcard)
post[:CardNumber] = creditcard.number
post[:CardExpiryMonth] = sprintf("%.2i", creditcard.month)
@@ -40,21 +40,6 @@ def test_purchase_success_with_verification_value
assert_equal EwayGateway::MESSAGES["00"], response.message
end
- def test_invalid_expiration_date
- @credit_card_success.year = 2005
- assert response = @gateway.purchase(100, @credit_card_success, @params)
- assert_failure response
- assert response.test?
- end
-
- def test_purchase_with_invalid_verification_value
- @credit_card_success.verification_value = 'AAA'
- assert response = @gateway.purchase(100, @credit_card_success, @params)
- assert_nil response.authorization
- assert_failure response
- assert response.test?
- end
-
def test_purchase_success_without_verification_value
@credit_card_success.verification_value = nil
@@ -7,7 +7,7 @@ def setup
)
@credit_card = credit_card('4646464646464646')
-
+
@options = {
:order_id => '1230123',
:email => 'bob@testbob.com',
@@ -20,58 +20,65 @@ def setup
:zip => '12345'
},
:description => 'purchased items'
- }
+ }
+ end
+
+ def test_purchase_without_billing_address
+ @options.delete(:billing_address)
+ assert_raise(ArgumentError) do
+ @gateway.purchase(@amount, @credit_card, @options)
+ end
end
-
+
def test_successful_purchase
@gateway.expects(:ssl_post).returns(successful_purchase_response)
-
+
assert response = @gateway.purchase(@amount, @credit_card, @options)
assert_instance_of Response, response
assert_success response
assert_equal '123456', response.authorization
end
-
+
def test_failed_purchase
@gateway.expects(:ssl_post).returns(failed_purchase_response)
-
+
assert response = @gateway.purchase(@amount, @credit_card, @options)
assert_instance_of Response, response
assert_failure response
end
-
+
def test_amount_style
assert_equal '1034', @gateway.send(:amount, 1034)
-
+
assert_raise(ArgumentError) do
@gateway.send(:amount, '10.34')
end
end
-
+
def test_ensure_does_not_respond_to_authorize
assert !@gateway.respond_to?(:authorize)
end
-
+
def test_ensure_does_not_respond_to_capture
assert !@gateway.respond_to?(:capture) || @gateway.method(:capture).owner != @gateway.class
end
-
+
def test_test_url_without_cvn
assert_equal EwayGateway::TEST_URL, @gateway.send(:gateway_url, false, true)
end
-
+
def test_test_url_with_cvn
assert_equal EwayGateway::TEST_CVN_URL, @gateway.send(:gateway_url, true, true)
end
-
+
def test_live_url_without_cvn
assert_equal EwayGateway::LIVE_URL, @gateway.send(:gateway_url, false, false)
end
-
+
def test_live_url_with_cvn
assert_equal EwayGateway::LIVE_CVN_URL, @gateway.send(:gateway_url, true, false)
end
-
+
def test_add_address
post = {}
@gateway.send(:add_address, post, @options)
@@ -96,7 +103,7 @@ def successful_purchase_response
</ewayResponse>
XML
end
-
+
def failed_purchase_response
<<-XML
<?xml version="1.0"?>
@@ -114,5 +121,3 @@ def failed_purchase_response
XML
end
end
-
-

0 comments on commit 1b0ef23

Please sign in to comment.