blib/lib/Business/OnlinePayment/viaKLIX.pm

filter: Statementstmt 31.6% 37 / 117 Branchbran 8.8% 3 / 34 Conditioncond 4.3% 1 / 23 MC/DCmcdc 0.0% 0 / 14 Subroutinesub 54.5% 6 / 11 Podpod 100% 5 / 5 totaltotal 25.4% 52 / 204 CC 30 SCAR 36.6
CC
30
Cov
24%
submit
93.1
debug
42.0
required_fields
42.0
CRAP 38.7
↑ Summary
1 package Business::OnlinePayment::viaKLIX;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use vars qw($VERSION $DEBUG);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use Carp qw(carp croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 ▶use base qw(Business::OnlinePayment::HTTPS);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 $VERSION = '0.02';
10 2 $VERSION = eval $VERSION;
11 2 $DEBUG = 0;
12  
13 0 ▶sub debug {
Subroutine debug: not called CC=6 SCAR=37.4
Pod documented
14 0 my $self = shift;
15  
16 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
17 0 ▶ my $level = shift || 0;
Condition0%0/2
shift() || 0
l!l
00
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
18 0 ▶ if ( ref($self) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self) { } 0 0 0
19 0 $self->{"__DEBUG"} = $level;
20 }
21 else {
22 0 $DEBUG = $level;
23 }
24 0 $Business::OnlinePayment::HTTPS::DEBUG = $level;
25 }
26 0 ▶ return ref($self) ? ( $self->{"__DEBUG"} || $DEBUG ) : $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
ref $self ? : 0 0 0
Condition0%0/3
$self->{"__DEBUG"} or $Business::OnlinePayment::viaKLIX::DEBUG
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"__DEBUG"} or $Business::OnlinePayment::viaKLIX::DEBUG
$self->{"__DEBUG"} $Business::OnlinePayment::viaKLIX::DEBUG
Truth table0%0/3
A or B
A= $self->{"__DEBUG"}B= $Business::OnlinePayment::viaKLIX::DEBUG
ABresult
1X1
011
000
27 }
28  
29 2 ▶sub set_defaults {
Subroutine set_defaults: called CC=4 SCAR=16.5
Pod documented
30 2 my $self = shift;
31 2 my %opts = @_;
32  
33 # standard B::OP methods/data
34 2 $self->server("www.viaKLIX.com");
35 2 $self->port("443");
36 2 $self->path("/process.asp");
37  
38 2 $self->build_subs(qw(
39 order_number avs_code cvv2_response
40 response_page response_code response_headers
41 ));
42  
43 # module specific data
44 2 ▶ if ( $opts{debug} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"debug"}) 0 2 2
45 0 $self->debug( $opts{debug} );
46 0 delete $opts{debug};
47 }
48  
49 2 my %_defaults = ();
50 2 foreach my $key (keys %opts) {
51 0 ▶ $key =~ /^default_(\w*)$/ or next;
Branch: 1 branch
BranchTrueFalseTotal
$key =~ /^default_(\w*)$/ or next 0 0 0
52 0 $_defaults{$1} = $opts{$key};
53 0 delete $opts{$key};
54 }
55 2 $self->{_defaults} = \%_defaults;
56  
57 }
58  
59 0 ▶sub _map_fields {
Subroutine _map_fields: not called CC=3 SCAR=24.8
60 0 my ($self) = @_;
61  
62 0 my %content = $self->content();
63  
64 #ACTION MAP
65 0 my %actions = (
66 'normal authorization' => 'SALE', # Authorization/Settle transaction
67 'credit' => 'CREDIT', # Credit (refund)
68 );
69  
70 $content{'ssl_transaction_type'} = $actions{ lc( $content{'action'} ) }
71 0 ▶ || $content{'action'};
Condition0%0/3
$actions{lc $content{'action'}} || $content{'action'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$actions{lc $content{'action'}} || $content{'action'}
$actions{lc $content{'action'}} $content{'action'}
Truth table0%0/3
A || B
A= $actions{lc $content{'action'}}B= $content{'action'}
ABresult
1X1
011
000
72  
73 # TYPE MAP
74 0 my %types = (
75 'visa' => 'CC',
76 'mastercard' => 'CC',
77 'american express' => 'CC',
78 'discover' => 'CC',
79 'cc' => 'CC',
80 );
81  
82 0 ▶ $content{'type'} = $types{ lc( $content{'type'} ) } || $content{'type'};
Condition0%0/3
$types{lc $content{'type'}} || $content{'type'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$types{lc $content{'type'}} || $content{'type'}
$types{lc $content{'type'}} $content{'type'}
Truth table0%0/3
A || B
A= $types{lc $content{'type'}}B= $content{'type'}
ABresult
1X1
011
000
83  
84 0 $self->transaction_type( $content{'type'} );
85  
86 # stuff it back into %content
87 0 $self->content(%content);
88 }
89  
90 0 ▶sub _revmap_fields {
Subroutine _revmap_fields: not called CC=3 SCAR=24.8
91 0 my ( $self, %map ) = @_;
92 0 my %content = $self->content();
93 0 foreach ( keys %map ) {
94 $content{$_} =
95 ref( $map{$_} )
96 0 ? ${ $map{$_} }
97 0 ▶ : $content{ $map{$_} };
Branch: 1 branch
BranchTrueFalseTotal
ref $map{$_} ? : 0 0 0
98 }
99 0 $self->content(%content);
100 }
101  
102 4 ▶sub expdate_mmyy {
Subroutine expdate_mmyy: called CC=4 SCAR=14.8
Pod documented
103 4 my $self = shift;
104 4 my $expiration = shift;
105 4 my $expdate_mmyy;
106 4 ▶ if ( defined($expiration) and $expiration =~ /^(\d+)\D+\d*(\d{2})$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $expiration and $expiration =~ /^(\d+)\D+\d*(\d{2})$/) 4 0 4
Condition33%1/3
defined $expiration and $expiration =~ /^(\d+)\D+\d*(\d{2})$/
!ll&&!rl&&r
004
MC/DC0%0/2
defined $expiration and $expiration =~ /^(\d+)\D+\d*(\d{2})$/
defined $expiration $expiration =~ /^(\d+)\D+\d*(\d{2})$/
Truth table33%1/3
A and B
A= defined $expirationB= $expiration =~ /^(\d+)\D+\d*(\d{2})$/
ABresult
0X0
100
111
107 4 my ( $month, $year ) = ( $1, $2 );
108 4 $expdate_mmyy = sprintf( "%02d", $month ) . $year;
109 }
110 4 ▶ return defined($expdate_mmyy) ? $expdate_mmyy : $expiration;
Branch: 1 branch
BranchTrueFalseTotal
defined $expdate_mmyy ? : 4 0 4
111 }
112  
113 0 ▶sub required_fields {
Subroutine required_fields: not called CC=6 SCAR=37.4
Pod documented
114 0 my($self,@fields) = @_;
115  
116 0 my @missing;
117 0 my %content = $self->content();
118 0 foreach(@fields) {
119 next
120 0 ▶ if (exists $content{$_} && defined $content{$_} && $content{$_}=~/\S+/);
Branch: 1 branch
BranchTrueFalseTotal
if exists $content{$_} and defined $content{$_} and $content{$_} =~ /\S+/ 0 0 0
Condition0%0/6
exists $content{$_} and defined $content{$_} and $content{$_} =~ /\S+/
!ll&&!rl&&r
000
exists $content{$_} and defined $content{$_}
!ll&&!rl&&r
000
MC/DC0%0/3
exists $content{$_} and defined $content{$_} and $content{$_} =~ /\S+/
exists $content{$_} defined $content{$_} $content{$_} =~ /\S+/
Truth table0%0/4
A and B and C
A= exists $content{$_}B= defined $content{$_}C= $content{$_} =~ /\S+/
ABCresult
0XX0
10X0
1100
1111
121 0 push(@missing, $_);
122 }
123  
124 0 ▶ Carp::croak("missing required field(s): " . join(", ", @missing) . "\n")
Branch: 1 branch
BranchTrueFalseTotal
if @missing 0 0 0
125 if(@missing);
126  
127 }
128  
129 0 ▶sub submit {
Subroutine submit: not called CC=10 SCAR=45.3
Pod documented
130 1 my ($self) = @_;
131  
132 1 $self->_map_fields();
133  
134 1 my %content = $self->content;
135  
136 1 my %required;
137 0 $required{CC_SALE} = [ qw( ssl_transaction_type ssl_merchant_id ssl_pin
138 ssl_amount ssl_card_number ssl_exp_date
139 ) ];
140 0 $required{CC_CREDIT} = $required{CC_SALE};
141 0 my %optional;
142 0 $optional{CC_SALE} = [ qw( ssl_user_id ssl_salestax ssl_cvv2 ssl_cvv2cvc2
143 ssl_description ssl_invoice_number
144 ssl_customer_code ssl_company ssl_first_name
145 ssl_last_name ssl_avs_address ssl_address2
146 ssl_city ssl_state ssl_avs_zip ssl_country
147 ssl_phone ssl_email ssl_ship_to_company
148 ssl_ship_to_first_name ssl_ship_to_last_name
149 ssl_ship_to_address ssl_ship_to_city
150 ssl_ship_to_state ssl_ship_to_zip
151 ssl_ship_to_country
152 ) ];
153 0 $optional{CC_CREDIT} = $optional{CC_SALE};
154  
155 0 my $type_action = $self->transaction_type(). '_'. $content{ssl_transaction_type};
156 0 ▶ unless ( exists($required{$type_action}) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $required{$type_action}) 0 0 0
157 0 $self->error_message("viaKLIX can't handle transaction type: ".
158 "$content{action} on " . $self->transaction_type() );
159 0 $self->is_success(0);
160 0 return;
161 }
162  
163 0 my $expdate_mmyy = $self->expdate_mmyy( $content{"expiration"} );
164 0 my $zip = $content{'zip'};
165 0 $zip =~ s/[^[:alnum:]]//g;
166  
167 0 ▶ my $cvv2indicator = 'present' if ( $content{"cvv2"} ); # visa only
Branch: 1 branch
BranchTrueFalseTotal
if $content{"cvv2"} 0 0 0
168  
169 0 $self->_revmap_fields(
170  
171 ssl_merchant_id => 'login',
172 ssl_pin => 'password',
173  
174 ssl_amount => 'amount',
175 ssl_card_number => 'card_number',
176 ssl_exp_date => \$expdate_mmyy, # MMYY from 'expiration'
177 ssl_cvv2 => \$cvv2indicator,
178 ssl_cvv2cvc2 => 'cvv2',
179 ssl_description => 'description',
180 ssl_invoice_number => 'invoice_number',
181 ssl_customer_code => 'customer_id',
182  
183 ssl_first_name => 'first_name',
184 ssl_last_name => 'last_name',
185 ssl_avs_address => 'address',
186 ssl_city => 'city',
187 ssl_state => 'state',
188 ssl_avs_zip => \$zip, # 'zip' with non-alnums removed
189 ssl_country => 'country',
190 ssl_phone => 'phone',
191 ssl_email => 'email',
192  
193 );
194  
195 0 my %params = $self->get_fields( @{$required{$type_action}},
196 0 @{$optional{$type_action}},
197 );
198  
199 0 foreach ( keys ( %{($self->{_defaults})} ) ) {
200 0 ▶ $params{$_} = $self->{_defaults}->{$_} unless exists($params{$_});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $params{$_} 0 0 0
201 }
202  
203 0 ▶ $params{ssl_test_mode}='true' if $self->test_transaction;
Branch: 1 branch
BranchTrueFalseTotal
if $self->test_transaction 0 0 0
204
205 0 $params{ssl_show_form}='false';
206 0 $params{ssl_result_format}='ASCII';
207  
208 0 $self->required_fields(@{$required{$type_action}});
209
210 0 ▶ warn join("\n", map{ "$_ => $params{$_}" } keys(%params)) if $DEBUG > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $Business::OnlinePayment::viaKLIX::DEBUG > 1 0 0 0
211 0 my ( $page, $resp, %resp_headers ) =
212 $self->https_post( %params );
213  
214 0 $self->response_code( $resp );
215 0 $self->response_page( $page );
216 0 $self->response_headers( \%resp_headers );
217  
218 0 ▶ warn "$page\n" if $DEBUG > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $Business::OnlinePayment::viaKLIX::DEBUG > 1 0 0 0
219 # $page should contain key/value pairs
220  
221 0 my $status ='';
222 0 my %results = map { s/\s*$//; split '=', $_, 2 } split '^', $page;
223  
224 # AVS and CVS values may be set on success or failure
225 0 $self->avs_code( $results{ssl_avs_response} );
226 0 $self->cvv2_response( $results{ ssl_cvv2_response } );
227 0 $self->result_code( $status = $results{ ssl_result } );
228 0 $self->order_number( $results{ ssl_txn_id } );
229 0 $self->authorization( $results{ ssl_approval_code } );
230 0 $self->error_message( $results{ ssl_result_message } );
231  
232  
233 0 ▶ if ( $resp =~ /^(HTTP\S+ )?200/ && $status eq "0" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($resp =~ /^(HTTP\S+ )?200/ and $status eq '0') { } 0 0 0
Condition0%0/3
$resp =~ /^(HTTP\S+ )?200/ and $status eq 0
!ll&&!rl&&r
000
MC/DC0%0/2
$resp =~ /^(HTTP\S+ )?200/ and $status eq 0
$resp =~ /^(HTTP\S+ )?200/ $status eq 0
Truth table0%0/3
A and B
A= $resp =~ /^(HTTP\S+ )?200/B= $status eq 0
ABresult
0X0
100
111
234 0 $self->is_success(1);
235 } else {
236 0 $self->is_success(0);
237 }
238 }
239  
240 2 1;
241  
242 __END__
↑ Summary