first changes for 3.00_01 test release
authorivan <ivan>
Fri, 3 Sep 2004 23:20:25 +0000 (23:20 +0000)
committerivan <ivan>
Fri, 3 Sep 2004 23:20:25 +0000 (23:20 +0000)
Changes
MANIFEST
META.yml
Makefile.PL
OnlinePayment.pm
OnlinePayment/HTTPS.pm [new file with mode: 0644]
README
notes_for_module_writers
t/bop.t [new file with mode: 0644]
t/bop_https.t [new file with mode: 0644]

diff --git a/Changes b/Changes
index 8a01eab..635b2b4 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,8 @@
 Revision history for Perl extension Business::OnlinePayment.
 
 Revision history for Perl extension Business::OnlinePayment.
 
+3.00_01  Thu Aug 26 04:49:26 2004
+       - first of the v3 dev releases
+
 0.01  Sun Jul 25 13:59:10 1999
        - original version; created by h2xs 1.19
 
 0.01  Sun Jul 25 13:59:10 1999
        - original version; created by h2xs 1.19
 
index c59ac4a..78026b8 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -3,6 +3,8 @@ Changes
 MANIFEST
 Makefile.PL
 OnlinePayment.pm
 MANIFEST
 Makefile.PL
 OnlinePayment.pm
-test.pl
+OnlinePayment/HTTPS.pm
+t/bop.t
+t/bop_https.t
 notes_for_module_writers
 META.yml                                 Module meta-data (added by MakeMaker)
 notes_for_module_writers
 META.yml                                 Module meta-data (added by MakeMaker)
index 631a86d..7e0edd2 100644 (file)
--- a/META.yml
+++ b/META.yml
@@ -1,11 +1,12 @@
 # http://module-build.sourceforge.net/META-spec.html
 #XXXXXXX This is a prototype!!!  It will change in the future!!! XXXXX#
 name:         Business-OnlinePayment
 # http://module-build.sourceforge.net/META-spec.html
 #XXXXXXX This is a prototype!!!  It will change in the future!!! XXXXX#
 name:         Business-OnlinePayment
-version:      2.01
+version:      3.00_01
 version_from: OnlinePayment.pm
 installdirs:  site
 requires:
 version_from: OnlinePayment.pm
 installdirs:  site
 requires:
-    Net::SSLeay:                   0
+    URI::Escape:                   0
+    Tie::IxHash:                   0
 
 distribution_type: module
 generated_by: ExtUtils::MakeMaker version 6.17
 
 distribution_type: module
 generated_by: ExtUtils::MakeMaker version 6.17
index b3115c2..93a5ebd 100644 (file)
@@ -4,8 +4,17 @@ use ExtUtils::MakeMaker;
 WriteMakefile(
     'NAME'         => 'Business::OnlinePayment',
     'VERSION_FROM' => 'OnlinePayment.pm', # finds $VERSION
 WriteMakefile(
     'NAME'         => 'Business::OnlinePayment',
     'VERSION_FROM' => 'OnlinePayment.pm', # finds $VERSION
-    'AUTHOR'       => 'Jason Kohles <email@jasonkohles.com>',
+    'AUTHOR'       => 'Ivan Kohler <ivan-business-onlinepayment@420.am>',
     'NORECURS'     => 1, # dont descend into subdirectories
     'NORECURS'     => 1, # dont descend into subdirectories
-    'PREREQ_PM'    => {'Net::SSLeay' => 0},
+    '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
+
+                      },
     #'dist'         => {CI => 'ci -l'},
 );
     #'dist'         => {CI => 'ci -l'},
 );
index 3262436..c34ad8f 100644 (file)
@@ -1,18 +1,21 @@
 package Business::OnlinePayment;
 
 use strict;
 package Business::OnlinePayment;
 
 use strict;
-use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $AUTOLOAD);
+use vars qw($VERSION); # @ISA @EXPORT @EXPORT_OK $AUTOLOAD);
+use Carp;
 
 require 5.004;
 
 require 5.004;
