blib/lib/Finance/Bank/Sporo.pm

filter: Statementstmt 27.2% 18 / 66 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 33.3% 4 / 12 Podpod 100% 5 / 5 totaltotal 27.5% 27 / 98 CC 8 SCAR 23.4
CC
8
Cov
23%
new
30.0
configure
6.0
pay_link
6.0
CRAP 10.4
↑ Summary
1 ##############################################################################
2 #
3 # Copyright (c) 2000 Jan 'Kozo' Vajda <Jan.Vajda@pobox.sk>
4 # All rights reserved.
5 #
6 ##############################################################################
7  
8 package Finance::Bank::Sporo;
9 1 require Exporter;
10  
11 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $AUTOLOAD);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use URI::Escape;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 ### my initial version was 0.11
17 1 $VERSION = '0.16';
18  
19 1 @ISA = qw(Exporter);
20  
21 # Items to export into callers namespace by default
22 1 @EXPORT = qw();
23  
24 # Other items we are prepared to export if requested
25 1 @EXPORT_OK = qw();
26  
27  
28 =head1 NAME
29  
30 Finance::Bank::Sporo - Perl extension for B<SporoPay> of Slovenska Sporitelna.
31  
32 =head1 VERSION
33  
34 0.16
35  
36 =head1 SYNOPSIS
37  
38 use Finance::Bank::Sporo;
39  
40 $sporo_obj = Bank::Sporo->new($prenumber,$number);
41  
42 $sporo_obj->configure(
43 amt => $amt,
44 vs => $vs,
45 ss => $ss,
46 rurl => $rurl,
47 param => $param,
48 );
49  
50  
51 print $sporo_obj->pay_form();
52  
53 =head1 DESCRIPTION
54  
55 Module for generating pay forms and links for B<SporoPay> of Slovenska
56 Sporitelna (http://www.slsp.sk/).
57  
58 =head1 USE
59  
60 =head2 Functions ( or Methods ? )
61  
62 =item new
63  
64 $sporo_obj = Finance::Bank::Sporo->new($prenumber,$number);
65  
66 This creates a new Finance::Bank::Sporo object using $prenumber as a "Predcisle uctu"
67 and $number as a "Cislo uctu"
68  
69 =cut
70  
71  
72 0 ▶sub new {
Subroutine new: not called CC=5 SCAR=34.0
Pod documented
73 0 my $type = shift;
74 0 ▶ my $class = ref($type) || $type;
Condition0%0/3
ref $type || $type
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $type || $type
ref $type $type
Truth table0%0/3
A || B
A= ref $typeB= $type
ABresult
1X1
011
000
75 0 ▶ croak "Usage $class->new (PRENUMBER, NUMBER)" if ( @_ != 2 ) ;
Branch: 1 branch
BranchTrueFalseTotal
if @_ != 2 0 0 0
76 0 my $self = {};
77 0 bless $self, $class;
78  
79 0 $self->{'prenumber'} = shift;
80 0 $self->{'prenumber'} = sprintf("%06.0d",$self->{'prenumber'});
81 0 $self->{'number'} = shift;
82 0 $self->{'number'} = sprintf("%010.0d",$self->{'number'});
83  
84 0 ▶ croak "Number must be 10 numbers" if ( length($self->{'number'}) != 10 );
Branch: 1 branch
BranchTrueFalseTotal
if length $self->{"number"} != 10 0 0 0
85 0 ▶ croak "PreNumber must be 6 numbers" if ( length($self->{'prenumber'}) != 6 );
Branch: 1 branch
BranchTrueFalseTotal
if length $self->{"prenumber"} != 6 0 0 0
86
87 0 $self->_init;
88  
89 0 return($self);
90 }
91  
92 0 ▶sub _init {
Subroutine _init: not called CC=1 SCAR=6.9
93 0 my $self = shift;
94  
95 ### default values
96 0 $self->{'action_url'} = "https://ib.slsp.sk/epayment/epayment/epayment.xml";
97 0 $self->{'image_src'} = '/PICS/sporopay_logo.gif';
98 0 $self->{'currency'} = 'SKK';
99 0 $self->{'kbanky'} = '0900';
100 0 $self->{'ss'} = '';
101 0 return($self);
102 }
103  
104  
105 =item configure
106  
107 $sporo_obj->configure(
108 amt => $amt,
109 vs => $vs,
110 ss => $ss,
111 rurl => $rurl,
112 param => $param,
113 image_src => '/PICS/sporopay_logo.gif',
114 );
115  
116  
117 Set correct values to object.
118 Possible parameters is:
119 amt => Amount
120 vs => Variable Symbol
121 ss => Specific Symbol
122 rurl => Redirect URL
123 image_src => Path to image ( relative to DocumentRoot )
124 param => any parameter
125
126 Possible but default correct parameter is:
127  
128 action_url => SporoPayPay action URL
129 default:
130 https://ib.slsp.sk/epayment/epayment/epayment.xml
131  
132 image_src => Path to image ( relative to DocumentRoot )
133 default:
134 /PICS/sporopay_logo.gif
135  
136
137  
138 =cut
139  
140 0 ▶sub configure {
Subroutine configure: not called CC=2 SCAR=17.9
Pod documented
141 0 my $self = shift;
142 0 my (%arg) = @_;
143  
144 ### normalization
145 0 foreach (keys %arg) {
146 ### konvert name to lowercase
147 0 $self->{"\L$_"} = $arg{$_};
148 }
149 0 return($self);
150 }
151  
152 =item pay_form
153  
154 print $sporo_obj->pay_form();
155  
156 Return HTML FORM.
157  
158 =cut
159  
160 0 ▶sub pay_form {
Subroutine pay_form: not called CC=1 SCAR=6.9
Pod documented
161 0 my $self =shift;
162  
163 0 my $action = $self->{action_url};
164  
165  
166 0 my $sporo_form = <<EOM;
167 <!-- SporoPay form start -->
168 <form action="$action" method=POST>
169 <input type=hidden name=pu_predcislo value="$self->{prenumber}">
170 <input type=hidden name=pu_cislo value="$self->{number}">
171 <input type=hidden name=pu_kbanky value="$self->{kbanky}">
172 <input type=hidden name=suma value="$self->{amt}">
173 <input type=hidden name=mena value="$self->{currency}">
174 <input type=hidden name=vs value="$self->{vs}">
175 <input type=hidden name=ss value="$self->{ss}">
176 <input type=hidden name=url value="$self->{rurl}">
177 <input type=hidden name=param value="$self->{param}">
178 <input type=image src="$self->{image_src}" border=0>
179 </form>
180 <!-- SporoPay form end -->
181 EOM
182  
183 0 return($sporo_form);
184 }
185  
186 =item generic_pay_form
187  
188 print $sporo_obj->generic_pay_form($type);
189  
190 Return HTML FORM for payment with submit button.
191  
192 =cut
193  
194 0 ▶sub generic_pay_form {
Subroutine generic_pay_form: not called CC=1 SCAR=6.9
Pod documented
195 0 my $self =shift;
196  
197 0 my $action = $self->{action_url};
198  
199  
200 0 my $sporo_form = <<EOM;
201 <!-- SporoPay form start -->
202 <form action="$action" method=POST>
203 <input type=hidden name=pu_predcislo value="$self->{prenumber}">
204 <input type=hidden name=pu_cislo value="$self->{number}">
205 <input type=hidden name=pu_kbanky value="$self->{kbanky}">
206 <input type=hidden name=suma value="$self->{amt}">
207 <input type=hidden name=mena value="$self->{currency}">
208 <input type=hidden name=vs value="$self->{vs}">
209 <input type=hidden name=ss value="$self->{ss}">
210 <input type=hidden name=url value="$self->{rurl}">
211 <input type=hidden name=param value="$self->{param}">
212 <input type=submit value="Suhlasim">
213 </form>
214 <!-- SporoPay form end -->
215 EOM
216  
217 0 return($sporo_form);
218 }
219  
220  
221  
222 =item pay_link
223  
224 print $sporo_obj->pay_link();
225  
226 Return URL for payment.
227  
228 =cut
229  
230 0 ▶sub pay_link {
Subroutine pay_link: not called CC=2 SCAR=17.9
Pod documented
231 0 my $self =shift;
232  
233 0 my $action = $self->{action_url};
234  
235 0 my $sporo_form = <<EOM;
236 $action ?
237 pu_predcislo=$self->{prenumber} &
238 pu_cislo=$self->{number} &
239 pu_kbanky=$self->{kbanky} &
240 suma=$self->{amt} &
241 mena=$self->{currency} &
242 vs=$self->{vs} &
243 ss=$self->{ss} &
244 url=$self->{rurl} &
245 EOM
246  
247 0 ▶if ( $self->{param} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"param"}) 0 0 0
248 0 my $param = uri_escape($self->{param},"^A-Za-z0-9");
249 0 $sporo_form .= <<EOM;
250 param=$param
251 EOM
252 }
253 0 $sporo_form =~ s/\n//og;
254 0 $sporo_form =~ s/\s+//og;
255  
256 0 return($sporo_form);
257 }
258  
259  
260 0 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: not called CC=2 SCAR=17.9
261 0 my $self = shift;
262 0 my $value = shift;
263 0 my ($name) = $AUTOLOAD;
264  
265 0 ($name) = ( $name =~ /^.*::(.*)/);
266  
267 0 ▶ $self->{$name} = $value if ( defined $value );
Branch: 1 branch
BranchTrueFalseTotal
if defined $value 0 0 0
268  
269 0 return($self->{$name});
270
271 }
272  
273 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=1 SCAR=0.0
274 ### bye bye
275 }
276  
277 1 1;
278  
279 __END__
↑ Summary