summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorivan <ivan>2002-12-17 14:04:31 +0000
committerivan <ivan>2002-12-17 14:04:31 +0000
commit449221e481daad31410736547ee5741a00f0f4b8 (patch)
tree1b2bd2206640fabfbef9958fb845e7358ea4cec3
initial importBEGIN
-rw-r--r--Changes5
-rw-r--r--MANIFEST9
-rw-r--r--Makefile.PL15
-rw-r--r--PaymentsGateway.pm155
-rw-r--r--README22
-rw-r--r--t/bop.t5
-rw-r--r--t/load.t5
-rw-r--r--t2/bad_check.t33
-rw-r--r--t2/check.t30
9 files changed, 279 insertions, 0 deletions
diff --git a/Changes b/Changes
new file mode 100644
index 0000000..a1a13fa
--- /dev/null
+++ b/Changes
@@ -0,0 +1,5 @@
+Revision history for Perl extension Business::OnlinePayment::PaymentsGateway
+
+0.01 unreleased
+ -original version; created by ivan 1.0 on an aeroplane to OAK
+
diff --git a/MANIFEST b/MANIFEST
new file mode 100644
index 0000000..1b977f8
--- /dev/null
+++ b/MANIFEST
@@ -0,0 +1,9 @@
+PaymentsGateway.pm
+Changes
+MANIFEST
+Makefile.PL
+README
+t/load.t
+t/bop.t
+t2/check.t.t
+t2/bad_check.t
diff --git a/Makefile.PL b/Makefile.PL
new file mode 100644
index 0000000..b0e2216
--- /dev/null
+++ b/Makefile.PL
@@ -0,0 +1,15 @@
+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::PaymentsGateway',
+ 'VERSION_FROM' => 'PaymentsGateway.pm', # finds $VERSION
+ 'AUTHOR' => 'Ivan Kohler <ivan-paymentsgateway@420.am>',
+ #'NORECURS' => 1, # dont descend into subdirectories
+ 'PREREQ_PM' => { 'Net::SSLeay' => '0',
+ #'Text::CSV_XS' => 0,
+ 'Business::OnlinePayment' => '0',
+ #'Business::CreditCard' => 0.27,
+ },
+);
+
diff --git a/PaymentsGateway.pm b/PaymentsGateway.pm
new file mode 100644
index 0000000..9070e1d
--- /dev/null
+++ b/PaymentsGateway.pm
@@ -0,0 +1,155 @@
+package Business::OnlinePayment::PaymentsGateway;
+
+use strict;
+use Carp;
+use Business::OnlinePayment
+use Net::SSLeay qw(sslcat);
+use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $DEBUG);
+
+require Exporter;
+
+@ISA - qw( Exporter AutoLoader Business::OnlinePayment);
+@EXPORT = qw();
+@EXPORT_OK = qw();
+$VERSION = '0.01';
+
+$DEBUG = 0;
+
+sub set_defaults {
+ my $self = shift;
+ $self->server('');
+ $self->port( 5050 + 1000 * $self->test_transaction() );
+ #$self->build_subs();
+}
+
+sub map_fields {
+ my $self = shift;
+ my %content = $self->content();
+
+ #ACTION MAP
+ my %actions = (
+ 'normal authorization' => 0,
+ 'authorization only' => 1,
+ 'post authorization' => 2,
+ 'credit' => 3,
+ );
+
+ my %types = (
+ 'visa' => 10,
+ 'mastercard' => 10,
+ 'american express' => 10,
+ 'discover' => 10,
+ 'cc' => 10,
+ 'check' => 20,
+ );
+
+ #pg_type/action = action + type
+
+ $self->transaction_type( $actions{ lc($content{'action'}) }
+ + $types{ lc($content{'type' }) } );
+
+ #$self->content(%content);
+}
+
+sub revmap_fields {
+ my($self, %map) = @_;
+ my %content = $self->content();
+ foreach(keys %map) {
+ $content{$_} = ref($map{$_})
+ ? ${ $map{$_} }
+ : $content{$map{$_}};
+ }
+ $self->content(%content);
+}
+
+sub submit {
+ my $self = shift;
+ $self->map_fields();
+
+ my %content = $self->content();
+
+ $self->revmap_fields(
+ 'pg_merchant_id' => 'login',
+ 'pg_password' => 'password',
+ 'pg_transaction_type' => \($self->transaction_type()),
+ #'pg_merchant_data_1'
+ #...
+ #'pg_merchant_data_9'
+ 'pg_total_amount' => 'amount',
+ #'pg_sales_tax_amount'
+ 'pg_consumer_id' => 'customer_id',
+ 'ecom_consumerorderid' => 'invoice_number', #???
+ #'ecom_walletid' =>
+ 'pg_billto_postal_name_company' => 'company', #????
+ 'ecom_billto_postal_name_first' => 'first_name', #????
+ 'ecom_billto_postal_name_last' => 'last_name', # ????
+ 'ecom_billto_postal_street_line1' => 'address',
+ #'ecom_billto_postal_street_line2'
+ 'ecom_billto_postal_city' => 'city',
+ 'ecom_billto_postal_stateprov' => 'state',
+ 'ecom_billto_postal_postalcode' => 'zip',
+ 'ecom_billto_postal_countrycode' => 'country',
+ 'ecom_billto_telecom_phone_number' => 'phone',
+ 'ecom_billto_online_email' => 'email',
+ #'pg_billto_ssn'
+ #'pg_billto_dl_number'
+ #'pg_billto_dl_state'
+ 'ecom_payment_check_trn' => 'routing_code',
+ 'ecom_payment_check_account' => 'account_number',
+ 'ecom_payment_check_account_type' => \'C', #checking
+ #'ecom_payment_check_checkno' =>
+ );
+
+ # name (first_name & last_name ) ?
+ # fax
+
+ # card_number exp_date
+
+ #account_number routing_code bank_name
+
+ my @fields = qw( pg_merchant_id pg_password pg_transaction_type ),
+ ( map { "pg_merchant_$_" } (1..9) ),
+ qw( pg_total_amount pg_sales_tax_amount pg_consumer_id
+ ecom_consumerorderid ecom_walletid
+ pg_billto_postal_name_company
+ ecom_billto_postal_name_first ecom_billto_postal_name_last
+ ecom_billto_postal_street_line1
+ ecom_billto_postal_street_line2
+ ecom_billto_postal_city ecom_billto_postal_stateprov
+ ecom_billto_postal_postalcode ecom_billto_postal_countrycode
+ ecom_billto_telecom_phone_number ecom_billto_online_email
+ pg_billto_ssn pg_billto_dl_number pg_billto_dl_state
+ );
+
+ if ( $content{'type'} =~ /^check$/i ) {
+ push @fields, qw( ecom_payment_check_trn
+ ecom_payment_check_account
+ ecom_payment_check_account_type );
+ } else {
+ croak $content{$type}. ' not (yet) supported';
+ }
+
+ my $request = join("\n", map { "$_=$content{$_}" } @fields ). "\n";
+
+ my $reply = sslcat( $self->server(), $self->port(), $request );
+
+ my %response = map { /^(\w+)=(.*)$/
+ or warn "can't parse response line: $_";
+ ($1, $2);
+ } split(/\n/, $reply);
+
+ if ( $response{'pg_response_type'} eq 'A' ) {
+ $self->is_success(1);
+ $self->response_code($response{'pg_response_code'});
+ $self->authorization($response{'pg_authorization_code'});
+ } else {
+ $self->is_success(0);
+ $self->response_code($response{'pg_response_code'});
+ $self->error_message($response{'pg_response_description'});
+ }
+}
+
+1;
+
+#pod goes here
+
diff --git a/README b/README
new file mode 100644
index 0000000..a02ad6a
--- /dev/null
+++ b/README
@@ -0,0 +1,22 @@
+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::PaymentsGateway, an Business::OnlinePayment
+backend module for PaymentsGateway.net ACH Direct. It is only useful if you
+have a merchant account with PaymentsGateway.net
+
+This module implements the interface documented in the
+"PaymentsGateway.net Integration Guide, Version 2.1, September 2002"
+
+There are additional tests in t2/ that may be useful to you once you have a
+login and password.
+
+Ivan Kohler <ivan-paymentsgateway@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
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
index 0000000..119744b
--- /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::PaymentsGateway;
+$loaded = 1;
+print "ok 1\n";
diff --git a/t2/bad_check.t b/t2/bad_check.t
new file mode 100644
index 0000000..3ce505e
--- /dev/null
+++ b/t2/bad_check.t
@@ -0,0 +1,33 @@
+BEGIN { $| = 1; print "1..1\n"; }
+
+use Business::OnlinePayment;
+
+# checks are broken it seems
+my $ctx = new Business::OnlinePayment("PaymentsGateway");
+$ctx->content(
+ type => 'CHECK',
+ login => 'testing',
+ password => 'testing',
+ action => 'Normal Authorization',
+ amount => '49.95',
+ invoice_number => '100100',
+ customer_id => 'jsk',
+ first_name => 'Tofu',
+ last_name => 'Beast',
+ #account_number => '12345',
+ account_number => 'badaccountnumber',
+ #routing_code => '123456789',
+ routing_code => 'badroutingcode',
+ bank_name => 'First National Test Bank',
+);
+$ctx->test_transaction(1); # test, dont really charge
+$ctx->submit();
+
+print $ctx->is_success()."\n";
+
+if($ctx->is_success()) {
+ print "not ok 1\n";
+} else {
+ #warn $ctx->error_message();
+ print "ok 1\n";
+}
diff --git a/t2/check.t b/t2/check.t
new file mode 100644
index 0000000..e253e24
--- /dev/null
+++ b/t2/check.t
@@ -0,0 +1,30 @@
+BEGIN { $| = 1; print "1..1\n"; }
+
+use Business::OnlinePayment;
+
+# checks are broken it seems
+my $ctx = new Business::OnlinePayment("PaymentsGateway");
+$ctx->content(
+ type => 'CHECK',
+ login => 'testing',
+ password => 'testing',
+ action => 'Normal Authorization',
+ amount => '49.95',
+ invoice_number => '100100',
+ customer_id => 'jsk',
+ first_name => 'Tofu',
+ last_name => 'Beast',
+ account_number => '12345',
+ routing_code => '123456789',
+ bank_name => 'First National Test Bank',
+);
+$ctx->test_transaction(1); # test, dont really charge
+$ctx->submit();
+
+print $ctx->is_success()."\n";
+
+if($ctx->is_success()) {
+ print "ok 1\n";
+} else {
+ print "not ok 1 (".$ctx->error_message().")\n";
+}