blib/lib/PagSeguro/Status.pm

filter: Statementstmt 41.4% 17 / 41 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 27.2% 3 / 11 Podpod 100% 3 / 3 totaltotal 40.3% 23 / 57 CC 2 SCAR 8.6
CC
2
Cov
40%
xml_generate
6.0
__ANON__
2.0
__ANON__
2.0
CRAP 2.4
↑ Summary
1 package PagSeguro::Status;
2  
3 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use WWW::Mechanize;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 has 'mechanize' => (
8 isa => 'Object',
9 is => 'ro',
10 0 ▶ default => sub { WWW::Mechanize->new( agent_alias => 'Windows IE 6' ) }
Subroutine __ANON__: not called CC=1 SCAR=6.9
11 2 );
12  
13 =head1 NAME
14  
15 PagSeguro::Status - To know informations about PagSeguro payments!
16  
17 =head1 VERSION
18  
19 Version 0.01
20  
21 =cut
22  
23 2 our $VERSION = '0.02';
24  
25 =head1 SYNOPSIS
26  
27 use PagSeguro::Status;
28 my $a = PagSeguro::Status->new(
29 paglogin => 'youruser@...',
30 pagpass => 'youpass...'
31 from_date => dd/mm/yyyy
32 to_date => dd/mm/yyyy
33 );
34 print $a->fetch_xml #returns a XML;
35  
36 If you do not give the argument "from_date" and "to_date" the default is 1 month.
37  
38 =cut
39  
40 2 has 'paglogin' => ( is => 'rw', required => 1, isa => 'Str' );
41 2 has 'pagpass' => ( is => 'rw', required => 1, isa => 'Str' );
42 has 'from_date' => (
43 is => 'rw',
44 isa => 'Str',
45 0 ▶ default => sub { DateTime->now->subtract( months => 1 )->dmy('/') }
Subroutine __ANON__: not called CC=1 SCAR=6.9
46 2 );
47 has 'to_date' => (
48 is => 'rw',
49 isa => 'Str',
50 0 ▶ default => sub { DateTime->now->dmy('/') }
Subroutine __ANON__: not called CC=1 SCAR=6.9
51 2 );
52  
53 =head2 login
54  
55 Do the login
56  
57 =cut
58  
59 0 ▶sub login {
Subroutine login: not called CC=1 SCAR=6.9
Pod documented
60 0 my $self = shift;
61 0 $self->mechanize->get('https://pagseguro.uol.com.br/');
62 0 $self->mechanize->submit_form(
63 form_number => 1,
64 fields => {
65 userName => $self->paglogin,
66 password => $self->pagpass,
67 }
68 );
69 }
70  
71 =head2 get_days
72  
73 Get the information between from_date and to_date.
74  
75 =cut
76  
77 0 ▶sub get_days {
Subroutine get_days: not called CC=1 SCAR=6.9
Pod documented
78 0 my $self = shift;
79 0 $self->mechanize->get(
80 'https://pagseguro.uol.com.br/transaction/search.jhtml');
81 0 $self->mechanize->submit_form(
82 form_number => 1,
83 fields => {
84 dateFrom => $self->from_date,
85 dateTo => $self->to_date
86 }
87 );
88 0 return 1;
89 }
90  
91 =head2 xml_generate
92  
93 To generate the XML
94  
95 =cut
96  
97 0 ▶sub xml_generate {
Subroutine xml_generate: not called CC=2 SCAR=17.9
Pod documented
98 0 my $self = shift;
99 0 $self->mechanize->get(
100 'https://pagseguro.uol.com.br/transaction/createFile.jhtml?fileType=xml'
101 );
102 0 ▶ if ( $self->mechanize->content =~ /ok\|(.+?)\n/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->mechanize->content =~ /ok\|(.+?)\n/) { } 0 0 0
103 0 my $xml_name = $1;
104 0 return $xml_name;
105 }
106 else {
107 0 die "could not take the xml name";
108 }
109 }
110  
111 0 ▶before 'fetch_xml' => sub { my $self = shift; $self->login; $self->get_days };
Subroutine __ANON__: not called CC=1 SCAR=3.5
112  
113 =head2 fetch_xml
114  
115 Fetch the xml, returns a XML :D
116  
117 =cut
118  
119 0 ▶sub fetch_xml {
Subroutine fetch_xml: not called CC=1 SCAR=6.9
120 0 my $self = shift;
121 0 my $xml_name = $self->xml_generate;
122  
123 # PagSeguro is really sux, maybe have to wait some seconds
124 # to generate de XML
125 0 sleep 5;
126  
127 0 $self->mechanize->get(
128 'https://pagseguro.uol.com.br/transaction/sendFile.jhtml?fileName='
129 . $xml_name );
130 0 return $self->mechanize->content;
131 }
132  
133 =head1 AUTHOR
134  
135 Daniel de Oliveira Mantovani, C<< <daniel.oliveira.mantovani at gmail.com> >>
136  
137 =head1 BUGS
138  
139 Please report any bugs or feature requests to C<bug-pagseguro-status at rt.cpan.org>, or through
140 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=PagSeguro-Status>. I will be notified, and then you'll
141 automatically be notified of progress on your bug as I make changes.
142  
143  
144  
145  
146 =head1 SUPPORT
147  
148 You can find documentation for this module with the perldoc command.
149  
150 perldoc PagSeguro::Status
151  
152  
153 You can also look for information at:
154  
155 =over 4
156  
157 =item * RT: CPAN's request tracker (report bugs here)
158  
159 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=PagSeguro-Status>
160  
161 =item * AnnoCPAN: Annotated CPAN documentation
162  
163 L<http://annocpan.org/dist/PagSeguro-Status>
164  
165 =item * CPAN Ratings
166  
167 L<http://cpanratings.perl.org/d/PagSeguro-Status>
168  
169 =item * Search CPAN
170  
171 L<http://search.cpan.org/dist/PagSeguro-Status/>
172  
173 =back
174  
175  
176 =head1 ACKNOWLEDGEMENTS
177  
178  
179 =head1 LICENSE AND COPYRIGHT
180  
181 Copyright 2011 Daniel de Oliveira Mantovani.
182  
183 This program is free software; you can redistribute it and/or modify it
184 under the terms of either: the GNU General Public License as published
185 by the Free Software Foundation; or the Artistic License.
186  
187 See http://dev.perl.org/licenses/ for more information.
188  
189  
190 =cut
191  
192 2 666; # PagSeguro is the devil!
↑ Summary