0.05: patch from Randall Whitman to fix follow-up transactions
authorIvan Kohler <ivan@freeside.biz>
Sat, 10 Nov 2012 22:24:39 +0000 (14:24 -0800)
committerIvan Kohler <ivan@freeside.biz>
Sat, 10 Nov 2012 22:24:39 +0000 (14:24 -0800)
Changes
MANIFEST
README
eSelectPlus.pm
t/capture_ca.t [new file with mode: 0644]
t/capture_us.t [new file with mode: 0644]

diff --git a/Changes b/Changes
index 0173368..6aa60b1 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,7 +1,18 @@
 Revision history for Perl extension Business::OnlinePayment::eSelectPlus
 
-0.04  Sat Oct 20 03:15:54 PDT 2012
-        - Fix voids
+0.05  Sat Nov 10 14:20:42 PST 2012
+        - Pre-auth, capture/completion, voids and credits are now supported.
+          Note: testing preauth seems to work only with test store #1 (CAD).
+        - Backwards-compatibility note (align usage of 'authorization' &
+          'order_number' with notes_for_module_writers_v3 (3.0.1)):
+          + authorization() now returns gateway transaction number (TransId)
+            rather than bank authorization code (AuthCode)
+          + order_number() now returns ReceiptId rather than ReferenceNum
+        - by Randall Whitman <www.whizman.com> on contract to
+          DonorWare LLC dba donor.com <cpan @ donor . com>.
+
+0.04  unreleased
+        - Fix voids ("purchasecorrection" not "void")
 
 0.03  Tue Mar  1 13:40:08 PST 2011
         - Update for compatibility with US Moneris.  Backwards-compatibility
@@ -22,7 +33,7 @@ Revision history for Perl extension Business::OnlinePayment::eSelectPlus
         - Remove extra spaces and other odd characters in Message.
         - by Randall Whitman <www.whizman.com> on contract to
           DonorWare LLC dba donor.com <cpan @ donor . com>.
-        - fix tests, die on connction errors per B:OP spec
+        - fix tests, die on connection errors per B:OP spec  (ivan)
 
 0.01  Wed Mar 16 02:39:29 PST 2005
        - original version; created by ivan 1.0
index 9f4a58a..93cf9a5 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -14,3 +14,7 @@ t/bad_card_ca.t
 t/bad_card_us.t
 t/crypt_bad_card_ca.t
 t/crypt_bad_card_us.t
+t/capture_ca.t
+t/capture_us.t
+t/void_us.t
+t/void_ca.t
diff --git a/README b/README
index f4be1d1..d9c85d2 100644 (file)
--- a/README
+++ b/README
@@ -1,5 +1,6 @@
 Copyright (c) 2004 Ivan Kohler
-Copyright (c) 2008 DonorWare LLC
+Copyright (c) 2012 Freeside Internet Services, Inc.
+Copyright (c) 2008-2011 DonorWare LLC
 All rights reserved. This program is free software; you can redistribute it
 and/or modify it under the  same terms as Perl itself.
 
index 8ba1495..8ef134f 100644 (file)
@@ -8,7 +8,7 @@ use Business::OnlinePayment::HTTPS 0.03;
 use vars qw($VERSION $DEBUG @ISA);
 
 @ISA = qw(Business::OnlinePayment::HTTPS);
