File Coverage

blib/lib/Business/CyberSource/Report/PaymentEvents.pm
Criterion Covered Total %
statement 32 32 100.0
branch 9 12 75.0
condition 4 6 66.6
subroutine 7 7 100.0
pod 1 1 100.0
total 53 58 91.3


line stmt bran cond sub pod time code
1             package Business::CyberSource::Report::PaymentEvents;
2              
3 4     4   25581 use strict;
  4         7  
  4         125  
4 4     4   17 use warnings;
  4         6  
  4         134  
5              
6 4     4   18 use base 'Business::CyberSource::Report';
  4         5  
  4         1012  
7              
8 4     4   46 use Carp;
  4         7  
  4         276  
9 4     4   1970 use HTTP::Request::Common qw();
  4         68844  
  4         101  
10 4     4   2330 use LWP::UserAgent qw();
  4         61895  
  4         1237  
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             our $VERSION = '1.2.0';
25              
26             our $TEST_URL = 'https://ebctest.cybersource.com/ebctest';
27             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. This is useful for tests, see the documentation
81             for L in particular.
82              
83             =back
84              
85             =cut
86              
87             sub retrieve
88             {
89 7     7 1 8709 my ( $self, %args ) = @_;
90 7         11 my $format = delete( $args{'format'} );
91 7         10 my $date = delete( $args{'date'} );
92 7   33     20 my $user_agent = delete( $args{'user_agent'} ) || LWP::UserAgent->new();
93              
94             # Verify the format.
95 7 100 100     98 croak "The format needs to be 'csv' or 'xml'"
96             unless defined( $format ) && ( $format =~ m/^(csv|xml)$/ );
97              
98             # Verify the date.
99 5 100       23 croak 'You need to specify a date for the transactions to retrieve'
100             unless defined( $date );
101 4 100       34 croak 'The format for the date of the transactions to retrieve is YYYY/MM/DD'
102             unless $date =~ m/^\d{4}\/\d{2}\/\d{2}$/;
103              
104             # Prepare the URL to hit.
105 3 50       28 my $url = ( $self->use_production_system() ? $PRODUCTION_URL : $TEST_URL )
106             . '/DownloadReport/' . $date . '/' . $self->get_merchant_id()
107             . '/PaymentEventsReport.' . $format;
108              
109             # Send the query.
110 3         15 my $request = HTTP::Request::Common::GET( $url );
111 3         7815 $request->authorization_basic(
112             $self->get_username(),
113             $self->get_password(),
114             );
115              
116 3         1444 my $response = $user_agent->request( $request );
117 3 50       3076 croak "Could not get a response from CyberSource"
118             unless defined $response;
119 3 50       9 croak "CyberSource returned the following error: " . $response->status_line()
120             unless $response->is_success();
121              
122 3         28 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.
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
150              
151             =item *
152              
153             AnnoCPAN: Annotated CPAN documentation
154              
155             L
156              
157             =item *
158              
159             CPAN Ratings
160              
161             L
162              
163             =item *
164              
165             MetaCPAN
166              
167             L
168              
169             =back
170              
171              
172             =head1 AUTHOR
173              
174             L, C<< >>.
175              
176              
177             =head1 ACKNOWLEDGEMENTS
178              
179             I originally developed this project for ThinkGeek
180             (L). 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             1;