require 'test_helper'
class WirecardTest < Test::Unit::TestCase
TEST_AUTHORIZATION_GUWID = 'C822580121385121429927'
def setup
@gateway = WirecardGateway.new(:login => '', :password => '', :signature => '')
@credit_card = credit_card('4200000000000000')
@declined_card = credit_card('4000300011112220')
@unsupported_card = credit_card('4200000000000000', :type => :maestro)
@amount = 111
@options = {
:order_id => '1',
:billing_address => address,
:description => 'Wirecard Purchase',
:email => 'soleone@example.com'
}
@address_without_state = {
:name => 'Jim Smith',
:address1 => '1234 My Street',
:company => 'Widgets Inc',
:city => 'Ottawa',
:zip => 'K12 P2A',
:country => 'CA',
:state => nil,
}
end
def test_successful_authorization
@gateway.expects(:ssl_post).returns(successful_authorization_response)
assert response = @gateway.authorize(@amount, @credit_card, @options)
assert_instance_of Response, response
assert_success response
assert response.test?
assert_equal TEST_AUTHORIZATION_GUWID, response.authorization
end
def test_wrong_credit_card_authorization
@gateway.expects(:ssl_post).returns(wrong_creditcard_authorization_response)
assert response = @gateway.authorize(@amount, @declined_card, @options)
assert_instance_of Response, response
assert_failure response
assert response.test?
assert_false response.authorization
assert response.message[/credit card number not allowed in demo mode/i]
end
def test_successful_authorization_and_capture
@gateway.expects(:ssl_post).returns(successful_authorization_response)
assert response = @gateway.authorize(@amount, @credit_card, @options)
assert_success response
assert_equal TEST_AUTHORIZATION_GUWID, response.authorization
@gateway.expects(:ssl_post).returns(successful_capture_response)
assert response = @gateway.capture(@amount, response.authorization, @options)
assert_success response
assert response.test?
assert response.message[/this is a demo/i]
end
def test_unauthorized_capture
@gateway.expects(:ssl_post).returns(unauthorized_capture_response)
assert response = @gateway.capture(@amount, "1234567890123456789012", @options)
assert_failure response
assert response.message["Could not find referenced transaction for GuWID 1234567890123456789012."]
end
def test_doesnt_raise_an_error_if_no_state_is_provided_in_address
options = @options.merge(:billing_address => @address_without_state)
@gateway.expects(:ssl_post).returns(unauthorized_capture_response)
assert_nothing_raised do
@gateway.authorize(@amount, @credit_card, options)
end
end
private
# Authorization success
def successful_authorization_response
<<-XML
test dummy data
Wirecard remote test purchase
1
C822580121385121429927
709678
THIS IS A DEMO TRANSACTION USING CREDIT CARD NUMBER 420000****0000. NO REAL MONEY WILL BE TRANSFERED.
INFO
ACK
2008-06-19 06:53:33
XML
end
# Authorization failure
# TODO: replace with real xml string here (current way seems to complicated)
def wrong_creditcard_authorization_response
error = <<-XML
DATA_ERROR
24997
Credit card number not allowed in demo mode.
Only demo card number '4200000000000000' is allowed for VISA in demo mode.
XML
result_node = ''
auth = 'AuthorizationCode'
successful_authorization_response.gsub('ACK', 'NOK') \
.gsub(result_node, result_node + error) \
.gsub(/<#{auth}>\w+<\/#{auth}>/, "<#{auth}><\/#{auth}>") \
.gsub(/.+<\/Info>/, '')
end
# Capture success
def successful_capture_response
<<-XML
test dummy data
Wirecard remote test purchase
1
C833707121385268439116
915025
THIS IS A DEMO TRANSACTION USING CREDIT CARD NUMBER 420000****0000. NO REAL MONEY WILL BE TRANSFERED.
INFO
ACK
2008-06-19 07:18:04
XML
end
# Capture failure
def unauthorized_capture_response
<<-XML
test dummy data
Test dummy FunctionID
a2783d471ccc98825b8c498f1a62ce8f
C865683121385576058270
INFO
NOK
DATA_ERROR
20080
Could not find referenced transaction for GuWID 1234567890123456789012.
2008-06-19 08:09:20
XML
end
# Purchase success
def successful_purchase_response
<<-XML
test dummy data
Wirecard remote test purchase
1
C865402121385575982910
531750
THIS IS A DEMO TRANSACTION USING CREDIT CARD NUMBER 420000****0000. NO REAL MONEY WILL BE TRANSFERED.
INFO
ACK
2008-06-19 08:09:19
XML
end
# Purchase failure
def wrong_creditcard_purchase_response
<<-XML
test dummy data
Wirecard remote test purchase
1
C824697121385153203112
INFO
NOK
DATA_ERROR 24997
Credit card number not allowed in demo mode.
Only demo card number '4200000000000000' is allowed for VISA in demo mode.
2008-06-19 06:58:51
XML
end
end