Business::PhoneBill::Allopass - A class for micro-payment system from Allopass
use Business::PhoneBill::Allopass; my $allopass=Business::PhoneBill::Allopass->new($session_file, [$ttl]); die "Cann't create class: ".$allopass unless ref $allopass; # Check access if ($allopass->check($document_id, [$RECALL])){ print "OK\n"; } else { print $allopass->get_last_error; } # No further access for this user $allopass->end_session($document_id); =head1 DESCRIPTION
This class provides you an easy api to the allopass.com system. It automatically handles user sessions.
Please consider using Business::PhoneBill::Allopass::Simple if you don't need session management.
See http://www.allopass.com/index.php4?ADV=1508058 for more informations on their system and how it basically works.
$allopass=Billing::Allopass->new($session_file, [$ttl]);
$session_file is the physical location for the session file. The webserver must have write access to it. If not, this constructor returns a text error message.
$ttl is the number of minutes of inactivity for automatically removing sessions. Default : 60.
You have to test if the returned value is a reference.
$ok=$allopass->check($document_id, [$RECALL]);
The RECALL parameter is provided by Allopass.com when it redirects the visitor to your website, after the secret code verification. Returns 1 if authorization is successfull. Next accesses to the script will be protected by the session-based system, and you no longer need to provide the $RECALL argument..
=cut
sub check {
my $self=shift;
my $doc_id=shift || return 0;
my $code = shift || '';
my ($res, $ua, $req);
if ($self->_is_session($doc_id)) {
return 1;
} elsif ($code) {
$ua = LWP::UserAgent->new;
$ua->agent('Business::PhoneBill::Allopass/'.$VERSION);
$req = POST $baseurl,
[
'CODE' => $code ,
'AUTH' => $doc_id ,
];
$res = $ua->simple_request($req)->as_string;
if($self->_is_res_ok($res)) {
$self->_add_session($doc_id, $code);
$self->_set_error('Allopass Recall OK');
return 1;
}
}
0;
}
$allopass->end_session($document_id);
$allopass->get_last_error();
$ok=$allopass->check_code($document_id, $code, [$datas], [$ap_ca]);
$ttl=$allopass->ttl([$ttl]);
Session expiration time, in minutes.
$allopass->os(1);
You need to set it to 1 only if your OS doesn't support flock (windoze ???).
Jetez un oeil sur http://www.it-development.be/software/PERL/Business-PhoneBill-Allopass/ pour la documentation en français.
Bernard Nauwelaerts <bpn#it-development%be>
GPL. Enjoy! See COPYING for further informations on the GPL.