Skip to content

Commit

Permalink
Update PaymentExpressGateway to remove test_result_from_cc_number.
Browse files Browse the repository at this point in the history
git-svn-id: https://activemerchant.googlecode.com/svn/trunk/active_merchant@592 6513ea26-6c20-0410-8a68-89cd7235086d
  • Loading branch information
codyfauser committed Jan 25, 2008
1 parent 26471f6 commit f1d0ced
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 98 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
@@ -1,5 +1,6 @@
= ActiveMerchant CHANGELOG

* Update PaymentExpressGateway to remove test_result_from_cc_number. [cody]
* Update PaySecure to remove test_result_from_cc_number. [cody]
* Update NetbillingGateway to support avs and cvv data. Remove test_result_from_cc_number. [cody]
* Replace all usage of :address with :billing_address in test cases [cody]
Expand Down
24 changes: 8 additions & 16 deletions lib/active_merchant/billing/gateways/payment_express.rb
@@ -1,7 +1,7 @@
require 'rexml/document'

module ActiveMerchant
module Billing
module ActiveMerchant #:nodoc:
module Billing #:nodoc:

# In NZ DPS supports ANZ, Westpac, National Bank, ASB and BNZ.
# In Australia DPS supports ANZ, NAB, Westpac, CBA, St George and Bank of South Australia.
Expand Down Expand Up @@ -33,8 +33,6 @@ class PaymentExpressGateway < Gateway
:validate => 'Validate'
}

POST_HEADERS = { "Content-Type" => "application/x-www-form-urlencoded" }

# We require the DPS gateway username and password when the object is created.
def initialize(options = {})
# A DPS username and password must exist
Expand Down Expand Up @@ -180,7 +178,7 @@ def add_transaction_type(xml, action)
end

def add_invoice(xml, options)
xml.add_element("TxnId").text = options[:order_id] unless options[:order_id].blank?
xml.add_element("TxnId").text = options[:order_id].to_s.slice(0, 16) unless options[:order_id].blank?
xml.add_element("MerchantReference").text = options[:description] unless options[:description].blank?
end

Expand All @@ -204,24 +202,18 @@ def commit(action, request)
add_credentials(request)
add_transaction_type(request, action)

# Next, post it to the server
response = ssl_post(PAYMENT_URL, request.to_s, POST_HEADERS)

# Parse the XML response
@response = parse_response(response)

success = @response[:success] == APPROVED
test = @response[:test_mode] == '1'
response = parse( ssl_post(PAYMENT_URL, request.to_s) )

