From 2bdce7b0c9d7468d676ee4bfa824b1fb0cbba207 Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 14 Jan 2003 05:52:12 +0000 Subject: [PATCH] initial import --- Changes | 5 ++ LinkPoint.pm | 238 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ MANIFEST | 9 +++ Makefile.PL | 12 +++ README | 21 +++++ t/bad_auth.t | 43 ++++++++++ t/bop.t | 5 ++ t/credit_card.t | 42 ++++++++++ t/load.t | 5 ++ 9 files changed, 380 insertions(+) create mode 100644 Changes create mode 100644 LinkPoint.pm create mode 100644 MANIFEST create mode 100644 Makefile.PL create mode 100644 README 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..3cc6166 --- /dev/null +++ b/Changes @@ -0,0 +1,5 @@ +Revision history for Perl extension Business::OnlinePayment::PayflowPro. + +0.01 unreleased + - original version; created by ivan 1.0 + diff --git a/LinkPoint.pm b/LinkPoint.pm new file mode 100644 index 0000000..45d0fb8 --- /dev/null +++ b/LinkPoint.pm @@ -0,0 +1,238 @@ +package Business::OnlinePayment::PayflowPro; + +use strict; +use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); +use Carp qw(croak); +use AutoLoader; +use Business::OnlinePayment; + +use PFProAPI; #Payflow PRO SDK from Verisign + +require Exporter; + +@ISA = qw(Exporter AutoLoader Business::OnlinePayment); +@EXPORT = qw(); +@EXPORT_OK = qw(); +$VERSION = '0.02'; + +sub set_defaults { + my $self = shift; + + #$self->server('staging.linkpt.net'); + $self->server('secure.linkpt.net'); + $self->port('1139'); + +} + +sub map_fields { + my($self) = @_; + + my %content = $self->content(); + + #ACTION MAP + my %actions = ('normal authorization' => 'ApproveSale', + 'authorization only' => 'CapturePayment', + 'credit' => 'ReturnOrder', + 'post authorization' => 'BillOrders', + ); + $content{'action'} = $actions{lc($content{'action'})} || $content{'action'}; + + # stuff it back into %content + $self->content(%content); +} + +sub build_subs { + my $self = shift; + foreach(@_) { + #no warnings; #not 5.005 + local($^W)=0; + eval "sub $_ { my \$self = shift; if(\@_) { \$self->{$_} = shift; } return \$self->{$_}; }"; + } +} + +sub remap_fields { + my($self,%map) = @_; + + my %content = $self->content(); + foreach(keys %map) { + $content{$map{$_}} = $content{$_}; + } + $self->content(%content); +} + +sub revmap_fields { + my($self, %map) = @_; + my %content = $self->content(); + foreach(keys %map) { +# warn "$_ = ". ( ref($map{$_}) +# ? ${ $map{$_} } +# : $content{$map{$_}} ). "\n"; + $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) = @_; + + + $self->map_fields(); + + my %content = $self->content; + + my($month, $year); + unless ( $content{action} eq 'BillOrders' ) { + + if ( $self->transaction_type() =~ + /^(cc|visa|mastercard|american express|discover)$/i + ) { + } else { + Carp::croak("PayflowPro can't handle transaction type: ". + $self->transaction_type()); + } + + $content{'expiration'} =~ /^(\d+)\D+\d*(\d{2})$/ + or croak "unparsable expiration $content{expiration}"; + + ( $month, $year ) = ( $1, $2 ); + $month = '0'. $month if $month =~ /^\d$/; + $year += 2000 if $year < 2000; #not y4k safe, oh shit + } + + $content{'address'} =~ /^(\S+)\s/; + my $addrnum = $1; + + $self->server('staging.linkpt.net') if $self->test_transaction; + + $self->revmap_fields( + hostname => \( $self->server ), + port => \( $self->port ), + storename => \( $self->storename ), + keyfile => \( $self->keyfile ), + addrnum => \$addrnum, + + cardNumber => 'card_number', + cardExpMonth => \$month, + cardExpYear => \$year, + ); + + my $lperl = new LPERL + $self->lbin, + 'FILE', + $self->can('tmp') + ? $self->tmp + : '/tmp'; + my $action = $content{action}; + + $self->required_fields(qw/ + hostname port storename keyfile amount cardNumber cardExpMonth cardExpYear + /); + + my %post_data = $self->get_fields(qw/ + hostname port storename keyfile + result + amount cardNumber cardExpMonth cardExpYear + name email phone address city state zip country + /); + + #print "$_ => $post_data{$_}\n" foreach keys %post_data; + + my %response; + { + local($^W)=0; + %response = $lperl->$action(\%post_data); + } + + if ( $response{'statusCode'} == 0 ) { + $self->is_success(0); + $self->result_code(''); + $self->error_message($response{'statusMessage'}); + } else { + $self->is_success(1); + $self->result_code($response{'AVCCode'}); + $self->authorization($response{'trackingID'}); +# $self->order_number($response{'neworderID'}); + } + +} + +1; +__END__ + +=head1 NAME + +Business::OnlinePayment::PayflowPro - Verisign PayflowPro backend for Business::OnlinePayment + +=head1 SYNOPSIS + + use Business::OnlinePayment; + + my $tx = new Business::OnlinePayment( 'PayflowPro', + 'storename' => 'your_store_number', + 'keyfile' => '/path/to/keyfile.pem', + 'lbin' => '/path/to/binary/lbin', + 'tmp' => '/secure/tmp', # a secure tmp directory + ); + + $tx->content( + type => 'VISA', + action => 'Normal Authorization', + description => 'Business::OnlinePayment test', + amount => '49.95', + invoice_number => '100100', + customer_id => 'jsk', + name => 'Jason Kohles', + address => '123 Anystreet', + city => 'Anywhere', + state => 'UT', + zip => '84058', + email => 'ivan-payflowpro@420.am', + card_number => '4007000000027', + expiration => '09/99', + ); + $tx->submit(); + + if($tx->is_success()) { + print "Card processed successfully: ".$tx->authorization."\n"; + } else { + print "Card was rejected: ".$tx->error_message."\n"; + } + +=head1 SUPPORTED TRANSACTION TYPES + +=head2 Visa, MasterCard, American Express, JCB, Discover/Novus, Carte blanche/Diners Club + +=head1 DESCRIPTION + +For detailed information see L. + +=head1 COMPATIBILITY + +This module implements an interface to the PayflowPro Perl API, which can +be downloaded at https://manager.verisign.com/ with a valid login. + +=head1 BUGS + +=head1 AUTHOR + +Ivan Kohler + +Based on Busienss::OnlinePayment::AuthorizeNet written by Jason Kohles. + +=head1 SEE ALSO + +perl(1), L. + +=cut + diff --git a/MANIFEST b/MANIFEST new file mode 100644 index 0000000..8e82abf --- /dev/null +++ b/MANIFEST @@ -0,0 +1,9 @@ +PayflowPro.pm +Changes +MANIFEST +Makefile.PL +README +t/bop.t +t/load.t +t/bad_auth.t +t/credit_card.t diff --git a/Makefile.PL b/Makefile.PL new file mode 100644 index 0000000..ba4b8ea --- /dev/null +++ b/Makefile.PL @@ -0,0 +1,12 @@ +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::PayflowPro', + 'VERSION_FROM' => 'PayflowPro.pm', # finds $VERSION + 'AUTHOR' => 'Ivan Kohler ', + 'PREREQ_PM' => { 'Business::OnlinePayment' => 0, + #?# 'PFProAPI' => 0, + }, + #'NORECURS' => 1, # dont descend into subdirectories +); diff --git a/README b/README new file mode 100644 index 0000000..7a83743 --- /dev/null +++ b/README @@ -0,0 +1,21 @@ +Copyright (c) 2003 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::PayflowPro, an Business::OnlinePayment +backend module for Verisign Payflow Pro. It is only useful if you have a +merchant account with Verisign Payment Services: +http://www.verisign.com/products/payment.html and the "Payflow Pro SDK": +https://manager.verisign.com/ + +It is based on Business::OnlinePayment::AuthorizeNet written by Jason Kohles. + +#There are additional tests in t2/ that may be useful to you once you have a +#store number and key file. + +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/t/bad_auth.t b/t/bad_auth.t new file mode 100644 index 0000000..e0db291 --- /dev/null +++ b/t/bad_auth.t @@ -0,0 +1,43 @@ +BEGIN { $| = 1; print "1..2\n"; } + +use Business::OnlinePayment; + +my $tx = new Business::OnlinePayment("PayflowPro", +# 'storename' => '000000', +# 'keyfile' => '/path/to/cert.pem', +# 'lbin' => '/path/to/lbin', +# 'tmp' => '/path/to/secure/tempdir', +); + +$tx->content( + type => 'VISA', + action => 'Normal Authorization', + description => 'Business::OnlinePayment::PayflowPro visa test', + amount => '0.01', + first_name => 'Tofu', + last_name => 'Beast', + address => '123 Anystreet', + city => 'Anywhere', + state => 'UT', + zip => '84058', + country => 'US', + email => 'ivan-payflowpro@420.am', + card_number => '4007000000027', + expiration => '12/2002', +# result => 'DECLINE', +); + +$tx->test_transaction(1); + +$tx->submit(); + +if($tx->is_success()) { + print "not ok 1\n"; + $auth = $tx->authorization; + warn "********* $auth ***********\n"; +} else { + print "ok 1\n"; + warn '***** '. $tx->error_message. " *****\n"; + exit; +} + 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..e0ce71c --- /dev/null +++ b/t/credit_card.t @@ -0,0 +1,42 @@ +BEGIN { $| = 1; print "1..2\n"; } + +use Business::OnlinePayment; + +my $tx = new Business::OnlinePayment("PayflowPro", +# 'storename' => '000000', +# 'keyfile' => '/path/to/cert.pem', +# 'lbin' => '/path/to/lbin', +# 'tmp' => '/path/to/secure/tempdir', +); + +$tx->content( + type => 'VISA', + action => 'Normal Authorization', + description => 'Business::OnlinePayment::PayflowPro visa test', + amount => '0.01', + first_name => 'Tofu', + last_name => 'Beast', + address => '123 Anystreet', + city => 'Anywhere', + state => 'UT', + zip => '84058', + country => 'US', + email => 'ivan-payflowpro@420.am', + card_number => '4007000000027', + expiration => '12/2003', +); + +$tx->test_transaction(1); + +$tx->submit(); + +if($tx->is_success()) { + print "ok 1\n"; + $auth = $tx->authorization; + warn "********* $auth ***********\n"; +} else { + print "not ok 1\n"; + warn '***** '. $tx->error_message. " *****\n"; + exit; +} + diff --git a/t/load.t b/t/load.t new file mode 100644 index 0000000..d2a7f26 --- /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::PayflowPro; +$loaded = 1; +print "ok 1\n"; -- 2.11.0