Apache-Centipaid

 view release on metacpan or  search on metacpan

Centipaid.pm  view on Meta::CPAN

# Apache::Centipaid
# Version $Revision: 1.3 $
#
# $Id: Centipaid.pm,v 1.3 2003/01/25 18:20:54 root Exp root $
#
# Written by Adonis El Fakih (adonis@aynacorp.com) Copyright 2002
# 
# This perl module allows site administrators to integrate the
# centipaid.com payment system without making changes to their 
# existing website.
#
# centipaid offers a micropayment solution that allows users
# to pay for online access using an internet stamp, inctead of
# paying using a credit card number, which requieres the user 
# to divulge their credit card number to the site operator.
# for more information on the micro-payment system please visit
# http://www.centipaid.com/
# 
#
# This module may be distributed under the GPL v2 or later.
#
#


package Apache::Centipaid;

use Apache ();
use Apache::Constants qw(OK REDIRECT AUTH_REQUIRED DECLINED FORBIDDEN DECLINED SERVER_ERROR);
use Apache::File;
use IO::Socket;
use Net::hostent;
use DBI;
use CGI::Cookie;



use strict;

$Apache::Centipaid::VERSION = '1.3.1';

sub need_to_pay($) {
	my $r = shift(@_);
	my $payto = $r->dir_config("acct") || 0;
	my $amount = $r->dir_config("amount") || 0;
	my $duration = $r->dir_config("duration") || 0;
	my $uri =  $r->uri;
	my $access =  $r->dir_config("access") || 0;
	my $domain =  $r->dir_config("domain") || 0;
	my $lang =  $r->dir_config("lang") || "en";
	my $https =  $r->dir_config("https") || "https://pay.centipaid.com";

	$r->content_type('text/html');
	$r->header_out(Location =>"$https/?payto=$payto&amount=$amount&duration=$duration&access=$access&domain=$domain&path=$uri&lang=$lang");
	return REDIRECT;

}


sub to_seconds ($) {
    my $duration = shift(@_);
    my $multi;
    my $seconds;

    if ( $duration =~ /^(\d+)(.+)/ ) {
    	my $num = $1;
	my $ltr = $2;
		if ( lc($ltr) eq "m" ) { $multi = 30*24*60*60;}
		if ( lc($ltr) eq "w" ) { $multi = 7*24*60*60;}
		if ( lc($ltr) eq "d" ) { $multi = 24*60*60;}
		if ( lc($ltr) eq "h" ) { $multi = 60*60;}
		$seconds = $multi * $num;
	}

    return $seconds;

Centipaid.pm  view on Meta::CPAN

} 

1;

__END__

=head1 NAME

$Revision: 1.3 $

B<Apache::Centipaid> - mod_perl AuthenHandler 


=head1 SYNOPSIS


 #in httpd.com  
 <directory /document_root/path_path>
 AuthName centipaid
 AuthType custom
 PerlAuthenHandler Apache::Centipaid
 require valid-user 

 PerlSetVar acct account_name
 PerlSetVar pass receipt_password
 PerlSetVar amount 0.01
 PerlSetVar duration 1d
 PerlSetVar access /pay_path
 PerlSetVar domain your.domain.name
 PerlSetVar lang en
 PerlSetVar enforce_ip 0

 PerlSetVar https https://pay.centipaid.com   
 PerlSetVar authserver centipaid_receipt_server
 PerlSetvar authport 2021
    
 PerlSetVar dbtype mysql
 PerlSetVar dbhost localhost
 PerlSetVar dbport 3306
 PerlSetVar dbname centipaid_rcpt
 perlSetVar dbuser user
 perlSetVar dbpass pass
 </directory>


=head1 REQUIRES

Perl5.004_04, mod_perl 1.15, IO::Socket, Net::hostent, DBI, DBD, DBD::mysql, CGI::Cookie;


=head1 DESCRIPTION

B<Apache::Centipaid> is a mod_perl Authentication handler used in 
granting access to users wishing to access paid web services, after 
making payment on centipaid.com which process micropayments using
internet stamps. 

Centipaid.com offers websites the flexibility to charge small amounts
of money, also refered to as B<micropayment>, to users wishing to
access to their web services without the complexity of setting up 
e-commerce enabled site, or to deal with expensive credit card 
processing options. Users benefit from not having to reveal their
identity or credit card information everytime they decide to visit a 
website.  Instead, centipaid allows users to simply pay using
a pre-paid internet stamp, by simply uploading the stamp to centipaid's
site. The stamps are valid in all sites using centipaid.com payment
system.

To access a site, recipts are issued by centipaid and are used to track 
valid payments.  This information is captured and processed by the
Apache::Centipaid module.  The information is then stored locally to 
any SQL database installed.  The module relies on DBD/DBI interface
so as long as the database has a DBD interface installed under Perl,
and utilizes SQL to make queries and inserts, then you should be able 
to maintain and track your receipts.

B<How does it work?>
A user visits a website, or a section with a site, that requieres an
accecss fee.  The webserver will intercept the request, and realize that
the user has not made a payment, and hence they are directed to 
centipaid.com to pay for access.  Centipaid will inform the user what 
they are paying for in a standard language, along with the fee associated 
with the access, and the duration of the granted access.

If the user agrees to the terms, s/he proceeds to select an electronic
stamp from his computer that has enough funds to pay for the access.
Centipaid will autheticate the stamp, deduct the access fee, and issue the
user a receipt number.  The user will see a receipt on his page that 
re-iterates the terms, amount paid, and internet stamp balance. A link will 
be also available for the user to click on to be transported back to the
page they came from, along with the receipt number.  Once the user makes
a payment, they are shown the amount paid, the balance left on the card,
and a link back to the page they were trying to access.  Once they press
the link, they are forwarded back to the initial page they tried to 
access.

At this stage, Apache::Centipaid realizes that a rececipt is being submited
as payment.  It takes the receipt number and autheticates with centipaid's 
receipt server to insure that the receipt is a valid one, and that the 
proper funds have been paid.

If the rececipt is valid, then the information is stored locally.  The 
information stored included the ip of the client (for optional enforcment 
of payment tied to ip), amount paid, date of transaction, expiry date, 
and the zone the payment covers.  And since centipaid micropayment system 
is designed to allow users to pay without having to provide username, 
password or any other payment information other than the recipt 
number, it makes the process easy to manage and neither the payer or 
payee have to worry about financial information falling into the wrong 
hands. 

B<How do we track payments?>
When a user makes a payment, the Apache::Centipaid module inserts a cookie 
that contains the receipt number, and it sets the expiry of the cookie
based on the payment B<duration> specified in the configuration file.  
Everytime a user visits protected areas in a site, the cookie is 
inspected, and if it exists it is matched with the receipt database.  if 
it is found, and the expiry date has not been met, then they are granted 
access.  If the receipt is non existent, or past its expiry date, the 
user is prompted to make payment again.  

Please reffer to centipaid.com for the most updated version of this 
module, since other methods of tracking payment may be available.



( run in 0.944 second using v1.01-cache-2.11-cpan-39bf76dae61 )