From 7af3e137d97474aa364a585359bbfb400f0594cf Mon Sep 17 00:00:00 2001 From: fbriere Date: Mon, 13 Feb 2006 21:10:31 +0000 Subject: Initial import --- t/10base.t | 4 ++ t/20emit.t | 143 ++++++++++++++++++++++++++++++++++++++++++++++++++++ t/30parse.t | 163 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ t/40live.t | 32 ++++++++++++ 4 files changed, 342 insertions(+) create mode 100755 t/10base.t create mode 100755 t/20emit.t create mode 100755 t/30parse.t create mode 100755 t/40live.t (limited to 't') diff --git a/t/10base.t b/t/10base.t new file mode 100755 index 0000000..2f956f2 --- /dev/null +++ b/t/10base.t @@ -0,0 +1,4 @@ +use Test::More tests => 2; + +BEGIN { use_ok('Business::OnlinePayment') }; +BEGIN { use_ok('Business::OnlinePayment::InternetSecure') }; diff --git a/t/20emit.t b/t/20emit.t new file mode 100755 index 0000000..a162f10 --- /dev/null +++ b/t/20emit.t @@ -0,0 +1,143 @@ +use Test::More tests => 4 + 2; + +BEGIN { use_ok('Business::OnlinePayment') }; +BEGIN { use_ok('Business::OnlinePayment::InternetSecure') }; +BEGIN { use_ok('XML::Simple', qw(xml_in)) }; +BEGIN { use_ok('Encode') }; + +use charnames ':full'; # Why doesn't this work with use_ok? + +use constant TRANSACTIONS => ( + { + _test => 0, + + action => 'Normal Authorization', + + type => 'Visa', + card_number => '0000000000000000', + exp_date => '2004-07', + cvv2 => '000', + + name => "Fr\N{LATIN SMALL LETTER E WITH ACUTE}d\N{LATIN SMALL LETTER E WITH ACUTE}ric Bri\N{LATIN SMALL LETTER E WITH GRAVE}re", + company => '', + address => '123 Street', + city => 'Metropolis', + state => 'ZZ', + zip => 'A1A 1A1', + country => 'CA', + phone => '(555) 555-1212', + email => 'fbriere@fbriere.net', + + amount => undef, + currency => 'CAD', + taxes => 'GST PST', + + description => [ + { + amount => 9.99, + quantity => 5, + sku => 'a:001', + description => 'Some product', + }, + { + amount => 5.65, + description => 'Shipping', + }, + { + amount => 10.00, + description => 'Some HST example', + taxes => 'HST', + }, + ], + }, + { + _test => 1, + + action => 'Normal Authorization', + + type => 'Visa', + card_number => '0000000000000000', + exp_date => '7/2004', + + name => "Fr\x{e9}d\x{e9}ric Bri\x{e8}re", + + amount => 12.95, + currency => 'USD', + taxes => '', + description => "Box o' goodies", + }, +); + + +my $txn = new Business::OnlinePayment 'InternetSecure', merchant_id => '0000'; + +$/ = ''; +foreach (TRANSACTIONS) { + $txn->test_transaction(delete $_->{_test}); + $txn->content(%$_); + is_deeply( + xml_in(Encode::encode('utf8', $txn->to_xml)), + xml_in(scalar ) + ); +} + + +__DATA__ + + + 0000 + 0000000000000000 + 07 + 2004 + 1 + 000 + 9.99::5::a 001::Some product::{CAD}{GST}{PST}|5.65::1::::Shipping::{CAD}{GST}{PST}|10.00::1::::Some HST example::{CAD}{HST} + Frédéric Brière + + 123 Street + Metropolis + ZZ + A1A 1A1 + CA + (555) 555-1212 + fbriere@fbriere.net + + + + + + + + + + + + + + 0000 + 0000000000000000 + 07 + 2004 + 0 + + 12.95::1::::Box o' goodies::{USD}{TEST} + Frédéric Brière + + + + + + + + + + + + + + + + + + + diff --git a/t/30parse.t b/t/30parse.t new file mode 100755 index 0000000..8780731 --- /dev/null +++ b/t/30parse.t @@ -0,0 +1,163 @@ +use Test::More tests => 1 + 2 * 5; + +BEGIN { use_ok('Business::OnlinePayment') }; + + +use constant FIELDS => (qw( result_code authorization total_amount )); + +use constant RESULTS => ( + [ 1, '2000', 'T00000', 3.88 ], + [ 0, '98e05', undef, 3.88 ], + ); + + +my $txn = new Business::OnlinePayment 'InternetSecure', merchant_id => '0000'; + +$/ = ''; +foreach (RESULTS) { + my @results = @$_; + + my $xml = ; + $txn->parse_response($xml); + + is($txn->server_response, $xml, 'server_response'); + + if (shift @results) { + ok($txn->is_success, 'expecting success'); + } else { + ok(!$txn->is_success, 'expecting failure'); + } + + foreach (FIELDS) { + no strict 'refs'; + is($txn->$_, shift @results, $_); + } +} + + +__DATA__ + + + 4994 + 1096019995.5012 + 0 + John Smith + 2003/12/17 09:59:58 + Test Card Number + 2000 + T00000 + Test Approved + 3.88 + + + 001 + Test Product 1 + 1 + 3.10 + 3.10 + + {USD} + {GST} + {TEST} + + + + 010 + Test Product 2 + 1 + 0.20 + 0.20 + + {GST} + {TEST} + + + + 020 + Test Product 3 + 1 + 0.33 + 0.33 + + {GST} + {TEST} + + + + GST + Canadian GST Charged + 1 + 0.25 + 0.25 + + {TAX} + {CALCULATED} + + + + 3.10::1::001::Test Product 1::{USD}{GST}{TEST}|0.20::1::010::Test Product 2::{GST}{TEST}|0.33::1::020::Test Product 3::{GST}{TEST}|0.25::1::GST::Canadian GST Charged::{TAX}{CALCULATED} + + + + + + + 4994 + 1096021915.5853 + 729 + John Smith + 2003/12/17 10:31:58 + VI + 98e05 + + Incorrect Card Number - Please Retry + 3.88 + + + 001 + Test Product 1 + 1 + 3.10 + 3.10 + + {USD} + {GST} + + + + 010 + Test Product 2 + 1 + 0.20 + 0.20 + + {GST} + + + + 020 + Test Product 3 + 1 + 0.33 + 0.33 + + {GST} + + + + GST + Canadian GST Charged + 1 + 0.25 + 0.25 + + {TAX} + {CALCULATED} + + + + 3.10::1::001::Test Product 1::{USD}{GST}|0.20::1::010::Test Product 2::{GST}|0.33::1::020::Test Product 3::{GST}|0.25::1::GST::Canadian GST Charged::{TAX}{CALCULATED} + + + + diff --git a/t/40live.t b/t/40live.t new file mode 100755 index 0000000..4d59f68 --- /dev/null +++ b/t/40live.t @@ -0,0 +1,32 @@ +use Test::More; + +BEGIN { + plan skip_all => 'MERCHANT_ID environment variable not set' + unless defined $ENV{MERCHANT_ID}; +}; + +BEGIN { plan tests => 1 + 2 }; + +BEGIN { use_ok('Business::OnlinePayment') }; + + +my $txn = new Business::OnlinePayment 'InternetSecure', + merchant_id => $ENV{MERCHANT_ID}; + +$txn->test_transaction(1); + +$txn->content( + action => 'Normal Authorization', + type => 'Visa', + card_number => '0000000000000000', + exp_date => '2004/07', + name => "Fr\x{e9}d\x{e9}ric Bri\x{e8}re", + amount => 0.01, + ); + +$txn->submit; + +is($txn->result_code, '2000', 'is result_code 2000?'); +is($txn->cardholder, "Fr\x{e9}d\x{e9}ric Bri\x{e8}re", + 'is cardholder encoded properly?'); + -- cgit v1.2.1