r60669 - in /branches/upstream/libbusiness-onlinepayment-perl/current: Changes MANIFEST META.yml Makefile.PL OnlinePayment.pm OnlinePayment/HTTPS.pm README TODO notes_for_module_writers_v3

gregoa at users.alioth.debian.org gregoa at users.alioth.debian.org
Tue Jul 27 20:24:34 UTC 2010


Author: gregoa
Date: Tue Jul 27 20:24:05 2010
New Revision: 60669

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=60669
Log:
[svn-upgrade] new version libbusiness-onlinepayment-perl (3.01)

Modified:
    branches/upstream/libbusiness-onlinepayment-perl/current/Changes
    branches/upstream/libbusiness-onlinepayment-perl/current/MANIFEST
    branches/upstream/libbusiness-onlinepayment-perl/current/META.yml
    branches/upstream/libbusiness-onlinepayment-perl/current/Makefile.PL
    branches/upstream/libbusiness-onlinepayment-perl/current/OnlinePayment.pm
    branches/upstream/libbusiness-onlinepayment-perl/current/OnlinePayment/HTTPS.pm
    branches/upstream/libbusiness-onlinepayment-perl/current/README
    branches/upstream/libbusiness-onlinepayment-perl/current/TODO
    branches/upstream/libbusiness-onlinepayment-perl/current/notes_for_module_writers_v3

Modified: branches/upstream/libbusiness-onlinepayment-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libbusiness-onlinepayment-perl/current/Changes?rev=60669&op=diff
==============================================================================
--- branches/upstream/libbusiness-onlinepayment-perl/current/Changes (original)
+++ branches/upstream/libbusiness-onlinepayment-perl/current/Changes Tue Jul 27 20:24:05 2010
@@ -1,4 +1,18 @@
 Revision history for Perl extension Business::OnlinePayment.
+
+3.01    Wed Jul 14 13:54:57 PDT 2010
+        - Add optional transaction fields to documentation: tax, freight,
+          duty, tax_exempt, po_number.
+        - Add return fields to documentation: order_number, avs_code,
+          cvv2_response, response_code, response_headers, response_page.
+        - Add beginning of introspection interface for processor modules.
+        - Add electronic check fields to documentation: bank_city, bank_state
+        - Add clarification to notes_for_module_writers_v3 on authorization vs.
+          order_number
+        - (3.01_03) Add ECHECK_void_requires_account to introspection
+        - (3.01_04) Refactor most of the B:OP:HTTPS code out to Net:HTTPS::Any
+        - (3.01_04) Add card_token documentation.  Add token_support to
+          introspection.
 
 3.00     Mon Aug 17 15:55:11 PDT 2009
         - It finally happened.

Modified: branches/upstream/libbusiness-onlinepayment-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libbusiness-onlinepayment-perl/current/MANIFEST?rev=60669&op=diff
==============================================================================
--- branches/upstream/libbusiness-onlinepayment-perl/current/MANIFEST (original)
+++ branches/upstream/libbusiness-onlinepayment-perl/current/MANIFEST Tue Jul 27 20:24:05 2010
@@ -14,3 +14,4 @@
 notes_for_module_writers
 notes_for_module_writers_v3
 META.yml                                 Module meta-data (added by MakeMaker)
+TODO

Modified: branches/upstream/libbusiness-onlinepayment-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libbusiness-onlinepayment-perl/current/META.yml?rev=60669&op=diff
==============================================================================
--- branches/upstream/libbusiness-onlinepayment-perl/current/META.yml (original)
+++ branches/upstream/libbusiness-onlinepayment-perl/current/META.yml Tue Jul 27 20:24:05 2010
@@ -1,12 +1,23 @@
-# http://module-build.sourceforge.net/META-spec.html
-#XXXXXXX This is a prototype!!!  It will change in the future!!! XXXXX#
-name:         Business-OnlinePayment
-version:      3.00
-version_from: OnlinePayment.pm
-installdirs:  site
+--- #YAML:1.0
+name:               Business-OnlinePayment
+version:            3.01
+abstract:           ~
+author:
+    - Ivan Kohler <ivan-business-onlinepayment at 420.am>
+license:            unknown
+distribution_type:  module
+configure_requires:
+    ExtUtils::MakeMaker:  0
+build_requires:
+    ExtUtils::MakeMaker:  0
 requires:
-    URI::Escape:                   0
-    Tie::IxHash:                   0
-
-distribution_type: module
-generated_by: ExtUtils::MakeMaker version 6.17
+    Net::HTTPS::Any:  0
+    Tie::IxHash:      0
+no_index:
+    directory:
+        - t
+        - inc
+generated_by:       ExtUtils::MakeMaker version 6.55_02
+meta-spec:
+    url:      http://module-build.sourceforge.net/META-spec-v1.4.html
+    version:  1.4

