1 package Business::OnlinePayment::PayflowPro;
4 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
7 use Business::OnlinePayment;
9 #PayflowPRO SDK from Verisign
10 use PFProAPI qw( pfpro );
14 @ISA = qw(Exporter AutoLoader Business::OnlinePayment);
22 #$self->server('staging.linkpt.net');
23 $self->server('payflow.verisign.com');
27 vendor partner order_number cert_path avs_code cvv2_code
35 my %content = $self->content();
38 my %actions = ('normal authorization' => 'S', #Sale
39 'authorization only' => 'A', #Authorization
40 'credit' => 'C', #Credit (refund)
41 'post authorization' => 'D', #Delayed Capture
44 $content{'action'} = $actions{lc($content{'action'})} || $content{'action'};
47 my %types = ('visa' => 'C',
49 'american express' => 'C',
54 $content{'type'} = $types{lc($content{'type'})} || $content{'type'};
55 $self->transaction_type($content{'type'});
57 # stuff it back into %content
58 $self->content(%content);
64 #no warnings; #not 5.005
66 eval "sub $_ { my \$self = shift; if(\@_) { \$self->{$_} = shift; } return \$self->{$_}; }";
73 my %content = $self->content();
75 $content{$map{$_}} = $content{$_};
77 $self->content(%content);
82 my %content = $self->content();
84 # warn "$_ = ". ( ref($map{$_})
86 # : $content{$map{$_}} ). "\n";
87 $content{$_} = ref($map{$_})
91 $self->content(%content);
95 my($self,@fields) = @_;
97 my %content = $self->content();
99 foreach( grep defined $content{$_}, @fields) { $new{$_} = $content{$_}; }
108 my %content = $self->content;
110 my($month, $year, $zip);
112 #unless ( $content{action} eq 'BillOrders' ) {
114 if ( $self->transaction_type() eq 'C' ) {
116 Carp::croak("PayflowPro can't (yet?) handle transaction type: ".
117 $self->transaction_type());
120 if ( exists($content{'expiration'}) && defined($content{'expiration'})
121 && length($content{'expiration'}) ) {
122 $content{'expiration'} =~ /^(\d+)\D+\d*(\d{2})$/
123 or croak "unparsable expiration $content{expiration}";
125 ( $month, $year ) = ( $1, $2 );
126 $month = '0'. $month if $month =~ /^\d$/;
129 $zip = $content{'zip'} =~ s/\D//;
132 #$content{'address'} =~ /^(\S+)\s/;
135 $self->server('test-payflow.verisign.com') if $self->test_transaction;
137 $self->revmap_fields(
138 ACCT => 'card_number',
139 EXPDATE => \( $month.$year ),
142 #VENDOR => \( $self->vendor ),
144 PARTNER => \( $self->partner ),
153 COMMENT1 => 'description',
154 COMMENT2 => 'invoice_number',
155 COMPANYNAME => 'company',
156 COUNTRY => 'country',
157 FIRSTNAME => 'first_name',
158 LASTNAME => 'last_name',
164 ORIGID => 'order_number'
168 my @required = qw( TRXTYPE TENDER PARTNER VENDOR USER PWD );
169 if ( $self->transaction_type() eq 'C' ) { #credit card
170 if ( $self->action() =~ /^[CDV]$/ && exists($content{'ORIGID'})
171 && defined($content{'ORIGID'}) && length($content{'ORIGID'}) ) {
172 push @required, qw(ORIGID);
174 push @required, qw(AMT ACCT EXPDATE);
177 $self->required_fields(@required);
179 my %params = $self->get_fields(qw(
180 ACCT EXPDATE AMT USER VENDOR PARTNER PWD TRXTYPE TENDER
182 CITY COMMENT1 COMMENT2 COMPANYNAME COUNTRY FIRSTNAME LASTNAME NAME EMAIL
187 #print "$_ => $params{$_}\n" foreach keys %params;
189 $ENV{'PFPRO_CERT_PATH'} = $self->cert_path;
190 my( $response, $resultstr ) = pfpro( \%params, $self->server, $self->port );
192 #if ( $response->{'RESULT'} == 0 ) {
193 if ( $response->{'RESULT'} eq '0' ) { #want an explicit zero, not just
195 $self->is_success(1);
196 $self->result_code( $response->{'RESULT'} );
197 $self->error_message( $response->{'RESPMSG'} );
198 $self->authorization( $response->{'AUTHCODE'} );
199 $self->order_number( $response->{'PNREF'} );
201 if ( $response->{AVSADDR} eq 'Y' && $response->{AVSZIP} eq 'Y' ) {
203 } elsif ( $response->{AVSADDR} eq 'Y' ) {
205 } elsif ( $response->{AVSZIP} eq 'Y' ) {
207 } elsif ( $response->{AVSADDR} eq 'N' || $response->{AVSZIP} eq 'N' ) {
210 $self->avs_code( $avs_code );
211 $self->cvv2_code( $response->{'CVV2MATCH'});
213 $self->is_success(0);
214 $self->result_code( $response->{'RESULT'} );
215 $self->error_message( $response->{'RESPMSG'} );
225 Business::OnlinePayment::PayflowPro - Verisign PayflowPro backend for Business::OnlinePayment
229 use Business::OnlinePayment;
231 my $tx = new Business::OnlinePayment( 'PayflowPro',
232 'vendor' => 'your_vendor',
233 'partner' => 'your_partner',
234 'cert_path' => '/path/to/your/certificate/file/', #just the dir
239 action => 'Normal Authorization',
240 description => 'Business::OnlinePayment test',
242 invoice_number => '100100',
243 customer_id => 'jsk',
244 name => 'Jason Kohles',
245 address => '123 Anystreet',
249 email => 'ivan-payflowpro@420.am',
250 card_number => '4007000000027',
251 expiration => '09/04',
255 order_number => 'string', # returned by $tx->order_number() from an
256 # "authorization only" or
257 # "normal authorization" action, used by a
258 # "credit", "void", or "post authorization"
262 if($tx->is_success()) {
263 print "Card processed successfully: ".$tx->authorization."\n";
264 print "order number: ". $tx->order_number. "\n";
265 print "AVS code: ". $tx->avs_code. "\n"; # Y - Address and ZIP match
266 # A - Address matches but not ZIP
267 # Z - ZIP matches bu tnot address
269 # E - AVS error or unsupported
271 print "CVV2 code: ". $tx->cvv2_code. "\n";
274 print "Card was rejected: ".$tx->error_message;
275 print " (CVV2 mismatch)" if $tx->result_code == 114;
279 =head1 SUPPORTED TRANSACTION TYPES
281 =head2 Visa, MasterCard, American Express, JCB, Discover/Novus, Carte blanche/Diners Club, CC
283 =head1 SUPPORTED ACTIONS
285 =head2 Normal Authorization, Authorization Only, Post Authorization, Credit, Void
289 For detailed information see L<Business::OnlinePayment>.
293 This module implements an interface to the PayflowPro Perl API, which can
294 be downloaded at https://manager.verisign.com/ with a valid login.
300 Ivan Kohler <ivan-payflowpro@420.am>
302 Based on Busienss::OnlinePayment::AuthorizeNet written by Jason Kohles.
306 perl(1), L<Business::OnlinePayment>.