Business::PhoneBill::Allopass - A class for micro-payment system from Allopass


NAME

Business::PhoneBill::Allopass - A class for micro-payment system from Allopass


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.


SEE ALSO

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.


METHODS

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.

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; } 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; }

end_session - Ends user session for specified document.
    $allopass->end_session($document_id);
get_last_error - Returns last recorded error
    $allopass->get_last_error();
check_code - Checks if a client have access to this document

    $ok=$allopass->check_code($document_id, $code, [$datas], [$ap_ca]);


PROPERTIES

ttl - Session time to live property.
    $ttl=$allopass->ttl([$ttl]);

Session expiration time, in minutes.

os - Operating system property.
    $allopass->os(1);
    
    You need to set it to 1 only if your OS doesn't support flock (windoze ???).


Other documentation

Jetez un oeil sur http://www.it-development.be/software/PERL/Business-PhoneBill-Allopass/ pour la documentation en français.


AUTHOR

Bernard Nauwelaerts <bpn#it-development%be>


LICENSE

GPL. Enjoy! See COPYING for further informations on the GPL.