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();
36 my %actions = ('normal authorization' => 'S', #Sale
37 'authorization only' => 'A', #Authorization
38 'credit' => 'C', #Credit (refund)
39 'post authorization' => 'D', #Delayed Capture
42 $content{'action'} = $actions{lc($content{'action'})} || $content{'action'};
45 my %types = ('visa' => 'C',
47 'american express' => 'C',
52 $content{'type'} = $types{lc($content{'type'})} || $content{'type'};
53 $self->transaction_type($content{'type'});
55 # stuff it back into %content
56 $self->content(%content);
62 #no warnings; #not 5.005
64 eval "sub $_ { my \$self = shift; if(\@_) { \$self->{$_} = shift; } return \$self->{$_}; }";
71 my %content = $self->content();
73 $content{$map{$_}} = $content{$_};
75 $self->content(%content);
80 my %content = $self->content();
82 # warn "$_ = ". ( ref($map{$_})
84 # : $content{$map{$_}} ). "\n";
85 $content{$_} = ref($map{$_})
89 $self->content(%content);
93 my($self,@fields) = @_;
95 my %content = $self->content();
97 foreach( grep defined $content{$_}, @fields) { $new{$_} = $content{$_}; }
106 my %content = $self->content;
108 my($month, $year, $zip);
110 #unless ( $content{action} eq 'BillOrders' ) {
112 if ( $self->transaction_type() eq 'C' ) {
114 Carp::croak("PayflowPro can't (yet?) handle transaction type: ".
115 $self->transaction_type());
118 if ( exists($content{'expiration'}) && defined($content{'expiration'})
119 && length($content{'expiration'}) ) {
120 $content{'expiration'} =~ /^(\d+)\D+\d*(\d{2})$/
121 or croak "unparsable expiration $content{expiration}";
123 ( $month, $year ) = ( $1, $2 );
124 $month = '0'. $month if $month =~ /^\d$/;
127 $zip = $content{'zip'} =~ s/\D//;
130 #$content{'address'} =~ /^(\S+)\s/;
133 $self->server('test-payflow.verisign.com') if $self->test_transaction;
135 $self->revmap_fields(
136 ACCT => 'card_number',
137 EXPDATE => \( $month.$year ),
140 #VENDOR => \( $self->vendor ),
142 PARTNER => \( $self->partner ),
151 COMMENT1 => 'description',
152 COMMENT2 => 'invoice_number',
153 COMPANYNAME => 'company',
154 COUNTRY => 'country',
155 FIRSTNAME => 'first_name',
156 LASTNAME => 'last_name',
162 ORIGID => 'order_number'
166 my @required = qw( TRXTYPE TENDER PARTNER VENDOR USER PWD );
167 if ( $self->transaction_type() eq 'C' ) { #credit card
168 if ( $self->action() =~ /^[CDV]$/ && exists($content{'ORIGID'})
169 && defined($content{'ORIGID'}) && length($content{'ORIGID'}) ) {
170 push @required, qw(ORIGID);
172 push @required, qw(AMT ACCT EXPDATE);
175 $self->required_fields(@required);
177 my %params = $self->get_fields(qw(
178 ACCT EXPDATE AMT USER VENDOR PARTNER PWD TRXTYPE TENDER
180 CITY COMMENT1 COMMENT2 COMPANYNAME COUNTRY FIRSTNAME LASTNAME NAME EMAIL
185 #print "$_ => $params{$_}\n" foreach keys %params;
187 $ENV{'PFPRO_CERT_PATH'} = $self->cert_path;
188 my( $response, $resultstr ) = pfpro( \%params, $self->server, $self->port );
190 #if ( $response->{'RESULT'} == 0 ) {
191 if ( $response->{'RESULT'} eq '0' ) { #want an explicit zero, not just
193 $self->is_success(1);
194 $self->result_code( $response->{'RESULT'} );
195 $self->error_message( $response->{'RESPMSG'} );
196 $self->authorization( $response->{'AUTHCODE'} );
197 $self->order_number( $response->{'PNREF'} );
199 if ( $response->{AVSADDR} eq 'Y' && $response->{AVSZIP} eq 'Y' ) {
201 } elsif ( $response->{AVSADDR} eq 'Y' ) {
203 } elsif ( $response->{AVSZIP} eq 'Y' ) {
205 } elsif ( $response->{AVSADDR} eq 'N' || $response->{AVSZIP} eq 'N' ) {
208 $self->avs_code( $avs_code );
210 $self->is_success(0);
211 $self->result_code( $response->{'RESULT'} );
212 $self->error_message( $response->{'RESPMSG'} );
222 Business::OnlinePayment::PayflowPro - Verisign PayflowPro backend for Business::OnlinePayment
226 use Business::OnlinePayment;
228 my $tx = new Business::OnlinePayment( 'PayflowPro',
229 'vendor' => 'your_vendor',
230 'partner' => 'your_partner',
231 'cert_path' => '/path/to/your/certificate/file/', #just the dir
236 action => 'Normal Authorization',
237 description => 'Business::OnlinePayment test',
239 invoice_number => '100100',
240 customer_id => 'jsk',
241 name => 'Jason Kohles',
242 address => '123 Anystreet',
246 email => 'ivan-payflowpro@420.am',
247 card_number => '4007000000027',
248 expiration => '09/04',
252 order_number => 'string', # returned by $tx->order_number() from an
253 # "authorization only" or
254 # "normal authorization" action, used by a
255 # "credit", "void", or "post authorization"
259 if($tx->is_success()) {
260 print "Card processed successfully: ".$tx->authorization."\n";
261 print "order number: ". $tx->order_number. "\n";
262 print "AVS code: ". $tx->avs_code. "\n"; # Y - Address and ZIP match
263 # A - Address matches but not ZIP
264 # Z - ZIP matches bu tnot address
266 # E - AVS error or unsupported
270 print "Card was rejected: ".$tx->error_message;
271 print " (CVV2 mismatch)" if $tx->result_code == 114;
275 =head1 SUPPORTED TRANSACTION TYPES
277 =head2 Visa, MasterCard, American Express, JCB, Discover/Novus, Carte blanche/Diners Club, CC
279 =head1 SUPPORTED ACTIONS
281 =head2 Normal Authorization, Authorization Only, Post Authorization, Credit, Void
285 For detailed information see L<Business::OnlinePayment>.
289 This module implements an interface to the PayflowPro Perl API, which can
290 be downloaded at https://manager.verisign.com/ with a valid login.
296 Ivan Kohler <ivan-payflowpro@420.am>
298 Based on Busienss::OnlinePayment::AuthorizeNet written by Jason Kohles.
302 perl(1), L<Business::OnlinePayment>.