# Return a response
PaymentExpressResponse.new(success, @response[:response_text], @response,
:test => test,
:authorization => @response[:dps_txn_ref]
PaymentExpressResponse.new(response[:success] == APPROVED, response[:response_text], response,
:test => response[:test_mode] == '1',
:authorization => response[:dps_txn_ref]
)
end

# Response XML documentation: http://www.paymentexpress.com/technical_resources/ecommerce_nonhosted/pxpost.html#XMLTxnOutput
def parse_response(xml_string)
def parse(xml_string)
response = {}

xml = REXML::Document.new(xml_string)
Expand Down
60 changes: 25 additions & 35 deletions test/remote/gateways/remote_payment_express_test.rb
@@ -1,74 +1,65 @@
require File.dirname(__FILE__) + '/../../test_helper'

class RemotePaymentExpressTest < Test::Unit::TestCase
LOGIN = 'LOGIN'
PASSWORD = 'PASSWORD'


def setup
@gateway = PaymentExpressGateway.new(fixtures(:payment_express))

@creditcard = credit_card('4111111111111111')
@credit_card = credit_card

@options = {
:billing_address => {
:name => 'Cody Fauser',
:address1 => '1234 Shady Brook Lane',
:city => 'Ottawa',
:state => 'ON',
:country => 'CA',
:zip => '90210',
:phone => '555-555-5555'
},
:email => 'cody@example.com',
:description => 'Store purchase'
:order_id => generate_order_id,
:billing_address => address,
:email => 'cody@example.com',
:description => 'Store purchase'
}

@amount = 100
end

def test_successful_purchase
assert response = @gateway.purchase(100, @creditcard, @options)
assert response = @gateway.purchase(@amount, @credit_card, @options)
assert_equal "APPROVED", response.message
assert_success response
assert response.test?
assert_not_nil response.authorization
end

def test_successful_purchase_with_reference_id
@options[:order_id] = rand(100000)
assert response = @gateway.purchase(100, @creditcard, @options)
assert response = @gateway.purchase(@amount, @credit_card, @options)
assert_equal "APPROVED", response.message
assert_success response
assert response.test?
assert_not_nil response.authorization
end

def test_declined_purchase
assert response = @gateway.purchase(176, @creditcard, @options)
assert response = @gateway.purchase(176, @credit_card, @options)
assert_equal 'DECLINED', response.message
assert_failure response
assert response.test?
end

def test_successful_authorization
assert response = @gateway.authorize(100, @creditcard, @options)
assert response = @gateway.authorize(@amount, @credit_card, @options)
assert_equal "APPROVED", response.message
assert_success response
assert response.test?
assert_not_nil response.authorization
end

def test_authorize_and_capture
amount = 100
assert auth = @gateway.authorize(amount, @creditcard, @options)
assert auth = @gateway.authorize(@amount, @credit_card, @options)
assert_success auth
assert_equal 'APPROVED', auth.message
assert auth.authorization
assert capture = @gateway.capture(amount, auth.authorization)
assert capture = @gateway.capture(@amount, auth.authorization)
assert_success capture
end

def test_purchase_and_credit
amount = 10000
assert purchase = @gateway.purchase(amount, @creditcard, @options)
assert purchase = @gateway.purchase(amount, @credit_card, @options)
assert_success purchase
assert_equal 'APPROVED', purchase.message
assert !purchase.authorization.blank?
Expand All @@ -77,7 +68,7 @@ def test_purchase_and_credit
end

def test_failed_capture
assert response = @gateway.capture(100, '999')
assert response = @gateway.capture(@amount, '999')
assert_failure response
assert_equal 'IVL DPSTXNREF', response.message
end
Expand All @@ -87,13 +78,13 @@ def test_invalid_login
:login => '',
:password => ''
)
assert response = gateway.purchase(100, @creditcard, @options)
assert response = gateway.purchase(@amount, @credit_card, @options)
assert_equal 'Invalid Credentials', response.message
assert_failure response
end

def test_store_credit_card
assert response = @gateway.store(@creditcard)
assert response = @gateway.store(@credit_card)
assert_success response
assert_equal "APPROVED", response.message
assert !response.token.blank?
Expand All @@ -102,7 +93,7 @@ def test_store_credit_card

def test_store_with_custom_token
token = Time.now.to_i.to_s #hehe
assert response = @gateway.store(@creditcard, :billing_id => token)
assert response = @gateway.store(@credit_card, :billing_id => token)
assert_success response
assert_equal "APPROVED", response.message
assert !response.token.blank?
Expand All @@ -111,26 +102,25 @@ def test_store_with_custom_token
end

def test_store_invalid_credit_card
original_number = @creditcard.number
@creditcard.number = 2
original_number = @credit_card.number
@credit_card.number = 2

assert response = @gateway.store(@creditcard)
assert response = @gateway.store(@credit_card)
assert_failure response
ensure
@creditcard.number = original_number
@credit_card.number = original_number
end

def test_store_and_charge
assert response = @gateway.store(@creditcard)
assert response = @gateway.store(@credit_card)
assert_success response
assert_equal "APPROVED", response.message
assert (token = response.token)

assert purchase = @gateway.purchase( 100, token)
assert purchase = @gateway.purchase( @amount, token)
assert_equal "APPROVED", purchase.message
assert_success purchase
assert_not_nil purchase.authorization
end