Modified: branches/upstream/libbusiness-onlinepayment-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libbusiness-onlinepayment-perl/current/Makefile.PL?rev=60669&op=diff
==============================================================================
--- branches/upstream/libbusiness-onlinepayment-perl/current/Makefile.PL (original)
+++ branches/upstream/libbusiness-onlinepayment-perl/current/Makefile.PL Tue Jul 27 20:24:05 2010
@@ -8,14 +8,8 @@
     'PMLIBDIRS'    => [ 'OnlinePayment', 'FraudDetect' ],
     'NORECURS'     => 1, # dont descend into subdirectories
     'PREREQ_PM'    => { 
-                        # for HTTPS (maybe it should be a separate dist?)
-                        'URI::Escape' => 0,
-                        'Tie::IxHash' => 0,
-
-                        # 'Net::SSLeay' => 0,
-                        # or 'Crypt::SSLeay' => 0,
-                        #    'URI
-
+                        'Tie::IxHash'     => 0,
+                        'Net::HTTPS::Any' => 0,
                       },
     #'dist'         => {CI => 'ci -l'},
 );

Modified: branches/upstream/libbusiness-onlinepayment-perl/current/OnlinePayment.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libbusiness-onlinepayment-perl/current/OnlinePayment.pm?rev=60669&op=diff
==============================================================================
--- branches/upstream/libbusiness-onlinepayment-perl/current/OnlinePayment.pm (original)
+++ branches/upstream/libbusiness-onlinepayment-perl/current/OnlinePayment.pm Tue Jul 27 20:24:05 2010
@@ -1,35 +1,80 @@
 package Business::OnlinePayment;
 
 use strict;
-use vars qw($VERSION);
+use vars qw($VERSION %_info_handler);
 use Carp;
 
 require 5.005;
 
-$VERSION = '3.00';
+$VERSION = '3.01';
 $VERSION = eval $VERSION; # modperlstyle: convert the string into a number
 
 # Remember subclasses we have "wrapped" submit() with _pre_submit()
 my %Presubmit_Added = ();
 
