blib/lib/Business/OnlinePayment/Vindicia/Select.pm

filter: Statementstmt 82.3% 210 / 255 Branchbran 50.0% 42 / 84 Conditioncond 33.3% 17 / 51 MC/DCmcdc 3.4% 1 / 29 Subroutinesub 91.1% 31 / 34 Podpod 100% 10 / 10 totaltotal 67.1% 311 / 463 CC 72 SCAR 27.6
CC
72
Cov
69%
_resp_simplify_hash
110.0
_resp_simplify
20.0
_call_soap
9.4
CRAP 15.8
↑ Summary
1 package Business::OnlinePayment::Vindicia::Select;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use base qw{Business::OnlinePayment};
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use vars qw($me $DEBUG $VERSION); ## no critic (Variables::ProhibitPackageVars)
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use HTTP::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use XML::Writer;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use XML::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Business::CreditCard qw(cardtype);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use List::MoreUtils qw(any);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Log::Scrubber qw(disable $SCRUBBER scrubber :Carp scrubber_add_scrubber);
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 1 $me = 'Business::OnlinePayment::Vindicia::Select';
17 1 $DEBUG = 0;
18 1 $VERSION = '0.003';
19  
20 =head1 NAME
21  
22 Business::OnlinePayment::Vindicia::Select - Backend for Business::OnlinePayment
23  
24 =head1 SYNOPSIS
25  
26 This is a plugin for the Business::OnlinePayment interface. Please refer to that documentation for general usage.
27  
28 use Business::OnlinePayment;
29 my $tx = Business::OnlinePayment->new(
30 "Vindicia::Select",
31 default_Origin => 'NEW', # or RECURRING
32 );
33  
34 $tx->content(
35 type => 'CC',
36 login => 'testdrive',
37 password => '123qwe',
38 action => 'billTransactions',
39 description => 'FOO*Business::OnlinePayment test',
40 amount => '49.95',
41 customer_id => 'tfb',
42 name => 'Tofu Beast',
43 address => '123 Anystreet',
44 city => 'Anywhere',
45 state => 'UT',
46 zip => '84058',
47 card_number => '4007000000027',
48 expiration => '09/02',
49 cvv2 => '1234', #optional
50 invoice_number => '54123',
51 vindicia_nvp => {
52 custom => 'data',
53 goes => 'here',
54 },
55 );
56 $tx->submit();
57  
58 =head1 DESCRIPTION
59  
60 Used via Business::OnlinePayment for processing payments through the Vindicia processor.
61  
62 =head1 METHODS AND FUNCTIONS
63  
64 See Business::OnlinePayment for the complete list. The following methods either override the methods in Business::OnlinePayment or provide additional functions.
65  
66 =head2 result_code
67  
68 Returns the response error code. Will be empty if no code is returned, or if multiple codes can exist.
69  
70 =head2 error_message
71  
72 Returns the response error description text. Will be empty if no code error is returned, or if multiple errors can exist.
73  
74 =head2 server_request
75  
76 Returns the complete request that was sent to the server. The request has been stripped of card_num, cvv2, and password. So it should be safe to log.
77  
78 =cut
79  
80 12 ▶sub server_request {
Subroutine server_request: called CC=3 SCAR=11.0
Pod documented
81 12 my ( $self, $val, $tf ) = @_;
82 12 ▶ if ($val) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val) 4 8 12
83 4 $self->{server_request} = scrubber $val;
84 4 ▶ $self->server_request_dangerous($val,1) unless $tf;
Branch: 1 branch
BranchTrueFalseTotal
unless $tf 4 0 4
85 }
86 12 return $self->{server_request};
87 }
88  
89 =head2 server_request_dangerous
90  
91 Returns the complete request that was sent to the server. This could contain data that is NOT SAFE to log. It should only be used in a test environment, or in a PCI compliant manner.
92  
93 =cut
94  
95 4 ▶sub server_request_dangerous {
Subroutine server_request_dangerous: called CC=3 SCAR=11.3
Pod documented
96 4 my ( $self, $val, $tf ) = @_;
97 4 ▶ if ($val) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val) 4 0 4
98 4 $self->{server_request_dangerous} = $val;
99 4 ▶ $self->server_request($val,1) unless $tf;
Branch: 1 branch
BranchTrueFalseTotal
unless $tf 0 4 4
100 }
101 4 return $self->{server_request_dangerous};
102 }
103  
104 =head2 server_response
105  
106 Returns the complete response from the server. The response has been stripped of card_num, cvv2, and password. So it should be safe to log.
107  
108 =cut
109  
110 12 ▶sub server_response {
Subroutine server_response: called CC=3 SCAR=11.0
Pod documented
111 12 my ( $self, $val, $tf ) = @_;
112 12 ▶ if ($val) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val) 4 8 12
113 4 $self->{server_response} = scrubber $val;
114 4 ▶ $self->server_response_dangerous($val,1) unless $tf;
Branch: 1 branch
BranchTrueFalseTotal
unless $tf 4 0 4
115 }
116 12 return $self->{server_response};
117 }
118  
119 =head2 server_response_dangerous
120  
121 Returns the complete response from the server. This could contain data that is NOT SAFE to log. It should only be used in a test environment, or in a PCI compliant manner.
122  
123 =cut
124  
125 4 ▶sub server_response_dangerous {
Subroutine server_response_dangerous: called CC=3 SCAR=11.3
Pod documented
126 4 my ( $self, $val, $tf ) = @_;
127 4 ▶ if ($val) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val) 4 0 4
128 4 $self->{server_response_dangerous} = $val;
129 4 ▶ $self->server_response($val,1) unless $tf;
Branch: 1 branch
BranchTrueFalseTotal
unless $tf 0 4 4
130 }
131 4 return $self->{server_response_dangerous};
132 }
133  
134 =head1 Handling of content(%content) data:
135  
136 =head2 action
137  
138 The following actions are valid
139  
140 normal authorization
141 authorization only
142 post authorization
143 credit
144 void
145 auth reversal
146  
147 =head1 TESTING
148  
149 The test suite runs using mocked data results.
150 All tests are run using MOCKED return values.
151 If you wish to run REAL tests then add these ENV variables.
152  
153 export PERL_BUSINESS_VINDICIA_USERNAME=your_test_user
154 export PERL_BUSINESS_VINDICIA_PASSWORD=your_test_password
155  
156 If you would like to create your own tests, or mock your own responses you can do the following
157  
158 use Business::OnlinePayment;
159 my $tx = Business::OnlinePayment->new(
160 "Vindicia::Select",
161 default_Origin => 'NEW', # or RECURRING
162 );
163 push @{$client->{'mocked'}}, {
164 action => 'billTransactions', # must match the action you call, or the script will die
165 login => 'mocked', # must match the login credentials used, or the script will die
166 resp => 'ok_duplicate', # or you can return a HASH of the actual data you want to mock
167 };
168  
169 =head1 FUNCTIONS
170  
171 =head2 _info
172  
173 Return the introspection hash for BOP 3.x
174  
175 =cut
176  
177 4 ▶sub _info {
Subroutine _info: called CC=1 SCAR=0.0
178 return {
179 4 info_compat => '0.01',
180 gateway_name => 'Vindicia Select - SOAP API',
181 gateway_url => 'http://www.vindicia.com',
182 module_version => $VERSION,
183 supported_types => ['CC','ECHECK'],
184 supported_actions => {
185 CC => [
186  
187 #non-standard bop actions
188 'billTransactions',
189 'fetchBillingResults',
190 'fetchByMerchantTransactionId',
191 'refundTransactions',
192 ],
193 },
194 };
195 }
196  
197 =head2 set_defaults
198  
199 Used by BOP to set default values during "new"
200  
201 =cut
202  
203 1 ▶sub set_defaults {
Subroutine set_defaults: called CC=1 SCAR=0.0
Pod documented
204 1 my ($self, %opts) = @_;
205  
206 1 $self->build_subs(
207 qw( order_number md5 avs_code cvv2_response card_token cavv_response failure_status verify_SSL )
208 );
209  
210 1 $self->test_transaction(0);
211 1 $self->{_scrubber} = \&_default_scrubber;
212 }
213  
214 =head2 test_transaction
215  
216 Get/set the server used for processing transactions. Possible values are Live, Certification, and Sandbox
217 Default: Live
218  
219 #Live
220 $self->test_transaction(0);
221  
222 #Test
223 $self->test_transaction(1);
224  
225 #Read current value
226 $val = $self->test_transaction();
227  
228 =cut
229  
230 2 ▶sub test_transaction {
Subroutine test_transaction: called CC=6 SCAR=19.0
Pod documented
231 2 my $self = shift;
232 2 my $testMode = shift;
233 0 ▶ if (! defined $testMode) { $testMode = $self->{'test_transaction'} || 0; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $testMode) 0 2 2
Condition0%0/2
$self->{'test_transaction'} || 0
l!l
00
MC/DC0%0/1
$self->{'test_transaction'} || 0
$self->{'test_transaction'}
Truth table0%0/2
A
A= $self->{'test_transaction'}
Aresult
11
00
234  
235 2 $self->require_avs(0);
236 2 $self->verify_SSL(0);
237 2 $self->port('443');
238 2 $self->path('v1.1/soap.pl'); #https://soap.prodtest.sj.vindicia.com/v1.1/soap.pl
239 2 ▶ if (lc($testMode) eq 'sandbox' || lc($testMode) eq 'test' || $testMode eq '1') {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $testMode eq 'sandbox' or lc $testMode eq 'test' or $testMode eq '1') { } 1 1 2
Condition50%3/6
lc $testMode eq "sandbox" or lc $testMode eq "test" or $testMode eq 1
l!l&&r!l&&!r
011
lc $testMode eq "sandbox" or lc $testMode eq "test"
l!l&&r!l&&!r
002
MC/DC33%1/3
lc $testMode eq "sandbox" or lc $testMode eq "test" or $testMode eq 1
lc $testMode eq "sandbox" lc $testMode eq "test" $testMode eq 1
Truth table50%2/4
A or B or C
A= lc $testMode eq "sandbox"B= lc $testMode eq "test"C= $testMode eq 1
ABCresult
1XX1
01X1
0011
0000
240 1 $self->server('soap.staging.us-west.vindicia.com');
241 1 $self->{'test_transaction'} = 1;
242 } else {
243 1 $self->server('soap.vindicia.com');
244 1 $self->{'test_transaction'} = 0;
245 }
246 2 return $self->{'test_transaction'};
247 }
248  
249 =head2 submit
250  
251 Do a Business::OnlinePayment style action on Vindicia
252  
253 =cut
254  
255 4 ▶sub submit {
Subroutine submit: called CC=2 SCAR=6.9
256 4 my ($self) = @_;
257  
258 4 local $SCRUBBER=1;
259 4 $self->_tx_init;
260  
261 4 my %content = $self->content();
262 4 my $action = $content{'action'};
263 4 ▶ die 'unsupported action' unless any { $action eq $_ } @{$self->_info()->{'supported_actions'}->{'CC'}};
Subroutine __ANON__: called CC=1 SCAR=0.1
Branch: 1 branch
BranchTrueFalseTotal
unless &any(sub { $action eq $_; } , @{$self->_info->{"supported_actions"}{"CC"};}) 0 4 4
264 4 $self->$action();
265 }
266  
267 =head2 billTransactions
268  
269 Send a batch of transactions to Vindicia for collection
270  
271 is_success means the call was successful, it does NOT mean all of your transactions were accepted
272 In order to verify your transaction you need to look at result->{'response'} for an ARRAY of potential
273 errors, if no errors exist the result will not have a response array
274  
275 =cut
276  
277 1 ▶sub billTransactions {
Subroutine billTransactions: called CC=7 SCAR=20.6
Pod documented
278 1 my ($self) = @_;
279 1 local $SCRUBBER=1;
280 1 $self->_tx_init;
281 1 my %content = $self->content();
282  
283 1 my $transactions = [];
284 1 ▶ if ($content{'card_number'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content{"card_number"}) 1 0 1
285 # make it so you can submit a single transaction using the normal
286 # BOP content system, this is OPTIONAL
287 1 $self->_add_trans($transactions,\%content);
288 }
289 1 foreach my $trans (@{$content{'transactions'}}) {
290 # Additional transactions may be submitted using a transactions array
291 # It should follow the same rules that the normal %content hash does
292 # for transactional data
293 4 $self->_add_trans($transactions,$trans);
294 }
295  
296 1 my $ret = $self->_call_soap('billTransactions', 'transactions', $transactions);
297 1 ▶ $self->is_success($ret->{'return'}->{'returnString'} && $ret->{'return'}->{'returnString'} eq 'OK' ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
$ret->{'return'}{'returnString'} && $ret->{'return'}{'returnString'} eq 'OK' ? : 1 0 1
Condition33%1/3
$ret->{"return"}{"returnString"} and $ret->{"return"}{"returnString"} eq "OK"
!ll&&!rl&&r
001
MC/DC0%0/2
$ret->{"return"}{"returnString"} and $ret->{"return"}{"returnString"} eq "OK"
$ret->{"return"}{"returnString"} $ret->{"return"}{"returnString"} eq "OK"
Truth table33%1/3
A and B
A= $ret->{"return"}{"returnString"}B= $ret->{"return"}{"returnString"} eq "OK"
ABresult
0X0
100
111
298 1 $self->order_number($ret->{'return'}->{'soapId'});
299  
300 # make everyone's life easier my making sure this is always an array
301 1 ▶ $ret->{'response'} = [$ret->{'response'}] if exists $ret->{'response'} && ref $ret->{'response'} ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if exists $ret->{"response"} and ref $ret->{"response"} ne "ARRAY" 0 1 1
Condition33%1/3
exists $ret->{"response"} and ref $ret->{"response"} ne "ARRAY"
!ll&&!rl&&r
010
MC/DC0%0/2
exists $ret->{"response"} and ref $ret->{"response"} ne "ARRAY"
exists $ret->{"response"} ref $ret->{"response"} ne "ARRAY"
Truth table33%1/3
A and B
A= exists $ret->{"response"}B= ref $ret->{"response"} ne "ARRAY"
ABresult
0X0
100
111
302  
303 1 $ret;
304 }
305  
306 5 ▶sub _add_trans {
Subroutine _add_trans: called CC=6 SCAR=19.1
307 5 my ($self,$transactions,$content) = @_;
308 my $trans = {
309 subscriptionId => $content->{'subscription_number'},
310 paymentMethodId => $content->{'card_token'},
311 merchantTransactionId => $content->{'invoice_number'},
312 customerId => $content->{'customer_number'},
313 divisionNumber => $content->{'division_number'},
314 authCode => $content->{'authorization'},
315 paymentMethodIsTokenized => 0,
316 status => 'Failed', #we shouldn't be here unless we already failed
317 timestamp => $content->{'timestamp'},
318 amount => $content->{'amount'},
319 currency => $content->{'currency'} || 'USD',
320 5 ▶ creditCardAccount => $content->{'card_number'},
Condition50%1/2
$content->{'currency'} || 'USD'
l!l
05
MC/DC0%0/1
$content->{'currency'} || 'USD'
$content->{'currency'}
Truth table50%1/2
A
A= $content->{'currency'}
Aresult
11
00
321 };
322 5 ▶ if ($content->{'vindicia_nvp'} && ref $content->{'vindicia_nvp'} eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if ($content->{"vindicia_nvp"} and ref $content->{"vindicia_nvp"} eq "HASH") 5 0 5
Condition33%1/3
$content->{"vindicia_nvp"} and ref $content->{"vindicia_nvp"} eq "HASH"
!ll&&!rl&&r
005
MC/DC0%0/2
$content->{"vindicia_nvp"} and ref $content->{"vindicia_nvp"} eq "HASH"
$content->{"vindicia_nvp"} ref $content->{"vindicia_nvp"} eq "HASH"
Truth table33%1/3
A and B
A= $content->{"vindicia_nvp"}B= ref $content->{"vindicia_nvp"} eq "HASH"
ABresult
0X0
100
111
323 # A common vindica_nvp would be "vin:Divison"
324 5 push @{$trans->{'nameValues'}}, {
325 name => $_,
326 value => $content->{'vindicia_nvp'}->{$_},
327 5 ▶ } foreach grep { (!ref $content->{'vindicia_nvp'}->{$_}) or die "Invalid vindicia_nvp format" } keys %{$content->{'vindicia_nvp'}};
Condition50%1/2
!ref($content->{'vindicia_nvp'}{$_}) || die('Invalid vindicia_nvp format')
l!l
50
MC/DC0%0/1
!ref($content->{'vindicia_nvp'}{$_}) || die('Invalid vindicia_nvp format')
!ref($content->{'vindicia_nvp'}{$_})
Truth table50%1/2
not(A)
A= !ref($content->{'vindicia_nvp'}{$_})
Aresult
11
00
328 }
329 5 push @{$transactions}, $trans;
330 };
331  
332 =head2 fetchBillingResults
333  
334 Lookup changes in a time period
335  
336 $tx->content(
337 login => 'testdrive',
338 password => '123qwe',
339 action => 'fetchBillingResults',
340 start_timestamp => '2012-09-11T21:34:32.265Z',
341 end_timestamp => '2012-09-11T22:34:32.265Z',
342 page => '0', # optional, defaults to zero
343 page_size => '100', # optional, defaults to 100
344 );
345 my $response = $tx->submit();
346  
347 =cut
348  
349 1 ▶sub fetchBillingResults {
Subroutine fetchBillingResults: called CC=7 SCAR=22.0
Pod documented
350 1 my ($self) = @_;
351 1 local $SCRUBBER=1;
352 1 $self->_tx_init;
353 1 my %content = $self->content();
354 my $ret = $self->_call_soap('fetchBillingResults',
355 'timestamp', $content{'start_timestamp'},
356 'endTimestamp', $content{'end_timestamp'},
357 'page', ($content{'page'}//0),
358 1 ▶ 'pageSize', ($content{'page_size'}//100),
Condition50%2/4
$content{"page"} // 0
l!l
10
$content{"page_size"} // 100
l!l
10
MC/DC0%0/1
$content{"page"} // 0
$content{"page"}
MC/DC0%0/1
$content{"page_size"} // 100
$content{"page_size"}
Truth table50%1/2
A
A= $content{"page"}
Aresult
11
00
Truth table50%1/2
A
A= $content{"page_size"}
Aresult
11
00
359 );
360 1 ▶ $self->is_success($ret->{'return'}->{'returnString'} && $ret->{'return'}->{'returnString'} eq 'OK' ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
$ret->{'return'}{'returnString'} && $ret->{'return'}{'returnString'} eq 'OK' ? : 1 0 1
Condition33%1/3
$ret->{"return"}{"returnString"} and $ret->{"return"}{"returnString"} eq "OK"
!ll&&!rl&&r
001
MC/DC0%0/2
$ret->{"return"}{"returnString"} and $ret->{"return"}{"returnString"} eq "OK"
$ret->{"return"}{"returnString"} $ret->{"return"}{"returnString"} eq "OK"
Truth table33%1/3
A and B
A= $ret->{"return"}{"returnString"}B= $ret->{"return"}{"returnString"} eq "OK"
ABresult
0X0
100
111
361 1 $self->order_number($ret->{'return'}->{'soapId'});
362  
363 # make everyone's life easier my making sure this is always an array
364 1 ▶ $ret->{'transactions'} = [$ret->{'transactions'}] if exists $ret->{'transactions'} && ref $ret->{'transactions'} ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if exists $ret->{"transactions"} and ref $ret->{"transactions"} ne "ARRAY" 0 1 1
Condition33%1/3
exists $ret->{"transactions"} and ref $ret->{"transactions"} ne "ARRAY"
!ll&&!rl&&r
100
MC/DC0%0/2
exists $ret->{"transactions"} and ref $ret->{"transactions"} ne "ARRAY"
exists $ret->{"transactions"} ref $ret->{"transactions"} ne "ARRAY"
Truth table33%1/3
A and B
A= exists $ret->{"transactions"}B= ref $ret->{"transactions"} ne "ARRAY"
ABresult
0X0
100
111
365  
366 1 $ret;
367 }
368  
369 =head2 fetchByMerchantTransactionId
370  
371 Lookup a specific transaction in Vindicia
372  
373 $tx->content(
374 login => 'testdrive',
375 password => '123qwe',
376 action => 'fetchByMerchantTransactionId',
377 invoice_number => 'abc123',
378 );
379 my $response = $tx->submit();
380  
381 =cut
382  
383 1 ▶sub fetchByMerchantTransactionId {
Subroutine fetchByMerchantTransactionId: called CC=2 SCAR=7.0
Pod documented
384 1 my ($self) = @_;
385 1 local $SCRUBBER=1;
386 1 $self->_tx_init;
387 1 my %content = $self->content();
388 1 my $ret = $self->_call_soap('fetchByMerchantTransactionId', 'merchantTransactionId', $content{'invoice_number'});
389 1 ▶ $self->is_success($ret->{'transaction'} ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
$ret->{'transaction'} ? : 1 0 1
390 1 $self->order_number($ret->{'return'}->{'soapId'});
391 1 $ret;
392 }
393  
394 =head2 refundTransactions
395  
396 Cancel or refund (sadly you can't choose one) a transaction.
397  
398 $tx->content(
399 login => 'testdrive',
400 password => '123qwe',
401 action => 'refundTransactions',
402 invoice_number => 'abc123',
403 );
404 my $response = $tx->submit();
405  
406 =cut
407  
408 1 ▶sub refundTransactions {
Subroutine refundTransactions: called CC=6 SCAR=19.5
Pod documented
409 1 my ($self) = @_;
410 1 local $SCRUBBER=1;
411 1 $self->_tx_init;
412 1 my %content = $self->content();
413  
414 1 my @refunds;
415 1 ▶ push @refunds, $content{'invoice_number'} if exists $content{'invoice_number'};
Branch: 1 branch
BranchTrueFalseTotal
if exists $content{"invoice_number"} 1 0 1
416 # TODO, do we even care to send more than one?
417  
418 1 my $ret = $self->_call_soap('refundTransactions', 'refunds', \@refunds);
419 1 ▶ $self->is_success($ret->{'return'}->{'returnString'} && $ret->{'return'}->{'returnString'} eq 'OK' ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
$ret->{'return'}{'returnString'} && $ret->{'return'}{'returnString'} eq 'OK' ? : 1 0 1
Condition33%1/3
$ret->{"return"}{"returnString"} and $ret->{"return"}{"returnString"} eq "OK"
!ll&&!rl&&r
001
MC/DC0%0/2
$ret->{"return"}{"returnString"} and $ret->{"return"}{"returnString"} eq "OK"
$ret->{"return"}{"returnString"} $ret->{"return"}{"returnString"} eq "OK"
Truth table33%1/3
A and B
A= $ret->{"return"}{"returnString"}B= $ret->{"return"}{"returnString"} eq "OK"
ABresult
0X0
100
111
420 1 $self->order_number($ret->{'return'}->{'soapId'});
421  
422 # make everyone's life easier my making sure this is always an array
423 1 ▶ $ret->{'response'} = [$ret->{'response'}] if exists $ret->{'response'} && ref $ret->{'response'} ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if exists $ret->{"response"} and ref $ret->{"response"} ne "ARRAY" 0 1 1
Condition33%1/3
exists $ret->{"response"} and ref $ret->{"response"} ne "ARRAY"
!ll&&!rl&&r
100
MC/DC0%0/2
exists $ret->{"response"} and ref $ret->{"response"} ne "ARRAY"
exists $ret->{"response"} ref $ret->{"response"} ne "ARRAY"
Truth table33%1/3
A and B
A= exists $ret->{"response"}B= ref $ret->{"response"} ne "ARRAY"
ABresult
0X0
100
111
424  
425 # Important note: Vindica does NOT return an error message if the invoice_number is not found.... it simply ignores that invoice
426  
427 1 $ret;
428 }
429  
430 4 ▶sub _call_soap {
Subroutine _call_soap: called CC=8 SCAR=22.4
431 4 my ($self, $action, @pairs) = @_;
432 4 my %content = $self->content();
433  
434 4 my $post_data;
435 4 my $writer = XML::Writer->new(
436 OUTPUT => \$post_data,
437 DATA_MODE => 1,
438 DATA_INDENT => 2,
439 ENCODING => 'UTF-8',
440 );
441  
442 4 $writer->xmlDecl();
443 4 $writer->startTag('SOAP-ENV:Envelope',
444 "xmlns:ns0" => "http://soap.vindicia.com/v1_1/Select",
445 "xmlns:ns1" => "http://schemas.xmlsoap.org/soap/envelope/",
446 "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance",
447 "xmlns:SOAP-ENV" => "http://schemas.xmlsoap.org/soap/envelope/",
448 );
449 4 $writer->startTag('ns1:Body');
450 4 $writer->startTag("ns0:$action");
451 4 $writer->startTag('auth');
452 4 $writer->dataElement('version', '1.1' );
453 4 $writer->dataElement('login', $content{'login'} );
454 4 $writer->dataElement('password', $content{'password'});
455 4 $writer->dataElement('userAgent', "$me $VERSION" );
456 4 $writer->endTag('auth');
457 4 ▶ while (scalar @pairs) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @pairs) 7 4 11
458 7 my $item = shift @pairs;
459 7 my $value = shift @pairs;
460 7 $self->_xmlwrite( $writer, $item, $value );
461 }
462 4 $writer->endTag("ns0:$action");
463 4 $writer->endTag('ns1:Body');
464 4 $writer->endTag('SOAP-ENV:Envelope');
465 4 $writer->end();
466  
467 4 $self->server_request( $post_data );
468  
469 4 ▶ if (ref $self->{'mocked'} eq 'ARRAY' && scalar @{$self->{'mocked'}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{"mocked"} eq "ARRAY" and scalar @{$self->{"mocked"};}) 4 0 4
Condition50%1/2
ref $self->{"mocked"} eq "ARRAY" and scalar @{$self->{"mocked"};}
!ll
04
MC/DC0%0/1
ref $self->{"mocked"} eq "ARRAY" and scalar @{$self->{"mocked"};}
ref $self->{"mocked"} eq "ARRAY"
Truth table50%1/2
A
A= ref $self->{"mocked"} eq "ARRAY"
Aresult
00
11
470 4 my $mock = shift @{$self->{'mocked'}};
471 4 ▶ die "Unexpected mock action" unless $mock->{'action'} eq $action;
Branch: 1 branch
BranchTrueFalseTotal
unless $mock->{"action"} eq $action 0 4 4
472 4 ▶ die "Unexpected mock login" unless $mock->{'login'} eq $content{'login'};
Branch: 1 branch
BranchTrueFalseTotal
unless $mock->{"login"} eq $content{"login"} 0 4 4
473 4 ▶ my $resp = ((ref $mock->{'resp'}) ? $mock->{'resp'} : $self->_common_mock($action,$mock->{'resp'}));
Branch: 1 branch
BranchTrueFalseTotal
ref $mock->{'resp'} ? : 0 4 4
474 4 $self->server_response( "MOCKED\n\n".Dumper $resp );
475 4 return $resp;
476 }
477  
478 0 my $url = 'https://'.$self->server.'/'.$self->path;
479 0 my $verify_ssl = 1;
480 0 my $response = HTTP::Tiny->new( verify_SSL=>$verify_ssl )->request('POST', $url, {
481 headers => {
482 'Content-Type' => 'text/xml;charset=UTF-8',
483 'SOAPAction' => "http://soap.vindicia.com/v1_1/Select#$action",
484 },
485 content => $post_data,
486 } );
487 0 $self->server_response( $response->{'content'} );
488 0 ▶ my $resp = eval { XMLin($response->{'content'})->{'soap:Body'}->{$action.'Response'} } || {};
Condition0%0/2
eval { do { XMLin($response->{'content'})->{'soap:Body'}{$action . 'Response'} } } || {}
l!l
00
MC/DC0%0/1
eval { do { XMLin($response->{'content'})->{'soap:Body'}{$action . 'Response'} } } || {}
eval { do { XMLin($response->{'content'})->{'soap:Body'}{$action . 'Response'} } }
Truth table0%0/2
A
A= eval { do { XMLin($response->{'content'})->{'soap:Body'}{$action . 'Response'} } }
Aresult
11
00
489 0 $resp = $self->_resp_simplify($resp);
490 #use Data::Dumper; warn Dumper $post_data,$response->{'content'},$resp;
491 0 $resp;
492 }
493  
494 0 ▶sub _resp_simplify {
Subroutine _resp_simplify: not called CC=4 SCAR=30.0
495 0 my ($self,$resp) = @_;
496 0 delete $resp->{'xmlns'};
497 0 foreach my $t (keys %{$resp}) {
498 0 ▶ if (ref $resp->{$t} eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $resp->{$t} eq 'ARRAY') { } 0 0 0
elsif (ref $resp->{$t} eq 'HASH') { } 0 0 0
499 0 $resp->{$t} = $self->_resp_simplify_array($resp->{$t});
500 } elsif (ref $resp->{$t} eq 'HASH') {
501 0 $resp->{$t} = $self->_resp_simplify_hash($resp->{$t});
502 }
503 }
504 0 $resp;
505 }
506  
507 0 ▶sub _resp_simplify_array {
Subroutine _resp_simplify_array: not called CC=2 SCAR=17.9
508 0 my ($self,$resp) = @_;
509 0 foreach my $value (@{$resp}) {
510 0 $self->_resp_simplify_hash($value);
511 }
512 0 $resp;
513 }
514  
515 0 ▶sub _resp_simplify_hash {
Subroutine _resp_simplify_hash: not called CC=10 SCAR=47.0
516 0 my ($self,$resp) = @_;
517 0 delete $resp->{'xsi:type'};
518 0 delete $resp->{'xmlns'};
519 0 foreach my $t (keys %{$resp}) {
520 0 ▶ if ($t eq 'nameValues') {
Branch: 2 branches
BranchTrueFalseTotal
if ($t eq 'nameValues') { } 0 0 0
elsif (ref $resp->{$t} eq 'HASH' and exists $resp->{$t}{'content'} || exists $resp->{$t}{'xmlns'}) { } 0 0 0
521 0 my $arr = $resp->{$t};
522 0 ▶ $arr = [$arr] unless ref $arr eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $arr eq "ARRAY" 0 0 0
523 0 my $hash = {};
524 0 foreach my $t2 (@{$arr}) {
525 0 my $n = $t2->{'name'}->{'content'};
526 0 my $v = $t2->{'value'}->{'content'};
527 0 ▶ if (!exists $hash->{$n}) {
Branch: 2 branches
BranchTrueFalseTotal
if (not exists $hash->{$n}) { } 0 0 0
elsif (ref $hash->{$n}) { } 0 0 0
528 0 $hash->{$n} = $v;
529 } elsif (ref $hash->{$n}) {
530 0 push @{$hash->{$n}}, $v;
531 } else {
532 0 $hash->{$n} = [$hash->{$n},$v];
533 }
534 }
535 0 $resp->{$t} = $hash;
536 ▶ } elsif (ref $resp->{$t} eq 'HASH' && (exists $resp->{$t}->{'content'} || exists $resp->{$t}->{'xmlns'})) {
Condition0%0/6
ref $resp->{$t} eq "HASH" and exists $resp->{$t}{"content"} || exists $resp->{$t}{"xmlns"}
!ll&&!rl&&r
000
exists $resp->{$t}{"content"} or exists $resp->{$t}{"xmlns"}
l!l&&r!l&&!r
000
MC/DC0%0/3
ref $resp->{$t} eq "HASH" and exists $resp->{$t}{"content"} || exists $resp->{$t}{"xmlns"}
ref $resp->{$t} eq "HASH" exists $resp->{$t}{"content"} exists $resp->{$t}{"xmlns"}
Truth table0%0/4
A and B or C
A= ref $resp->{$t} eq "HASH"B= exists $resp->{$t}{"content"}C= exists $resp->{$t}{"xmlns"}
ABCresult
0XX0
1000
11X1
1011
537 0 $resp->{$t} = $resp->{$t}->{'content'};
538 }
539 }
540 0 $resp;
541 }
542  
543 6 ▶sub _default_scrubber {
Subroutine _default_scrubber: called CC=3 SCAR=13.5
544 6 my $cc = shift;
545 6 my $del = 'DELETED';
546 6 ▶ if (length($cc) > 11) {
Branch: 2 branches
BranchTrueFalseTotal
if (length $cc > 11) { } 6 0 6
elsif (length $cc > 5) { } 0 0 0
547 6 $del = substr($cc,0,6).('X'x(length($cc)-10)).substr($cc,-4,4); # show first 6 and last 4
548 } elsif (length($cc) > 5) {
549 0 $del = substr($cc,0,2).('X'x(length($cc)-4)).substr($cc,-2,2); # show first 2 and last 2
550 } else {
551 0 $del = ('X'x(length($cc)-2)).substr($cc,-2,2); # show last 2
552 }
553 6 return $del;
554 }
555  
556 16 ▶sub _scrubber_add_card {
Subroutine _scrubber_add_card: called CC=2 SCAR=6.9
557 16 my ( $self, $cc ) = @_;
558 16 ▶ return if ! $cc;
Branch: 1 branch
BranchTrueFalseTotal
unless $cc 10 6 16
559 6 my $scrubber = $self->{_scrubber};
560 6 scrubber_add_scrubber({quotemeta($cc)=>&{$scrubber}($cc)});
561 }
562  
563 8 ▶sub _tx_init {
Subroutine _tx_init: called CC=5 SCAR=16.2
564 8 my ( $self, $opts ) = @_;
565  
566 # initialize/reset the reporting methods
567 8 $self->is_success(0);
568 8 $self->server_request('');
569 8 $self->server_response('');
570 8 $self->error_message('');
571  
572 # some calls are passed via the content method, others are direct arguments... this way we cover both
573 8 my %content = $self->content();
574 8 foreach my $ptr (\%content,$opts) {
575 16 ▶ next if ! $ptr;
Branch: 1 branch
BranchTrueFalseTotal
unless $ptr 8 8 16
576 8 ▶ my $passkey = quotemeta($ptr->{'password'}||'');
Condition50%1/2
$ptr->{'password'} || ''
l!l
80
MC/DC0%0/1
$ptr->{'password'} || ''
$ptr->{'password'}
Truth table50%1/2
A
A= $ptr->{'password'}
Aresult
11
00
577 8 ▶ my $cvv2key = $ptr->{'cvv2'} ? '(?<=[^\d])'.quotemeta($ptr->{'cvv2'}).'(?=[^\d])' : '';
Branch: 1 branch
BranchTrueFalseTotal
$ptr->{'cvv2'} ? : 0 8 8
578 8 scrubber_init({
579 $passkey => 'DELETED',
580 $cvv2key => 'DELETED',
581 });
582 8 $self->_scrubber_add_card($ptr->{'card_number'});
583 8 $self->_scrubber_add_card($ptr->{'account_number'});
584 }
585 }
586  
587 93 ▶sub _xmlwrite {
Subroutine _xmlwrite: called CC=7 SCAR=19.5
588 93 my ( $self, $writer, $item, $value ) = @_;
589 93 ▶ if ( ref($value) eq 'HASH' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $value eq 'HASH') { } 10 83 93
elsif (ref $value eq 'ARRAY') { } 7 76 83
590 10 ▶ my $attr = $value->{'attr'} ? $value->{'attr'} : {};
Branch: 1 branch
BranchTrueFalseTotal
$value->{'attr'} ? : 0 10 10
591 10 $writer->startTag( $item, %{$attr} );
592 10 foreach ( keys(%{$value}) ) {
593 75 ▶ next if $_ eq 'attr';
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "attr" 0 75 75
594 75 $self->_xmlwrite( $writer, $_, $value->{$_} );
595 }
596 10 $writer->endTag($item);
597 } elsif ( ref($value) eq 'ARRAY' ) {
598 7 foreach ( @{$value} ) {
599 11 $self->_xmlwrite( $writer, $item, $_ );
600 }
601 } else {
602 76 $writer->startTag($item);
603 76 $writer->characters($value);
604 76 $writer->endTag($item);
605 }
606 }
607  
608 1 my $common_mock = {
609 billTransactions => {
610 ok => {
611 'return' => {
612 'returnString' => 'OK',
613 'returnCode' => '200',
614 'soapId' => 'aaaaaa4817abcba350f9bded7024a44d9e03b42b',
615 },
616 },
617 ok_duplicate => {
618 'return' => {
619 'returnString' => 'OK',
620 'returnCode' => '200',
621 'soapId' => 'aaaaaa4817abcba350f9bded7024a44d9e03b42b',
622 },
623 'response' => [
624 {
625 'code' => '400',
626 'merchantTransactionId' => 'TEST-1477512979.48453-3',
627 'description' => 'Billing has already been attempted for Transaction ID TEST-1477512979.48453-3'
628 },
629 ],
630 },
631 },
632 fetchBillingResults => {
633 ok => {
634 'return' => {
635 'returnString' => 'OK',
636 'returnCode' => '200',
637 'soapId' => 'aaaaaa4817abcba350f9bded7024a44d9e03b42b',
638 },
639 },
640 },
641 refundTransactions => {
642 ok => {
643 'return' => {
644 'returnString' => 'OK',
645 'returnCode' => '200',
646 'soapId' => 'aaaaaa4817abcba350f9bded7024a44d9e03b42b',
647 },
648 },
649 },
650 fetchByMerchantTransactionId => {
651 ok => {
652 'return' => {
653 'returnCode' => '200',
654 'returnString' => 'OK',
655 'soapId' => 'aaaaaa727eca030a16ddad54e4eaf8088a5fa322'
656 },
657 'transaction' => {
658 'currency' => 'USD',
659 'authCode' => '123456',
660 'selectTransactionId' => 'TEST-1477513825.95777',
661 'amount' => '9000',
662 'subscriptionId' => 'TEST-1477513825.95775',
663 'paymentMethodIsTokenized' => '0',
664 'creditCardAccountHash' => 'aaaaaa96f35af3876fc509665b3dc23a0930aab1',
665 'nameValues' => {
666 'vin:BillingCycle' => '0',
667 'vin:RetryNumber' => '0'
668 },
669 'paymentMethodId' => '1',
670 'divisionNumber' => '1',
671 'subscriptionStartDate' => '2016-10-26T13:30:26-07:00',
672 'creditCardAccount' => '411111XXXXXX1111',
673 'status' => 'Failed',
674 'VID' => 'aaaaaa5286ba2a8199a651d9f7afbee9a015fbb2',
675 'customerId' => '123',
676 'timestamp' => '2012-09-11T15:34:32-07:00',
677 'merchantTransactionId' => 'TEST-1477513825.95777'
678 }
679 },
680 },
681 };
682 4 ▶sub _common_mock {
Subroutine _common_mock: called CC=2 SCAR=7.2
683 4 my ($self,$action,$label) = @_;
684 4 ▶ return $common_mock->{$action}->{$label} || die 'Mock label not found, label: '.$label."\n";
Condition50%1/2
$common_mock->{$action}{$label} || die('Mock label not found, label: ' . $label . "\n")
l!l
40
MC/DC0%0/1
$common_mock->{$action}{$label} || die('Mock label not found, label: ' . $label . "\n")
$common_mock->{$action}{$label}
Truth table50%1/2
A
A= $common_mock->{$action}{$label}
Aresult
11
00
685 }
686  
687 1 1;
↑ Summary