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');
26 $self->build_subs(qw( vendor partner order_number cert_path ));
33 my %content = $self->content();
35 my $action = lc($content{'action'});
36 if ( $action eq 'normal authorization' ) {
38 croak "$action not (yet) supported";
42 my %actions = ('normal authorization' => 'S', #Sale
43 'authorization only' => 'A', #Authorization
44 'credit' => 'C', #Credit (refund)
45 'post authorization' => 'D', #Delayed Capture
48 $content{'action'} = $actions{lc($content{'action'})} || $content{'action'};
51 my %types = ('visa' => 'C',
53 'american express' => 'C',
58 $content{'type'} = $types{lc($content{'type'})} || $content{'type'};
59 $self->transaction_type($content{'type'});
61 # stuff it back into %content
62 $self->content(%content);
68 #no warnings; #not 5.005
70 eval "sub $_ { my \$self = shift; if(\@_) { \$self->{$_} = shift; } return \$self->{$_}; }";
77 my %content = $self->content();
79 $content{$map{$_}} = $content{$_};
81 $self->content(%content);
86 my %content = $self->content();
88 # warn "$_ = ". ( ref($map{$_})
90 # : $content{$map{$_}} ). "\n";
91 $content{$_} = ref($map{$_})
95 $self->content(%content);
99 my($self,@fields) = @_;
101 my %content = $self->content();
103 foreach( grep defined $content{$_}, @fields) { $new{$_} = $content{$_}; }
112 my %content = $self->content;
114 my($month, $year, $zip);
116 #unless ( $content{action} eq 'BillOrders' ) {
118 if ( $self->transaction_type() eq 'C' ) {
120 Carp::croak("PayflowPro can't (yet?) handle transaction type: ".
121 $self->transaction_type());
124 if ( exists($content{'expiration'}) && defined($content{'expiration'})
125 && length($content{'expiration'}) ) {
126 $content{'expiration'} =~ /^(\d+)\D+\d*(\d{2})$/
127 or croak "unparsable expiration $content{expiration}";
129 ( $month, $year ) = ( $1, $2 );
130 $month = '0'. $month if $month =~ /^\d$/;
133 $zip = $content{'zip'} =~ s/\D//;
136 #$content{'address'} =~ /^(\S+)\s/;
139 $self->server('test-payflow.verisign.com') if $self->test_transaction;
141 $self->revmap_fields(
142 ACCT => 'card_number',
143 EXPDATE => \( $month.$year ),
146 #VENDOR => \( $self->vendor ),
148 PARTNER => \( $self->partner ),
157 COMMENT1 => 'description',
158 COMMENT2 => 'invoice_number',
159 COMPANYNAME => 'company',
160 COUNTRY => 'country',
161 FIRSTNAME => 'first_name',
162 LASTNAME => 'last_name',
168 ORIGID => 'order_number'
172 my @required = qw( TRXTYPE TENDER PARTNER VENDOR USER PWD );
173 if ( $self->transaction_type() eq 'C' ) { #credit card
174 if ( $self->action() =~ /^[CDV]$/ && exists($content{'ORIGID'})
175 && defined($content{'ORIGID'}) && length($content{'ORIGID'}) ) {
176 push @required, qw(ORIGID);
178 push @required, qw(AMT ACCT EXPDATE);
181 $self->required_fields(@required);
183 my %params = $self->get_fields(qw(
184 ACCT EXPDATE AMT USER VENDOR PARTNER PWD TRXTYPE TENDER
186 CITY COMMENT1 COMMENT2 COMPANYNAME COUNTRY FIRSTNAME LASTNAME NAME EMAIL
191 #print "$_ => $params{$_}\n" foreach keys %params;
193 $ENV{'PFPRO_CERT_PATH'} = $self->cert_path;
194 my( $response, $resultstr ) = pfpro( \%params, $self->server, $self->port );
196 #if ( $response->{'RESULT'} == 0 ) {
197 if ( $response->{'RESULT'} eq '0' ) { #want an explicit zero, not just
199 $self->is_success(1);
200 $self->result_code( $response->{'RESULT'} );
201 $self->error_message( $response->{'RESPMSG'} );
202 $self->authorization( $response->{'AUTHCODE'} );
203 $self->order_number( $response->{'PNREF'} );
205 if ( $response->{AVSADDR} eq 'Y' && $response->{AVSZIP} eq 'Y' ) {
207 } elsif ( $response->{AVSADDR} eq 'Y' ) {
209 } elsif ( $response->{AVSZIP} eq 'Y' ) {
211 } elsif ( $response->{AVSADDR} eq 'N' || $response->{AVSZIP} eq 'N' ) {
214 $self->avs_code( $avs_code );
216 $self->is_success(0);
217 $self->result_code( $response->{'RESULT'} );
218 $self->error_message( $response->{'RESPMSG'} );
228 Business::OnlinePayment::PayflowPro - Verisign PayflowPro backend for Business::OnlinePayment
232 use Business::OnlinePayment;
234 my $tx = new Business::OnlinePayment( 'PayflowPro',
235 'vendor' => 'your_vendor',
236 'partner' => 'your_partner',
237 'cert_path' => '/path/to/your/certificate/file/', #just the dir
242 action => 'Normal Authorization',
243 description => 'Business::OnlinePayment test',
245 invoice_number => '100100',
246 customer_id => 'jsk',
247 name => 'Jason Kohles',
248 address => '123 Anystreet',
252 email => 'ivan-payflowpro@420.am',
253 card_number => '4007000000027',
254 expiration => '09/04',
258 order_number => 'string', # returned by $tx->order_number() from an
259 # "authorization only" or
260 # "normal authorization" action, used by a
261 # "credit", "void", or "post authorization"
265 if($tx->is_success()) {
266 print "Card processed successfully: ".$tx->authorization."\n";
267 print "order number: ". $tx->order_number. "\n";
268 print "AVS code: ". $tx->avs_code. "\n"; # Y - Address and ZIP match
269 # A - Address matches but not ZIP
270 # Z - ZIP matches bu tnot address
272 # E - AVS error or unsupported
276 print "Card was rejected: ".$tx->error_message;
277 print " (CVV2 mismatch)" if $tx->result_code == 114;
281 =head1 SUPPORTED TRANSACTION TYPES
283 =head2 Visa, MasterCard, American Express, JCB, Discover/Novus, Carte blanche/Diners Club, CC
285 =head1 SUPPORTED ACTIONS
287 =head2 Normal Authorization, Authorization Only, Post Authorization, Credit, Void
291 For detailed information see L<Business::OnlinePayment>.
295 This module implements an interface to the PayflowPro Perl API, which can
296 be downloaded at https://manager.verisign.com/ with a valid login.
302 Ivan Kohler <ivan-payflowpro@420.am>
304 Based on Busienss::OnlinePayment::AuthorizeNet written by Jason Kohles.
308 perl(1), L<Business::OnlinePayment>.