File Coverage

blib/lib/Business/CPI/Gateway/Test.pm
Criterion Covered Total %
statement 32 32 100.0
branch 9 10 90.0
condition n/a
subroutine 2 2 100.0
pod 1 1 100.0
total 44 45 97.7


line stmt bran cond sub pod time code
1             package Business::CPI::Gateway::Test;
2             # ABSTRACT: Fake gateway
3              
4 6     6   7283 use Moo;
  6         47351  
  6         32  
5              
6             our $VERSION = '0.922'; # VERSION
7              
8             extends 'Business::CPI::Gateway::Base';
9             with 'Business::CPI::Role::Gateway::FormCheckout';
10              
11             sub get_hidden_inputs {
12 3     3 1 6 my ( $self, $info ) = @_;
13              
14 3         5 my $buyer = $info->{buyer};
15 3         6 my $cart = $info->{cart};
16              
17 3         67 my @hidden_inputs = (
18             receiver_email => $self->receiver_id,
19             currency => $self->currency,
20             encoding => $self->form_encoding,
21             payment_id => $info->{payment_id},
22             buyer_name => $buyer->name,
23             buyer_email => $buyer->email,
24             );
25              
26 3         20 my %buyer_extra = (
27             address_line1 => 'shipping_address',
28             address_line2 => 'shipping_address2',
29             address_city => 'shipping_city',
30             address_state => 'shipping_state',
31             address_country => 'shipping_country',
32             address_zip_code => 'shipping_zip',
33             );
34              
35 3         13 for (keys %buyer_extra) {
36 18 100       65 if (my $value = $buyer->$_) {
37 11         32 push @hidden_inputs, ( $buyer_extra{$_} => $value );
38             }
39             }
40              
41 3         16 my %cart_extra = (
42             discount => 'discount_amount',
43             handling => 'handling_amount',
44             tax => 'tax_amount',
45             );
46              
47 3         13 for (keys %cart_extra) {
48 9 50       39 if (my $value = $cart->$_) {
49 9         3977 push @hidden_inputs, ( $cart_extra{$_} => $value );
50             }
51             }
52              
53 3         10 my $i = 1;
54              
55 3         4 foreach my $item (@{ $info->{items} }) {
  3         10  
56 6         51 push @hidden_inputs,
57             (
58             "item${i}_id" => $item->id,
59             "item${i}_desc" => $item->description,
60             "item${i}_price" => $item->price,
61             "item${i}_qty" => $item->quantity,
62             );
63              
64 6 100       19 if (my $weight = $item->weight) {
65 1         5 push @hidden_inputs, ( "item${i}_weight" => $weight * 1000 ); # show in grams
66             }
67              
68 6 100       31 if (my $ship = $item->shipping) {
69 1         3 push @hidden_inputs, ( "item${i}_shipping" => $ship );
70             }
71              
72 6 100       16 if (my $ship = $item->shipping_additional) {
73 1         4 push @hidden_inputs, ( "item${i}_shipping2" => $ship );
74             }
75              
76 6         16 $i++;
77             }
78              
79 3         6 $i = 1;
80              
81 3         6 foreach my $receiver (@{ $cart->_receivers }) {
  3         12  
82 2         24 push @hidden_inputs,
83             (
84             "receiver${i}_id" => $receiver->account->gateway_id,
85             "receiver${i}_percent" => sprintf("%.2f", 0+$receiver->percent_amount),
86             );
87 2         496 $i++;
88             }
89              
90 3         43 return @hidden_inputs;
91             }
92              
93             # TODO
94             # use SQLite?
95             # sub get_notification_details {}
96             # sub query_transactions {}
97             # sub get_transaction_details {}
98              
99             1;
100              
101             __END__