From a6890d361554f119a7230efec5c59e615b1728ed Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 22 Jan 2003 10:48:48 +0000 Subject: 0.01 --- PayflowPro.pm | 161 ++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 94 insertions(+), 67 deletions(-) (limited to 'PayflowPro.pm') 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(); -- cgit v1.2.1