-my %fields = (
-    authorization        => undef,
-    error_message        => undef,
-    failure_status       => undef,
-    fraud_detect         => undef,
-    is_success           => undef,
-    maximum_risk         => undef,
-    path                 => undef,
-    port                 => undef,
-    require_avs          => undef,
-    result_code          => undef,
-    server               => undef,
-    server_response      => undef,
-    test_transaction     => undef,
-    transaction_type     => undef,
-    fraud_score          => undef,
-    fraud_transaction_id => undef,
+my @methods = qw(
+    authorization
+    order_number
+    error_message
+    failure_status
+    fraud_detect
+    is_success
+    maximum_risk
+    path
+    port
+    require_avs
+    result_code
+    server
+    server_response
+    test_transaction
+    transaction_type
+    fraud_score
+    fraud_transaction_id
+    response_code
+    response_header
+    response_page
 );
+
+#fallback
+sub _info {
+  my $class = shift;
+  ( my $gw = $class ) =~ s/^Business::OnlinePayment:://;
+  {
+    'info_compat'    => '0.00',
+    'gateway_name'   => $gw,
+    'module_notes'   => "Module does not yet provide info.",
+  };
+}
+
+#allow classes to declare info in a flexible way, but return normalized info
+%_info_handler = (
+  'supported_types'   => sub {
+    my( $class, $v ) = @_;
+    my $types = ref($v) ? $v : [ $v ];
+    $types = { map { $_=>1 } @$types } if ref($v) eq 'ARRAY';
+    $types;
+  },
+  'supported_actions' => sub {
+    my( $class, $v ) = @_;
+    return $v if ref($v) eq 'HASH';
+    $v = [ $v ] unless ref($v);
+    my $types = $class->info('supported_types');
+    { map { $_ => $v } keys %$types };
+  },
+);
+
+sub info {
+  my $class = shift; #class or object
+  my $info = $class->_info;
+  if ( @_ ) {
+    my $key = shift;
+    exists($_info_handler{$key})
+      ? &{ $_info_handler{$key} }( $class, $info->{$key} )
+      : $info->{$key};
+  } else {
+    wantarray ? ( keys %$info ) : [ keys %$info ];
+  }
+}
 
 sub new {
     my($class,$processor,%data) = @_;
@@ -41,7 +86,7 @@
     croak("unknown processor $processor ($@)") if $@;
 
     my $self = bless {processor => $processor}, $subclass;
-    $self->build_subs(keys %fields);
+    $self->build_subs(@methods);
 
     if($self->can("set_defaults")) {
         $self->set_defaults(%data);
@@ -112,7 +157,7 @@
               unless ( $@ =~ m/^Can\'t locate/ );
         } else {
             my $risk_tx = bless( { processor => $fraud_detection }, $subclass );
-            $risk_tx->build_subs(keys %fields);
+            $risk_tx->build_subs(@methods);
             if ($risk_tx->can('set_defaults')) {
                 $risk_tx->set_defaults();
             }
@@ -195,6 +240,17 @@
         next if($self->can($_));
         eval "sub $_ { my \$self = shift; if(\@_) { \$self->{$_} = shift; } return \$self->{$_}; }";
     }
+}
+
+#helper method
+
+sub silly_bool {
+  my( $self, $value ) = @_;
+  return 1 if $value =~ /^[yt]/i;
+  return 0 if $value =~ /^[fn]/i;
+  #return 1 if $value == 1;
+  #return 0 if $value == 0;
+  $value; #die??
 }
 
 1;
@@ -230,9 +286,9 @@
 Business::OnlinePayment is a generic module for processing payments
 through online credit card processors, electronic cash systems, etc.
 
-=head1 METHODS AND FUNCTIONS
-
-=head2 new($processor, %processor_options);
+=head1 CONSTRUCTOR
+
+=head2 new($processor, %processor_options)
 
 Create a new Business::OnlinePayment object, $processor is required,
 and defines the online processor to use.  If necessary, processor
@@ -243,7 +299,9 @@
 only if absolutely necessary (especially path), as the processor
 module was probably written with a specific target script in mind.
 
-=head2 content(%content);
+=head1 TRANSACTION SETUP METHODS
+
+=head2 content(%content)
 
 The information necessary for the transaction, this tends to vary a
 little depending on the processor, so we have chosen to use a system
@@ -254,130 +312,173 @@
 
 =over 4
 
-=item * login
+=item login
 
 Your login name to use for authentication to the online processor.
 
-=item * password
+=item password
 
 Your password to use for authentication to the online processor.
 
 =back
 
-=head3 GENERAL TRANSACTION FIELDS
+=head3 REQUIRED TRANSACTION FIELDS
 
 =over 4
 
-=item * type
+=item type
 
 Transaction type, supported types are: CC (credit card), ECHECK
 (electronic check) and LEC (phone bill billing).  Deprecated types
-are: Visa, MasterCard, American Express, Discover, Check (not all
-processors support all these transaction types).
-
-=item * action
-
-What to do with the transaction (currently available are: Normal
-Authorization, Authorization Only, Credit, Post Authorization,
-Recurring Authorization, Modify Recurring Authorization,
-Cancel Recurring Authorization)
-
-=item * description
+are: Visa, MasterCard, American Express, Discover, Check.  Not all
+processors support all transaction types.
+
+=item action
+
+What action being taken by this transaction. Currently available are:
+
+=over 8
+
+=item Normal Authorization
+
+=item Authorization Only
+
+=item Post Authorization
+
+=item Void
+
+=item Credit
+
+=item Recurring Authorization
+
+=item Modify Recurring Authorization
+
+=item Cancel Recurring Authorization
+
+=back
+
+=item amount
+
+The amount of the transaction.  No dollar signs or currency identifiers,
+just a whole or floating point number (i.e. 26, 26.1 or 26.13).
+
+=back
+
+=head3 OPTIONAL TRANSACTION FIELDS
+
+=over 4
+
+=item description
 
 A description of the transaction (used by some processors to send
 information to the client, normally not a required field).
 
-=item * amount
-
-The amount of the transaction, most processors don't want dollar signs
-and the like, just a floating point number.
-
-=item * invoice_number
+=item invoice_number
 
 An invoice number, for your use and not normally required, many
 processors require this field to be a numeric only field.
 
+=item po_number
+
+Purchase order number (normally not required).
+
+=item tax
+
+Tax amount (portion of amount field, not added to it).
+
+=item freight
+
+Freight amount (portion of amount field, not added to it).
+
+=item duty
+
+Duty amount (portion of amount field, not added to it).
+
+=item tax_exempt
+
+Tax exempt flag (i.e. TRUE, FALSE, T, F, YES, NO, Y, N, 1, 0).
+
 =back
 
 =head3 CUSTOMER INFO FIELDS
 
 =over 4
 
-=item * customer_id
+=item customer_id
 
 A customer identifier, again not normally required.
 
-=item * name
+=item name
 
 The customer's name, your processor may not require this.
 
-=item * first_name
-
-=item * last_name
+=item first_name
+
+=item last_name
 
 The customer's first and last name as separate fields.
 
-=item * company
+=item company
 
 The customer's company name, not normally required.
 
-=item * address
+=item address
 
 The customer's address (your processor may not require this unless you
 are requiring AVS Verification).
 
-=item * city
+=item city
 
 The customer's city (your processor may not require this unless you
 are requiring AVS Verification).
 
-=item * state
+=item state
 
 The customer's state (your processor may not require this unless you
 are requiring AVS Verification).
 
-=item * zip
+=item zip
 
 The customer's zip code (your processor may not require this unless
 you are requiring AVS Verification).
 
-=item * country
+=item country
 
 Customer's country.
 
-=item * ship_first_name
-
-=item * ship_last_name
-
-=item * ship_company
-
-=item * ship_address
-
-=item * ship_city
-
-=item * ship_state
-
-=item * ship_zip
-
-=item * ship_country
+=item ship_first_name
+
+=item ship_last_name
+
+=item ship_company
+
+=item ship_address
+
+=item ship_city
+
+=item ship_state
+
+=item ship_zip
+
+=item ship_country
 
 These shipping address fields may be accepted by your processor.
 Refer to the description for the corresponding non-ship field for
 general information on each field.
 
-=item * phone
+=item phone
 
 Customer's phone number.
 
-=item * fax
+=item fax
 
 Customer's fax number.
 
-=item * email
+=item email
 
 Customer's email address.
 
-=item * customer_ip
+=item customer_ip
 
 IP Address from which the transaction originated.
 
