- include most of the patches from Frédéric Brière at fbriere.net
authorplobbes <plobbes>
Sat, 18 Oct 2008 18:12:46 +0000 (18:12 +0000)
committerplobbes <plobbes>
Sat, 18 Oct 2008 18:12:46 +0000 (18:12 +0000)
- request_id now only generates a new id when not set
- cvv2_code brought back for backwards compatibility
- client_certification_id now defaults to
  "ClientCertificationIdNotSet" (value is reqd but unused per developer docs)
- client_timeout set to 45 by defaults (as recommended by developer docs)
- several doc updates and some reorg

PayflowPro.pm

index c7d31f3..b53c39c 100644 (file)
@@ -9,12 +9,26 @@ use Business::OnlinePayment::HTTPS 0.06;
 
 use base qw(Business::OnlinePayment::HTTPS);
 
-$VERSION = '0.07_05';
+$VERSION = '0.07_06';
 $VERSION = eval $VERSION;
 $DEBUG   = 0;
 
+# return current request_id or generate a new one if not yet set
 sub request_id {
     my $self = shift;
+    if ( ref($self) ) {
+        $self->{"__request_id"} = shift if (@_); # allow value change/reset
+        $self->{"__request_id"} = $self->_new_request_id()
+          unless ( $self->{"__request_id"} );
+        return $self->{"__request_id"};
+    }
+    else {
+        return $self->_new_request_id();
+    }
+}
+
+sub _new_request_id {
+    my $self = shift;
     my $md5  = Digest::MD5->new();
     $md5->add( $$, time(), rand(time) );
     return $md5->hexdigest();
@@ -36,6 +50,9 @@ sub debug {
     return ref($self) ? ( $self->{"__DEBUG"} || $DEBUG ) : $DEBUG;
 }
 
+# cvv2_code: support legacy code and but deprecate method
+sub cvv2_code { shift->cvv2_response(@_); }
+
 sub set_defaults {
     my $self = shift;
     my %opts = @_;
@@ -47,7 +64,8 @@ sub set_defaults {
     $self->path("/transaction");
 
     $self->build_subs(qw( 
-                          partner vendor client_certification_id
+                          partner vendor
+                          client_certification_id client_timeout
                           headers test_server
                           cert_path
                           order_number avs_code cvv2_response
@@ -60,8 +78,13 @@ sub set_defaults {
         delete $opts{debug};
     }
 
-    $self->test_server( "pilot-payflowpro.verisign.com" );
+    # HTTPS Interface Dev Guide: must be set but will be removed in future
+    $self->client_certification_id("ClientCertificationIdNotSet");
+
+    # required: 45 secs recommended by HTTPS Interface Dev Guide
+    $self->client_timeout(45);
 
+    $self->test_server( "pilot-payflowpro.verisign.com" );
 }
 
 sub _map_fields {
@@ -200,11 +223,14 @@ sub submit {
           )
     );
 
-    # get header data, get request_id from %content if defined for ease of use
+    # get header data
     my %req_headers = %{ $self->headers || {} };
+
+    # get request_id from %content if defined for ease of use
     if ( defined $content{"request_id"} ) {
-        $req_headers{"X-VPS-Request-ID"} = $content{"request_id"};
+        $self->request_id( $content{"request_id"} );
     }
+
     unless ( defined( $req_headers{"X-VPS-Request-ID"} ) ) {
         $req_headers{"X-VPS-Request-ID"} = $self->request_id();
     }
@@ -214,6 +240,10 @@ sub submit {
           $self->client_certification_id;
     }
 
+    unless ( defined( $req_headers{"X-VPS-Client-Timeout"} ) ) {
+        $req_headers{"X-VPS-Client-Timeout"} = $self->client_timeout();
+    }
+
     my %options = (
         "Content-Type" => "text/namevalue",
         "headers"      => \%req_headers,
@@ -280,9 +310,9 @@ Business::OnlinePayment::PayflowPro - Payflow Pro backend for Business::OnlinePa
   
   my $tx = new Business::OnlinePayment(
       'PayflowPro',
-      'vendor'    => 'your_vendor',
-      'partner'   => 'your_partner',
-      'client_certification_id' => 'assigned_certification_id', #see NOTE below
+      'vendor'  => 'your_vendor',
+      'partner' => 'your_partner',
+      'client_certification_id' => 'GuidUpTo32Chars',
   );
   
   # See the module documentation for details of content()
@@ -341,8 +371,8 @@ modules supports.
 
 =item set_defaults()
 
-This method sets the 'server' attribute to 'payflowpro.verisign.com' and
-the port attribute to '443'.  This method also sets up the
+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.
 
 =item submit()
@@ -351,9 +381,10 @@ L</Module specific methods> described below.
 
 =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:
+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
 
@@ -370,23 +401,53 @@ supported by multiple gateways modules and expected to be standardized soon:
 This module provides the following methods which are not currently
 part of the standard Business::OnlinePayment interface:
 
-=over 4
+=head2 client_certification_id()
 
-=item L<expdate_mmyy()|/expdate_mmyy()>
+This gets/sets the X-VPS-VITCLIENTCERTIFICATION-ID which is REQUIRED
+and defaults to "ClientCertificationIdNotSet".  This is described in
+Website Payments Pro HTTPS Interface Developer's Guide as follows:
 
-=item L<requeset_id()/request_id()>
+"A random globally unique identifier (GUID) that is currently
+required. This requirement will be removed in the future. At this
+time, you can send any alpha-numeric ID up to 32 characters in length.
 
-=item L<debug()|/debug()>
+NOTE: Once you have created this ID, do not change it. Use the same ID
+for every transaction."
 
-=back
+=head2 client_timeout()
+
+Timeout value, in seconds, after which this transaction should be
+aborted.  Defaults to 45, the value recommended by the Website
+Payments Pro HTTPS Interface Developer's Guide.
+
+=head2 debug()
+
+Enable or disble debugging.  The value specified here will also set
+$Business::OnlinePayment::HTTPS::DEBUG in submit() to aid in
+troubleshooting problems.
+
+=head2 expdate_mmyy()
+
+The expdate_mmyy() method takes a single scalar argument (typically
+the value in $content{expiration}) and attempts to parse and format
+and put the date in MMYY format as required by PayflowPro
+specification.  If unable to parse the expiration date simply leave it
+as is and let the PayflowPro system attempt to handle it as-is.
+
+=head2 request_id()
+
+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.  If a request_id is not set, then Digest::MD5 is used to
+attempt to generate a request_id for a transaction.
 
 =head2 Deprecated methods
 
 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.
+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.
 
 =over 4
 
@@ -396,6 +457,8 @@ no longer used.
 
 =item cert_path()
 
+=item cvv2_code()
+
 =back
 
 =head1 Settings
@@ -537,39 +600,11 @@ follows:
 The cvv2_response() method returns the CVV2MATCH field, which is a
 response message returned with the transaction result.
 
-=head2 expdate_mmyy()
-
-The expdate_mmyy() method takes a single scalar argument (typically
-the value in $content{expiration}) and attempts to parse and format
-and put the date in MMYY format as required by PayflowPro
-specification.  If unable to parse the expiration date simply leave it
-as is and let the PayflowPro system attempt to handle it as-is.
-
-=head2 request_id()
-
-The request_id() method uses Digest::MD5 to attempt to generate a
-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 debug()
-
-Enable or disble debugging.  The value specified here will also set
-$Business::OnlinePayment::HTTPS::DEBUG in submit() to aid in
-troubleshooting problems.
-
 =head1 COMPATIBILITY
 
-As of 0.07, this module communicates with the Payflow gateway directly and no
-longer requires the Payflow Pro SDK or other download.  Thanks to Phil Lobbes
-for this great work.
-
-=head1 NOTE ON CERTIFICATION ID
-
-The Payflow API that this module interfaces with is not yet an officially
-supported service and is still subject to change.  At this time, you need to
-contact payflowintegrator@paypal.com for a certification ID to connect and run
-transactions using this module.
+As of 0.07, this module communicates with the Payflow gateway directly
+and no longer requires the Payflow Pro SDK or other download.  Thanks
+to Phil Lobbes for this great work.
 
 =head1 AUTHORS