From a6890d361554f119a7230efec5c59e615b1728ed Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 22 Jan 2003 10:48:48 +0000 Subject: [PATCH] 0.01 --- Changes | 2 +- Makefile.PL | 2 +- PayflowPro.pm | 161 +++++++++++++++++++++++++++++++++----------------------- README | 3 -- t/bad_auth.t | 18 ++++--- t/credit_card.t | 16 +++--- 6 files changed, 115 insertions(+), 87 deletions(-) diff --git a/Changes b/Changes index 3cc6166..899b9ed 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,5 @@ Revision history for Perl extension Business::OnlinePayment::PayflowPro. -0.01 unreleased +0.01 Wed Jan 22 02:47:25 PST 2003 - original version; created by ivan 1.0 diff --git a/Makefile.PL b/Makefile.PL index ba4b8ea..c624b4b 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -6,7 +6,7 @@ WriteMakefile( 'VERSION_FROM' => 'PayflowPro.pm', # finds $VERSION 'AUTHOR' => 'Ivan Kohler ', 'PREREQ_PM' => { 'Business::OnlinePayment' => 0, - #?# 'PFProAPI' => 0, + 'PFProAPI' => 0, }, #'NORECURS' => 1, # dont descend into subdirectories ); diff --git a/PayflowPro.pm b/PayflowPro.pm index 45d0fb8..16e499b 100644 --- a/PayflowPro.pm +++ b/PayflowPro.pm @@ -6,21 +6,24 @@ use Carp qw(croak); use AutoLoader; use Business::OnlinePayment; -use PFProAPI; #Payflow PRO SDK from Verisign +#PayflowPRO SDK from Verisign +use PFProAPI qw( pfpro ); require Exporter; @ISA = qw(Exporter AutoLoader Business::OnlinePayment); @EXPORT = qw(); @EXPORT_OK = qw(); -$VERSION = '0.02'; +$VERSION = '0.01'; sub set_defaults { my $self = shift; #$self->server('staging.linkpt.net'); - $self->server('secure.linkpt.net'); - $self->port('1139'); + $self->server('payflow.verisign.com'); + $self->port('443'); + + $self->build_subs(qw( vendor partner order_number cert_path )); } @@ -29,14 +32,31 @@ sub map_fields { my %content = $self->content(); + my $action = lc($content{'action'}); + if ( $action eq 'normal authorization' ) { + } else { + croak "$action not (yet) supported"; + } + #ACTION MAP - my %actions = ('normal authorization' => 'ApproveSale', - 'authorization only' => 'CapturePayment', - 'credit' => 'ReturnOrder', - 'post authorization' => 'BillOrders', + my %actions = ('normal authorization' => 'S', #Sale + 'authorization only' => 'A', #Authorization + 'credit' => 'C', #Credit (refund) + 'post authorization' => 'D', #Delayed Capture ); $content{'action'} = $actions{lc($content{'action'})} || $content{'action'}; + # TYPE MAP + my %types = ('visa' => 'C', + 'mastercard' => 'C', + 'american express' => 'C', + 'discover' => 'C', + 'cc' => 'C' + #'check' => 'ECHECK', + ); + $content{'type'} = $types{lc($content{'type'})} || $content{'type'}; + $self->transaction_type($content{'type'}); + # stuff it back into %content $self->content(%content); } @@ -87,18 +107,19 @@ sub submit { my($self) = @_; + + $self->map_fields(); my %content = $self->content; - my($month, $year); - unless ( $content{action} eq 'BillOrders' ) { + my($month, $year, $zip); + + #unless ( $content{action} eq 'BillOrders' ) { - if ( $self->transaction_type() =~ - /^(cc|visa|mastercard|american express|discover)$/i - ) { + if ( $self->transaction_type() eq 'C' ) { } else { - Carp::croak("PayflowPro can't handle transaction type: ". + Carp::croak("PayflowPro can't (yet?) handle transaction type: ". $self->transaction_type()); } @@ -107,62 +128,70 @@ sub submit { ( $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; + $zip = $content{'zip'} =~ s/\D//; + #} + + #$content{'address'} =~ /^(\S+)\s/; + #my $addrnum = $1; - $self->server('staging.linkpt.net') if $self->test_transaction; + $self->server('test-payflow.verisign.com') 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, + ACCT => 'card_number', + EXPDATE => \( $month.$year ), + AMT => 'amount', + USER => 'login', + #VENDOR => \( $self->vendor ), + VENDOR => 'login', + PARTNER => \( $self->partner ), + PWD => 'password', + TRXTYPE => 'action', + TENDER => 'type', + + STREET => 'address', + ZIP => \$zip, + + CITY => 'city', + COMMENT1 => 'description', + COMMENT2 => 'invoice_number', + COMPANYNAME => 'company', + COUNTRY => 'country', + FIRSTNAME => 'first_name', + LASTNAME => 'last_name', + NAME => 'name', + EMAIL => 'email', + STATE => 'state', + ); - 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); - } + $self->required_fields(qw( + ACCT EXPDATE AMT USER VENDOR PARTNER PWD TRXTYPE TENDER )); - if ( $response{'statusCode'} == 0 ) { - $self->is_success(0); - $self->result_code(''); - $self->error_message($response{'statusMessage'}); - } else { + my %params = $self->get_fields(qw( + ACCT EXPDATE AMT USER VENDOR PARTNER PWD TRXTYPE TENDER + STREET ZIP + CITY COMMENT1 COMMENT2 COMPANYNAME COUNTRY FIRSTNAME LASTNAME NAME EMAIL + STATE + )); + + #print "$_ => $params{$_}\n" foreach keys %params; + + $ENV{'PFPRO_CERT_PATH'} = $self->cert_path; + my( $response, $resultstr ) = pfpro( \%params, $self->server, $self->port ); + + #if ( $response->{'RESULT'} == 0 ) { + if ( $response->{'RESULT'} eq '0' ) { #want an explicit zero, not just + #numerically equal $self->is_success(1); - $self->result_code($response{'AVCCode'}); - $self->authorization($response{'trackingID'}); -# $self->order_number($response{'neworderID'}); + $self->result_code( $response->{'RESULT'} ); + $self->error_message( $response->{'RESPMSG'} ); + $self->authorization( $response->{'AUTHCODE'} ); + $self->order_number( $response->{'PNREF'} ); + } else { + $self->is_success(0); + $self->result_code( $response->{'RESULT'} ); + $self->error_message( $response->{'RESPMSG'} ); } } @@ -179,10 +208,8 @@ Business::OnlinePayment::PayflowPro - Verisign PayflowPro backend for Business:: 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 + 'vendor' => 'your_vendor', + 'partner' => 'your_partner', ); $tx->content( @@ -199,7 +226,7 @@ Business::OnlinePayment::PayflowPro - Verisign PayflowPro backend for Business:: zip => '84058', email => 'ivan-payflowpro@420.am', card_number => '4007000000027', - expiration => '09/99', + expiration => '09/04', ); $tx->submit(); diff --git a/README b/README index 7a83743..0218153 100644 --- a/README +++ b/README @@ -10,9 +10,6 @@ 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 diff --git a/t/bad_auth.t b/t/bad_auth.t index e0db291..2ed6e69 100644 --- a/t/bad_auth.t +++ b/t/bad_auth.t @@ -1,16 +1,17 @@ -BEGIN { $| = 1; print "1..2\n"; } +BEGIN { $| = 1; print "1..1\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', + #'vendor' => 'your_vendor', + 'partner' => 'verisign', + 'cert_path' => '/home/ivan/Business-OnlinePayment-PayflowPro.docs/verisign/payflowpro/linux/certs/', ); $tx->content( type => 'VISA', + login => 'test231', + password => '231test', action => 'Normal Authorization', description => 'Business::OnlinePayment::PayflowPro visa test', amount => '0.01', @@ -22,9 +23,10 @@ $tx->content( zip => '84058', country => 'US', email => 'ivan-payflowpro@420.am', - card_number => '4007000000027', - expiration => '12/2002', -# result => 'DECLINE', + #card_number => '4007000000027', + #card_number => '4111111111111111', + card_number => '4111111111111112', + expiration => '12/2004', ); $tx->test_transaction(1); diff --git a/t/credit_card.t b/t/credit_card.t index e0ce71c..1ca1be7 100644 --- a/t/credit_card.t +++ b/t/credit_card.t @@ -1,16 +1,17 @@ -BEGIN { $| = 1; print "1..2\n"; } +BEGIN { $| = 1; print "1..1\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', + #'vendor' => 'your_vendor', + 'partner' => 'verisign', + 'cert_path' => '/home/ivan/Business-OnlinePayment-PayflowPro.docs/verisign/payflowpro/linux/certs/', ); $tx->content( type => 'VISA', + login => 'test231', + password => '231test', action => 'Normal Authorization', description => 'Business::OnlinePayment::PayflowPro visa test', amount => '0.01', @@ -22,8 +23,9 @@ $tx->content( zip => '84058', country => 'US', email => 'ivan-payflowpro@420.am', - card_number => '4007000000027', - expiration => '12/2003', + #card_number => '4007000000027', + card_number => '4111111111111111', + expiration => '12/2004', ); $tx->test_transaction(1); -- 2.11.0