@@ -387,28 +488,41 @@
 
 =over 4
 
-=item * card_number
+=item card_number
 
 Credit card number.
 
-=item * cvv2
+=item expiration
+
+Credit card expiration.
+
+=item cvv2
 
 CVV2 number (also called CVC2 or CID) is a three- or four-digit
 security code used to reduce credit card fraud.
 
-=item * expiration
-
-Credit card expiration.
-
-=item * track1
+=item card_token
+
+If supported by your gateway, you can pass a card_token instead of a
+card_number and expiration.
+
+=cut
+
+#=item card_response
+#
+#Some card_token schemes implement a challenge/response handshake.  In those
+#cases, this field is used for the response.  In most cases the handshake
+#it taken care of by the gateway module.
+
+=item track1
 
 Track 1 on the magnetic stripe (Card present only)
 
-=item * track2
+=item track2
 
 Track 2 on the magnetic stripe (Card present only)
 
-=item * recurring billing
+=item recurring billing
 
 Recurring billing flag
 
@@ -418,53 +532,54 @@
 
 =over 4
 
-=item * account_number
-
-Bank account number for electronic checks or electronic funds
-transfer.
-
-=item * routing_code
-
-Bank's routing code for electronic checks or electronic funds
-transfer.
-
-=item * account_type
-
-Account type for electronic checks or electronic funds transfer.  Can be
-(case-insensitive): B<Personal Checking>, B<Personal Savings>,
-B<Business Checking> or B<Business Savings>.
-
-=item * account_name
-
-Account holder's name for electronic checks or electronic funds
-transfer.
-
-=item * bank_name
-
-Bank's name for electronic checks or electronic funds transfer.
-
-=item * check_type
-
-Check type for electronic checks or electronic funds transfer.
-
-=item * customer_org
+=item account_number
+
+Bank account number
+
+=item routing_code
+
+Bank's routing code
+
+=item account_type
+
+Account type.  Can be (case-insensitive): B<Personal Checking>,
+B<Personal Savings>, B<Business Checking> or B<Business Savings>.
+
+=item account_name
+
+Account holder's name.
+
+=item bank_name
+
+Bank name.
+
+=item bank_city
+
+Bank city.
+
+=item bank_state
+
+Bank state.
+
+=item check_type
+
+Check type.
+
+=item customer_org
 
 Customer organization type.
 
-=item * customer_ssn
-
-Customer's social security number.  Typically only required for
-electronic checks or electronic funds transfer.
-
-=item * license_num
-
-Customer's driver's license number.  Typically only required for
-electronic checks or electronic funds transfer.
-
-=item * license_dob
-
-Customer's date of birth.  Typically only required for electronic
-checks or electronic funds transfer.
+=item customer_ssn
+
+Customer's social security number.
+
+=item license_num
+
+Customer's driver's license number.
+
+=item license_dob
+
+Customer's date of birth.
 
 =back
 
@@ -472,17 +587,17 @@
 
 =over 4
 
-=item * interval 
+=item interval 
 
 Interval expresses the amount of time between billings: digits, whitespace
 and units (currently "days" or "months" in either singular or plural form).
 
-=item * start
+=item start
 
 The date of the first transaction (used for processors which allow delayed
 start) expressed as YYYY-MM-DD.
 
