Apache-Centipaid
view release on metacpan or search on metacpan
Centipaid.pm view on Meta::CPAN
#
# 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;
}
sub handler {
my ($r) = shift;
my $debug = $r->dir_config("debug") || 0;
my $payto = $r->dir_config("acct") || 0;
my $server = $r->dir_config("authserver") || 0;
my $port = $r->dir_config("authport") || 0;
my $pass = $r->dir_config("pass") || 0;
my $amount = $r->dir_config("amount") || 0;
my $access = $r->dir_config("access") || 0;
my $domain = $r->dir_config("domain") || 0;
my $duration = to_seconds($r->dir_config("duration") || 0);
my $enforce_ip = $r->dir_config("enforce_ip") || 0;
# database variables
my $dbtype = $r->dir_config("dbtype") || "mysql";
my $dbhost = $r->dir_config("dbhost") || "localhost";
my $dbport = $r->dir_config("dbport") || "3306";
my $dbname = $r->dir_config("dbname") || 0;
my $dbuser = $r->dir_config("dbuser") || 0;
my $dbpass = $r->dir_config("dbpass") || 0;
#request info
my $c = $r->connection;
my $ip = $c->remote_ip;
my %args = $r->args;
my $uri = $r->uri;
my $cookie_name = $r->auth_name . "_". $r->auth_type;
my $prefix = "$$ Apache::Centipaid";
# connect to the database
my $dsn = "DBI:$dbtype:database=$dbname;host=$dbhost;port=$dbport";
my $dbh = DBI->connect($dsn,$dbuser,$dbpass);
my $connect_to ="$server:$port";
my $line;
my $and;
#cookie information
my %cookies = CGI::Cookie->parse($r->header_in('Cookie'));
my $cookie;
if ( $cookies{$cookie_name} =~ /$cookie_name=([^;]+)/ ) { $cookie = $1; }
#print some stats if debug is on
$r->log_error("$prefix: payto $payto") if $debug >= 2;
( run in 2.187 seconds using v1.01-cache-2.11-cpan-d8267643d1d )