Business/CyberSource/Client.pm

filter: Statementstmt 70.0% 82 / 117 Branchbran 8.3% 2 / 24 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 78.5% 22 / 28 Podpod 100% 1 / 1 totaltotal 59.4% 107 / 180 CC 16 SCAR 33.5
CC
16
Cov
57%
submit
110.0
_build__rules
20.0
__ANON__
6.0
CRAP 28.5
↑ Summary Business/CyberSource/Rule/ExpiredCard.pm »
1 package Business::CyberSource::Client;
2 4 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 4 our $VERSION = '0.010007'; # VERSION
8  
9 4 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 with 'MooseY::RemoteHelper::Role::Client';
11  
12 4 ▶use Type::Utils qw( duck_type );
Subroutine BEGIN: called CC=1 SCAR=0.0
13 4 ▶use Type::Params qw( compile Invocant );
Subroutine BEGIN: called CC=1 SCAR=0.0
14 4 ▶use MooseX::Types::Common::String qw( NonEmptyStr NonEmptySimpleStr );
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 4 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 4 ▶use Module::Runtime qw( use_module );
Subroutine BEGIN: called CC=1 SCAR=0.0
18 4 ▶use Module::Load qw( load );
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 4 ▶use XML::Compile::SOAP::WSS 1.04;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 4 ▶use XML::Compile::WSDL11;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 4 ▶use XML::Compile::SOAP11;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 4 ▶use XML::Compile::Transport::SOAPHTTP;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 use File::ShareDir::ProjectDistDir 1.000
25 4 ▶ dist_file => defaults => { strict => 1 };
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 4 our @CARP_NOT = ( __PACKAGE__, qw( Class::MOP::Method::Wrapped ) );
28  
29 sub submit { ## no critic ( Subroutines::RequireArgUnpacking )
30 0 ▶ state $check = compile( Invocant, duck_type(['serialize']));
Subroutine submit: not called CC=10 SCAR=47.0
Pod documented
31 0 my ( $self, $request ) = $check->( @_ );
32  
33 0 ▶ if ( $self->has_rules && ! $self->rules_is_empty ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_rules and not $self->rules_is_empty) 0 0 0
Condition0%0/3
$self->has_rules and not $self->rules_is_empty
!ll&&!rl&&r
000
MC/DC0%0/2
$self->has_rules and not $self->rules_is_empty
$self->has_rules not $self->rules_is_empty
Truth table0%0/3
A and not(B)
A= $self->has_rulesB= not $self->rules_is_empty
ABresult
0X0
100
111
34 0 my $result;
35 0 RULE: foreach my $rule ( @{ $self->_rules } ) {
36 0 $result = $rule->run( $request );
37 0 ▶ last RULE if defined $result;
Branch: 1 branch
BranchTrueFalseTotal
if defined $result 0 0 0
38 }
39 0 ▶ return $self->_response_factory->create( $result, $request )
Branch: 1 branch
BranchTrueFalseTotal
if defined $result 0 0 0
40 if defined $result
41 ;
42 }
43  
44 my %request = (
45 merchantID => $self->user,
46 clientEnvironment => $self->env,
47 clientLibrary => $self->name,
48 clientLibraryVersion => $self->version,
49 0 %{ $request->serialize },
50 );
51  
52 0 ▶ if ( $self->debug >= 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->debug >= 1) 0 0 0
53 0 load 'Carp';
54 0 load 'Data::Printer', alias => 'Dumper';
55  
56 0 Carp::carp( 'REQUEST HASH: ' . Dumper( \%request ) );
57 }
58  
59 0 my ( $answer, $trace ) = $self->_soap_client->( %request );
60  
61 0 ▶ if ( $self->debug >= 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->debug >= 2) 0 0 0
62 0 Carp::carp "\n> " . $trace->request->as_string;
63 0 Carp::carp "\n< " . $trace->response->as_string;
64 }
65  
66 0 $request->_http_trace( $trace );
67  
68 0 ▶ if ( $answer->{Fault} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($answer->{"Fault"}) 0 0 0
69 die ## no critic ( ErrorHandling::RequireCarping )
70 use_module('Business::CyberSource::Exception::SOAPFault')
71 0 ->new( $answer->{Fault} );
72 }
73  
74 0 ▶ if ( $self->debug >= 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->debug >= 1) 0 0 0
75 0 Carp::carp( 'RESPONSE HASH: ' . Dumper( $answer ) );
76 }
77  
78 0 return $self->_response_factory->create( $answer->{result}, $request );
79 }
80  
81 sub _build_soap_client {
82 2 ▶ my $self = shift;
Subroutine _build_soap_client: called CC=1 SCAR=0.0
83 # order in this subroutine matters changing it may break stuff
84  
85 2 my $wss = XML::Compile::SOAP::WSS->new( version => '1.1' );
86  
87 2 my $wsdl = XML::Compile::WSDL11->new( $self->cybs_wsdl );
88 2 $wsdl->importDefinitions( $self->cybs_xsd );
89  
90 2 $wss->basicAuth(
91 username => $self->user,
92 password => $self->pass,
93 );
94  
95 2 my $call = $wsdl->compileClient('runTransaction');
96  
97 2 return $call;
98 }
99  
100 sub _build_cybs_wsdl {
101 2 ▶ my $self = shift;
Subroutine _build_cybs_wsdl: called CC=2 SCAR=7.1
102  
103 2 ▶ my $dir = $self->test ? 'test' : 'production';
Branch: 1 branch
BranchTrueFalseTotal
$self->test ? : 2 0 2
104  
105 2 return dist_file(
106 'Business-CyberSource',
107 $dir
108 . '/'
109 . 'CyberSourceTransaction_'
110 . $self->_version_for_filename
111 . '.wsdl'
112 );
113 }
114  
115 sub _build_cybs_xsd {
116 2 ▶ my $self = shift;
Subroutine _build_cybs_xsd: called CC=2 SCAR=7.1
117  
118 2 ▶ my $dir = $self->test ? 'test' : 'production';
Branch: 1 branch
BranchTrueFalseTotal
$self->test ? : 2 0 2
119  
120 2 return dist_file(
121 'Business-CyberSource',
122 $dir
123 . '/'
124 . 'CyberSourceTransaction_'
125 . $self->_version_for_filename
126 . '.xsd'
127 );
128 }
129  
130 sub _build__rules {
131 0 ▶ my $self = shift;
Subroutine _build__rules: not called CC=4 SCAR=30.0
132  
133 0 ▶ return [] if ! $self->has_rules || $self->rules_is_empty;
Branch: 1 branch
BranchTrueFalseTotal
if not $self->has_rules or $self->rules_is_empty 0 0 0
Condition0%0/3
not $self->has_rules or $self->rules_is_empty
l!l&&r!l&&!r
000
MC/DC0%0/2
not $self->has_rules or $self->rules_is_empty
not $self->has_rules $self->rules_is_empty
Truth table0%0/3
not(A) or B
A= not $self->has_rulesB= $self->rules_is_empty
ABresult
1X1
011
000
134  
135 my @rules
136 = map {
137 0 ▶ $self->_rule_factory->create( $_, { client => $self } ) if defined $_
Branch: 1 branch
BranchTrueFalseTotal
if defined $_ 0 0 0
138 } $self->list_rules;
139  
140 0 return \@rules;
141 }
142  
143 sub _version_for_filename {
144 4 ▶ my $self = shift;
Subroutine _version_for_filename: called CC=1 SCAR=0.0
145 4 my $version = $self->cybs_api_version;
146 4 $version =~ s/\./_/xms;
147 4 return $version;
148 }
149  
150 4 has _soap_client => (
151 isa => 'CodeRef',
152 is => 'ro',
153 lazy => 1,
154 init_arg => undef,
155 builder => '_build_soap_client',
156 );
157  
158 has _response_factory => (
159 isa => 'Object',
160 is => 'ro',
161 lazy => 1,
162 default => sub {
163 return
164 0 ▶ use_module('Business::CyberSource::Factory::Response')
Subroutine __ANON__: not called CC=1 SCAR=6.9
165 ->new;
166 },
167 4 );
168  
169 has _rule_factory => (
170 isa => 'Object',
171 is => 'ro',
172 lazy => 1,
173 default => sub {
174 0 ▶ return use_module('Business::CyberSource::Factory::Rule')->new;
Subroutine __ANON__: not called CC=1 SCAR=6.9
175 },
176 4 );
177  
178 has rules => (
179 isa => 'ArrayRef[Str]',
180 predicate => 'has_rules',
181 traits => ['Array'],
182 is => 'ro',
183 reader => undef,
184 2 ▶ default => sub { [qw( ExpiredCard RequestIDisZero )] },
Subroutine __ANON__: called CC=1 SCAR=0.0
185 4 handles => {
186 list_rules => 'elements',
187 rules_is_empty => 'is_empty',
188 },
189 );
190  
191 4 has _rules => (
192 isa => 'ArrayRef[Object]',
193 is => 'ro',
194 lazy_build => 1,
195 traits => ['Array'],
196 );
197  
198 has version => (
199 required => 0,
200 lazy => 1,
201 init_arg => undef,
202 is => 'ro',
203 isa => 'Str',
204 default => sub {
205 0 ▶ my $version
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$Business::CyberSource::VERSION ? : 0 0 0
206 = $Business::CyberSource::VERSION ? $Business::CyberSource::VERSION
207 : '0'
208 ;
209 0 return $version;
210 },
211 4 );
212  
213 has name => (
214 required => 0,
215 lazy => 1,
216 init_arg => undef,
217 is => 'ro',
218 isa => 'Str',
219 1 ▶ default => sub { return 'Business::CyberSource' },
Subroutine __ANON__: called CC=1 SCAR=0.0
220 4 );
221  
222 has env => (
223 required => 0,
224 lazy => 1,
225 init_arg => undef,
226 is => 'ro',
227 isa => 'Str',
228 default => sub {
229 0 ▶ return "Perl $Config{version} $Config{osname} $Config{osvers} $Config{archname}";
Subroutine __ANON__: not called CC=1 SCAR=6.9
230 },
231 4 );
232  
233 4 has cybs_api_version => (
234 required => 0,
235 lazy => 1,
236 is => 'ro',
237 isa => 'Str',
238 default => '1.71',
239 );
240  
241 4 has cybs_wsdl => (
242 lazy => 1,
243 is => 'ro',
244 isa => 'Str',
245 builder => '_build_cybs_wsdl',
246 );
247  
248 4 has cybs_xsd => (
249 lazy => 1,
250 is => 'ro',
251 isa => 'Str',
252 builder => '_build_cybs_xsd',
253 );
254  
255  
256 4 __PACKAGE__->meta->make_immutable;
257 4 1;
258  
259 # ABSTRACT: User Agent Responsible for transmitting the Response
260  
261 __END__
262  
263 =pod
264  
265 =encoding UTF-8
266  
267 =head1 NAME
268  
269 Business::CyberSource::Client - User Agent Responsible for transmitting the Response
270  
271 =head1 VERSION
272  
273 version 0.010007
274  
275 =head1 SYNOPSIS
276  
277 use Business::CyberSource::Client;
278  
279 my $request = 'Some Business::CyberSource::Request Object';
280  
281 my $client = Business::CyberSource::Request->new({
282 user => 'Merchant ID',
283 pass => 'API KEY',
284 test => 1,
285 });
286  
287 my $response = $client->run_transaction( $request );
288  
289 =head1 DESCRIPTION
290  
291 A service object that is meant to provide a way to run the requested
292 transactions.
293  
294 =head1 WITH
295  
296 L<MooseY::RemoteHelper::Role::Client>
297  
298 =head1 METHODS
299  
300 =head2 submit
301  
302 my $response = $client->submit( $request );
303  
304 Takes a L<Business::CyberSource::Request> subclass as a parameter and returns
305 a L<Business::CyberSource::Response>
306  
307 =head1 ATTRIBUTES
308  
309 =head2 user
310  
311 CyberSource Merchant ID
312  
313 =head2 pass
314  
315 CyberSource API KEY
316  
317 =head2 test
318  
319 Boolean value when false your requests will go to the live server, when
320 true they will go to the testing server.
321  
322 =head2 debug
323  
324 Integer value that causes the HTTP request/response to be output to STDOUT
325 when a transaction is run. defaults to value of the environment variable
326  
327 =over
328  
329 =item value 0
330  
331 no output (default)
332  
333 =item value 1
334  
335 request/response hashref
336  
337 =item value 2
338  
339 1 plus actual HTTP and XML
340  
341 =back
342  
343 =head2 rules
344  
345 ArrayRef of L<Rule Names|Business::CyberSource::Rule>. Rules names are modules
346 prefixed by L<Business::CyberSource::Rule>. By default both
347 L<Business::CyberSource::Rule::ExpiredCard> and
348 L<Business::CyberSource::Rule::RequestIDisZero> are included. If you decide to
349 add more rules remember to add C<qw( ExpiredCard RequestIDisZero )> to the
350 new ArrayRef ( if you want them ).
351  
352 =head2 name
353  
354 Client Name defaults to L<Business::CyberSource>
355  
356 =head2 version
357  
358 Client Version defaults to the version of this library
359  
360 =head2 env
361  
362 defaults to specific parts of perl's config hash
363  
364 =head2 cybs_wsdl
365  
366 A L<Path::Class::File> to the WSDL definition file
367  
368 =head2 cybs_xsd
369  
370 A L<Path::Class::File> to the XSD definition file
371  
372 =head2 cybs_api_version
373  
374 CyberSource API version, currently 1.71
375  
376 =head1 BUGS
377  
378 Please report any bugs or feature requests on the bugtracker website
379 https://github.com/xenoterracide/business-cybersource/issues
380  
381 When submitting a bug or request, please include a test-file or a
382 patch to an existing test-file that illustrates the bug or desired
383 feature.
384  
385 =head1 AUTHOR
386  
387 Caleb Cushing <xenoterracide@gmail.com>
388  
389 =head1 COPYRIGHT AND LICENSE
390  
391 This software is Copyright (c) 2016 by Caleb Cushing <xenoterracide@gmail.com>.
392  
393 This is free software, licensed under:
394  
395 The Artistic License 2.0 (GPL Compatible)
396  
397 =cut
↑ Summary Business/CyberSource/Rule/ExpiredCard.pm »