diff options
Diffstat (limited to 't')
-rwxr-xr-x | t/10base.t | 4 | ||||
-rwxr-xr-x | t/20emit.t | 143 | ||||
-rwxr-xr-x | t/30parse.t | 163 | ||||
-rwxr-xr-x | t/40live.t | 32 |
4 files changed, 342 insertions, 0 deletions
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>) + ); +} + + +__DATA__ +<?xml version="1.0" encoding="utf-8" standalone="yes"?> +<TranxRequest> + <MerchantNumber>0000</MerchantNumber> + <xxxCardNumber>0000000000000000</xxxCardNumber> + <xxxCCMonth>07</xxxCCMonth> + <xxxCCYear>2004</xxxCCYear> + <CVV2>1</CVV2> + <CVV2Indicator>000</CVV2Indicator> + <Products>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}</Products> + <xxxName>Frédéric Brière</xxxName> + <xxxCompany></xxxCompany> + <xxxAddress>123 Street</xxxAddress> + <xxxCity>Metropolis</xxxCity> + <xxxProvince>ZZ</xxxProvince> + <xxxPostal>A1A 1A1</xxxPostal> + <xxxCountry>CA</xxxCountry> + <xxxPhone>(555) 555-1212</xxxPhone> + <xxxEmail>fbriere@fbriere.net</xxxEmail> + <xxxShippingName></xxxShippingName> + <xxxShippingCompany></xxxShippingCompany> + <xxxShippingAddress></xxxShippingAddress> + <xxxShippingCity></xxxShippingCity> + <xxxShippingProvince></xxxShippingProvince> + <xxxShippingPostal></xxxShippingPostal> + <xxxShippingCountry></xxxShippingCountry> + <xxxShippingPhone></xxxShippingPhone> + <xxxShippingEmail></xxxShippingEmail> +</TranxRequest> + +<?xml version="1.0" encoding="utf-8" standalone="yes"?> +<TranxRequest> + <MerchantNumber>0000</MerchantNumber> + <xxxCardNumber>0000000000000000</xxxCardNumber> + <xxxCCMonth>07</xxxCCMonth> + <xxxCCYear>2004</xxxCCYear> + <CVV2>0</CVV2> + <CVV2Indicator></CVV2Indicator> + <Products>12.95::1::::Box o' goodies::{USD}{TEST}</Products> + <xxxName>Frédéric Brière</xxxName> + <xxxCompany></xxxCompany> + <xxxAddress></xxxAddress> + <xxxCity></xxxCity> + <xxxProvince></xxxProvince> + <xxxPostal></xxxPostal> + <xxxCountry></xxxCountry> + <xxxPhone></xxxPhone> + <xxxEmail></xxxEmail> + <xxxShippingName></xxxShippingName> + <xxxShippingCompany></xxxShippingCompany> + <xxxShippingAddress></xxxShippingAddress> + <xxxShippingCity></xxxShippingCity> + <xxxShippingProvince></xxxShippingProvince> + <xxxShippingPostal></xxxShippingPostal> + <xxxShippingCountry></xxxShippingCountry> + <xxxShippingPhone></xxxShippingPhone> + <xxxShippingEmail></xxxShippingEmail> +</TranxRequest> + 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 = <DATA>; + $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__ +<?xml version="1.0" encoding="UTF-8"?> +<TranxResponse> + <MerchantNumber>4994</MerchantNumber> + <ReceiptNumber>1096019995.5012</ReceiptNumber> + <SalesOrderNumber>0</SalesOrderNumber> + <xxxName>John Smith</xxxName> + <Date>2003/12/17 09:59:58</Date> + <CardType>Test Card Number</CardType> + <Page>2000</Page> + <ApprovalCode>T00000</ApprovalCode> + <Verbiage>Test Approved</Verbiage> + <TotalAmount>3.88</TotalAmount> + <Products> + <product> + <code>001</code> + <description>Test Product 1</description> + <quantity>1</quantity> + <price>3.10</price> + <subtotal>3.10</subtotal> + <flags> + <flag>{USD}</flag> + <flag>{GST}</flag> + <flag>{TEST}</flag> + </flags> + </product> + <product> + <code>010</code> + <description>Test Product 2</description> + <quantity>1</quantity> + <price>0.20</price> + <subtotal>0.20</subtotal> + <flags> + <flag>{GST}</flag> + <flag>{TEST}</flag> + </flags> + </product> + <product> + <code>020</code> + <description>Test Product 3</description> + <quantity>1</quantity> + <price>0.33</price> + <subtotal>0.33</subtotal> + <flags> + <flag>{GST}</flag> + <flag>{TEST}</flag> + </flags> + </product> + <product> + <code>GST</code> + <description>Canadian GST Charged</description> + <quantity>1</quantity> + <price>0.25</price> + <subtotal>0.25</subtotal> + <flags> + <flag>{TAX}</flag> + <flag>{CALCULATED}</flag> + </flags> + </product> + </Products> + <DoubleColonProducts>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}</DoubleColonProducts> + <AVSResponseCode /> + <CVV2ResponseCode /> +</TranxResponse> + +<?xml version="1.0" encoding="UTF-8"?> +<TranxResponse> + <MerchantNumber>4994</MerchantNumber> + <ReceiptNumber>1096021915.5853</ReceiptNumber> + <SalesOrderNumber>729</SalesOrderNumber> + <xxxName>John Smith</xxxName> + <Date>2003/12/17 10:31:58</Date> + <CardType>VI</CardType> + <Page>98e05</Page> + <ApprovalCode /> + <Verbiage>Incorrect Card Number - Please Retry</Verbiage> + <TotalAmount>3.88</TotalAmount> + <Products> + <product> + <code>001</code> + <description>Test Product 1</description> + <quantity>1</quantity> + <price>3.10</price> + <subtotal>3.10</subtotal> + <flags> + <flag>{USD}</flag> + <flag>{GST}</flag> + </flags> + </product> + <product> + <code>010</code> + <description>Test Product 2</description> + <quantity>1</quantity> + <price>0.20</price> + <subtotal>0.20</subtotal> + <flags> + <flag>{GST}</flag> + </flags> + </product> + <product> + <code>020</code> + <description>Test Product 3</description> + <quantity>1</quantity> + <price>0.33</price> + <subtotal>0.33</subtotal> + <flags> + <flag>{GST}</flag> + </flags> + </product> + <product> + <code>GST</code> + <description>Canadian GST Charged</description> + <quantity>1</quantity> + <price>0.25</price> + <subtotal>0.25</subtotal> + <flags> + <flag>{TAX}</flag> + <flag>{CALCULATED}</flag> + </flags> + </product> + </Products> + <DoubleColonProducts>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}</DoubleColonProducts> + <AVSResponseCode /> + <CVV2ResponseCode /> +</TranxResponse> + 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?'); + |