-require Exporter;
+#require Exporter;
 
 
-@ISA = qw(Exporter AutoLoader);
-@EXPORT = qw();
-@EXPORT_OK = qw();
+#@ISA = (); #qw(Exporter AutoLoader);
+#@EXPORT = qw();
+#@EXPORT_OK = qw();
 
 
-$VERSION = do { my @r=(q$Revision: 1.1 $=~/\d+/g);sprintf "%d."."%02d"x$#r,@r};
-
-use Carp();
+$VERSION = '3.00_01';
+sub VERSION { #Argument "3.00_01" isn't numeric in subroutine entry
+  local($^W)=0;
+  UNIVERSAL::VERSION(@_);
+}
 
 my %fields = (
     is_success       => undef,
 
 my %fields = (
     is_success       => undef,
@@ -78,19 +81,21 @@ sub required_fields {
 }
 
 sub get_fields {
 }
 
 sub get_fields {
-    my($self,@fields) = @_;
+    my($self, @fields) = @_;
 
     my %content = $self->content();
 
     my %content = $self->content();
-    my %new = ();
-    foreach(@fields) { $new{$_} = $content{$_}; }
-    return %new;
+
+    #my %new = ();
+    #foreach(@fields) { $new{$_} = $content{$_}; }
+    #return %new;
+    map { $_ => $content{$_} } grep defined $content{$_}, @fields;
 }
 
 sub remap_fields {
     my($self,%map) = @_;
 
     my %content = $self->content();
 }
 
 sub remap_fields {
     my($self,%map) = @_;
 
     my %content = $self->content();
-    foreach(%map) {
+    foreach( keys %map ) {
         $content{$map{$_}} = $content{$_};
     }
     $self->content(%content);
         $content{$map{$_}} = $content{$_};
     }
     $self->content(%content);
@@ -302,10 +307,12 @@ Retrieve or change the processor submission port (CHANGE AT YOUR OWN RISK).
 
 Retrieve or change the processor submission path (CHANGE AT YOUR OWN RISK).
 
 
 Retrieve or change the processor submission path (CHANGE AT YOUR OWN RISK).
 
-=head1 AUTHOR
+=head1 AUTHORS
 
 Jason Kohles, email@jasonkohles.com
 
 
 Jason Kohles, email@jasonkohles.com
 
+(v3 rewrite) Ivan Kohler <ivan-business-onlinepayment@420.am>
+
 =head1 DISCLAIMER
 
 THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
 =head1 DISCLAIMER
 
 THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
@@ -315,6 +322,8 @@ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 
 =head1 SEE ALSO
 
 
 =head1 SEE ALSO
 
+http://420.am/business-onlinepayment/
+
 For verification of credit card checksums, see L<Business::CreditCard>.
 
 =cut
 For verification of credit card checksums, see L<Business::CreditCard>.
 
 =cut
diff --git a/OnlinePayment/HTTPS.pm b/OnlinePayment/HTTPS.pm
new file mode 100644 (file)
index 0000000..0ba897d
--- /dev/null
@@ -0,0 +1,171 @@
+package Business::OnlinePayment::HTTPS;
+
+use strict;
+use vars qw($VERSION @ISA $ssl_module $skip_NetSSLeay);
+#use URI;
+#use URI::QueryParam;
+use URI::Escape;
+use Tie::IxHash;
+
+@ISA = qw( Business::OnlinePayment );
+
+$VERSION = '0.01';
+
+BEGIN {
+
+        $ssl_module = '';
+
+        eval {
+                die if defined($skip_NetSSLeay) && $skip_NetSSLeay;
+                require Net::SSLeay;
+                #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 "Net::SSLeay (+URI) or Crypt::SSLeay (+LWP) is required";
+        }
+
+}
+
+=head1 NAME
+
+Business::OnlinePayment::HTTPS - Base class for HTTPS payment APIs
+
+=head1 SYNOPSIS
+
+  package Business::OnlinePayment::MyProcessor
+  @ISA = qw( Business::OnlinePayment::HTTPS );
+
+  sub submit {
+          my $self = shift;
+
+          #...
+
+          # pass a list (order is preserved, if your gateway needs that)
+          ($page, $response, %reply_headers)
+            = $self->https_get( field => 'value', ... );
+
+          #or a hashref
+          my %hash = ( field => 'value', ... );
+          ($page, $response_code, %reply_headers)
+            = $self->https_get( $hashref );
+
+          #...
+  }
+
+=head1 DESCRIPTION
+
+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 ).
+
+=head1 METHODS
+
+=over 4
+
+=item https_get HASHREF | FIELD => VALUE, ...
+
+Accepts parameters as either a hashref or a list of fields and values.  In the
+latter case, ordering is preserved (see L<Tie::IxHash> to do so when passing a
+hashref).
+
+Returns a list consisting of the page content as a string, the HTTP response
+code, and a list of key/value pairs representing the HTTP response headers.
+
+=cut
+
+sub https_get {
+  my $self = shift;
+
+  #accept a hashref or a list (keep it ordered)
+  my $post_data;
+  if ( ref($_[0]) ) {
+    $post_data = shift;
+  } else {
+    tie my %hash, 'Tie::IxHash', @_;
+    $post_data = \%hash;
+  }
+
+  my $path = $self->path;
+  if ( keys %$post_data ) {
+
+    #my $u = URI->new("", "https");
+    #$u->query_param(%$post_data);
+    #$path .= '?'. $u->query;
+
+    $path .= '?'. join('&',
+      map { uri_escape($_).'='. uri_escape($post_data->{$_}) }
+      keys %$post_data
+    );
+    #warn $path;
+
+  }
+
+  my $referer = ''; ### XXX referer!!!
+  my %headers;
+  $headers{'Referer'} = $referer if length($referer);
+
+  if ( $ssl_module eq 'Net::SSLeay' ) {
+
+    import Net::SSLeay qw(get_https make_headers);
+    my $headers = make_headers(%headers);
+    get_https( $self->server, $self->port, $path, $referer, $headers );
+
+  } elsif ( $ssl_module eq 'Crypt::SSLeay' ) {
+
+    import HTTP::Request::Common qw(GET);
+
+    my $ua = new LWP::UserAgent;
+    my $res = $ua->request(
+      GET( 'https://'. $self->server. ':'. $self->port. '/'. $path )
+    );
+
+    #( $res->as_string, # wtf?
+    ( $res->content,
+      $res->code,
+      map { $_ => $res->header($_) } $res->header_field_names
+    );
+
+  } else {
+
+    die "unknown SSL module $ssl_module";
+
+  }
+
+}
+
+=item https_post
+
+Not yet implemented
+
+=cut
+
+sub https_post {
+  my $self = shift;
+
+  die "not yet implemented";
+}
+
+=back
+
+=head1 SEE ALSO 
+
+L<Business::OnlinePayment>
+
+=cut
+
+1;
+
diff --git a/README b/README
index 0a35167..80b59d3 100644 (file)
--- a/README
+++ b/README
@@ -1,7 +1,8 @@
 *****************************************************************************
 *****************************************************************************
-* Copyright (c) 1999-2004 Jason Kohles. All rights reserved. This program   *
-* is free software; you can redistribute it and/or modify it under the same *
-* terms as Perl itself.                                                     *
+* Copyright (c) 1999-2004 Jason Kohles.                                     *
+* Copyright (c) 2004 Ivan Kohler                                            *
+* All rights reserved. This program is free software; you can redistribute  *
+* it and/or modify it under the same terms as Perl itself.                  *
 *****************************************************************************
 
 Business::OnlinePayment is a generic interface for processing payments through
 *****************************************************************************
 
 Business::OnlinePayment is a generic interface for processing payments through
@@ -11,8 +12,11 @@ solution").
 
 IMPORTANT: Business::OnlinePayment only defines the frontend interface to the
 system, in order to use it you also need to have at least one backend
 
 IMPORTANT: Business::OnlinePayment only defines the frontend interface to the
 system, in order to use it you also need to have at least one backend
-processing module installed, there used to be a list here, but so many people
-have contributed backends now that it is easier to search CPAN to find them.
+processing module installed.
 
 
-http://search.cpan.org/search?m=all&q=Business::OnlinePayment::
+Homepage:
+  http://420.am/business-onlinepayment/
+
+Search CPAN for backends:
+  http://search.cpan.org/search?m=all&q=Business::OnlinePayment::
 
 
index 9d6d0c2..bead4e8 100644 (file)
@@ -1,4 +1,8 @@
-$Id: notes_for_module_writers,v 1.1 2004-09-03 23:10:51 ivan Exp $
+These are the old v2 notes.  Business::OnlinePayment::OpenECHO is the first
+"v3-ish" module, if you're writing an HTTPS-interface module, try starting
+from there until there's better v3 module writer's docs.
+
+$Id: notes_for_module_writers,v 1.2 2004-09-03 23:20:25 ivan Exp $
 
 Information on creating a new processor backend to go with
 Business::OnlinePayment.
 
 Information on creating a new processor backend to go with
 Business::OnlinePayment.
diff --git a/t/bop.t b/t/bop.t
new file mode 100644 (file)
index 0000000..78526b6
--- /dev/null
+++ b/t/bop.t
@@ -0,0 +1,9 @@
+# test 1
+BEGIN { $| = 1; print "1..1\n"; }
+END {print "not ok 1\n" unless $loaded;}
+
+use Business::OnlinePayment;
+$loaded = 1;
+print "ok 1\n";
+
+
diff --git a/t/bop_https.t b/t/bop_https.t
new file mode 100644 (file)
index 0000000..533e496
--- /dev/null
@@ -0,0 +1,9 @@
+# test 1
+BEGIN { $| = 1; print "1..1\n"; }
+END {print "not ok 1\n" unless $loaded;}
+
+use Business::OnlinePayment::HTTPS;
+$loaded = 1;
+print "ok 1\n";
+
+