-=item * periods
+=item periods
 
 The number of cycles of interval length for which billing should occur 
 (inclusive of 'trial periods' if the processor supports recurring billing
@@ -490,16 +605,39 @@
 
 =back
 
-=head2 submit();
+=head2 test_transaction()
+
+Most processors provide a test mode, where submitted transactions will
+not actually be charged or added to your batch, calling this function
+with a true argument will turn that mode on if the processor supports
+it, or generate a fatal error if the processor does not support a test
+mode (which is probably better than accidentally making real charges).
+
+=head2 require_avs()
+
+Providing a true argument to this module will turn on address
+verification (if the processor supports it).
+
+=head1 TRANSACTION SUBMISSION METHOD
+
+=head2 submit()
 
 Submit the transaction to the processor for completion
 
-=head2 is_success();
+=head1 TRANSACTION RESULT METHODS
+
+=head2 is_success()
 
 Returns true if the transaction was submitted successfully, false if
 it failed (or undef if it has not been submitted yet).
 
-=head2 failure_status();
+=head2 error_message()
+
+If the transaction has been submitted but was not accepted, this
+function will return the provided error message (if any) that the
+processor returned.
+
+=head2 failure_status()
 
 If the transaction failed, it can optionally return a specific failure
 status (normalized, not gateway-specific).  Currently defined statuses
@@ -512,72 +650,131 @@
 status is an entirely optional field that is only set for specific
 kinds of failures.
 
-=head2 result_code();
+=head2 authorization()
+
+If the transaction has been submitted and accepted, this function will
+provide you with the authorization code that the processor returned.
+Store this if you would like to run inquiries or refunds on the transaction
+later.
+
+=head2 order_number()
+
+The unique order number for the transaction generated by the gateway.  Store
+this if you would like to run inquiries or refunds on the transaction later.
+
+=head2 card_token()
+
+If supported by your gateway, a card_token can be used in a subsequent
+transaction to refer to a card number.
+
+=head2 fraud_score()
+
+Retrieve or change the fraud score from any Business::FraudDetect plugin
+
+=head2 fraud_transaction_id()
+
+Retrieve or change the transaction id from any Business::FraudDetect plugin
+
+=head2 response_code()
+
+=head2 response_headers()
+
+=head2 response_page()
+
+These three fields are set by some processors (especially those which use
+HTTPS) when the transaction fails at the communication level rather than
+as a transaction.
+
+response_code is the HTTP response code and message, i.e.
+'500 Internal Server Error'.
+
+response_headers is a hash reference of the response headers
+
+response_page is the raw content.
+
+=head2 result_code()
 
 Returns the precise result code that the processor returned, these are
 normally one letter codes that don't mean much unless you understand
 the protocol they speak, you probably don't need this, but it's there
 just in case.
 
-=head2 test_transaction();
-
-Most processors provide a test mode, where submitted transactions will
-not actually be charged or added to your batch, calling this function
-with a true argument will turn that mode on if the processor supports
-it, or generate a fatal error if the processor does not support a test
-mode (which is probably better than accidentally making real charges).
-
-=head2 require_avs();
-
-Providing a true argument to this module will turn on address
-verification (if the processor supports it).
-
-=head2 transaction_type();
+=head2 avs_code()
+
+=head2 cvv2_response()
+
+=head1 MISCELLANEOUS INTERNAL METHODS
+
+=head2 transaction_type()
 
 Retrieve the transaction type (the 'type' argument to contents()).
 Generally only used internally, but provided in case it is useful.
 
-=head2 error_message();
-
-If the transaction has been submitted but was not accepted, this
-function will return the provided error message (if any) that the
-processor returned.
-
-=head2 authorization();
-
-If the transaction has been submitted and accepted, this function will
-provide you with the authorization code that the processor returned.
-
-=head2 server();
+=head2 server()
 
 Retrieve or change the processor submission server address (CHANGE AT
 YOUR OWN RISK).
 
-=head2 port();
+=head2 port()
 
 Retrieve or change the processor submission port (CHANGE AT YOUR OWN
 RISK).
 
-=head2 path();
+=head2 path()
 
 Retrieve or change the processor submission path (CHANGE AT YOUR OWN
 RISK).
 
-=head2 fraud_score();
-
-Retrieve or change the fraud score from any Business::FraudDetect plugin
-
-=head2 fraud_transaction_id();
-
-Retrieve or change the transaction id from any Business::FraudDetect plugin
+=head1 HELPER METHODS FOR GATEWAY MODULE AUTHORS
+
+=head2 build_subs( @sub_names )
+
+Build setter/getter subroutines for new return values.
+
+=head2 get_fields( @fields )
+
+Get the named fields if they are defined.
+
+=head2 remap_fields( %map )
+
+Remap field content (and stuff it back into content).
+
+=head2 required_fields( @fields )
+
+Croaks if any of the required fields are not present.
+
+=head2 dump_contents
+
+=head2 silly_bool( $value )
+
+Returns 0 if the value starts with y, Y, t or T.
+Returns 1 if the value starts with n, N, f or F.
+Otherwise returns the value itself.
+
+Use this for handling boolean content like tax_exempt.
 
 =head1 AUTHORS
 
+(v2 series)
+
 Jason Kohles, email at jasonkohles.com
 
-(v3 rewrite) Ivan Kohler <ivan-business-onlinepayment at 420.am>
+(v3 rewrite)
+
+Ivan Kohler <ivan-business-onlinepayment at 420.am>
 
 Phil Lobbes E<lt>phil at perkpartners dot comE<gt>
+
+=head1 COPYRIGHT
+
+Copyright (c) 1999-2004 Jason Kohles
+Copyright (c) 2004 Ivan Kohler
+Copyright (c) 2007-2010 Freeside Internet Services, Inc.
+
+All rights reserved.
+
+This program is free software; you can redistribute it and/or modify it under
+the same terms as Perl itself.
 
 =head1 HOMEPAGE
 

Modified: branches/upstream/libbusiness-onlinepayment-perl/current/OnlinePayment/HTTPS.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libbusiness-onlinepayment-perl/current/OnlinePayment/HTTPS.pm?rev=60669&op=diff
==============================================================================
--- branches/upstream/libbusiness-onlinepayment-perl/current/OnlinePayment/HTTPS.pm (original)
+++ branches/upstream/libbusiness-onlinepayment-perl/current/OnlinePayment/HTTPS.pm Tue Jul 27 20:24:05 2010
@@ -1,45 +1,13 @@
 package Business::OnlinePayment::HTTPS;
 
 use strict;
-use vars qw($VERSION $DEBUG $ssl_module $skip_NetSSLeay);
-use URI::Escape;
+use base qw(Business::OnlinePayment);
+use vars qw($VERSION $DEBUG);
 use Tie::IxHash;
-use base qw(Business::OnlinePayment);
+use Net::HTTPS::Any 0.10;
 
-$VERSION = '0.09';
+$VERSION = '0.10';
 $DEBUG   = 0;
-
-BEGIN {
-
-    $ssl_module = '';
-
-    eval {
-        die if defined($skip_NetSSLeay) && $skip_NetSSLeay;
-        require Net::SSLeay;
-        Net::SSLeay->VERSION(1.30);
-
-        #import Net::SSLeay
-        #  qw(get_https post_https make_form make_headers);
-        $ssl_module = 'Net::SSLeay';
-    };
-
-    if ($@) {
-        eval {
-            require LWP::UserAgent;
-            require HTTP::Request::Common;
-            require Crypt::SSLeay;
-
-            #import HTTP::Request::Common qw(GET POST);
-            $ssl_module = 'Crypt::SSLeay';
-        };
-    }
-
-    unless ($ssl_module) {
-        die "One of Net::SSLeay (v1.30 or later)"
-          . " or Crypt::SSLeay (+LWP) is required";
-    }
-
-}
 
 =head1 NAME
 
@@ -72,7 +40,8 @@
 This is a base class for HTTPS based gateways, providing useful code
 for implementors of HTTPS payment APIs.
 
-It depends on Net::SSLeay _or_ ( Crypt::SSLeay and LWP::UserAgent ).
+It depends on Net::HTTPS::Any, which in turn depends on
+Net::SSLeay _or_ ( Crypt::SSLeay and LWP::UserAgent ).
 
 =head1 METHODS
 
@@ -88,108 +57,53 @@
 response code and message (i.e. "200 OK" or "404 Not Found"), and a list of
 key/value pairs representing the HTTP response headers.
 
-The options hashref supports setting headers and Content-Type:
+The options hashref supports setting headers:
 
   {
       headers => { 'X-Header1' => 'value', ... },
-      Content-Type => 'text/namevalue',
   }
 
 =cut
+
+#      Content-Type => 'text/namevalue',
 
 sub https_get {
     my $self = shift;
 
     # handle optional options hashref
-    my $opts;
+    my $opts = {};
     if ( scalar(@_) > 1 and ref( $_[0] ) eq "HASH" ) {
-        $opts = shift;
+      $opts = shift;
     }
 
     # accept a hashref or a list (keep it ordered)
     my $post_data;
     if ( ref( $_[0] ) eq 'HASH' ) {
-        $post_data = shift;
-    }
-    elsif ( scalar(@_) > 1 ) {
-        tie my %hash, 'Tie::IxHash', @_;
-        $post_data = \%hash;
-    }
-    elsif ( scalar(@_) == 1 ) {
-        $post_data = shift;
-    }
-    else {
-        die "https_get called with no params\n";
-    }
-
-    $opts->{"Content-Type"} ||= "application/x-www-form-urlencoded";
-
-    ### XXX referer!!!
-    my %headers;
-    if ( ref( $opts->{headers} ) eq "HASH" ) {
-        %headers = %{ $opts->{headers} };
-    }
-    $headers{'Host'} ||= $self->server;
-
-    my $path = $self->path;
-    if ( keys %$post_data ) {
-        $path .= '?'
-          . join( '&',
-            map { uri_escape($_) . '=' . uri_escape( $post_data->{$_} ) }
-              keys %$post_data );
+      $post_data = shift;
+    } elsif ( scalar(@_) > 1 ) {
+      tie my %hash, 'Tie::IxHash', @_;
+      $post_data = \%hash;
+    } elsif ( scalar(@_) == 1 ) {
+      $post_data = shift;
+    } else {
+      die "https_get called with no params\n";
     }
 
     $self->build_subs(qw( response_page response_code response_headers ));
 
-    if ( $ssl_module eq 'Net::SSLeay' ) {
+    my( $res_page, $res_code, @res_headers) = Net::HTTPS::Any::https_get( 
+      'host'    => $self->server,
+      'path'    => $self->path,
+      'headers' => $opts->{headers},
+      'args'    => $post_data,
+      'debug'   => $DEBUG,
+    );
 
-        import Net::SSLeay qw(get_https make_headers);
-        my $headers = make_headers(%headers);
+    $self->response_page( $res_page );
+    $self->response_code( $res_code );
+    $self->response_headers( { @res_headers } );
 
-        my( $res_page, $res_code, @res_headers ) =
-          get_https( $self->server,
-                     $self->port,
-                     $path,
-                     $headers,
-                     "",
-                     $opts->{"Content-Type"},
-                   );
-
-        $res_code =~ /^(HTTP\S+ )?(.*)/ and $res_code = $2;
-
-        $self->response_page( $res_page );
-        $self->response_code( $res_code );
-        $self->response_headers( { @res_headers } );
-
-        ( $res_page, $res_code, @res_headers );
-
-    } elsif ( $ssl_module eq 'Crypt::SSLeay' ) {
-
-        import HTTP::Request::Common qw(GET);
-
-        my $url = 'https://' . $self->server;
-        $url .= ':' . $self->port
-          unless $self->port == 443;
-        $url .= "/$path";
-
-        my $ua = new LWP::UserAgent;
-        foreach my $hdr ( keys %headers ) {
-            $ua->default_header( $hdr => $headers{$hdr} );
-        }
-        my $res = $ua->request( GET($url) );
-
-        my @res_headers = map { $_ => $res->header($_) }
-                              $res->header_field_names;
-
-        $self->response_page( $res->content );
-        $self->response_code( $res->code. ' '. $res->message );
-        $self->response_headers( { @res_headers } );
-
-        ( $res->content, $res->code. ' '. $res->message, @res_headers );
-
-    } else {
-        die "unknown SSL module $ssl_module";
-    }
+    ( $res_page, $res_code, @res_headers );
 
 }
 
@@ -218,115 +132,42 @@
     my $self = shift;
 
     # handle optional options hashref
-    my $opts;
+    my $opts = {};
     if ( scalar(@_) > 1 and ref( $_[0] ) eq "HASH" ) {
         $opts = shift;
     }
 
+    my %post = (
+      'host'         => $self->server,
+      'path'         => $self->path,
+      'headers'      => $opts->{headers},
+      'Content-Type' => $opts->{'Content-Type'},
+      'debug'        => $DEBUG,
+    );
+
     # accept a hashref or a list (keep it ordered)
-    my $post_data;
+    my $post_data = '';
+    my $content = undef;
     if ( ref( $_[0] ) eq 'HASH' ) {
-        $post_data = shift;
-    }
-    elsif ( scalar(@_) > 1 ) {
-        tie my %hash, 'Tie::IxHash', @_;
-        $post_data = \%hash;
-    }
-    elsif ( scalar(@_) == 1 ) {
-        $post_data = shift;
-    }
-    else {
-        die "https_post called with no params\n";
-    }
-
-    $opts->{"Content-Type"} ||= "application/x-www-form-urlencoded";
-
-    ### XXX referer!!!
-    my %headers;
-    if ( ref( $opts->{headers} ) eq "HASH" ) {
-        %headers = %{ $opts->{headers} };
-    }
-    $headers{'Host'} ||= $self->server;
-
-    if ( $DEBUG && ref($post_data) ) {
-        warn "post data:\n",
-          join( '',
-            map { "  $_ => " . $post_data->{$_} . "\n" } keys %$post_data );
+      $post{'args'} = shift;
+    } elsif ( scalar(@_) > 1 ) {
+      tie my %hash, 'Tie::IxHash', @_;
+      $post{'args'} = \%hash;
+    } elsif ( scalar(@_) == 1 ) {
+      $post{'content'} = shift;
+    } else {
+      die "https_post called with no params\n";
     }
 
     $self->build_subs(qw( response_page response_code response_headers ));
 
-    if ( $ssl_module eq 'Net::SSLeay' ) {
+    my( $res_page, $res_code, @res_headers)= Net::HTTPS::Any::https_post(%post);
 
-        import Net::SSLeay qw(post_https make_headers make_form);
-        my $headers = make_headers(%headers);
+    $self->response_page( $res_page );
+    $self->response_code( $res_code );
+    $self->response_headers( { @res_headers } );
 
-        if ($DEBUG) {
-            no warnings 'uninitialized';
-            warn $self->server . ':' . $self->port . $self->path . "\n";
-            $Net::SSLeay::trace = $DEBUG;
-        }
-
-        my $raw_data = ref($post_data) ? make_form(%$post_data) : $post_data;
-
-        my( $res_page, $res_code, @res_headers ) =
-          post_https( $self->server,
-                      $self->port,
-                      $self->path,
-                      $headers,
-                      $raw_data,
-                      $opts->{"Content-Type"},
-                    );
-
-        $res_code =~ /^(HTTP\S+ )?(.*)/ and $res_code = $2;
-
-        $self->response_page( $res_page );
-        $self->response_code( $res_code );
-        $self->response_headers( { @res_headers } );
-
-        ( $res_page, $res_code, @res_headers );
-
-    } elsif ( $ssl_module eq 'Crypt::SSLeay' ) {
-
-        import HTTP::Request::Common qw(POST);
-
-        my $url = 'https://' . $self->server;
-        $url .= ':' . $self->port
-          unless $self->port == 443;
-        $url .= $self->path;
-
-        if ($DEBUG) {
-            warn $url;
-        }
-
-        my $ua = new LWP::UserAgent;
-        foreach my $hdr ( keys %headers ) {
-            $ua->default_header( $hdr => $headers{$hdr} );
-        }
-
-        my $res;
-        if ( ref($post_data) ) {
-            $res = $ua->request( POST( $url, [%$post_data] ) );
-        }
-        else {
-            my $req = new HTTP::Request( 'POST' => $url );
-            $req->content_type( $opts->{"Content-Type"} );
-            $req->content($post_data);
-            $res = $ua->request($req);
-        }
-
-        my @res_headers = map { $_ => $res->header($_) }
-                              $res->header_field_names;
-
-        $self->response_page( $res->content );
-        $self->response_code( $res->code. ' '. $res->message );
-        $self->response_headers( { @res_headers } );
-
-        ( $res->content, $res->code. ' '. $res->message, @res_headers );
-
-    } else {
-        die "unknown SSL module $ssl_module";
-    }
+    ( $res_page, $res_code, @res_headers );
 
 }
 
