line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mollie::Micropayment;
|
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
44767
|
use strict;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
51
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
38
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
6
|
use Carp;
|
|
1
|
|
|
|
|
261
|
|
|
1
|
|
|
|
|
122
|
|
7
|
1
|
|
|
1
|
|
1545
|
use LWP::Simple;
|
|
1
|
|
|
|
|
143839
|
|
|
1
|
|
|
|
|
9
|
|
8
|
1
|
|
|
1
|
|
1073
|
use XML::Simple;
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
require Exporter;
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our @ISA = qw(Exporter);
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# Items to export into callers namespace by default. Note: do not export
|
15
|
|
|
|
|
|
|
# names by default without a very good reason. Use EXPORT_OK instead.
|
16
|
|
|
|
|
|
|
# Do not simply export all your public functions/methods/constants.
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# This allows declaration use Mollie::Micropayment ':all';
|
19
|
|
|
|
|
|
|
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
|
20
|
|
|
|
|
|
|
# will save memory.
|
21
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw(
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
) ] );
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
our @EXPORT = qw(
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
);
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
our $VERSION = '0.04';
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
##################################################
|
35
|
|
|
|
|
|
|
# Object constructor
|
36
|
|
|
|
|
|
|
##################################################
|
37
|
|
|
|
|
|
|
sub new {
|
38
|
|
|
|
|
|
|
my($class,$wordlist,$replacement) = @_;
|
39
|
|
|
|
|
|
|
my $self = { };
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# default vars
|
42
|
|
|
|
|
|
|
$self->{'partnerid'} = undef;
|
43
|
|
|
|
|
|
|
$self->{'amount'} = 1.30;
|
44
|
|
|
|
|
|
|
$self->{'report'} = undef;
|
45
|
|
|
|
|
|
|
$self->{'country'} = 31;
|
46
|
|
|
|
|
|
|
$self->{'servicenumber'} = undef;
|
47
|
|
|
|
|
|
|
$self->{'paycode'} = undef;
|
48
|
|
|
|
|
|
|
$self->{'duration'} = undef;
|
49
|
|
|
|
|
|
|
$self->{'mode'} = undef;
|
50
|
|
|
|
|
|
|
$self->{'costperminute'} = undef;
|
51
|
|
|
|
|
|
|
$self->{'costpercall'} = undef;
|
52
|
|
|
|
|
|
|
$self->{'currency'} = undef;
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# after a paycheck is done, we can use these vars
|
55
|
|
|
|
|
|
|
$self->{'payed'} = "false";
|
56
|
|
|
|
|
|
|
$self->{'durationdone'} = 0;
|
57
|
|
|
|
|
|
|
$self->{'durationleft'} = undef;
|
58
|
|
|
|
|
|
|
$self->{'paystatus'} = undef;
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# And I give you my blessing
|
62
|
|
|
|
|
|
|
return bless $self,$class;
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
}
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
##################################################
|
67
|
|
|
|
|
|
|
# For debugging purposes only!
|
68
|
|
|
|
|
|
|
##################################################
|
69
|
|
|
|
|
|
|
sub printenv {
|
70
|
|
|
|
|
|
|
my $self = shift;
|
71
|
|
|
|
|
|
|
warn __PACKAGE__ . '->printenv() has been deprecated and will be removed in the future!';
|
72
|
|
|
|
|
|
|
foreach my $key(sort(keys(%{$self}))) {
|
73
|
|
|
|
|
|
|
print $key . ": " . $self->{$key} . "\n";
|
74
|
|
|
|
|
|
|
}
|
75
|
|
|
|
|
|
|
}
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
##################################################
|
78
|
|
|
|
|
|
|
# Set/gets the partnerid gotten from Mollie
|
79
|
|
|
|
|
|
|
##################################################
|
80
|
|
|
|
|
|
|
sub partnerid {
|
81
|
|
|
|
|
|
|
my $self = shift;
|
82
|
|
|
|
|
|
|
if (@_) { $self->{"partnerid"} = shift }
|
83
|
|
|
|
|
|
|
return $self->{"partnerid"};
|
84
|
|
|
|
|
|
|
}
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
##################################################
|
87
|
|
|
|
|
|
|
# Set/gets the amount the user has to pay
|
88
|
|
|
|
|
|
|
# Amount can be a float (0.00) but must be over
|
89
|
|
|
|
|
|
|
# 0.40 because Mollie doesn't accept amounts
|
90
|
|
|
|
|
|
|
# lower than 0.41
|
91
|
|
|
|
|
|
|
##################################################
|
92
|
|
|
|
|
|
|
sub amount {
|
93
|
|
|
|
|
|
|
my($self,$amount) = @_;
|
94
|
|
|
|
|
|
|
if ($amount > 0 || $amount eq "endless") {
|
95
|
|
|
|
|
|
|
$self->{'amount'} = $amount;
|
96
|
|
|
|
|
|
|
} elsif(length($amount) == 0) {
|
97
|
|
|
|
|
|
|
# It's ok, user is asking the amount
|
98
|
|
|
|
|
|
|
} else {
|
99
|
|
|
|
|
|
|
croak("False amount has been set. Only 'endless' or a numeric value can be set.");
|
100
|
|
|
|
|
|
|
}
|
101
|
|
|
|
|
|
|
return $self->{'amount'};
|
102
|
|
|
|
|
|
|
}
|
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
##################################################
|
105
|
|
|
|
|
|
|
# Sets country code. Also checks if code is OK
|
106
|
|
|
|
|
|
|
##################################################
|
107
|
|
|
|
|
|
|
sub country {
|
108
|
|
|
|
|
|
|
my($self,$country) = @_;
|
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
my %codes;
|
112
|
|
|
|
|
|
|
$codes{'31'} = "NL";
|
113
|
|
|
|
|
|
|
$codes{'32'} = "BE";
|
114
|
|
|
|
|
|
|
$codes{'33'} = "FR";
|
115
|
|
|
|
|
|
|
$codes{'39'} = "IT";
|
116
|
|
|
|
|
|
|
$codes{'41'} = "CH";
|
117
|
|
|
|
|
|
|
$codes{'43'} = "AT";
|
118
|
|
|
|
|
|
|
$codes{'44'} = "UK";
|
119
|
|
|
|
|
|
|
$codes{'49'} = "DE";
|
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
if (int($country) && exists($codes{$country})) {
|
122
|
|
|
|
|
|
|
$self->{'country'} = $country;
|
123
|
|
|
|
|
|
|
} else {
|
124
|
|
|
|
|
|
|
croak("False country code used.");
|
125
|
|
|
|
|
|
|
}
|
126
|
|
|
|
|
|
|
}
|
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
##################################################
|
129
|
|
|
|
|
|
|
# Sets/gets the report URL. Can be used to let Mollie
|
130
|
|
|
|
|
|
|
# send a response to the adres(url) in $adres
|
131
|
|
|
|
|
|
|
##################################################
|
132
|
|
|
|
|
|
|
sub reporturl {
|
133
|
|
|
|
|
|
|
my $self = shift;
|
134
|
|
|
|
|
|
|
if (@_) { $self->{"report"} = shift }
|
135
|
|
|
|
|
|
|
return $self->{"report"};
|
136
|
|
|
|
|
|
|
}
|
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
##################################################
|
139
|
|
|
|
|
|
|
# Sets/gets the servicenumber
|
140
|
|
|
|
|
|
|
##################################################
|
141
|
|
|
|
|
|
|
sub servicenumber {
|
142
|
|
|
|
|
|
|
my $self = shift;
|
143
|
|
|
|
|
|
|
if (@_) { $self->{"servicenumber"} = shift }
|
144
|
|
|
|
|
|
|
return $self->{"servicenumber"};
|
145
|
|
|
|
|
|
|
}
|
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
##################################################
|
148
|
|
|
|
|
|
|
# Sets/gets paycode
|
149
|
|
|
|
|
|
|
##################################################
|
150
|
|
|
|
|
|
|
sub paycode {
|
151
|
|
|
|
|
|
|
my $self = shift;
|
152
|
|
|
|
|
|
|
if (@_) { $self->{"paycode"} = shift }
|
153
|
|
|
|
|
|
|
return $self->{"paycode"};
|
154
|
|
|
|
|
|
|
}
|
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
##################################################
|
157
|
|
|
|
|
|
|
# Get payment info from Mollie
|
158
|
|
|
|
|
|
|
##################################################
|
159
|
|
|
|
|
|
|
sub payinfo {
|
160
|
|
|
|
|
|
|
my $self = shift;
|
161
|
|
|
|
|
|
|
my $response = get( "http://www.mollie.nl/xml/micropayment/" .
|
162
|
|
|
|
|
|
|
"?a=fetch" .
|
163
|
|
|
|
|
|
|
"&partnerid=" . CGI::escape($self->{'partnerid'}) .
|
164
|
|
|
|
|
|
|
"&amount=" . CGI::escape($self->{'amount'}) .
|
165
|
|
|
|
|
|
|
"&servicenumber=" . CGI::escape($self->{'servicenumber'}) .
|
166
|
|
|
|
|
|
|
"&country=" . CGI::escape($self->{'country'}) .
|
167
|
|
|
|
|
|
|
"&report=" . CGI::escape($self->{'report'})
|
168
|
|
|
|
|
|
|
);
|
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
if(substr($response,0,5) eq "Error") {
|
171
|
|
|
|
|
|
|
croak("Error while retrieving payment info. Not a valid XML response!");
|
172
|
|
|
|
|
|
|
}
|
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
my $xs = XML::Simple->new();
|
175
|
|
|
|
|
|
|
my $xml = $xs->XMLin($response);
|
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
$self->{'servicenumber'} = exists($xml->{'item'}{'servicenumber'}) ? $xml->{'item'}{'servicenumber'} : undef;
|
178
|
|
|
|
|
|
|
$self->{'paycode'} = exists($xml->{'item'}{'paycode'}) ? $xml->{'item'}{'paycode'} : undef;
|
179
|
|
|
|
|
|
|
$self->{'amount'} = exists($xml->{'item'}{'amount'}) ? $xml->{'item'}{'amount'} : 0;
|
180
|
|
|
|
|
|
|
$self->{'duration'} = exists($xml->{'item'}{'duration'}) ? $xml->{'item'}{'duration'} : undef;
|
181
|
|
|
|
|
|
|
$self->{'mode'} = exists($xml->{'item'}{'mode'}) ? $xml->{'item'}{'mode'} : undef;
|
182
|
|
|
|
|
|
|
$self->{'costperminute'} = exists($xml->{'item'}{'costperminute'}) ? $xml->{'item'}{'costperminute'} : undef;
|
183
|
|
|
|
|
|
|
$self->{'costpercall'} = exists($xml->{'item'}{'costpercall'}) ? $xml->{'item'}{'costpercall'} : undef;
|
184
|
|
|
|
|
|
|
$self->{'currency'} = exists($xml->{'item'}{'currency'}) ? $xml->{'item'}{'currency'} : undef;
|
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
return 1;
|
187
|
|
|
|
|
|
|
}
|
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
##################################################
|
190
|
|
|
|
|
|
|
# Check the payment status from Mollie
|
191
|
|
|
|
|
|
|
##################################################
|
192
|
|
|
|
|
|
|
sub checkpayment {
|
193
|
|
|
|
|
|
|
my $self = shift;
|
194
|
|
|
|
|
|
|
my $response = get( "http://www.mollie.nl/xml/micropayment/" .
|
195
|
|
|
|
|
|
|
"?a=check" .
|
196
|
|
|
|
|
|
|
"&servicenumber=" . CGI::escape($self->{'servicenumber'}) .
|
197
|
|
|
|
|
|
|
"&paycode=" . CGI::escape($self->{'paycode'}));
|
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
if($response eq "Payment unknown.") {
|
200
|
|
|
|
|
|
|
croak("Error while checking payment. Not a valid XML response!");
|
201
|
|
|
|
|
|
|
}
|
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
my $xs = XML::Simple->new();
|
204
|
|
|
|
|
|
|
my $xml = $xs->XMLin($response);
|
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
$self->{'payed'} = exists($xml->{'item'}{'payed'}) ? $xml->{'item'}{'payed'} : "false";
|
208
|
|
|
|
|
|
|
$self->{'durationdone'} = exists($xml->{'item'}{'durationdone'}) ? $xml->{'item'}{'durationdone'} : 0;
|
209
|
|
|
|
|
|
|
$self->{'durationleft'} = exists($xml->{'item'}{'durationleft'}) ? $xml->{'item'}{'durationleft'} : undef;
|
210
|
|
|
|
|
|
|
$self->{'paystatus'} = exists($xml->{'item'}{'paystatus'}) ? $xml->{'item'}{'paystatus'} : undef;
|
211
|
|
|
|
|
|
|
$self->{'amount'} = exists($xml->{'item'}{'amount'}) ? $xml->{'item'}{'amount'} : undef;
|
212
|
|
|
|
|
|
|
$self->{'duration'} = exists($xml->{'item'}{'duration'}) ? $xml->{'item'}{'duration'} : undef;
|
213
|
|
|
|
|
|
|
$self->{'mode'} = exists($xml->{'item'}{'mode'}) ? $xml->{'item'}{'mode'} : undef;
|
214
|
|
|
|
|
|
|
$self->{'costperminute'} = exists($xml->{'item'}{'costperminute'}) ? $xml->{'item'}{'costperminute'} : undef;
|
215
|
|
|
|
|
|
|
$self->{'costpercall'} = exists($xml->{'item'}{'costpercall'}) ? $xml->{'item'}{'costpercall'} : undef;
|
216
|
|
|
|
|
|
|
$self->{'currency'} = exists($xml->{'item'}{'currency'}) ? $xml->{'item'}{'currency'} : undef;
|
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
return $self->{'payed'};
|
219
|
|
|
|
|
|
|
}
|
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
##################################################
|
222
|
|
|
|
|
|
|
# Check if user has completed payment or not
|
223
|
|
|
|
|
|
|
##################################################
|
224
|
|
|
|
|
|
|
sub is_payed {
|
225
|
|
|
|
|
|
|
my $self = shift;
|
226
|
|
|
|
|
|
|
return $self->{'payed'};
|
227
|
|
|
|
|
|
|
}
|
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
##################################################
|
230
|
|
|
|
|
|
|
# Retrieve currency (eur,dollar,gbp)
|
231
|
|
|
|
|
|
|
##################################################
|
232
|
|
|
|
|
|
|
sub currency {
|
233
|
|
|
|
|
|
|
my $self = shift;
|
234
|
|
|
|
|
|
|
return $self->{'currency'};
|
235
|
|
|
|
|
|
|
}
|
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
##################################################
|
238
|
|
|
|
|
|
|
# Retrieve the mode (ppc or ppm)
|
239
|
|
|
|
|
|
|
##################################################
|
240
|
|
|
|
|
|
|
sub mode {
|
241
|
|
|
|
|
|
|
my $self = shift;
|
242
|
|
|
|
|
|
|
return $self->{'mode'};
|
243
|
|
|
|
|
|
|
}
|
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
##################################################
|
246
|
|
|
|
|
|
|
# Retrieve cost per call. Only for ppc
|
247
|
|
|
|
|
|
|
##################################################
|
248
|
|
|
|
|
|
|
sub costpercall {
|
249
|
|
|
|
|
|
|
my $self = shift;
|
250
|
|
|
|
|
|
|
return $self->{'costpercall'};
|
251
|
|
|
|
|
|
|
}
|
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
##################################################
|
254
|
|
|
|
|
|
|
# Retrieve cost per minute. Only for ppm
|
255
|
|
|
|
|
|
|
##################################################
|
256
|
|
|
|
|
|
|
sub costperminute {
|
257
|
|
|
|
|
|
|
my $self = shift;
|
258
|
|
|
|
|
|
|
return $self->{'costperminute'};
|
259
|
|
|
|
|
|
|
}
|
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
##################################################
|
262
|
|
|
|
|
|
|
# Retrieve duration of call for ppm
|
263
|
|
|
|
|
|
|
##################################################
|
264
|
|
|
|
|
|
|
sub duration {
|
265
|
|
|
|
|
|
|
my $self = shift;
|
266
|
|
|
|
|
|
|
return $self->{'duration'};
|
267
|
|
|
|
|
|
|
}
|
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
1;
|
271
|
|
|
|
|
|
|
__END__
|