Business-PhoneBill-Allopass
view release on metacpan or search on metacpan
Allopass.pm view on Meta::CPAN
package Business::PhoneBill::Allopass;
use vars qw/$VERSION/;
$VERSION = "1.09";
=head1 NAME
Business::PhoneBill::Allopass - A class for micro-payment system from Allopass
=head1 SYNOPSIS
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.
=head1 SEE ALSO
Please consider using Business::PhoneBill::Allopass::Simple if you don't need session management.
See I<http://www.allopass.com/index.php4?ADV=1508058> for more informations on their system and how it basically works.
=cut
use strict;
use HTTP::Request::Common qw(POST);
use LWP::UserAgent;
use CGI::Cookie;
my $baseurl = 'http://www.allopass.com/check/vf.php4';
=head1 METHODS
=over 4
=item B<new> Class constructor. Provides session-based access check.
$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.
=cut
sub new {
my $class = shift;
my $ses_file= shift || return "You must provide writable session file name";
if (!-e $ses_file) {
open TEMP, ">$ses_file" or return "Cann't create session file: ".$!; close TEMP;
}
my $ttl=shift || 60;
my %arg = @_;
my $self = {
os => 0,
ttl => $ttl,
ses_file => $ses_file,
error => '',
hhttp => $arg{hhttp} || '',
code => '',
};
$self = bless $self, $class;
$self;
}
=item B<check> - Checks if a client have access to this document
$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;
( run in 2.528 seconds using v1.01-cache-2.11-cpan-c221a9de4ec )