diff options
author | fbriere <fbriere> | 2006-02-18 00:26:11 +0000 |
---|---|---|
committer | fbriere <fbriere> | 2006-02-18 00:26:11 +0000 |
commit | 227f87ababc68077ac00d2fb5ee52f080370cbff (patch) | |
tree | a81ffbbde08049285679dffcfd67108f3efb368d | |
parent | 2fcb22b534898f165cddcbbf8822020e77c8f248 (diff) |
Added taxes()
-rwxr-xr-x | InternetSecure.pm | 37 | ||||
-rwxr-xr-x | t/30parse.t | 23 |
2 files changed, 51 insertions, 9 deletions
diff --git a/InternetSecure.pm b/InternetSecure.pm index 10d7d6e..a7b1d0f 100755 --- a/InternetSecure.pm +++ b/InternetSecure.pm @@ -42,9 +42,12 @@ sub set_defaults { receipt_number sales_number uuid guid date card_type cardholder - total_amount + total_amount taxes avs_response cvv2_response )); + + # Just in case someone tries to call taxes() *before* submit() + $self->taxes( {} ); } # OnlinePayment's get_fields now filters out undefs in 3.x. :( @@ -223,6 +226,27 @@ sub infuse { } } +sub extract_taxes { + my ($self, $response) = @_; + + my %taxes; + + my $products = $response->{Products}; + return unless $products; + + foreach my $node (@$products) { + my $flags = $node->{flags}; + if ($flags && + grep($_ eq '{TAX}', @$flags) && + grep($_ eq '{CALCULATED}', @$flags)) + { + $taxes{ $node->{code} } = $node->{subtotal}; + } + } + + return %taxes; +} + # Parse the server's response and set various fields # sub parse_response { @@ -267,7 +291,7 @@ sub parse_response { $self->card_type(CARD_TYPES->{$self->card_type}); - $self->{products_raw} = $response->{Products}; + $self->taxes( { $self->extract_taxes($response) } ); return $self; } @@ -513,6 +537,11 @@ Date and time of the transaction. Format is C<YYYY/MM/DD hh:mm:ss>. Total amount billed for this order, including taxes. +=item taxes() + +Returns a I<reference> to a hash that maps tax names (such as C<GST>) to the +amount that was billed for each. + =item cardholder() Cardholder's name. This is currently a mere copy of the B<name> field passed @@ -535,10 +564,6 @@ following: =back -=item products_raw() - -... - =back diff --git a/t/30parse.t b/t/30parse.t index 7e8e678..3734631 100755 --- a/t/30parse.t +++ b/t/30parse.t @@ -6,7 +6,7 @@ use constant FIELDS => qw( date card_type avs_response cvv2_response - total_amount + total_amount taxes ); use constant RESULTS => ( @@ -22,6 +22,7 @@ use constant RESULTS => ( avs_response => undef, cvv2_response => undef, total_amount => 3.88, + taxes => { GST => 0.25 }, uuid => 'f81d4fae-7dec-11d0-a765-00a0c91e6bf6', guid => 'f81d4fae-7dec-11d0-a765-00a0c91e6bf6', }, @@ -37,6 +38,8 @@ use constant RESULTS => ( avs_response => undef, cvv2_response => undef, total_amount => 3.88, + taxes => { GST => 0.25, + PST => 0.27 }, uuid => undef, guid => undef, }, @@ -66,7 +69,7 @@ foreach my $results (RESULTS) { foreach (FIELDS) { no strict 'refs'; - is($txn->$_, $results->{$_}, $_); + is_deeply($txn->$_, $results->{$_}, $_); } } @@ -160,6 +163,7 @@ __DATA__ <flags> <flag>{USD}</flag> <flag>{GST}</flag> + <flag>{PST}</flag> </flags> </product> <product> @@ -170,6 +174,7 @@ __DATA__ <subtotal>0.20</subtotal> <flags> <flag>{GST}</flag> + <flag>{PST}</flag> </flags> </product> <product> @@ -180,6 +185,7 @@ __DATA__ <subtotal>0.33</subtotal> <flags> <flag>{GST}</flag> + <flag>{PST}</flag> </flags> </product> <product> @@ -193,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> |