end
79 changes: 32 additions & 47 deletions test/unit/gateways/payment_express_test.rb
Expand Up @@ -8,68 +8,39 @@ def setup
:password => 'PASSWORD'
)

@visa = CreditCard.new(
:number => '4242424242424242',
:month => 8,
:year => 2008,
:first_name => 'Longbob',
:last_name => 'Longsen',
:type => 'visa'
)
@visa = credit_card

@solo = CreditCard.new(
:type => "solo",
:number => "6334900000000005",
:month => 11,
:year => 2012,
:first_name => "Test",
:last_name => "Mensch",
:issue_number => '01'
)
@solo = credit_card("6334900000000005",
:type => "solo",
:issue_number => '01'
)

@address = { :address1 => '1234 My Street',
:address2 => 'Apt 1',
:company => 'Widgets Inc',
:city => 'Ottawa',
:state => 'ON',
:zip => 'K1C2N6',
:country => 'Canada',
:phone => '(555)555-5555'
}
end

def test_successful_request
@visa.number = 1
@options = {
:order_id => generate_order_id,
:billing_address => address,
:email => 'cody@example.com',
:description => 'Store purchase'
}

assert response = @gateway.purchase(100, @visa)
assert_success response
assert_equal '5555', response.authorization
assert response.test?
end

def test_unsuccessful_request
@visa.number = 2
assert response = @gateway.purchase(100, @visa)
assert_failure response
assert response.test?
@amount = 100
end

def test_default_currency
assert_equal 'NZD', PaymentExpressGateway.default_currency
end

def test_invalid_credentials
@gateway.expects(:ssl_post).returns(invalid_credentials_response)

assert response = @gateway.purchase(100, @visa)
assert response = @gateway.purchase(@amount, @visa, @options)
assert_equal 'Invalid Credentials', response.message
assert_failure response
end

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

assert response = @gateway.purchase(100, @visa)
assert response = @gateway.purchase(@amount, @visa, @options)
assert_success response
assert response.test?
assert_equal 'APPROVED', response.message
Expand All @@ -79,7 +50,7 @@ def test_successful_authorization
def test_successful_solo_authorization
@gateway.expects(:ssl_post).returns(successful_authorization_response)

assert response = @gateway.purchase(100, @solo)
assert response = @gateway.purchase(@amount, @solo, @options)
assert_success response
assert response.test?
assert_equal 'APPROVED', response.message
Expand Down Expand Up @@ -121,7 +92,7 @@ def test_purchase_using_token

@gateway.expects(:ssl_post).returns( successful_token_purchase_response )

assert response = @gateway.purchase(100, token)
assert response = @gateway.purchase(@amount, token, @options)
assert_success response
assert_equal 'APPROVED', response.message
assert_equal '0000000303ace8db', response.authorization
Expand All @@ -135,6 +106,20 @@ def test_supported_card_types
assert_equal [ :visa, :master, :american_express, :diners_club, :jcb ], PaymentExpressGateway.supported_cardtypes
end

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

response = @gateway.purchase(@amount, @credit_card, @options)
assert_nil response.avs_result['code']
end

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

response = @gateway.purchase(@amount, @credit_card, @options)
assert_nil response.cvv_result['code']
end

private
def invalid_credentials_response
'<Txn><ReCo>0</ReCo><ResponseText>Invalid Credentials</ResponseText></Txn>'
Expand All @@ -146,7 +131,7 @@ def successful_authorization_response
<Transaction success="1" reco="00" responsetext="APPROVED">
<Authorized>1</Authorized>
<MerchantReference>Test Transaction</MerchantReference>
<Cvc2></Cvc2>
<Cvc2>M</Cvc2>
<CardName>Visa</CardName>
<Retry>0</Retry>
<StatusRequired>0</StatusRequired>
Expand Down

0 comments on commit f1d0ced

Please sign in to comment.