From eda8afb58706595504627139c04de191ecb5eb71 Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 21 Jun 2002 01:54:55 +0000 Subject: [PATCH] initial import --- Changes | 4 ++ MANIFEST | 9 +++ Makefile.PL | 14 +++++ README | 16 +++++ eSec.pm | 181 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ t/bad_auth.t | 31 ++++++++++ t/bop.t | 5 ++ t/credit_card.t | 32 ++++++++++ t/load.t | 5 ++ 9 files changed, 297 insertions(+) create mode 100644 Changes create mode 100644 MANIFEST create mode 100644 Makefile.PL create mode 100644 README create mode 100644 eSec.pm create mode 100644 t/bad_auth.t create mode 100644 t/bop.t create mode 100644 t/credit_card.t create mode 100644 t/load.t diff --git a/Changes b/Changes new file mode 100644 index 0000000..75dd565 --- /dev/null +++ b/Changes @@ -0,0 +1,4 @@ +Revision history for Perl extension Business::OnlinePayment::eSec. + +0.01 unreleased + -original version; created by ivan 1.0 diff --git a/MANIFEST b/MANIFEST new file mode 100644 index 0000000..76b1619 --- /dev/null +++ b/MANIFEST @@ -0,0 +1,9 @@ +eSec.pm +Changes +MANIFEST +Makefile.PL +README +t/load.t +t/credit_card.t +t/bop.t +t/bad_auth.t diff --git a/Makefile.PL b/Makefile.PL new file mode 100644 index 0000000..b012b0b --- /dev/null +++ b/Makefile.PL @@ -0,0 +1,14 @@ +use ExtUtils::MakeMaker; +# See lib/ExtUtils/MakeMaker.pm for details of how to influence +# the contents of the Makefile that is written. +WriteMakefile( + 'NAME' => 'Business::OnlinePayment::eSec', + 'VERSION_FROM' => 'eSec.pm', # finds $VERSION + 'AUTHOR' => 'Ivan Kohler ', + #'NORECURS' => 1, # dont descend into subdirectories + 'PREREQ_PM' => { 'Net::SSLeay' => 0, + #'Text::CSV_XS' => 0, + 'Business::OnlinePayment' => 0, + 'Business::CreditCard' => 0.27, + }, +); diff --git a/README b/README new file mode 100644 index 0000000..8df5325 --- /dev/null +++ b/README @@ -0,0 +1,16 @@ +Copyright (c) 2002 Ivan Kohler +All rights reserved. This program is free software; you can redistribute it +and/or modify it under the same terms as Perl itself. + +This is Business::OnlinePayment::eSec, an Business::OnlinePayment backend +module for eSec. It is only useful if you have a merchant account with eSec: +http://www.esec.com.au/sep.html + +It based on Business::OnlinePayment::AuthorizeNet written by Jason Kohles. + +Ivan Kohler + +Business::OnlinePayment is a generic interface for processing payments through +online credit card processors, online check acceptance houses, etc. (If you +like buzzwords, call it an "multiplatform ecommerce-enabling middleware +solution"). diff --git a/eSec.pm b/eSec.pm new file mode 100644 index 0000000..ea7f1a3 --- /dev/null +++ b/eSec.pm @@ -0,0 +1,181 @@ +package Business::OnlinePayment::eSec; + +use strict; +use Carp; +use Business::OnlinePayment; +use Business::CreditCard; +use Net::SSLeay qw( make_form post_https ); +use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $DEBUG); + +require Exporter; + +@ISA = qw(Exporter AutoLoader Business::OnlinePayment); +@EXPORT = qw(); +@EXPORT_OK = qw(); +$VERSION = '0.01'; + +$DEBUG = 0; + +sub set_defaults { + my $self = shift; + $self->server('sec.aba.net.au'); + $self->port('443'); + $self->path('/cgi-bin/service/authint'); +} + +sub revmap_fields { + my($self,%map) = @_; + my %content = $self->content(); + foreach(keys %map) { + $content{$_} = ref($map{$_}) + ? ${ $map{$_} } + : $content{$map{$_}}; + } + $self->content(%content); +} + +sub get_fields { + my($self,@fields) = @_; + + my %content = $self->content(); + my %new = (); + foreach( grep defined $content{$_}, @fields) { $new{$_} = $content{$_}; } + return %new; +} + +sub submit { + my($self) = @_; + my %content = $self->content; + + my $action = lc($content{'action'}); + die 'eSec only supports "Authorization Only" transactions' + unless $action eq 'authorization only'; + + my %typemap = ( + "VISA card" => 'visa', + "MasterCard" => 'mastercard', + "Discover card" => 'discover', #not supported... + "American Express card" => 'amex', + "Diner's Club/Carte Blanche" => 'dinersclub', + "enRoute" => 'enroute', #not supported... + "JCB" => 'jcb', + "BankCard" => 'bankcard', + ); + my $cardtype = $self->test_transaction + ? 'testcard' + : $typemap{cardtype($content{'card_number'})}; + + $content{'expiration'} =~ /^(\d+)\D+(\d+)$/ + or croak "unparsable expiration $content{expiration}"; + my ($month, $year) = ( $1, $2 ); + $month += 0; + $year += 2000 if $year < 2000; #not y4k safe, oh shit + + $self->revmap_fields( + EPS_MERCHANT => 'login', + EPS_REFERENCEID => 'invoice_number', + EPS_CARDNUMBER => 'card_number', + EPS_CARDTYPE => \$cardtype, + EPS_EXPIRYMONTH => \$month, + EPS_EXPIRYYEAR => \$year, + EPS_NAMEONCARD => 'name', + EPS_AMOUNT => 'amount', + EPS_CCV => \'', + EPS_VERSION => \'2', + EPS_TEST => \( $self->test_transaction() ? 'true' : 'false' ), + ); + %content = $self->content; + if ( $DEBUG ) { + warn "content:$_ => $content{$_}\n" foreach keys %content; + } + + if ($self->transaction_type() eq 'CC' ) { + $self->required_fields(qw/type action amount card_number expiration/); + } else { + croak("eSec can't handle transaction type: ". + $self->transaction_type()); + } + + my %post_data = $self->get_fields( map "EPS_$_", qw( + MERCHANT REFERENCEID CARDNUMBER CARDTYPE EXPIRYMONTH EXPIRYYEAR + NAMEONCARD AMOUNT CCV VERSION TEST + ) ); + if ( $DEBUG ) { + warn "post_data:$_ => $post_data{$_}\n" foreach keys %post_data; + } + + my $pd = make_form(%post_data); + my $server = $self->server(); + my $port = $self->port(); + my $path = $self->path(); + my($page,$server_response,%headers) = + post_https($server,$port,$path,'',$pd); + + my( $r, $a, $m, $s, $e ) = + map { /^\s*\w+\s*\=\s*(.*)$/; $1; } split("\n", $page); + + if ( $m =~ /^200/ ) { + $self->is_success(1); + $self->result_code($e); + $self->authorization($a); + } else { + $self->is_success(0); + $self->result_code($e); + $self->error_message($m); + } + +} + +1; +__END__ + +=head1 NAME + +Business::OnlinePayment::eSec - eSec backend for Business::OnlinePayment + +=head1 SYNOPSIS + + use Business::OnlinePayment; + + my $tx = new Business::OnlinePayment("eSec"); + $tx->content( + type => 'CC', + login => 'test', #EPS_MERCHANT + action => 'Authorization Only', + description => 'Business::OnlinePayment test', + amount => '49.95', + invoice_number => '100100', + name => 'Tofu Beast', + card_number => '4007000000027', + expiration => '09/02', + ); + $tx->submit(); + + if($tx->is_success()) { + print "Card processed successfully: ".$tx->authorization."\n"; + } else { + print "Card was rejected: ".$tx->error_message."\n"; + } + +=head1 DESCRIPTION + +For detailed information see L. + +=head1 NOTE + +=head1 COMPATIBILITY + +This module implements eSec's API verison 2. See +http://www.esec.com.au/sep/content/eps_support/integrate/integrate_use.html +for details. + +=head1 AUTHOR + +Ivan Kohler + +=head1 SEE ALSO + +perl(1). L. + +=cut + diff --git a/t/bad_auth.t b/t/bad_auth.t new file mode 100644 index 0000000..46065ab --- /dev/null +++ b/t/bad_auth.t @@ -0,0 +1,31 @@ +BEGIN { $| = 1; print "1..1\n"; } + +use Business::OnlinePayment; + +my $tx = new Business::OnlinePayment("eSec", 'merchant_id' => 'test' ); +$tx->content( + type => 'CC', + login => 'test', #EPS_MERCHANT + action => 'Authorization only', + description => 'Business::OnlinePayment visa test', + amount => '49.95', + invoice_number => '100100', + customer_id => 'jsk', + first_name => 'Tofu', + last_name => 'Beast', + address => '123 Anystreet', + city => 'Anywhere', + state => 'UT', + zip => '84058', + card_number => 'testfailure', + expiration => '08/06', +); +$tx->test_transaction(1); # test, dont really charge +$tx->submit(); + +if($tx->is_success()) { + print "not ok 1\n"; + #warn $tx->error_message; +} else { + print "ok 1\n"; +} diff --git a/t/bop.t b/t/bop.t new file mode 100644 index 0000000..64332c5 --- /dev/null +++ b/t/bop.t @@ -0,0 +1,5 @@ +BEGIN { $| = 1; print "1..1\n"; } +END {print "not ok 1\n" unless $loaded;} +use Business::OnlinePayment; +$loaded = 1; +print "ok 1\n"; diff --git a/t/credit_card.t b/t/credit_card.t new file mode 100644 index 0000000..c4ffd3e --- /dev/null +++ b/t/credit_card.t @@ -0,0 +1,32 @@ +BEGIN { $| = 1; print "1..1\n"; } + +use Business::OnlinePayment; + +my $tx = new Business::OnlinePayment("eSec"); +$tx->content( + type => 'CC', + login => 'test', #EPS_MERCHANT + action => 'Authorization only', + description => 'Business::OnlinePayment visa test', + amount => '49.95', + invoice_number => '100100', + customer_id => 'jsk', + name => 'Tofu Beast', + first_name => 'Tofu', + last_name => 'Beast', + address => '123 Anystreet', + city => 'Anywhere', + state => 'UT', + zip => '84058', + card_number => 'testsuccess', + expiration => '08/06', +); +$tx->test_transaction(1); # test, dont really charge +$tx->submit(); + +if($tx->is_success()) { + print "ok 1\n"; +} else { + warn "*******". $tx->error_message. "*******"; + print "not ok 1\n"; +} diff --git a/t/load.t b/t/load.t new file mode 100644 index 0000000..5d2dfc1 --- /dev/null +++ b/t/load.t @@ -0,0 +1,5 @@ +BEGIN { $| = 1; print "1..1\n"; } +END {print "not ok 1\n" unless $loaded;} +use Business::OnlinePayment::AuthorizeNet; +$loaded = 1; +print "ok 1\n"; -- 2.11.0