Report/SingleTransaction.pm

filter: Statementstmt 100% 47 / 47 Branchbran 86.3% 19 / 22 Conditioncond 64.7% 11 / 17 MC/DCmcdc 33.3% 3 / 9 Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 85.4% 88 / 103 CC 18 SCAR 26.7
CC
18
Cov
90%
retrieve
18.9
BEGIN
1.0
BEGIN
1.0
CRAP 14.4
↑ Summary Report/PaymentEvents.pm »
1 package Business::CyberSource::Report::SingleTransaction;
2  
3 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 5 ▶use base 'Business::CyberSource::Report';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 5 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use HTTP::Request::Common qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use LWP::UserAgent qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12  
13 =head1 NAME
14  
15 Business::CyberSource::Report::SingleTransaction - Interface to CyberSource's Single Transaction report.
16  
17  
18 =head1 VERSION
19  
20 Version 1.2.0
21  
22 =cut
23  
24 5 our $VERSION = '1.2.0';
25  
26 5 our $TEST_URL = 'https://ebctest.cybersource.com/ebctest/Query';
27 5 our $PRODUCTION_URL = 'https://ebc.cybersource.com/ebc/Query';
28  
29  
30 =head1 SYNOPSIS
31  
32 This module is an interface to the Single Transaction report from CyberSource.
33  
34 use Business::CyberSource::Report;
35  
36 # Generate a report factory.
37 my $report_factory = Business::CyberSource::Report->new(
38 merchant_id => $merchant_id,
39 username => $username,
40 password => $password,
41 );
42  
43 # Build a Business::CyberSource::Report::SingleTransaction object.
44 my $single_transaction_report = $report_factory->build( 'SingleTransaction' );
45  
46 # Retrieve a Single Transaction report by Request ID.
47 $single_transaction_report->retrieve(
48 request_id => $request_id,
49 include_extended_detail => $include_extended_detail,
50 version => $version,
51 );
52  
53 # Retrieve a Single Transaction report using a combination of merchant
54 # reference number and
55 $single_transaction_report->retrieve(
56 merchant_reference_number => $merchant_reference_number,
57 target_date => $target_date,
58 include_extended_detail => $include_extended_detail,
59 version => $version,
60 );
61  
62 =head1 METHODS
63  
64  
65 =head2 retrieve()
66  
67 Build and send the request to CyberSource.
68  
69 # Retrieve a Single Transaction report by Request ID.
70 $single_transaction_report->retrieve(
71 request_id => $request_id,
72 include_extended_detail => $include_extended_detail,
73 version => $version,
74 );
75  
76 # Retrieve a Single Transaction report using a combination of merchant
77 # reference number and target date.
78 $single_transaction_report->retrieve(
79 merchant_reference_number => $merchant_reference_number,
80 target_date => $target_date,
81 include_extended_detail => $include_extended_detail,
82 version => $version,
83 );
84  
85 Parameters:
86  
87 =over
88  
89 =item * request_id (mandatory, if no merchant_reference_number/target_date)
90  
91 A request ID from CyberSource.
92  
93 =item * merchant_reference_number/target_date (mandatory, if no request_id)
94  
95 The reference number you sent with the original transaction. This is not a
96 number generated by CyberSource. This must be used in conjunction with a target
97 date, with the format YYYYMMDD.
98  
99 =item * include_extended_detail (optional)
100  
101 Can be set to 'Predecessor' or 'Related' to retrieve more information about the
102 transactions found.
103  
104 =item * version (default: 1.7)
105  
106 CyberSource offers multiple versions of the resulting XML. Available versions
107 are 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7.
108  
109 See L<http://apps.cybersource.com/library/documentation/dev_guides/Reporting_Developers_Guide/html/downloading.htm#downloading_10837_1027265>
110 for more details about the differences.
111  
112 =item * user_agent (optional)
113  
114 By default, C<LWP::UserAgent>. This is useful for tests, see the documentation
115 for L<Test::LWP::UserAgent> in particular.
116  
117 =back
118  
119 =cut
120  
121 sub retrieve
122 12 ▶{
Subroutine retrieve: called CC=18 SCAR=29.4
Pod documented
123 12 my ( $self, %args ) = @_;
124 12 my $request_id = delete( $args{'request_id'} );
125 12 my $merchant_reference_number = delete( $args{'merchant_reference_number'} );
126 12 my $target_date = delete( $args{'target_date'} );
127 12 ▶ my $user_agent = delete( $args{'user_agent'} ) || LWP::UserAgent->new();
Condition33%1/3
delete $args{'user_agent'} || 'LWP::UserAgent'->new
l!l&&r!l&&!r
1200
MC/DC0%0/2
delete $args{'user_agent'} || 'LWP::UserAgent'->new
delete $args{'user_agent'} 'LWP::UserAgent'->new
Truth table33%1/3
A || B
A= delete $args{'user_agent'}B= 'LWP::UserAgent'->new
ABresult
1X1
011
000
128  
129 # Defaults.
130 12 my $include_extended_detail = delete( $args{'include_extended_detail'} );
131 12 ▶ my $version = delete( $args{'version'} ) || '1.7';
Condition50%1/2
delete $args{'version'} || '1.7'
l!l
120
MC/DC0%0/1
delete $args{'version'} || '1.7'
delete $args{'version'}
Truth table50%1/2
A
A= delete $args{'version'}
Aresult
11
00
132  
133 # Verify the version number.
134 12 ▶ croak 'The version number can only be 1.1, 1.2, 1.3, 1.4, 1.5, 1.6 or 1.7'
Branch: 1 branch
BranchTrueFalseTotal
unless $version =~ /^1\.[1-7]$/ 1 11 12
135 unless $version =~ m/^1\.[1-7]$/;
136  
137 # Verify the value of $include_extended_detail.
138 11 ▶ if ( defined( $include_extended_detail ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $include_extended_detail) 10 1 11
139 {
140 10 ▶ croak "The value of 'include_extended_detail' needs to be either 'Predecessor' or 'Related'"
Branch: 1 branch
BranchTrueFalseTotal
unless $include_extended_detail =~ /^(?:Predecessor|Related)$/ 1 9 10
141 if $include_extended_detail !~ m/^(?:Predecessor|Related)$/;
142 9 ▶ croak "'include_extended_detail' is only available for versions >= 1.3"
Branch: 1 branch
BranchTrueFalseTotal
if $version < "1.3" 1 8 9
143 if $version < 1.3;
144 }
145  
146 # Prepare the request parameters.
147 9 my $request_parameters =
148 {
149 versionNumber => $version,
150 merchantID => $self->get_merchant_id(),
151 username => $self->get_username(),
152 password => $self->get_password(),
153 type => 'transaction',
154 subtype => 'transactionDetail',
155 };
156  
157 # Add the request_id or merchant_reference_number/target_date.
158 9 ▶ if ( defined( $request_id ) && !defined( $merchant_reference_number ) && !defined( $target_date ) )
Branch: 2 branches
BranchTrueFalseTotal
if (defined $request_id and not defined $merchant_reference_number and not defined $target_date) { } 4 5 9
elsif (not defined $request_id and defined $merchant_reference_number and defined $target_date) { } 2 3 5
Condition66%4/6
defined $request_id and not defined $merchant_reference_number and not defined $target_date
!ll&&!rl&&r
504
defined $request_id and not defined $merchant_reference_number
!ll&&!rl&&r
504
MC/DC33%1/3
defined $request_id and not defined $merchant_reference_number and not defined $target_date
defined $request_id not defined $merchant_reference_number not defined $target_date
Truth table50%2/4
A and not(B) and not(C)
A= defined $request_idB= not defined $merchant_reference_numberC= not defined $target_date
ABCresult
0XX0
10X0
1100
1111
159 {
160 4 $request_parameters->{'requestID'} = $request_id;
161 }
162 ▶ elsif ( !defined( $request_id ) && defined( $merchant_reference_number ) && defined( $target_date ) )
Condition83%5/6
not defined $request_id and defined $merchant_reference_number and defined $target_date
!ll&&!rl&&r
212
not defined $request_id and defined $merchant_reference_number
!ll&&!rl&&r
023
MC/DC66%2/3
not defined $request_id and defined $merchant_reference_number and defined $target_date
not defined $request_id defined $merchant_reference_number defined $target_date
Truth table75%3/4
not(A) and B and C
A= not defined $request_idB= defined $merchant_reference_numberC= defined $target_date
ABCresult
0XX0
10X0
1100
1111
163 {
164 2 ▶ croak 'The target_date format must be YYYYMMDD'
Branch: 1 branch
BranchTrueFalseTotal
unless $target_date =~ /^\d{8}$/ 1 1 2
165 unless $target_date =~ m/^\d{8}$/;
166  
167 1 $request_parameters->{'merchantReferenceNumber'} = $merchant_reference_number;
168 1 $request_parameters->{'targetDate'} = $target_date;
169 }
170 else
171 {
172 3 croak 'Please provide either a request_id or the combination of a '
173 . 'merchant_reference_number and target_date parameters';
174 }
175  
176 # Add option to get extended details.
177 5 ▶ $request_parameters->{'includeExtendedDetail'} = $include_extended_detail
Branch: 1 branch
BranchTrueFalseTotal
if defined $include_extended_detail 4 1 5
178 if defined( $include_extended_detail );
179  
180 # Send the query.
181 5 ▶ my $request = HTTP::Request::Common::POST(
Branch: 1 branch
BranchTrueFalseTotal
$self->use_production_system ? : 0 5 5
182 $self->use_production_system() ? $PRODUCTION_URL : $TEST_URL,
183 Content => $request_parameters,
184 );
185 5 $request->authorization_basic(
186 $self->get_username(),
187 $self->get_password(),
188 );
189  
190 5 my $response = $user_agent->request( $request );
191 5 ▶ croak "Could not get a response from CyberSource"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $response 0 5 5
192 unless defined $response;
193 5 ▶ croak "CyberSource returned the following error: " . $response->status_line()
Branch: 1 branch
BranchTrueFalseTotal
unless $response->is_success 0 5 5
194 unless $response->is_success();
195  
196 5 return $response->content();
197 }
198  
199  
200 =head1 BUGS
201  
202 Please report any bugs or feature requests through the web interface at
203 L<https://github.com/guillaumeaubert/Business-CyberSource-Report/issues/new>.
204 I will be notified, and then you'll automatically be notified of progress on
205 your bug as I make changes.
206  
207  
208 =head1 SUPPORT
209  
210 You can find documentation for this module with the perldoc command.
211  
212 perldoc Business::CyberSource::Report::SingleTransaction
213  
214  
215 You can also look for information at:
216  
217 =over 4
218  
219 =item *
220  
221 GitHub's request tracker
222  
223 L<https://github.com/guillaumeaubert/Business-CyberSource-Report/issues>
224  
225 =item *
226  
227 AnnoCPAN: Annotated CPAN documentation
228  
229 L<http://annocpan.org/dist/business-cybersource-report>
230  
231 =item *
232  
233 CPAN Ratings
234  
235 L<http://cpanratings.perl.org/d/business-cybersource-report>
236  
237 =item *
238  
239 MetaCPAN
240  
241 L<https://metacpan.org/release/Business-CyberSource-Report>
242  
243 =back
244  
245  
246 =head1 AUTHOR
247  
248 L<Guillaume Aubert|https://metacpan.org/author/AUBERTG>, C<< <aubertg at cpan.org> >>.
249  
250  
251 =head1 ACKNOWLEDGEMENTS
252  
253 I originally developed this project for ThinkGeek
254 (L<http://www.thinkgeek.com/>). Thanks for allowing me to open-source it!
255  
256  
257 =head1 COPYRIGHT & LICENSE
258  
259 Copyright 2011-2017 Guillaume Aubert.
260  
261 This code is free software; you can redistribute it and/or modify it under the
262 same terms as Perl 5 itself.
263  
264 This program is distributed in the hope that it will be useful, but WITHOUT ANY
265 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
266 PARTICULAR PURPOSE. See the LICENSE file for more details.
267  
268 =cut
269  
270  
271 5 1;
↑ Summary Report/PaymentEvents.pm »