@@ -334,7 +175,7 @@
 
 =head1 SEE ALSO
 
-L<Business::OnlinePayment>
+L<Business::OnlinePayment>, L<Net::HTTPS::Any>
 
 =cut
 

Modified: branches/upstream/libbusiness-onlinepayment-perl/current/README
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libbusiness-onlinepayment-perl/current/README?rev=60669&op=diff
==============================================================================
--- branches/upstream/libbusiness-onlinepayment-perl/current/README (original)
+++ branches/upstream/libbusiness-onlinepayment-perl/current/README Tue Jul 27 20:24:05 2010
@@ -1,6 +1,6 @@
 Copyright (c) 1999-2004 Jason Kohles
 Copyright (c) 2004 Ivan Kohler
-Copyright (c) 2007-2009 Freeside Internet Services, Inc.
+Copyright (c) 2007-2010 Freeside Internet Services, Inc.
 
 All rights reserved. This program is free software; you can redistribute
 it and/or modify it under the same terms as Perl itself.

Modified: branches/upstream/libbusiness-onlinepayment-perl/current/TODO
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libbusiness-onlinepayment-perl/current/TODO?rev=60669&op=diff
==============================================================================
--- branches/upstream/libbusiness-onlinepayment-perl/current/TODO (original)
+++ branches/upstream/libbusiness-onlinepayment-perl/current/TODO Tue Jul 27 20:24:05 2010
@@ -3,4 +3,7 @@
 - Use Net::HTTPS::Any
 - hmm... requires HTTP::Headers v1.59
 - move revmap_fields into the base class
