Renamed sales_number to order_number
[Business-OnlinePayment-InternetSecure.git] / t / 30parse.t
index 2917a47..435b67d 100755 (executable)
@@ -1,29 +1,67 @@
-use Test::More tests => 1 + 2 * 6;
+# vim:set syntax=perl:
 
-BEGIN { use_ok('Business::OnlinePayment') };
+use constant FIELDS => qw(
+                       result_code authorization error_message
+                       receipt_number order_number
+                       date
+                       card_type
+                       avs_code cvv2_response
+                       total_amount tax_amounts
+                       );
 
+use constant RESULTS => (
+                               {
+                                       is_success      => 1,
+                                       result_code     => '2000',
+                                       authorization   => 'T00000',
+                                       error_message   => undef,
+                                       receipt_number  => '1096019995.5012',
+                                       order_number    => 0,
+                                       date            => '2003/12/17 09:59:58',
+                                       card_type       => undef,
+                                       avs_code        => undef,
+                                       cvv2_response   => undef,
+                                       total_amount    => 3.88,
+                                       tax_amounts     => { GST => 0.25 },
+                                       uuid            => 'f81d4fae-7dec-11d0-a765-00a0c91e6bf6',
+                                       guid            => 'f81d4fae-7dec-11d0-a765-00a0c91e6bf6',
+                               },
+                               {
+                                       is_success      => 0,
+                                       result_code     => '98e05',
+                                       authorization   => undef,
+                                       error_message   => 'Real error message',
+                                       receipt_number  => '1096021915.5853',
+                                       order_number    => 729,
+                                       date            => '2003/12/17 10:31:58',
+                                       card_type       => 'Visa',
+                                       avs_code        => undef,
+                                       cvv2_response   => undef,
+                                       total_amount    => 3.88,
+                                       tax_amounts     => { GST => 0.25,
+                                                               PST => 0.27 },
+                                       uuid            => undef,
+                                       guid            => undef,
+                               },
+                       );
 
-use constant FIELDS => (qw( result_code authorization total_amount
-                               error_message ));
 
-use constant RESULTS => (
-               [ 1, '2000', 'T00000', 3.88, 'Test Approved' ],
-               [ 0, '98e05', undef, 3.88, 'Real error message' ],
-       );
+use Test::More tests => 1 + scalar(RESULTS) * (1 + 1 + scalar(FIELDS));
+
+BEGIN { use_ok('Business::OnlinePayment') };
+
 
 
 my $txn = new Business::OnlinePayment 'InternetSecure', merchant_id => '0000';
 
 $/ = '';
-foreach (RESULTS) {
-       my @results = @$_;
-
+foreach my $results (RESULTS) {
        my $xml = <DATA>;
        $txn->parse_response($xml);
 
        is($txn->server_response, $xml, 'server_response');
 
-       if (shift @results) {
+       if ($results->{is_success}) {
                ok($txn->is_success, 'expecting success');
        } else {
                ok(!$txn->is_success, 'expecting failure');
@@ -31,7 +69,7 @@ foreach (RESULTS) {
 
        foreach (FIELDS) {
                no strict 'refs';
-               is($txn->$_, shift @results, $_);
+               is_deeply($txn->$_, $results->{$_}, $_);
        }
 }
 
@@ -99,6 +137,7 @@ __DATA__
   <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 />
+  <GUID>f81d4fae-7dec-11d0-a765-00a0c91e6bf6</GUID>
 </TranxResponse>
 
 <?xml version="1.0" encoding="UTF-8"?>
@@ -124,6 +163,7 @@ __DATA__
       <flags>
         <flag>{USD}</flag>
        <flag>{GST}</flag>
+       <flag>{PST}</flag>
       </flags>
     </product>
     <product>
@@ -134,6 +174,7 @@ __DATA__
       <subtotal>0.20</subtotal>
       <flags>
        <flag>{GST}</flag>
+       <flag>{PST}</flag>
       </flags>
     </product>
     <product>
@@ -144,6 +185,7 @@ __DATA__
       <subtotal>0.33</subtotal>
       <flags>
        <flag>{GST}</flag>
+       <flag>{PST}</flag>
       </flags>
     </product>
     <product>
@@ -157,8 +199,19 @@ __DATA__
        <flag>{CALCULATED}</flag>
       </flags>
     </product>
+    <product>
+      <code>PST</code>
+      <description>PST Charged</description>
+      <quantity>1</quantity>
+      <price>0.27</price>
+      <subtotal>0.27</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>
+  <DoubleColonProducts>3.10::1::001::Test Product 1::{USD}{GST}{PST}|0.20::1::010::Test Product 2::{GST}{PST}|0.33::1::020::Test Product 3::{GST}{PST}|0.25::1::GST::Canadian GST Charged::{TAX}{CALCULATED}|0.27::1::PST::PST Charged::{TAX}{CALCULATED}</DoubleColonProducts>
   <AVSResponseCode />
   <CVV2ResponseCode />
 </TranxResponse>