initial checkin BUSINESS_ONLINEPAYMENT_SECUREHOSTINGUPG_0_01
authorivan <ivan>
Tue, 11 Jan 2005 07:10:23 +0000 (07:10 +0000)
committerivan <ivan>
Tue, 11 Jan 2005 07:10:23 +0000 (07:10 +0000)
14 files changed:
Changes [new file with mode: 0644]
MANIFEST [new file with mode: 0644]
Makefile.PL [new file with mode: 0644]
README [new file with mode: 0644]
SecureHostingUPG.pm [new file with mode: 0644]
htmlbad.html [new file with mode: 0644]
htmlgood.html [new file with mode: 0644]
t/bad_card.t [new file with mode: 0644]
t/bop.t [new file with mode: 0644]
t/credit_card.t [new file with mode: 0644]
t/crypt_bad_card.t [new file with mode: 0644]
t/crypt_credit_card.t [new file with mode: 0644]
t/crypt_load.t [new file with mode: 0644]
t/load.t [new file with mode: 0644]

diff --git a/Changes b/Changes
new file mode 100644 (file)
index 0000000..c8c5e61
--- /dev/null
+++ b/Changes
@@ -0,0 +1,2 @@
+0.01  Mon Dec 27 03:00:58 2004
+       - original version; created by ivan 1.0
diff --git a/MANIFEST b/MANIFEST
new file mode 100644 (file)
index 0000000..7b7be7c
--- /dev/null
+++ b/MANIFEST
@@ -0,0 +1,14 @@
+Changes
+MANIFEST
+Makefile.PL
+SecureHostingUPG.pm
+README
+htmlgood.html
+htmlbad.html
+t/load.t
+t/crypt_load.t
+t/credit_card.t
+t/crypt_credit_card.t
+t/bop.t
+t/bad_card.t
+t/crypt_bad_card.t
diff --git a/Makefile.PL b/Makefile.PL
new file mode 100644 (file)
index 0000000..f62e54c
--- /dev/null
@@ -0,0 +1,23 @@
+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::SecureHostingUPG',
+    'VERSION_FROM' => 'SecureHostingUPG.pm', # finds $VERSION
+    'AUTHOR'       => 'Ivan Kohler <ivan-securehostingupg@420.am>',
+    #'NORECURS'     => 1, # dont descend into subdirectories
+    'PREREQ_PM'    => {
+                        'Business::OnlinePayment' => 0,
+
+                        # 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'},
+);
+
diff --git a/README b/README
new file mode 100644 (file)
index 0000000..3c3a9c3
--- /dev/null
+++ b/README
@@ -0,0 +1,13 @@
+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.
+
+This is Business::OnlinePayment::SecureHostingUPG, an Business::OnlinePayment
+backend module for the SecureHosting Universal Payment Gateway.  It is only
+useful if you have a merchant account with SecureHosting:
+http://www.securehosting.com/sh2/upg_payment_service_provider_uk.htm
+
+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/SecureHostingUPG.pm b/SecureHostingUPG.pm
new file mode 100644 (file)
index 0000000..2ab6d1e
--- /dev/null
@@ -0,0 +1,250 @@
+package Business::OnlinePayment::SecureHostingUPG;\r
+\r
+use strict;\r
+use Carp;\r
+use Business::OnlinePayment 3;\r
+use Business::OnlinePayment::HTTPS;\r
+use vars qw($VERSION $DEBUG @ISA);\r
+\r
+@ISA = qw(Business::OnlinePayment::HTTPS);\r
+$VERSION = '0.03';\r
+$DEBUG = 0;\r
+\r
+sub set_defaults {\r
+       my $self = shift;\r
+\r
+       $self->server('www.secure-server-hosting.com');\r
+       $self->port('443');\r
+       $self->path('/secutran/transactionjs1.php');\r
+\r
+       $self->build_subs(qw(\r
+         order_number avs_code\r
+                        ));\r
+        # order_type\r
+       # md5 cvv2_response cavv_response\r
+\r
+}\r
+\r
+sub submit {\r
+    my($self) = @_;\r
+\r
+    #$self->map_fields();\r
+    $self->remap_fields(\r
+        #                => 'order_type',\r
+        #                => 'transaction_type',\r
+        login            => 'shreference',\r
+        password         => 'checkcode',\r
+        #authorization   => \r
+        #customer_ip     =>\r
+        name             => 'cardholdersname',\r
+        #first_name      =>\r
+        #last_name       =>\r
+        #company         =>\r
+        address          => 'cardholderaddr1',\r
+        #                => 'cardholderaddr2',\r
+        city             => 'cardholdercity',\r
+        state            => 'cardholderstate',\r
+        zip              => 'cardholderpostcode',\r
+        #country         =>\r
+        phone            => 'cardholdertelephonenumber',\r
+        #fax             =>\r
+        email            => 'cardholdersemail',\r
+        card_number      => 'cardnumber',\r
+        #                => 'cardexpiremonth',\r
+        #                => 'cardexpireyear',\r
+\r
+        'amount'         => 'transactionamount',\r
+        #invoice_number  =>\r
+        #customer_id     =>\r
+        #order_number    =>\r
+\r
+        currency          => 'transactioncurrency',\r
+\r
+        #expiration        =>\r
+        cvv2              => 'cv2',\r
+        issue_number      => 'switchnumber',\r
+    );\r
+\r
+    die "only Normal Authorization is currently supported"\r
+      unless $self->{_content}{'action'} =~ /^\s*normal\s*authorization\s*$/i;\r
+\r
+    #cardexpiremonth & cardexpireyear\r
+    $self->{_content}{'expiration'} =~ /^(\d+)\D+\d*(\d{2})$/\r
+      or croak "unparsable expiration ". $self->{_content}{expiration};\r
+    my( $month, $year ) = ( $1, $2 );\r
+    $month = '0'. $month if $month =~ /^\d$/;\r
+    $self->{_content}{cardexpiremonth} = $month;\r
+    $self->{_content}{cardexpireyear} = $year;\r
+\r
+    #cardstartmonth & cardstartyear\r
+    $self->{_content}{'card_start'} =~ /^(\d+)\D+\d*(\d{2})$/\r
+      or croak "unparsable card_start ". $self->{_content}{expiration};\r
+    my( $smonth, $syear ) = ( $1, $2 );\r
+    $smonth = '0'. $smonth if $smonth =~ /^\d$/;\r
+    $self->{_content}{cardstartmonth} = $smonth;\r
+    $self->{_content}{cardstartyear} = $syear;\r
+\r
+    $self->required_fields(qw(\r
+      shreference checkcode transactionamount transactioncurrency\r
+      cardexpireyear cardexpiremonth cardstartyear cardstartmonth\r
+      switchnumber cv2 cardnumber cardholdersname cardholdersemail\r
+    ));\r
+\r
+    my( $page, $response, @reply_headers) =\r
+      $self->https_post( $self->get_fields( $self->fields ) );\r
+    #my( $page, $response, @reply_headers) =\r
+    #  $self->https_get( $self->get_fields( $self->fields ) );\r
+\r
+    #my %reply_headers = @reply_headers;\r
+    #warn join('', map { "  $_ => $reply_headers{$_}\n" } keys %reply_headers )\r
+    #  if $DEBUG;\r
+\r
+    #XXX check $response and die if not 200?\r
+\r
+    #  avs_code\r
+    #  is_success\r
+    #  result_code\r
+    #  authorization\r
+    #md5 cvv2_response cavv_response ...?\r
+\r
+    $self->server_response($page);\r
+\r
+    my $result = $self->GetXMLProp($page, 'result');\r
+\r
+    if ( defined($result) && $result eq 'success' ) {\r
+      $self->is_success(1);\r
+      $self->avs_code( $self->GetXMLProp($page, 'cv2asvresult') );\r
+    } elsif ( defined($result) && $result eq 'failed' ) {\r
+      $self->is_success(0);\r
+      my $error = '';\r
+      my $tranerrdesc   = $self->GetXMLProp($page, 'tranerrdesc');\r
+      my $tranerrdetail = $self->GetXMLProp($page, 'tranerrdetail');\r
+      $error = $tranerrdesc if defined $tranerrdesc;\r
+      $error .= " - $tranerrdetail"\r
+        if defined $tranerrdetail && length $tranerrdetail;\r
+      $self->error_message($error);\r
+    } else {\r
+      die "unparsable response received from gateway".\r
+          ( $DEBUG ? ": $page" : '' );\r
+    }\r
+\r
+}\r
+\r
+\r
+sub fields {\r
+       my $self = shift;\r
+\r
+       qw(\r
+         shreference\r
+         checkcode\r
+         transactionamout\r
+         transactioncurrency\r
+         cardexpireyear\r
+         cardexpiremonth\r
+         cardstartyear\r
+         cardstartmonth\r
+         switchnumber\r
+         cv2\r
+         cardnumber\r
+         cardholdersname\r
+         cardholdersemail\r
+         cardholderaddr1\r
+         cardholderaddr2\r
+         cardholdercity\r
+         cardholderstate\r
+         cardholderpostcode\r
+         cardholdertelephonenumber\r
+       );\r
+}\r
+\r
+sub GetXMLProp {\r
+       my( $self, $raw, $prop ) = @_;\r
+       local $^W=0;\r
+\r
+       my $data;\r
+       ($data) = $raw =~ m"<$prop>(.*?)</$prop>"gsi;\r
+       #$data =~ s/<.*?>/ /gs;\r
+       chomp $data;\r
+       return $data;\r
+}\r
+\r
+1;\r
+\r
+__END__\r
+\r
+=head1 NAME\r
+\r
+Business::OnlinePayment::SecureHostingUPG - SecureHosting UPG backend module for Business::OnlinePayment\r
+\r
+=head1 SYNOPSIS\r
+\r
+  use Business::OnlinePayment;\r
+\r
+  ####\r
+  # One step transaction, the simple case.\r
+  ####\r
+\r
+  my $tx = new Business::OnlinePayment("SecureHostingUPG");\r
+  $tx->content(\r
+      type           => 'VISA',\r
+      login          => 'SecureHosting Reference',\r
+      password       => 'SecureHosting Checkcode value',\r
+      action         => 'Normal Authorization',\r
+      description    => 'Business::OnlinePayment test',\r
+      amount         => '49.95',\r
+      currency       => 'GBP',\r
+      name           => 'Tofu Beast',\r
+      address        => '123 Anystreet',\r
+      city           => 'Anywhere',\r
+      state          => 'UT',\r
+      zip            => '84058',\r
+      phone          => '420-867-5309',\r
+      email          => 'tofu.beast@example.com',\r
+      card_number    => '4005550000000019',\r
+      expiration     => '08/06',\r
+      card_start     => '05/04',\r
+      cvv2           => '1234', #optional\r
+      issue_number   => '5678',\r
+  );\r
+  $tx->submit();\r
+\r
+  if($tx->is_success()) {\r
+      print "Card processed successfully: ".$tx->authorization."\n";\r
+  } else {\r
+      print "Card was rejected: ".$tx->error_message."\n";\r
+  }\r
+\r
+=head1 SUPPORTED TRANSACTION TYPES\r
+\r
+=head2 CC, Visa, MasterCard, American Express, Discover\r
+\r
+Content required: type, login, password, action, amount, first_name, last_name, card_number, expiration.\r
+\r
+=head1 PREREQUISITES\r
+\r
+  URI::Escape\r
+  Tie::IxHash\r
+\r
+  Net::SSLeay _or_ ( Crypt::SSLeay and LWP )\r
+\r
+  The included htmlgood.html and htmlbad.html files must be uploaded to your\r
+  Secure Hosting account (Settings | File Manager).\r
+\r
+=head1 DESCRIPTION\r
+\r
+For detailed information see L<Business::OnlinePayment>.\r
+\r
+=head1 NOTE\r
+\r
+Only "Normal Authorization" is supported by the gateway.\r
+\r
+=head1 AUTHOR\r
+\r
+Ivan Kohler <ivan-securehostingupg@420.am>\r
+\r
+=head1 SEE ALSO\r
+\r
+perl(1). L<Business::OnlinePayment>.\r
+\r
+=cut\r
+\r
diff --git a/htmlbad.html b/htmlbad.html
new file mode 100644 (file)
index 0000000..dceb58c
--- /dev/null
@@ -0,0 +1,5 @@
+<?xml version"1.0">
+       <result>failed</result>
+       <tranerrdesc>$tranerrdesc</tranerrdesc>
+       <tranerrdetail>$tranerrdetail</tranerrdetail>
+</xml>
diff --git a/htmlgood.html b/htmlgood.html
new file mode 100644 (file)
index 0000000..cdcda5f
--- /dev/null
@@ -0,0 +1,4 @@
+<?xml version"1.0">
+       <result>success</result>
+       <cv2asvresult>$cv2avsresult</cv2asvresult>
+</xml>
diff --git a/t/bad_card.t b/t/bad_card.t
new file mode 100644 (file)
index 0000000..da64193
--- /dev/null
@@ -0,0 +1,47 @@
+BEGIN {$| = 1; print "1..1\n"; }
+
+eval "use Net::SSLeay;";
+if ( $@ ) {
+  print "ok 1 # Skipped: Net::SSLeay is not installed\n"; exit;
+}
+
+use Business::OnlinePayment;
+
+my $tx = new Business::OnlinePayment("SecureHostingUPG");
+
+#$Business::OnlinePayment::HTTPS::DEBUG = 1;
+#$Business::OnlinePayment::HTTPS::DEBUG = 1;
+#$Business::OnlinePayment::SecureHostingUPG::DEBUG = 1;
+#$Business::OnlinePayment::SecureHostingUPG::DEBUG = 1;
+
+$tx->content(
+    type           => 'VISA',
+    login          => 'SH207361', #SecureHosting Reference
+    password       => '495376',   #SecureHosting Checkcode value
+    action         => 'Normal Authorization',
+    description    => 'Business::OnlinePayment visa test',
+    amount         => '49.95',
+    currency       => 'GBP',
+    name           => 'Tofu Beast',
+    address        => '123 Anystreet',
+    city           => 'Anywhere',
+    state          => 'UT',
+    zip            => '84058',
+    phone          => '420-543-2199',
+    email          => 'tofu.beast@example.com',
+    card_number    => '4005550000000020',
+    expiration     => '08/06',
+    card_start     => '05/04',
+    cvv2           => '1234', #optional
+    issue_number   => '5678',
+);
+$tx->test_transaction(1); # test, dont really charge
+$tx->submit();
+
+if($tx->is_success()) {
+    print "not ok 1\n";
+} else {
+    #warn $tx->server_response."\n";
+    #warn  $tx->error_message. "\n";
+    print "ok 1\n";
+}
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/credit_card.t b/t/credit_card.t
new file mode 100644 (file)
index 0000000..d111585
--- /dev/null
@@ -0,0 +1,49 @@
+BEGIN { $| = 1; print "1..1\n"; }
+
+eval "use Net::SSLeay;";
+if ( $@ ) {
+  print "ok 1 # Skipped: Net::SSLeay is not installed\n"; exit;
+}
+
+use Business::OnlinePayment;
+
+my $tx = new Business::OnlinePayment("SecureHostingUPG");
+
+#$Business::OnlinePayment::HTTPS::DEBUG = 1;
+#$Business::OnlinePayment::HTTPS::DEBUG = 1;
+#$Business::OnlinePayment::SecureHostingUPG::DEBUG = 1;
+#$Business::OnlinePayment::SecureHostingUPG::DEBUG = 1;
+
+$tx->content(
+    type           => 'VISA',
+    login          => 'SH207361', #SecureHosting Reference
+    password       => '495376',   #SecureHosting Checkcode value
+    action         => 'Normal Authorization',
+    description    => 'Business::OnlinePayment visa test',
+    amount         => '49.95',
+    currency       => 'GBP',
+    name           => 'Tofu Beast',
+    address        => '123 Anystreet',
+    city           => 'Anywhere',
+    state          => 'UT',
+    zip            => '84058',
+    phone          => '420-543-2199',
+    email          => 'tofu.beast@example.com',
+    #card_number    => '4005550000000019',
+    card_number    => '4242424242424242',
+    expiration     => '01/06',
+    card_start     => '05/04',
+    cvv2           => '1234', #optional
+    issue_number   => '5678',
+);
+$tx->test_transaction(1); # test, dont really charge
+$tx->submit();
+
+if($tx->is_success()) {
+    print "ok 1\n";
+} else {
+    #warn $tx->server_response."\n";
+    warn $tx->error_message. "\n";
+    print "not ok 1\n";
+}
+
diff --git a/t/crypt_bad_card.t b/t/crypt_bad_card.t
new file mode 100644 (file)
index 0000000..1f8384b
--- /dev/null
@@ -0,0 +1,47 @@
+BEGIN {
+  $| = 1; print "1..1\n";
+  $Business::OnlinePayment::HTTPS::skip_NetSSLeay=1;
+  $Business::OnlinePayment::HTTPS::skip_NetSSLeay=1;
+}
+
+eval "use Crypt::SSLeay;";
+if ( $@ ) {
+  print "ok 1 # Skipped: Crypt::SSLeay is not installed\n"; exit;
+}
+
+use Business::OnlinePayment;
+
+my $tx = new Business::OnlinePayment("SecureHostingUPG");
+
+$tx->content(
+    type           => 'VISA',
+    login          => 'SH207361', #SecureHosting Reference
+    password       => '495376',   #SecureHosting Checkcode value
+    action         => 'Normal Authorization',
+    description    => 'Business::OnlinePayment visa test',
+    amount         => '49.95',
+    currency       => 'GBP',
+    name           => 'Tofu Beast',
+    address        => '123 Anystreet',
+    city           => 'Anywhere',
+    state          => 'UT',
+    zip            => '84058',
+    phone          => '420-543-2199',
+    email          => 'tofu.beast@example.com',
+    card_number    => '4005550000000020',
+    expiration     => '08/06',
+    card_start     => '05/04',
+    cvv2           => '1234', #optional
+    issue_number   => '5678',
+);
+$tx->test_transaction(1); # test, dont really charge
+$tx->submit();
+
+if($tx->is_success()) {
+    print "not ok 1\n";
+} else {
+    #warn $tx->server_response."\n";
+    #warn $tx->error_message. "\n";
+    print "ok 1\n";
+}
+
diff --git a/t/crypt_credit_card.t b/t/crypt_credit_card.t
new file mode 100644 (file)
index 0000000..8799603
--- /dev/null
@@ -0,0 +1,46 @@
+BEGIN {
+  $| = 1; print "1..1\n";
+  $Business::OnlinePayment::HTTPS::skip_NetSSLeay=1;
+  $Business::OnlinePayment::HTTPS::skip_NetSSLeay=1;
+}
+
+eval "use Crypt::SSLeay;";
+if ( $@ ) {
+  print "ok 1 # Skipped: Crypt::SSLeay is not installed\n"; exit;
+}
+
+use Business::OnlinePayment;
+
+my $tx = new Business::OnlinePayment("SecureHostingUPG");
+$tx->content(
+    type           => 'VISA',
+    login          => 'SH207361', #SecureHosting Reference
+    password       => '495376',   #SecureHosting Checkcode value
+    action         => 'Normal Authorization',
+    description    => 'Business::OnlinePayment visa test',
+    amount         => '49.95',
+    currency       => 'GBP',
+    name           => 'Tofu Beast',
+    address        => '123 Anystreet',
+    city           => 'Anywhere',
+    state          => 'UT',
+    zip            => '84058',
+    phone          => '420-543-2199',
+    email          => 'tofu.beast@example.com',
+    card_number    => '4005550000000019',
+    expiration     => '08/06',
+    card_start     => '05/04',
+    cvv2           => '1234', #optional
+    issue_number   => '5678',
+);
+$tx->test_transaction(1); # test, dont really charge
+$tx->submit();
+
+if($tx->is_success()) {
+    print "ok 1\n";
+} else {
+    #warn $tx->server_response."\n";
+    warn $tx->error_message. "\n";
+    print "not ok 1\n";
+}
+
diff --git a/t/crypt_load.t b/t/crypt_load.t
new file mode 100644 (file)
index 0000000..03bca03
--- /dev/null
@@ -0,0 +1,13 @@
+BEGIN {
+  $| = 1; print "1..1\n";
+  eval "use Crypt::SSLeay;";
+  if ( $@ ) {
+    print "ok 1 # Skipped: Crypt::SSLeay is not installed\n"; exit;
+  }
+  $Business::OnlinePayment::HTTPS::skip_NetSSLeay=1;
+  $Business::OnlinePayment::HTTPS::skip_NetSSLeay=1;
+}
+END {print "not ok 1\n" unless $loaded;}
+use Business::OnlinePayment::SecureHostingUPG;
+$loaded = 1;
+print "ok 1\n";
diff --git a/t/load.t b/t/load.t
new file mode 100644 (file)
index 0000000..1d6d6bc
--- /dev/null
+++ b/t/load.t
@@ -0,0 +1,12 @@
+BEGIN {
+  $| = 1; print "1..1\n";
+  eval "use Net::SSLeay;";
+  if ( $@ ) {
+    print "ok 1 # Skipped: Net::SSLeay is not installed\n"; exit;
+  }
+
+}
+END {print "not ok 1\n" unless $loaded;}
+use Business::OnlinePayment::SecureHostingUPG;
+$loaded = 1;
+print "ok 1\n";