-
+- remap_fields: Not the cleanest thing to mix up our namespace with the
+  processor-specific names.
+- Define a better model of exception handling that doesn't involve dying on
+  some things.

Modified: branches/upstream/libbusiness-onlinepayment-perl/current/notes_for_module_writers_v3
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libbusiness-onlinepayment-perl/current/notes_for_module_writers_v3?rev=60669&op=diff
==============================================================================
--- branches/upstream/libbusiness-onlinepayment-perl/current/notes_for_module_writers_v3 (original)
+++ branches/upstream/libbusiness-onlinepayment-perl/current/notes_for_module_writers_v3 Tue Jul 27 20:24:05 2010
@@ -4,9 +4,6 @@
 
 - If your gateway is HTTPS-based, use (or convert to)
   Business::OnlinePayment::HTTPS !!
-
-    - Business::OnlinePayment::OpenECHO is the first "v3-ish" module, try
-      starting from there.
 
 
 - Handling failures:
@@ -38,4 +35,78 @@
 
       (or add "failure_status" to your build_subs call if you have one during
       initialization)
-      
+
+
+- (NEW IN 3.01) Introspection:
+
+  - Add an _info subroutine to your module that returns a hashref of
+    information:
+
+      sub _info {
+        {
+          'info_compat'           => '0.01', # always 0.01 for now,
+                                             # 0.02 will have requirements
+          'gateway_name'          => 'Example Gateway',
+          'gateway_url'           => 'http://www.example.com/',
+          'module_version'        => $VERSION,
+          'supported_types'       => [ qw( CC ECHECK ) ],
+          'token_support'         => 0, #card storage/tokenization support
+          'test_transaction'      => 0, #set true if ->test_transaction(1) works
+          'supported_actions'     => [
+                                       'Normal Authorization',
+                                       'Authorization Only',
+                                       'Post Authorization',
+                                       'Void',
+                                       'Credit',
+                                     ],
+        };
+      }
+
+    # or a more complicated case:
+
+      sub _info {
+        {
+          'info_compat'           => '0.01', # always 0.01 for now,
+                                             # 0.02 will have requirements
+          'gateway_name'          => 'Example Gateway',
+          'gateway_url'           => 'http://www.example.com/',
+          'module_version'        => $VERSION,
+          'module_notes'          => 'usage notes',
+          'supported_types'       => [ qw( CC ECHECK ) ],
+          'token_support'         => 1,
+          'test_transaction'      => 1,
+          'supported_actions'     => { 'CC' => [
+                                         'Normal Authorization',
+                                         'Authorization Only',
+                                         'Post Authorization',
+                                         'Void',
+                                         'Credit',
+                                         'Recurring Authorization',
+                                         'Modify Recurring Authorization',
+                                         'Cancel Recurring Authorization',
+                                       ],
+                                       'ECHECK' => [
+                                         'Normal Authorization',
+                                         'Void',
+                                         'Credit',
+                                       ],
+                                     },
+          'CC_void_requires_card' => 1,
+          'ECHECK_void_requires_account' => 1, #routing_code, account_number, name 
+        };
+      }
+
+
+- authorization and order_number (NEWLY DOCUMENTED IN 3.01):
+
+  Gateways will return one or two values from Authorization Only and
+  Normal Authorization transactions that must be submitted back with a
+  Post Authorization, Void, or Credit transaction.
+
+  If the gateway returns one value, return this as "authorization"
+
+  If the gateway returns two values, return one as "authorization" and the
+  other as "order_number".  Typically "authorization" is the more low-level
+  value returned from the underlying processing network while "order_number"
+  is a unique tranaction id generated by the gateway.
+




More information about the Pkg-perl-cvs-commits mailing list