Allow taxes to be an array reference
authorfbriere <fbriere>
Sat, 18 Feb 2006 03:59:45 +0000 (03:59 +0000)
committerfbriere <fbriere>
Sat, 18 Feb 2006 03:59:45 +0000 (03:59 +0000)
InternetSecure.pm
t/20emit.t

index 9aa2d8d..f3eacc8 100755 (executable)
@@ -108,9 +108,14 @@ sub prod_string {
 
        my @flags = ($currency);
 
-       foreach (ref $data{taxes} ?
-                       @{ $data{taxes} } :
-                       split(' ' => $data{taxes} || '')) {
+       my @taxes;
+       if (ref $data{taxes}) {
+               @taxes = @{ $data{taxes} };
+       } elsif ($data{taxes}) {
+               @taxes = split ' ' => $data{taxes};
+       }
+
+       foreach (@taxes) {
                croak "Unknown tax code $_" unless /^(GST|PST|HST)$/i;
                push @flags, uc $_;
        }
@@ -148,8 +153,6 @@ sub to_xml {
        croak "Unknown currency code ", $content{currency}
                unless $content{currency} =~ /^(CAD|USD)$/;
        
-       $content{taxes} = uc($content{taxes} || '');
-
        my %data = $self->get_remap_fields(qw(
                        xxxCard_Number          card_number
 
@@ -467,10 +470,12 @@ C<CAD> (default) or C<USD>.
 
 =item taxes
 
-Taxes to be added automatically to B<amount> by InternetSecure.
+Taxes to be added automatically to B<amount> by InternetSecure.  Available
+taxes are C<GST>, C<PST> and C<HST>.
 
-Available taxes are C<GST>, C<PST> and C<HST>.  Multiple taxes can specified
-by concatenating them with spaces, such as C<GST HST>.
+This argument can either be a single string of taxes concatenated with spaces
+(such as C<GST PST>), or a reference to an array of taxes (such as C<[ "GST",
+"PST" ]>).
 
 =item name / company / address / city / state / zip / country / phone / email
 
index 1f24ea1..2fca9bd 100755 (executable)
@@ -1,6 +1,6 @@
-# vim:set syntax=perl:
+# vim:set syntax=perl encoding=utf-8:
 
-use Test::More tests => 4 + 2;
+use Test::More tests => 4 + 3;
 
 BEGIN { use_ok('Business::OnlinePayment') };
 BEGIN { use_ok('Business::OnlinePayment::InternetSecure') };
@@ -32,7 +32,7 @@ use constant TRANSACTIONS => (
 
                amount          => undef,
                currency        => 'USD',
-               taxes           => 'GST PST',
+               taxes           => 'HST',
 
                description => [
                                {
@@ -44,11 +44,12 @@ use constant TRANSACTIONS => (
                                {
                                amount          => 5.65,
                                description     => 'Shipping',
+                               taxes           => 'GST PST',
                                },
                                {
                                amount          => 10.00,
                                description     => 'Some HST example',
-                               taxes           => 'HST',
+                               taxes           => [ 'GST', 'PST' ],
                                },
                                ],
        },
@@ -63,6 +64,21 @@ use constant TRANSACTIONS => (
                name            => "Fr\x{e9}d\x{e9}ric Bri\x{e8}re",
 
                amount          => 12.95,
+               description     => "Box o' goodies",
+               currency        => 'USD',
+               taxes           => 'GST',
+       },
+       {
+               _test           => -1,
+
+               action          => 'Normal Authorization',
+
+               card_number     => '5111-1111-1111-1111',
+               exp_date        => '0704',
+
+               name            => "Fr\x{e9}d\x{e9}ric Bri\x{e8}re",
+
+               amount          => 13.95,
        },
 );
 
@@ -95,7 +111,7 @@ __DATA__
   <xxxCCYear>2004</xxxCCYear>
   <CVV2>1</CVV2>
   <CVV2Indicator>000</CVV2Indicator>
-  <Products>9.99::5::a 001::Some product::{USD}{GST}{PST}|5.65::1::::Shipping::{USD}{GST}{PST}|10.00::1::::Some HST example::{USD}{HST}</Products>
+  <Products>9.99::5::a 001::Some product::{USD}{HST}|5.65::1::::Shipping::{USD}{GST}{PST}|10.00::1::::Some HST example::{USD}{GST}{PST}</Products>
   <xxxName>Frédéric Brière</xxxName>
   <xxxCompany></xxxCompany>
   <xxxAddress>123 Street</xxxAddress>
@@ -124,7 +140,36 @@ __DATA__
   <xxxCCYear>2004</xxxCCYear>
   <CVV2>0</CVV2>
   <CVV2Indicator></CVV2Indicator>
-  <Products>12.95::1::::::{CAD}{TEST}</Products>
+  <Products>12.95::1::::Box o' goodies::{USD}{GST}{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>
+
+<?xml version="1.0" encoding="utf-8" standalone="yes"?>
+<TranxRequest>
+  <MerchantNumber>0000</MerchantNumber>
+  <xxxCard_Number>5111111111111111</xxxCard_Number>
+  <xxxCCMonth>07</xxxCCMonth>
+  <xxxCCYear>2004</xxxCCYear>
+  <CVV2>0</CVV2>
+  <CVV2Indicator></CVV2Indicator>
+  <Products>13.95::1::::::{CAD}{TESTD}</Products>
   <xxxName>Frédéric Brière</xxxName>
   <xxxCompany></xxxCompany>
   <xxxAddress></xxxAddress>