Report/PaymentEvents.pm

filter: Statementstmt 100% 36 / 36 Branchbran 75.0% 9 / 12 Conditioncond 66.6% 4 / 6 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 89.3% 59 / 66 CC 9 SCAR 17.9
CC
9
Cov
91%
retrieve
9.3
BEGIN
1.0
BEGIN
1.0
CRAP 6.0
« Report/SingleTransaction.pm ↑ Summary Report.pm »
1 package Business::CyberSource::Report::PaymentEvents;
2  
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  
6 4 ▶use base 'Business::CyberSource::Report';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use HTTP::Request::Common qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use LWP::UserAgent qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12  
13 =head1 NAME
14  
15 Business::CyberSource::Report::PaymentEvents - Interface to CyberSource's Payment Events report.
16  
17  
18 =head1 VERSION
19  
20 Version 1.2.0
21  
22 =cut
23  
24 4 our $VERSION = '1.2.0';
25  
26 4 our $TEST_URL = 'https://ebctest.cybersource.com/ebctest';
27 4 our $PRODUCTION_URL = 'https://ebc.cybersource.com/ebc';
28  
29  
30 =head1 SYNOPSIS
31  
32 This module is an interface to the Payment Events 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::PaymentEvents object.
44 my $payment_events_report = $report_factory->build( 'PaymentEvents' );
45  
46 # Retrieve the Payment Events report for a given date.
47 $payment_events_report->retrieve(
48 format => $format,
49 date => $date,
50 );
51  
52  
53 =head1 METHODS
54  
55 =head2 retrieve()
56  
57 Build and send the request to CyberSource.
58  
59 # Retrieve the Payment Events report for a given date.
60 $payment_events_report->retrieve(
61 format => $format,
62 date => $date,
63 );
64  
65 Parameters:
66  
67 =over
68  
69 =item * format (mandatory)
70  
71 The desired format of the report, 'csv' or 'xml'.
72  
73 =item * date (mandatory)
74  
75 The date of the transactions to include in the report, using the format
76 YYYY/MM/DD.
77  
78 =item * user_agent (optional)
79  
80 By default, C<LWP::UserAgent>. This is useful for tests, see the documentation
81 for L<Test::LWP::UserAgent> in particular.
82  
83 =back
84  
85 =cut
86  
87 sub retrieve
88 7 ▶{
Subroutine retrieve: called CC=9 SCAR=22.3
Pod documented
89 7 my ( $self, %args ) = @_;
90 7 my $format = delete( $args{'format'} );
91 7 my $date = delete( $args{'date'} );
92 7 ▶ 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
700
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
93  
94 # Verify the format.
95 7 ▶ croak "The format needs to be 'csv' or 'xml'"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $format and $format =~ /^(csv|xml)$/ 2 5 7
Condition100%3/3
defined $format and $format =~ /^(csv|xml)$/
!ll&&!rl&&r
115
MC/DC100%2/2
defined $format and $format =~ /^(csv|xml)$/
defined $format $format =~ /^(csv|xml)$/
Truth table100%3/3
A and B
A= defined $formatB= $format =~ /^(csv|xml)$/
ABresult
0X0
100
111
96 unless defined( $format ) && ( $format =~ m/^(csv|xml)$/ );
97  
98 # Verify the date.
99 5 ▶ croak 'You need to specify a date for the transactions to retrieve'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $date 1 4 5
100 unless defined( $date );
101 4 ▶ croak 'The format for the date of the transactions to retrieve is YYYY/MM/DD'
Branch: 1 branch
BranchTrueFalseTotal
unless $date =~ m[^\d{4}/\d{2}/\d{2}$] 1 3 4
102 unless $date =~ m/^\d{4}\/\d{2}\/\d{2}$/;
103  
104 # Prepare the URL to hit.
105 3 ▶ my $url = ( $self->use_production_system() ? $PRODUCTION_URL : $TEST_URL )
Branch: 1 branch
BranchTrueFalseTotal
$self->use_production_system ? : 0 3 3
106 . '/DownloadReport/' . $date . '/' . $self->get_merchant_id()
107 . '/PaymentEventsReport.' . $format;
108  
109 # Send the query.
110 3 my $request = HTTP::Request::Common::GET( $url );
111 3 $request->authorization_basic(
112 $self->get_username(),
113 $self->get_password(),
114 );
115  
116 3 my $response = $user_agent->request( $request );
117 3 ▶ croak "Could not get a response from CyberSource"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $response 0 3 3
118 unless defined $response;
119 3 ▶ croak "CyberSource returned the following error: " . $response->status_line()
Branch: 1 branch
BranchTrueFalseTotal
unless $response->is_success 0 3 3
120 unless $response->is_success();
121  
122 3 return $response->content();
123 }
124  
125  
126 =head1 BUGS
127  
128 Please report any bugs or feature requests through the web interface at
129 L<https://github.com/guillaumeaubert/Business-CyberSource-Report/issues/new>.
130 I will be notified, and then you'll automatically be notified of progress on
131 your bug as I make changes.
132  
133  
134 =head1 SUPPORT
135  
136 You can find documentation for this module with the perldoc command.
137  
138 perldoc Business::CyberSource::Report::PaymentEvents
139  
140  
141 You can also look for information at:
142  
143 =over 4
144  
145 =item *
146  
147 GitHub's request tracker
148  
149 L<https://github.com/guillaumeaubert/Business-CyberSource-Report/issues>
150  
151 =item *
152  
153 AnnoCPAN: Annotated CPAN documentation
154  
155 L<http://annocpan.org/dist/business-cybersource-report>
156  
157 =item *
158  
159 CPAN Ratings
160  
161 L<http://cpanratings.perl.org/d/business-cybersource-report>
162  
163 =item *
164  
165 MetaCPAN
166  
167 L<https://metacpan.org/release/Business-CyberSource-Report>
168  
169 =back
170  
171  
172 =head1 AUTHOR
173  
174 L<Guillaume Aubert|https://metacpan.org/author/AUBERTG>, C<< <aubertg at cpan.org> >>.
175  
176  
177 =head1 ACKNOWLEDGEMENTS
178  
179 I originally developed this project for ThinkGeek
180 (L<http://www.thinkgeek.com/>). Thanks for allowing me to open-source it!
181  
182  
183 =head1 COPYRIGHT & LICENSE
184  
185 Copyright 2011-2017 Guillaume Aubert.
186  
187 This code is free software; you can redistribute it and/or modify it under the
188 same terms as Perl 5 itself.
189  
190 This program is distributed in the hope that it will be useful, but WITHOUT ANY
191 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
192 PARTICULAR PURPOSE. See the LICENSE file for more details.
193  
194 =cut
195  
196  
197 4 1;
« Report/SingleTransaction.pm ↑ Summary Report.pm »