depend on B:OP:HTTPS 0.06 for Crypt::SSLeay fixes
[Business-OnlinePayment-PayflowPro.git] / PayflowPro.pm
index dca45ba..6439903 100644 (file)
@@ -5,10 +5,11 @@ use vars qw($VERSION $DEBUG);
 use Carp qw(carp croak);
 use CGI;
 use Digest::MD5;
+use Business::OnlinePayment::HTTPS 0.06;
 
 use base qw(Business::OnlinePayment::HTTPS);
 
-$VERSION = '0.07_01';
+$VERSION = '0.07_04';
 $VERSION = eval $VERSION;
 $DEBUG   = 0;
 
@@ -19,36 +20,6 @@ sub request_id {
     return $md5->hexdigest();
 }
 
-sub param {
-    my $self = shift;
-    my @args = @_;
-
-    $self->{__PARAM} ||= {};
-    my $param = $self->{__PARAM};
-
-    if (@args) {
-        if ( @args % 2 == 0 ) {
-            %$param = ( %$param, @args );
-        }
-        elsif ( @args == 1 ) {
-            my $arg = shift;
-            if ( ref($arg) eq "HASH" ) {
-                %$param = ( %$param, %$arg );
-                return keys %$arg;
-            }
-            else {
-                return $param->{$arg};
-            }
-        }
-        else {
-            croak("param: invalid arguments: @_\n");
-        }
-    }
-    else {
-        return ( keys %$param );
-    }
-}
-
 sub debug {
     my $self = shift;
 
@@ -65,37 +36,32 @@ sub debug {
     return ref($self) ? ( $self->{"__DEBUG"} || $DEBUG ) : $DEBUG;
 }
 
-sub cert_path {
-    carp( __PACKAGE__ . " cert_path method is deprecated" );
-    return undef;
-}
-
-# maybe get rid of build_subs() someday and use param()?
-sub vendor  { my $self = shift; return $self->param( "vendor",  @_ ); }
-sub partner { my $self = shift; return $self->param( "partner", @_ ); }
-sub order_number {
-    my $self = shift;
-    return $self->param( "order_number", @_ );
-}
-sub avs_code  { my $self = shift; return $self->param( "avs_code",  @_ ); }
-sub cvv2_code { my $self = shift; return $self->param( "cvv2_code", @_ ); }
-
 sub set_defaults {
     my $self = shift;
     my %opts = @_;
 
-    $self->server("payflow.verisign.com");
+    # standard B::OP methods/data
+    #$self->server("payflow.verisign.com");
+    $self->server("payflowpro.verisign.com");
     $self->port("443");
-    $self->path("");    # PayflowPro uses /transaction and /commit
+    $self->path("/transaction");
+
+    $self->build_subs(qw( 
+                          partner vendor client_certification_id
+                          headers test_server
+                          cert_path
+                          order_number avs_code cvv2_response
+                          response_page response_code response_headers
+                     ));
+
+    # module specific data
     if ( $opts{debug} ) {
         $self->debug( $opts{debug} );
         delete $opts{debug};
     }
-    $self->param(
-        "path_transaction" => "/transaction",
-        "path_commit"      => "/commit",
-        %opts
-    );
+
+    $self->test_server( "pilot-payflowpro.verisign.com" );
+
 }
 
 sub _map_fields {
@@ -173,10 +139,11 @@ sub submit {
     my $zip          = $content{'zip'};
     $zip =~ s/[^[:alnum:]]//g;
 
-    $self->server('pilot-payflowpro.verisign.com') if $self->test_transaction;
+    $self->server( $self->test_server ) if $self->test_transaction;
 
     my $vendor  = $self->vendor;
     my $partner = $self->partner;
+
     $self->_revmap_fields(
 
         # BUG?: VENDOR B::OP:PayflowPro < 0.05 backward compatibility.  If
@@ -234,12 +201,17 @@ sub submit {
     );
 
     # get header data, get request_id from %content if defined for ease of use
-    my %req_headers = %{ $self->param("headers") || {} };
+    my %req_headers = %{ $self->headers || {} };
     if ( defined $content{"request_id"} ) {
-        $req_headers{"X-VPS-REQUEST-ID"} = $content{"request_id"};
+        $req_headers{"X-VPS-Request-ID"} = $content{"request_id"};
     }
-    unless ( defined( $req_headers{"X-VPS-REQUEST-ID"} ) ) {
-        $req_headers{"X-VPS-REQUEST-ID"} = $self->request_id();
+    unless ( defined( $req_headers{"X-VPS-Request-ID"} ) ) {
+        $req_headers{"X-VPS-Request-ID"} = $self->request_id();
+    }
+
+    unless ( defined( $req_headers{"X-VPS-VIT-Client-Certification-Id"} ) ) {
+        $req_headers{"X-VPS-VIT-Client-Certification-Id"} =
+          $self->client_certification_id;
     }
 
     my %options = (
@@ -247,41 +219,15 @@ sub submit {
         "headers"      => \%req_headers,
     );
 
-    $self->path( $self->param("path_transaction") );
-    my ( $tpage, $tresp, %tresp_headers ) =
+    my ( $page, $resp, %resp_headers ) =
       $self->https_post( \%options, \%params );
 
-    $self->param(
-        "transaction_response" => {
-            page     => $tpage,
-            response => $tresp,
-            headers  => \%tresp_headers,
-        },
-    );
-
-    # $tpage should contain name=value[[&name=value]...] pairs
-    my $cgi = CGI->new("$tpage");
+    $self->response_code( $resp );
+    $self->response_page( $page );
+    $self->response_headers( \%resp_headers );
 
-    if ( $cgi->param("RESULT") eq "0" ) {
-        my $response_id = $tresp_headers{"X-VPS-RESPONSE-ID"};
-        $options{headers}->{"X-VPS-RESPONSE-ID"} = $response_id;
-        $self->path( $self->param("path_commit") );
-        my ( $cpage, $cresp, %cresp_headers ) =
-          $self->https_post( \%options, \%params );
-        $self->param(
-            "commit_response" => {
-                page     => $cpage,
-                response => $cresp,
-                headers  => \%cresp_headers,
-            },
-        );
-        my $comcgi = CGI->new("$cpage");
-
-        # merge commit results with transaction
-        foreach my $p ( $comcgi->param() ) {
-            $cgi->param( $p => $comcgi->param($p) );
-        }
-    }
+    # $page should contain name=value[[&name=value]...] pairs
+    my $cgi = CGI->new("$page");
 
     # AVS and CVS values may be set on success or failure
     my $avs_code;
@@ -305,7 +251,7 @@ sub submit {
     }
 
     $self->avs_code($avs_code);
-    $self->cvv2_code( $cgi->param("CVV2MATCH") );
+    $self->cvv2_response( $cgi->param("CVV2MATCH") );
     $self->result_code( $cgi->param("RESULT") );
     $self->order_number( $cgi->param("PNREF") );
     $self->error_message( $cgi->param("RESPMSG") );
@@ -336,6 +282,7 @@ Business::OnlinePayment::PayflowPro - Payflow Pro backend for Business::OnlinePa
       'PayflowPro',
       'vendor'    => 'your_vendor',
       'partner'   => 'your_partner',
+      'client_certification_id' => 'assigned_certification_id',
   );
   
   # See the module documentation for details of content()
@@ -356,6 +303,7 @@ Business::OnlinePayment::PayflowPro - Payflow Pro backend for Business::OnlinePa
       expiration     => '12/09',
       cvv2           => '123',
       order_number   => 'string',
+      request_id     => 'unique_identifier_for_transaction',
   );
   
   $tx->submit();
@@ -364,7 +312,7 @@ Business::OnlinePayment::PayflowPro - Payflow Pro backend for Business::OnlinePa
       print(
           "Card processed successfully: ", $tx->authorization, "\n",
           "order number: ",                $tx->order_number,  "\n",
-          "CVV2 code: ",                   $tx->cvv2_code,     "\n",
+          "CVV2 response: ",               $tx->cvv2_response, "\n",
           "AVS code: ",                    $tx->avs_code,      "\n",
       );
   }
@@ -393,7 +341,7 @@ modules supports.
 
 =item set_defaults()
 
-This method sets the 'server' attribute to 'payflow.verisign.com' and
+This method sets the 'server' attribute to 'payflowpro.verisign.com' and
 the port attribute to '443'.  This method also sets up the
 L</Module specific methods> described below.
 
@@ -401,6 +349,22 @@ L</Module specific methods> described below.
 
 =back
 
+=head1 Unofficial methods
+
+This module provides the following methods which are not officially part of the
+standard Business::OnlinePayment interface (as of 3.00_06) but are nevertheless
+supported by multiple gateways modules and expected to be standardized soon:
+
+=over 4
+
+=item L<order_number()|/order_number()>
+
+=item L<avs_code()|/avs_code()>
+
+=item L<cvv2_response()|/cvv2_response()>
+
+=back
+
 =head1 Module specific methods
 
 This module provides the following methods which are not currently
@@ -408,30 +372,30 @@ part of the standard Business::OnlinePayment interface:
 
 =over 4
 
-=item vendor()
+=item L<expdate_mmyy()|/expdate_mmyy()>
 
-=item partner()
+=item L<requeset_id()/request_id()>
 
-=item L<order_number()|/order_number()>
+=item L<debug()|/debug()>
 
-=item L<avs_code()|/avs_code()>
+=back
 
-=item L<cvv2_code()|/cvv2_code()>
+=head2 Deprecated methods
 
-=item L<expdate_mmyy()|/expdate_mmyy()>
+The following methods are deprecated and may be removed in a future
+release.  Values for vendor and partner should now be set as arguments to
+Business::OnlinePayment->new().  The value for cert_path was used to support
+passing a path to PFProAPI.pm (a Perl module/SDK from Verisign/Paypal) which is
+no longer used.
 
-=item L<requeset_id()/request_id()>
+=over 4
 
-=item L<param()|/param()>
+=item vendor()
 
-=item L<debug()|/debug()>
+=item partner()
 
 =item cert_path()
 
-This method is deprecated and will be removed in the next release.
-This method was used to support passing a path to PFProAPI.pm (a Perl
-module/SDK from Verisign/Paypal) which is no longer used.
-
 =back
 
 =head1 Settings
@@ -442,7 +406,7 @@ The following default settings exist:
 
 =item server
 
-payflow.verisign.com or test-payflow.verisign.com if
+payflowpro.verisign.com or pilot-payflowpro.verisign.com if
 test_transaction() is TRUE
 
 =item port
@@ -568,9 +532,9 @@ follows:
   N     - no match
   undef - AVS values not available
 
-=head2 cvv2_code()
+=head2 cvv2_response()
 
-The cvv2_code() method returns the CVV2MATCH field, which is a
+The cvv2_response() method returns the CVV2MATCH field, which is a
 response message returned with the transaction result.
 
 =head2 expdate_mmyy()
@@ -588,26 +552,6 @@ request_id for a transaction.  It is recommended that you specify your
 own unique request_id for each transaction in %content.  A request_id
 is REQUIRED by the PayflowPro processor.
 
-=head2 param()
-
-The param() method is used to get/set object parameters.  The param()
-method may be called in several different ways:
-
-Get the value of 'myparam':
-
-  my $value_or_reference = $self->param('myparam');
-
-Get a list of all parameters that exist:
-
-  my @params = $self->param();
-
-Set multiple parameters at the same time:
-
-  $self->param(
-      'key1' => 'val1',
-      'key2' => 'val2',
-  );
-
 =head2 debug()
 
 Enable or disble debugging.  The value specified here will also set