-$VERSION = '0.04';
+$VERSION = '0.05';
 $DEBUG = 0;
 
 sub set_defaults {
@@ -125,6 +125,9 @@ sub submit {
 
     } elsif ( $action eq 'completion' || $action eq 'purchasecorrection' ) {
 
+      $self->{_content}{comp_amount} = delete $self->{_content}{amount}
+        if $action eq 'completion';
+
       $self->required_fields( qw( login password order_number authorization ) );
 
     } elsif ( $action eq 'refund' ) {
@@ -159,9 +162,10 @@ sub submit {
 
     my( $page, $response, @reply_headers) = $self->https_post( $post_data );
 
-    #my %reply_headers = @reply_headers;
-    #warn join('', map { "  $_ => $reply_headers{$_}\n" } keys %reply_headers )
-    #  if $DEBUG;
+    if ($DEBUG > 1) {
+      my %reply_headers = @reply_headers;
+      warn join('', map { "  $_ => $reply_headers{$_}\n" } keys %reply_headers)
+    }
 
     if ($response !~ /^200/)  {
         # Connection error
@@ -169,7 +173,6 @@ sub submit {
         $self->is_success(0);
         my $diag_message = $response || "connection error";
         die $diag_message;
-
     }
 
     # avs_code - eSELECTplus_Perl_IG.pdf Appendix F
@@ -205,10 +208,8 @@ sub submit {
     die "gateway error: ". $self->GetXMLProp( $page, 'Message' )
       if $result =~ /^null$/i;
 
-    # New unique reference created by the gateway
-    $self->order_number($self->GetXMLProp($page, 'ReferenceNum'));
     # Original order_id supplied to the gateway
-    #$self->order_number($self->GetXMLProp($page, 'ReceiptId'));
+    $self->order_number($self->GetXMLProp($page, 'ReceiptId'));
 
     # We (Whizman & DonorWare) do not have enough info about "ISO"
     # response codes to make use of them.
@@ -219,7 +220,7 @@ sub submit {
 
     if ( $result =~ /^\d+$/ && $result < 50 ) {
         $self->is_success(1);
-        $self->authorization($self->GetXMLProp($page, 'AuthCode'));
+        $self->authorization($self->GetXMLProp($page, 'TransID'));
     } elsif ( $result =~ /^\d+$/ ) {
         $self->is_success(0);
         my $tmp_msg = $self->GetXMLProp( $page, 'Message' );
@@ -343,15 +344,24 @@ Content required: type, login, password, action, amount, card_number, expiration
 
 For detailed information see L<Business::OnlinePayment>.
 
-=head1 Note for Canadian merchants upgrading to 0.03
+=head1 NOTES
+
+=head2 Note for Canadian merchants upgrading to 0.03
 
 As of version 0.03, this module now defaults to the US Moneris.  Make sure to
 pass currency=>'CAD' for Canadian transactions.
 
+=head2 Note for upgrading to 0.05
+
+As of version 0.05, the bank authorization code is discarded (AuthCode),
+so that authorization() and order_number() can return the 2 fields needed
+for capture.  See also
+cpansearch.perl.org/src/IVAN/Business-OnlinePayment-3.02/notes_for_module_writers_v3
+
 =head1 AUTHOR
 
 Ivan Kohler <ivan-eselectplus@420.am>
-Randall Whitman <www.whizman.com>
+Randall Whitman L<whizman.com|http://whizman.com>
 
 =head1 SEE ALSO
 
diff --git a/t/capture_ca.t b/t/capture_ca.t
new file mode 100644 (file)
index 0000000..460ea7c
--- /dev/null
@@ -0,0 +1,74 @@
+#!/usr/bin/perl -w
+
+# B:OP eSelectPlus Canadian Pre-Auth & Capture
+# Portions loosely adapted from B:OP AuthorizeNet via B:OP Exact
+
+use Test::More;
+plan tests => 5;
+
+use_ok 'Business::OnlinePayment';
+
+my $amount;
+$amount = '1.00';
+my $order_id;
+$order_id = 'B:OP' . time;  # Caller generates order_id; cf. capture-us.t;
+
+my $tx = new Business::OnlinePayment("eSelectPlus");
+$tx->content(
+    login          => 'moot',
+    password       => 'moot',
+    action         => 'Authorization Only',
+    order_id       => $order_id,
+#    description    => 'Business::OnlinePayment visa test',
+    amount         => $amount,
+    currency       => 'CAD',
+#    name           => 'eSelectPlus Tester',
+    card_number    => '4242424242424242',
+    expiration     => '12/14',
+);
+
+$tx->test_transaction(1); # test, dont really charge
+
+$tx->submit();
+
+my $flag =
+    ok($tx->is_success(), 'Pre-Auth') or diag $tx->error_message;
+
+# note: long
+# use Data::Dumper;
+# diag(Dumper $tx);
+
+my $auth = $tx->authorization;             # TransID
+my $order_number = $tx->order_number;
+#$order_id = $tx->order_id;
+like $auth, qr/\d+/, 'authorization';
+like $order_number, qr/\d+/, 'order number';
+#ok $order_id, 'order ID';
+
+#warn "auth: $auth\n";
+#warn "order_number: $order_number\n";
+SKIP: {
+    skip 'Need pre-auth success, in order to test capture', 1
+        unless $flag;
+
+my $settle_tx = new Business::OnlinePayment("eSelectPlus");
+$settle_tx->content(
+    login          => 'moot',
+    password       => 'moot',
+    action         => 'Post Authorization',
+#    description    => 'Business::OnlinePayment visa test',
+    currency       => 'CAD',
+    amount         => $amount,
+    authorization  => $auth,
+#    order_id       => $order_id,
+    order_number   => $order_number,
+#    name           => 'eSelectPlus Tester',
+#    card_number    => '4242424242424242',
+#    expiration     => '12/12',
+);
+
+$settle_tx->test_transaction(1); # test, dont really charge
+$settle_tx->submit();
+
+ok($settle_tx->is_success(), 'Capture') || diag $settle_tx->error_message;
+}  # /skip or test
diff --git a/t/capture_us.t b/t/capture_us.t
new file mode 100644 (file)
index 0000000..f5952df
--- /dev/null
@@ -0,0 +1,73 @@
+#!/usr/bin/perl -w
+
+# B:OP eSelectPlus USA Pre-Auth & Capture
+# Portions loosely adapted from B:OP AuthorizeNet via B:OP Exact
+
+use Test::More;
+plan tests => 5;
+
+use_ok 'Business::OnlinePayment';
+
+my $amount;
+$amount = '1.00';
+my $order_id;
+#$order_id  = 'B:OP' . time;  # Generate inside B:OP; cf. capture_ca.t
+
+my $tx = new Business::OnlinePayment("eSelectPlus");
+$tx->content(
+    login          => 'moot',
+    password       => 'moot',
+    action         => 'Authorization Only',
+#    order_id       => $order_id,  # Generate inside B:OP
+#    description    => 'Business::OnlinePayment visa test',
+    amount         => $amount,
+#    name           => 'eSelectPlus Tester',
+    card_number    => '4242424242424242',
+    expiration     => '12/12',
+#    invoice_number   => 'freeform',
+);
+
+$tx->test_transaction(1); # test, dont really charge
+
+$tx->submit();
+
+my $flag =
+    ok($tx->is_success(), 'Pre-Auth') or diag $tx->error_message;
+
+# note: long
+# use Data::Dumper;
+# diag(Dumper $tx);
+
+my $auth = $tx->authorization;     # TransID
+my $order_number = $tx->order_number;
+#$order_id = $tx->order_id;
+like $auth, qr/\d+/, 'authorization';
+like $order_number, qr/\d+/, 'order number';
+#ok $order_id, 'order ID';
+
+#warn "auth: $auth\n";
+#warn "order_number: $order_number\n";
+SKIP: {
+    skip 'Need pre-auth success, in order to test capture', 1
+        unless $flag;
+
+my $settle_tx = new Business::OnlinePayment("eSelectPlus");
+$settle_tx->content(
+    login          => 'moot',
+    password       => 'moot',
+    action         => 'Post Authorization',
+#    description    => 'Business::OnlinePayment visa test',
+    amount         => $amount,
+    authorization  => $auth,
+#    order_id       => $order_id,
+    order_number   => $order_number,
+#    name           => 'eSelectPlus Tester',
+#    card_number    => '4242424242424242',  # not required
+#    expiration     => '12/12',
+);
+
+$settle_tx->test_transaction(1); # test, dont really charge
+$settle_tx->submit();
+
+ok($settle_tx->is_success(), 'Capture') || diag $settle_tx->error_message;
+}  # /skip or test