initial import BEGIN
authorivan <ivan>
Fri, 15 Feb 2002 01:19:27 +0000 (01:19 +0000)
committerivan <ivan>
Fri, 15 Feb 2002 01:19:27 +0000 (01:19 +0000)
Changes [new file with mode: 0644]
LinkPoint.pm [new file with mode: 0644]
MANIFEST [new file with mode: 0644]
Makefile.PL [new file with mode: 0644]
README [new file with mode: 0644]
t/bop.t [new file with mode: 0644]
t/load.t [new file with mode: 0644]
t2/bad_auth.t [new file with mode: 0644]
t2/credit_card.t [new file with mode: 0644]

diff --git a/Changes b/Changes
new file mode 100644 (file)
index 0000000..67f4aed
--- /dev/null
+++ b/Changes
@@ -0,0 +1,5 @@
+Revision history for Perl extension Business::OnlinePayment::LinkPoint.
+
+0.01  Wed Nov 21 04:00:26 2001
+       - original version; created by ivan 1.0
+
diff --git a/LinkPoint.pm b/LinkPoint.pm
new file mode 100644 (file)
index 0000000..9a77236
--- /dev/null
@@ -0,0 +1,228 @@
+package Business::OnlinePayment::LinkPoint;
+
+# $Id: LinkPoint.pm,v 1.1 2002-02-15 01:19:27 ivan Exp $
+
+use strict;
+use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
+use Carp qw(croak);
+use AutoLoader;
+use Business::OnlinePayment;
+
+use lperl; #lperl.pm from Linkpoint.
+
+require Exporter;
+
+@ISA = qw(Exporter AutoLoader Business::OnlinePayment);
+@EXPORT = qw();
+@EXPORT_OK = qw();
+$VERSION = '0.01';
+
+sub set_defaults {
+    my $self = shift;
+
+    #$self->server('staging.linkpt.net');
+    $self->server('secure.linkpt.net');
+    $self->port('1139');
+
+}
+
+sub map_fields {
+    my($self) = @_;
+
+    my %content = $self->content();
+
+    #ACTION MAP
+    my %actions = ('normal authorization' => 'ApproveSale',
+                   'authorization only'   => 'CapturePayment',
+                   'credit'               => 'ReturnOrder',
+                   'post authorization'   => 'BillOrders',
+                  );
+    $content{'action'} = $actions{lc($content{'action'})} || $content{'action'};
+
+    # stuff it back into %content
+    $self->content(%content);
+}
+
+sub remap_fields {
+    my($self,%map) = @_;
+
+    my %content = $self->content();
+    foreach(keys %map) {
+        $content{$map{$_}} = $content{$_};
+    }
+    $self->content(%content);
+}
+
+sub revmap_fields {
+    my($self, %map) = @_;
+    my %content = $self->content();
+    foreach(keys %map) {
+#    warn "$_ = ". ( ref($map{$_})
+#                         ? ${ $map{$_} }
+#                         : $content{$map{$_}} ). "\n";
+        $content{$_} = ref($map{$_})
+                         ? ${ $map{$_} }
+                         : $content{$map{$_}};
+    }
+    $self->content(%content);
+}
+
+sub get_fields {
+    my($self,@fields) = @_;
+
+    my %content = $self->content();
+    my %new = ();
+    foreach( grep defined $content{$_}, @fields) { $new{$_} = $content{$_}; }
+    return %new;
+}
+
+sub submit {
+    my($self) = @_;
+
+
+    $self->map_fields();
+
+    my %content = $self->content;
+
+    my($month, $year);
+    unless ( $content{action} eq 'BillOrders' ) {
+
+        if (  $self->transaction_type() =~
+                /^(cc|visa|mastercard|american express|discover)$/i
+           ) {
+        } else {
+            Carp::croak("LinkPoint can't handle transaction type: ".
+                        $self->transaction_type());
+        }
+
+      $content{'expiration'} =~ /^(\d+)\D+\d*(\d{2})$/
+        or croak "unparsable expiration $content{expiration}";
+
+      ( $month, $year ) = ( $1, $2 );
+      $month = '0'. $month if $month =~ /^\d$/;
+      $year += 2000 if $year < 2000; #not y4k safe, oh shit
+    }
+
+    $content{'address'} =~ /^(\S+)\s/;
+    my $addrnum = $1;
+
+    $self->server('staging.linkpt.net') if $self->test_transaction;
+
+    $self->revmap_fields(
+      hostname     => \( $self->server ),
+      port         => \( $self->port ),
+      storename    => \( $self->storename ),
+      keyfile      => \( $self->keyfile ),
+      addrnum      => \$addrnum,
+
+      cardNumber   => 'card_number',
+      cardExpMonth => \$month,
+      cardExpYear  => \$year,
+    );
+
+    my $lperl = new LPERL
+      $self->lbin,
+      'FILE',
+      $self->can('tmp')
+        ? $self->tmp
+        : '/tmp';
+    my $action = $content{action};
+
+    $self->required_fields(qw/
+      hostname port storename keyfile amount cardNumber cardExpMonth cardExpYear
+    /);
+
+    my %post_data = $self->get_fields(qw/
+      hostname port storename keyfile
+      result
+      amount cardNumber cardExpMonth cardExpYear
+      name email phone address city state zip country
+    /);
+
+    print "$_ => $post_data{$_}\n" foreach keys %post_data;
+    #die;
+
+    my %response = $lperl->$action(\%post_data);
+
+    if ( $response{'statusCode'} == 0 ) {
+      $self->is_success(0);
+      $self->result_code('');
+      $self->error_message($response{'statusMessage'});
+    } else {
+      $self->is_success(1);
+      $self->result_code($response{'AVCCode'});
+      $self->authorization($response{'trackingID'});
+#      $self->order_number($response{'neworderID'});
+    }
+
+}
+
+1;
+__END__
+
+=head1 NAME
+
+Business::OnlinePayment::LinkPoint - LinkPoint backend for Business::OnlinePayment
+
+=head1 SYNOPSIS
+
+  use Business::OnlinePayment;
+
+  my $tx = new Business::OnlinePayment( 'LinkPoint',
+    'storename' => 'your_store_number',
+    'keyfile'   => '/path/to/keyfile.pem',
+    'lbin'      => '/path/to/binary/lbin',
+    'tmp'       => '/secure/tmp',          # a secure tmp directory
+  );
+
+  $tx->content(
+      type           => 'VISA',
+      action         => 'Normal Authorization',
+      description    => 'Business::OnlinePayment test',
+      amount         => '49.95',
+      invoice_number => '100100',
+      customer_id    => 'jsk',
+      name           => 'Jason Kohles',
+      address        => '123 Anystreet',
+      city           => 'Anywhere',
+      state          => 'UT',
+      zip            => '84058',
+      email          => 'ivan-linkpoint@420.am',
+      card_number    => '4007000000027',
+      expiration     => '09/99',
+  );
+  $tx->submit();
+
+  if($tx->is_success()) {
+      print "Card processed successfully: ".$tx->authorization."\n";
+  } else {
+      print "Card was rejected: ".$tx->error_message."\n";
+  }
+
+=head1 SUPPORTED TRANSACTION TYPES
+
+=head2 Visa, MasterCard, American Express, JCB, Discover/Novus, Carte blanche/Diners Club
+
+=head1 DESCRIPTION
+
+For detailed information see L<Business::OnlinePayment>.
+
+=head1 COMPATIBILITY
+
+This module implements an interface to the LinkPoint Perl Wrapper
+http://www.linkpoint.com/product_solutions/internet/inet_index.html
+
+=head1 BUGS
+
+=head1 AUTHOR
+
+Ivan Kohler <ivan-linkpoint@420.am>
+
+Based on Busienss::OnlinePayment::AuthorizeNet written by Jason Kohles.
+
+=head1 SEE ALSO
+
+perl(1). L<Business::OnlinePayment>.
+
+=cut
+
diff --git a/MANIFEST b/MANIFEST
new file mode 100644 (file)
index 0000000..5bac7f5
--- /dev/null
+++ b/MANIFEST
@@ -0,0 +1,9 @@
+LinkPoint.pm
+Changes
+MANIFEST
+Makefile.PL
+README
+t/bop.t
+t/load.t
+t2/bad_auth.t
+t2/credit_card.t
diff --git a/Makefile.PL b/Makefile.PL
new file mode 100644 (file)
index 0000000..bb32ada
--- /dev/null
@@ -0,0 +1,9 @@
+use ExtUtils::MakeMaker;
+# See lib/ExtUtils/MakeMaker.pm for details of how to influence
+# the contents of the Makefile that is written.
+WriteMakefile(
+    'NAME'         => 'Business::OnlinePayment::LinkPoint',
+    'VERSION_FROM' => 'LinkPoint.pm', # finds $VERSION
+    'AUTHOR'       => 'Ivan Kohler <ivan-linkpoint@420.am>',
+    #'NORECURS'     => 1, # dont descend into subdirectories
+);
diff --git a/README b/README
new file mode 100644 (file)
index 0000000..eb6e6c3
--- /dev/null
+++ b/README
@@ -0,0 +1,21 @@
+Copyright (c) 2002 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.
+
+This is Business::OnlinePayment::LinkPoint, an Business::OnlinePayment
+backend module for the LinkPoint.  It is only useful if you have a merchant
+account with LinkPoint: http://www.linkpoint.com/ and the "LinkPoint Perl
+Wrapper":
+http://www.linkpoint.com/product_solutions/internet/lperl/lperl_main.html
+
+It is based on Businss::OnlinePayment::AuthorizeNet written by Jason Kohles.
+
+There are additional tests in t2/ that may be useful to you once you have a
+store number and key file.
+
+Ivan Kohler <ivan-linkpoint@420.am>
+
+Business::OnlinePayment is a generic interface for processing payments through
+online credit card processors, online check acceptance houses, etc.  (If you
+like buzzwords, call it an "multiplatform ecommerce-enabling middleware
+solution").
diff --git a/t/bop.t b/t/bop.t
new file mode 100644 (file)
index 0000000..64332c5
--- /dev/null
+++ b/t/bop.t
@@ -0,0 +1,5 @@
+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/load.t b/t/load.t
new file mode 100644 (file)
index 0000000..ac1adbd
--- /dev/null
+++ b/t/load.t
@@ -0,0 +1,5 @@
+BEGIN { $| = 1; print "1..1\n"; }
+END {print "not ok 1\n" unless $loaded;}
+use Business::OnlinePayment::LinkPoint;
+$loaded = 1;
+print "ok 1\n";
diff --git a/t2/bad_auth.t b/t2/bad_auth.t
new file mode 100644 (file)
index 0000000..7752df9
--- /dev/null
@@ -0,0 +1,43 @@
+BEGIN { $| = 1; print "1..2\n"; }
+
+use Business::OnlinePayment;
+
+my $tx = new Business::OnlinePayment("LinkPoint",
+  'storename' => '000000',
+  'keyfile'   => '/path/to/cert.pem',
+  'lbin'      => '/path/to/lbin',
+  'tmp'       => '/path/to/secure/tempdir',
+);
+
+$tx->content(
+    type           => 'VISA',
+    action         => 'Normal Authorization',
+    description    => 'Business::OnlinePayment::LinkPoint visa test',
+    amount         => '0.01',
+    first_name     => 'Tofu',
+    last_name      => 'Beast',
+    address        => '123 Anystreet',
+    city           => 'Anywhere',
+    state          => 'UT',
+    zip            => '84058',
+    country        => 'US',
+    email          => 'ivan-linkpoint@420.am',
+    card_number    => '4007000000027',
+    expiration     => '12/2002',
+    result         => 'DECLINE',
+);
+
+$tx->test_transaction(1);
+
+$tx->submit();
+
+if($tx->is_success()) {
+    print "not ok 1\n";
+    $auth = $tx->authorization;
+    warn "********* $auth ***********\n";
+} else {
+    print "ok 1\n";
+    warn '***** '. $tx->error_message. " *****\n";
+    exit;
+}
+
diff --git a/t2/credit_card.t b/t2/credit_card.t
new file mode 100644 (file)
index 0000000..b711222
--- /dev/null
@@ -0,0 +1,42 @@
+BEGIN { $| = 1; print "1..2\n"; }
+
+use Business::OnlinePayment;
+
+my $tx = new Business::OnlinePayment("LinkPoint",
+  'storename' => '000000',
+  'keyfile'   => '/path/to/cert.pem',
+  'lbin'      => '/path/to/lbin',
+  'tmp'       => '/path/to/secure/tempdir',
+);
+
+$tx->content(
+    type           => 'VISA',
+    action         => 'Normal Authorization',
+    description    => 'Business::OnlinePayment::LinkPoint visa test',
+    amount         => '0.01',
+    first_name     => 'Tofu',
+    last_name      => 'Beast',
+    address        => '123 Anystreet',
+    city           => 'Anywhere',
+    state          => 'UT',
+    zip            => '84058',
+    country        => 'US',
+    email          => 'ivan-linkpoint@420.am',
+    card_number    => '4007000000027',
+    expiration     => '12/2002',
+);
+
+$tx->test_transaction(1);
+
+$tx->submit();
+
+if($tx->is_success()) {
+    print "ok 1\n";
+    $auth = $tx->authorization;
+    warn "********* $auth ***********\n";
+} else {
+    print "not ok 1\n";
+    warn '***** '. $tx->error_message. " *****\n";
+    exit;
+}
+