diff options
Diffstat (limited to 't/30parse.t')
-rwxr-xr-x | t/30parse.t | 163 |
1 files changed, 163 insertions, 0 deletions
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> + |