Report.pm

filter: Statementstmt 100% 53 / 53 Branchbran 88.8% 16 / 18 Conditioncond 62.5% 5 / 8 MC/DCmcdc 40.0% 2 / 5 Subroutinesub 100% 12 / 12 Podpod 100% 7 / 7 totaltotal 92.2% 95 / 103 CC 15 SCAR 13.6
CC
15
Cov
94%
build
6.2
new
6.0
list_loaded
4.0
CRAP 3.9
« Report/PaymentEvents.pm ↑ Summary
1 package Business::CyberSource::Report;
2  
3 14 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 14 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 14 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 14 ▶use Class::Load qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 14 ▶use Storable qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10  
11 =head1 NAME
12  
13 Business::CyberSource::Report - Factory class for modules that retrieve CyberSource's XML reports.
14  
15  
16 =head1 VERSION
17  
18 Version 1.2.0
19  
20 =cut
21  
22 14 our $VERSION = '1.2.0';
23  
24 14 our $LOADED_REPORT_MODULES;
25  
26  
27 =head1 SYNOPSIS
28  
29 use Business::CyberSource::Report;
30 use Business::CyberSource::Report::Test;
31  
32 # Generate a report factory.
33 my $report_factory = Business::CyberSource::Report->new(
34 merchant_id => $merchant_id,
35 username => $username,
36 password => $password,
37 use_production_system => $use_production_system,
38 );
39  
40 # Use the factory to get a Business::CyberSource::Report::Test object with
41 # the correct connection parameters.
42 my $test_report = $report_factory->build( 'test' );
43  
44 # Retrieve a list of the report modules that have been loaded in memory,
45 # either via "use" or a require by build()
46 my $available_reports = $report_factory->list_loaded();
47  
48 =head1 METHODS
49  
50 =head2 new()
51  
52 Create a new Business::CyberSource::Report factory object.
53  
54 my $report_factory = Business::CyberSource::Report->new(
55 merchant_id => $merchant_id,
56 username => $username,
57 password => $password,
58 use_production_system => $use_production_system,
59 );
60  
61 Parameters:
62  
63 =over
64  
65 =item *
66  
67 merchant_id: a merchant ID provided by CyberSource.
68  
69 =item *
70  
71 username/password: login access information you can create in
72 CyberSource's B<production> Business Center. The access will be automatically
73 available then in the test Business Center. Don't forget to give that user
74 reporting permissions.
75  
76 =item *
77  
78 use_production_system: whether queries should be sent to the production
79 system (1) or the test system (0). Off by default.
80  
81 =back
82  
83 =cut
84  
85 sub new
86 18 ▶{
Subroutine new: called CC=6 SCAR=17.9
Pod documented
87 18 my ( $class, %args ) = @_;
88  
89 # Check for required arguments.
90 18 foreach my $arg ( qw( merchant_id password ) )
91 {
92 croak "The parameter >$arg< is missing"
93 34 ▶ if !defined( $args{ $arg } ) || ( $args{ $arg } eq '' );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $args{$arg} or $args{$arg} eq "" 4 30 34
Condition100%3/3
not defined $args{$arg} or $args{$arg} eq ""
l!l&&r!l&&!r
2230
MC/DC100%2/2
not defined $args{$arg} or $args{$arg} eq ""
not defined $args{$arg} $args{$arg} eq ""
Truth table100%3/3
not(A) or B
A= not defined $args{$arg}B= $args{$arg} eq ""
ABresult
1X1
011
000
94 }
95  
96 # By default per CyberSource's interface, the username is the merchant ID.
97 $args{'username'} = $args{'merchant_id'}
98 14 ▶ unless defined( $args{'username'} );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"username"} 0 14 14
99  
100 # By default, use the test environment.
101 $args{'use_production_system'} = 0
102 14 ▶ unless defined( $args{'use_production_system'} );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"use_production_system"} 3 11 14
103  
104 # Build the object, blessed with the child's class to simplify new() in
105 # children classes.
106 my $self = bless(
107 {
108 14 map { $_ => $args{ $_ } }
109 qw( merchant_id username version password use_production_system )
110 },
111 $class,
112 );
113  
114 14 return $self;
115 }
116  
117  
118 =head2 list_loaded()
119  
120 Return a list of report modules that have been loaded, either via a "use" or
121 dynamically when calling build().
122  
123 my $loaded_report_modules = $report_factory->list_loaded();
124  
125 =cut
126  
127 sub list_loaded
128 9 ▶{
Subroutine list_loaded: called CC=4 SCAR=13.9
Pod documented
129 9 my ( $self ) = @_;
130  
131 9 ▶ if ( !defined( $LOADED_REPORT_MODULES ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $Business::CyberSource::Report::LOADED_REPORT_MODULES) 6 3 9
132 {
133 6 $LOADED_REPORT_MODULES = {};
134  
135 6 my $main_module_path = __PACKAGE__;
136 6 $main_module_path =~ s/::/\//g;
137  
138 6 foreach my $module ( keys %INC )
139 {
140 1023 ▶ next unless $module =~ m/^\Q$main_module_path\/\E([^\/]+)\.pm/;
Branch: 1 branch
BranchTrueFalseTotal
unless $module =~ m[^\Q$main_module_path/\E([^/]+)\.pm] 1018 5 1023
141 5 $LOADED_REPORT_MODULES->{ $1 } = undef;
142 }
143 }
144  
145 9 return [ keys %$LOADED_REPORT_MODULES ];
146 }
147  
148  
149 =head2 build()
150  
151 Create a Business::CyberSource::Report::* object with the correct connection
152 parameters.
153  
154 # Use the factory to get a Business::CyberSource::Report::Test object with
155 # the correct connection parameters.
156 my $test_report = $report_factory->build( 'SingleTransaction' );
157  
158 Parameters:
159  
160 =over
161  
162 =item *
163  
164 The submodule name, such as SingleTransaction for
165 Business::CyberSource::Report::SingleTransaction.
166  
167 =back
168  
169 =cut
170  
171 sub build
172 6 ▶{
Subroutine build: called CC=6 SCAR=18.3
Pod documented
173 6 my ( $self, $module ) = @_;
174  
175 6 ▶ croak 'Please specify the name of the module to build'
Branch: 1 branch
BranchTrueFalseTotal
if not defined $module or $module eq "" 0 6 6
Condition33%1/3
not defined $module or $module eq ""
l!l&&r!l&&!r
006
MC/DC0%0/2
not defined $module or $module eq ""
not defined $module $module eq ""
Truth table33%1/3
not(A) or B
A= not defined $moduleB= $module eq ""
ABresult
1X1
011
000
176 if !defined( $module ) || ( $module eq '' );
177  
178 6 my $class = __PACKAGE__ . '::' . $module;
179  
180 # If the module isn't already loaded, do that now.
181 6 ▶ if ( scalar( grep { $module eq $_ } @{ $self->list_loaded() || [] } ) == 0 )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar grep({$module eq $_;} @{$self->list_loaded or [];}) == 0) 3 3 6
Condition50%1/2
$self->list_loaded || []
l!l
60
MC/DC0%0/1
$self->list_loaded || []
$self->list_loaded
Truth table50%1/2
A
A= $self->list_loaded
Aresult
11
00
182 {
183 3 ▶ Class::Load::load_optional_class( $class ) || croak "Failed to load $class, double-check the class name";
Branch: 1 branch
BranchTrueFalseTotal
Class::Load::load_optional_class($class) or croak("Failed to load $class, double-check the class name") 2 1 3
184 2 $LOADED_REPORT_MODULES->{ $module } = undef;
185 }
186  
187 5 my $object = bless(
188 # Create a copy of the factory's guts, the object will be a subclass of
189 # the factory and will be able to use all the information.
190 # Also, we don't want a change in the factory parameters to cascade to
191 # the objects previously built, so it makes sense to copy.
192 # TBD: copy only a selected subset of the content?
193 Storable::dclone( $self ),
194 $class,
195 );
196  
197 5 return $object;
198 }
199  
200  
201 =head1 ACCESSORS
202  
203 =head2 get_username()
204  
205 Return the username to use to connect to the service.
206  
207 my $username = $report_factory->get_username();
208  
209 =cut
210  
211 sub get_username
212 18 ▶{
Subroutine get_username: called CC=1 SCAR=0.0
Pod documented
213 18 my ( $self ) = @_;
214  
215 18 return $self->{'username'};
216 }
217  
218  
219 =head2 get_password()
220  
221 Return the password to use to connect to the service.
222  
223 my $password = $report_factory->get_password();
224  
225 =cut
226  
227 sub get_password
228 18 ▶{
Subroutine get_password: called CC=1 SCAR=0.0
Pod documented
229 18 my ( $self ) = @_;
230  
231 18 return $self->{'password'};
232 }
233  
234  
235 =head2 get_merchant_id()
236  
237 Return the merchant ID to use to connect to the service.
238  
239 my $merchant_id = $report_factory->get_merchant_id();
240  
241 =cut
242  
243 sub get_merchant_id
244 13 ▶{
Subroutine get_merchant_id: called CC=1 SCAR=0.0
Pod documented
245 13 my ( $self ) = @_;
246  
247 13 return $self->{'merchant_id'};
248 }
249  
250  
251 =head2 use_production_system()
252  
253 Return a boolean indicating whether the production system is used in queries.
254 Otherwise, the Test Business Center is used.
255  
256 my $use_production_system = $report_factory->use_production_system();
257  
258 =cut
259  
260 sub use_production_system
261 10 ▶{
Subroutine use_production_system: called CC=2 SCAR=6.9
Pod documented
262 10 my ( $self ) = @_;
263  
264 10 ▶ return $self->{'use_production_system'} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'use_production_system'} ? : 1 9 10
265 }
266  
267  
268 =head1 BUGS
269  
270 Please report any bugs or feature requests through the web interface at
271 L<https://github.com/guillaumeaubert/Business-CyberSource-Report/issues/new>.
272 I will be notified, and then you'll automatically be notified of progress on
273 your bug as I make changes.
274  
275  
276 =head1 SUPPORT
277  
278 You can find documentation for this module with the perldoc command.
279  
280 perldoc Business::CyberSource::Report
281  
282  
283 You can also look for information at:
284  
285 =over
286  
287 =item *
288  
289 GitHub's request tracker
290  
291 L<https://github.com/guillaumeaubert/Business-CyberSource-Report/issues>
292  
293 =item *
294  
295 AnnoCPAN: Annotated CPAN documentation
296  
297 L<http://annocpan.org/dist/business-cybersource-report>
298  
299 =item *
300  
301 CPAN Ratings
302  
303 L<http://cpanratings.perl.org/d/business-cybersource-report>
304  
305 =item *
306  
307 MetaCPAN
308  
309 L<https://metacpan.org/release/Business-CyberSource-Report>
310  
311 =back
312  
313  
314 =head1 AUTHOR
315  
316 L<Guillaume Aubert|https://metacpan.org/author/AUBERTG>, C<< <aubertg at cpan.org> >>.
317  
318  
319 =head1 ACKNOWLEDGEMENTS
320  
321 I originally developed this project for ThinkGeek
322 (L<http://www.thinkgeek.com/>). Thanks for allowing me to open-source it!
323  
324  
325 =head1 COPYRIGHT & LICENSE
326  
327 Copyright 2011-2017 Guillaume Aubert.
328  
329 This code is free software; you can redistribute it and/or modify it under the
330 same terms as Perl 5 itself.
331  
332 This program is distributed in the hope that it will be useful, but WITHOUT ANY
333 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
334 PARTICULAR PURPOSE. See the LICENSE file for more details.
335  
336 =cut
337  
338 14 1;
« Report/PaymentEvents.pm ↑ Summary