From 97caf6448f338be65d58b3331d3cb50084fa2793 Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 5 Jan 2006 03:15:12 +0000 Subject: [PATCH] initial import --- Changes | 6 + MANIFEST | 13 ++ Makefile.PL | 22 +++ README | 16 ++ lib/Business/OnlinePayment/TransactionCentral.pm | 241 +++++++++++++++++++++++ t/Business-OnlinePayment-TransactionCentral.t | 17 ++ t/bad_card.t | 48 +++++ t/bop.t | 5 + t/credit_card.t | 45 +++++ t/crypt_bad_card.t | 47 +++++ t/crypt_credit_card.t | 49 +++++ t/crypt_load.t | 13 ++ t/load.t | 12 ++ 13 files changed, 534 insertions(+) create mode 100644 Changes create mode 100644 MANIFEST create mode 100644 Makefile.PL create mode 100644 README create mode 100644 lib/Business/OnlinePayment/TransactionCentral.pm create mode 100644 t/Business-OnlinePayment-TransactionCentral.t create mode 100644 t/bad_card.t create mode 100644 t/bop.t create mode 100644 t/credit_card.t create mode 100644 t/crypt_bad_card.t create mode 100644 t/crypt_credit_card.t create mode 100644 t/crypt_load.t create mode 100644 t/load.t diff --git a/Changes b/Changes new file mode 100644 index 0000000..3cf390c --- /dev/null +++ b/Changes @@ -0,0 +1,6 @@ +Revision history for Perl extension Business::OnlinePayment::TransactionCentral. + +0.01 Wed Nov 23 05:14:43 2005 + - original version; created by h2xs 1.23 with options + -X -b 5.5.0 -n Business::OnlinePayment::TransactionCentral -v 0.01 + diff --git a/MANIFEST b/MANIFEST new file mode 100644 index 0000000..f6cb7b1 --- /dev/null +++ b/MANIFEST @@ -0,0 +1,13 @@ +Changes +Makefile.PL +MANIFEST +README +lib/Business/OnlinePayment/TransactionCentral.pm +t/Business-OnlinePayment-TransactionCentral.t +t/load.t +t/bad_card.t +t/bop.t +t/credit_card.t +t/crypt_bad_card.t +t/crypt_credit_card.t +t/crypt_load.t diff --git a/Makefile.PL b/Makefile.PL new file mode 100644 index 0000000..b61410b --- /dev/null +++ b/Makefile.PL @@ -0,0 +1,22 @@ +use 5.005; +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::TransactionCentral', + VERSION_FROM => 'lib/Business/OnlinePayment/TransactionCentral.pm', # finds $VERSION + 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 + }, + ($] >= 5.005 ? ## Add these new keywords supported since 5.005 + (ABSTRACT_FROM => 'lib/Business/OnlinePayment/TransactionCentral.pm', # retrieve abstract from module + AUTHOR => 'Ivan Kohler ') : ()), +); diff --git a/README b/README new file mode 100644 index 0000000..b78eb6b --- /dev/null +++ b/README @@ -0,0 +1,16 @@ +Copyright (c) 2005 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::TransactionCentral, an Business::OnlinePayment +backend module for the MerchantAnywhere Transaction Central gateway. It is +only useful if you have a merchant account with MerchantAnywhere: +http://www.merchantanywhere.com/ +http://www.merchantanywhere.com/ecshop/TC_elink.htm +http://www.merchantanywhere.com/ecshop/TC%20Interface%20NEW.pdf + +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/lib/Business/OnlinePayment/TransactionCentral.pm b/lib/Business/OnlinePayment/TransactionCentral.pm new file mode 100644 index 0000000..e16a484 --- /dev/null +++ b/lib/Business/OnlinePayment/TransactionCentral.pm @@ -0,0 +1,241 @@ +package Business::OnlinePayment::TransactionCentral; + +use 5.005; +use strict; +use Carp; +use Business::OnlinePayment 3; +use Business::OnlinePayment::HTTPS 0.02; +use vars qw($VERSION @ISA $DEBUG); + +@ISA = qw(Business::OnlinePayment::HTTPS); +$VERSION = '0.02'; +$DEBUG = 0; + +sub set_defaults { + my $self = shift; + + $self->server('webservices.primerchants.com'); + $self->port('443'); + $self->path('/billing/TransactionCentral/'); + + $self->build_subs(qw( order_number avs_code cvv2_response )); +} + +sub submit { + my($self) = @_; + + $self->revmap_fields( + 'MerchantID' => 'login', + 'RegKey' => 'password', + 'Amount' => 'amount', +# 'CreditAmount' => 'amount', + 'AccountNo' => 'card_number', + 'NameonAccount' => 'name', + 'AVSADDR' => 'address', + 'AVSZIP' => 'zip', + 'CCRURL' => \'', + 'CVV2' => 'cvv2', + 'TransID' => 'order_number', + 'TRANSROUTE' => 'routing_code', + ); + + #XXX also set required fields here... + + my @required_fields = qw(login password); + my %content = $self->content(); + my $action = $content{'action'}; + my $url = $self->path; + if ( + $content{'type'} =~ /^(cc|visa|mastercard|american express|discover)$/i + ) { + + if ( $action =~ /^\s*normal\s*authorization\s*$/i ) { + $url .= 'processCC.asp'; + + #REFID + $content{'REFID'} = int(rand(2**31)); + + #CCMonth & CCYear + $content{'expiration'} =~ /^(\d+)\D+\d*(\d{2})$/ + or croak "unparsable expiration ". $content{'expiration'}; + my( $month, $year ) = ( $1, $2 ); + #$month = '0'. $month if $month =~ /^\d$/; + $content{'CCMonth'} = $month; + $content{'CCYear'} = $year; + + #push @required_fields, qw( amount card_numb + } elsif ( $action =~ /^\s*authorization\s*only\s*$/i ) { + croak "Authorizaiton Only is not supported by Transaction Central"; + } elsif ( $action =~ /^\s*post\s*authorization\s*$/i ) { + croak "Post Authorizaiton is not supported by Transaction Central"; + } elsif ( $action =~ /^\s*(void|credit)\s*$/i ) { + $url .= 'voidcreditcconline.asp'; + + $content{'CreditAmount'} = delete $content{'Amount'}; + + } else { + croak "Unknown action $action"; + } + + } elsif ( $content{'type'} =~ /^check$/i ) { + + if ( $action =~ /^\s*normal\s*authorization\s*$/i ) { + $url .= 'processcheck.asp'; + $content{'AccountNo'} = $content{'account_number'}; + $content{'TRANSTYPE'} = $content{'account_type'} =~ /^s/i ? 'SA' : 'CK'; + + } elsif ( $action =~ /^\s*authorization\s*only\s*$/i ) { + croak "Authorizaiton Only is not supported by Transaction Central"; + } elsif ( $action =~ /^\s*post\s*authorization\s*$/i ) { + croak "Post Authorizaiton is not supported by Transaction Central"; + } elsif ( $action =~ /^\s*(void|credit)\s*$/i ) { + $url .= 'addckcreditupdtonline.asp'; + } else { + croak "Unknown action $action"; + } + + } else { + croak 'Unknown type: '. $content{'type'}; + } + $self->path($url); + $self->content(%content); + + my @fields = qw( + MerchantID RegKey Amount REFID AccountNo CCMonth CCYear NameonAccount + AVSADDR AVSZIP CCRURL CVV2 USER1 USER2 USER3 USER4 TrackData + TransID CreditAmount + DESCRIPTION DESCDATE TRANSTYPE TRANSROUTE + ); + + #my( $page, $response, %reply_headers ) = + my( $page, $response ) = + $self->https_post( $self->get_fields( @fields ) ); + + warn "\n" if $DEBUG > 1; + if ( $DEBUG > 2 ) { + warn "response: $response\n"; + # warn "reply headers: ". + # join(', ', map "$_ => $reply_headers{$_}", keys %reply_headers ). "\n"; + } + warn "raw response: $page\n" if $DEBUG > 1; + + my %return = map { /^(\w+)=(.*)$/ ? ( $1 => $2 ) : () } split(/&/, $page); + + if ( $DEBUG ) { warn "$_ => $return{$_}\n" foreach keys %return; } + + #$self->result_code( $return{'AVSCode'} ); + $self->avs_code( $return{'AVSCode'} ); + $self->cvv2_response( $return{'CVV2ResponseMsg'} ); + + if ( $return{'Auth'} =~ /^(\d+)$/ ) { + + $self->is_success(1); + $self->authorization( $return{'Auth'} ); + $self->order_number( $return{'TransID'} ); + + } else { + + $self->is_success(0); + $self->error_message( $return{'Notes'} ); + + } + +} + +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); +} + +1; + +__END__ + +=head1 NAME + +Business::OnlinePayment::TransactionCentral - Transaction Central backend module for Business::OnlinePayment + +=head1 SYNOPSIS + + use Business::OnlinePayment::TransactionCentral; + blah blah blah + +=head1 DESCRIPTION + + use Business::OnlinePayment; + + #### + # One step transaction, the simple case. + #### + + my $tx = new Business::OnlinePayment("Capstone"); + $tx->content( + type => 'CC', + login => '10011', #MerchantID + password => 'KK48NPYEJHMAH6DK', #Regkey + action => 'Normal Authorization', + description => 'Business::OnlinePayment test', + amount => '49.95', + name => 'Tofu Beast', + address => '123 Anystreet', + city => 'Anywhere', + state => 'UT', + zip => '84058', + phone => '420-867-5309', + email => 'tofu.beast@example.com', + card_number => '4012000000001', + expiration => '08/06', + cvv2 => '1234', #optional + ); + $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 CC, Visa, MasterCard, American Express, Discover + +Content required: type, login, password, action, amount, card_number, expiration. + +=head1 PREREQUISITES + + URI::Escape + #Tie::IxHash + + Net::SSLeay _or_ ( Crypt::SSLeay and LWP ) + +=head1 DESCRIPTION + +For detailed information see L. + +=head1 NOTE + +=head1 AUTHOR + +Ivan Kohler + +=head1 COPYRIGHT AND LICENSE + +Copyright (C) 2005 by Ivan Kohler + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself. + +=head1 SEE ALSO + +perl(1). L. + +=cut diff --git a/t/Business-OnlinePayment-TransactionCentral.t b/t/Business-OnlinePayment-TransactionCentral.t new file mode 100644 index 0000000..947e0c1 --- /dev/null +++ b/t/Business-OnlinePayment-TransactionCentral.t @@ -0,0 +1,17 @@ +# Before `make install' is performed this script should be runnable with +# `make test'. After `make install' it should work as `perl Business-OnlinePayment-TransactionCentral.t' + +######################### + +# change 'tests => 1' to 'tests => last_test_to_print'; + +use Test; +BEGIN { plan tests => 1 }; +use Business::OnlinePayment::TransactionCentral; +ok(1); # If we made it this far, we're ok. + +######################### + +# Insert your test code below, the Test::More module is use()ed here so read +# its man page ( perldoc Test::More ) for help writing this test script. + diff --git a/t/bad_card.t b/t/bad_card.t new file mode 100644 index 0000000..aa593bd --- /dev/null +++ b/t/bad_card.t @@ -0,0 +1,48 @@ +BEGIN {$| = 1; print "1..1\n"; } + +print "ok 1 # Skipped: No way to get a decline response out of test account"; +exit; + +eval "use Net::SSLeay;"; +if ( $@ ) { + print "ok 1 # Skipped: Net::SSLeay is not installed\n"; exit; +} + +use Business::OnlinePayment; + +my $tx = new Business::OnlinePayment("TransactionCentral"); + +#$Business::OnlinePayment::HTTPS::DEBUG = 1; +#$Business::OnlinePayment::HTTPS::DEBUG = 1; +$Business::OnlinePayment::TransactionCentral::DEBUG = 1; +$Business::OnlinePayment::TransactionCentral::DEBUG = 1; + +$tx->content( + type => 'VISA', + login => '10011', + password => 'KK48NPYEJHMAH6DK', #regkey + action => 'Normal Authorization', + amount => '32.32', + #card_number => '4012000000001', + #card_number => '4342424242424242', + card_number => '1', + expiration => '08/06', + cvv2 => '420', + name => 'Tofu Beast', + address => '123 Anystreet', + city => 'Anywhere', + state => 'UT', + zip => '84058', + country => 'US', + email => 'ivan-transactioncentral-test@420.am', +); +$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 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 index 0000000..eccbf01 --- /dev/null +++ b/t/credit_card.t @@ -0,0 +1,45 @@ +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("TransactionCentral"); + +#$Business::OnlinePayment::HTTPS::DEBUG = 1; +#$Business::OnlinePayment::HTTPS::DEBUG = 1; +#$Business::OnlinePayment::TransactionCentral::DEBUG = 1; +#$Business::OnlinePayment::TransactionCentral::DEBUG = 1; + +$tx->content( + type => 'VISA', + login => '10011', + password => 'KK48NPYEJHMAH6DK', #regkey + action => 'Normal Authorization', + description => 'Business::OnlinePayment::TransactionCentral test', + amount => '32', + card_number => '4012000000001', + expiration => '01/06', + cvv2 => '420', + name => 'Tofu Beast', + address => '123 Anystreet', + city => 'Anywhere', + state => 'UT', + zip => '84058', + country => 'US', + email => 'ivan-transactioncentral-test@420.am', +); +$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 index 0000000..f1b23e6 --- /dev/null +++ b/t/crypt_bad_card.t @@ -0,0 +1,47 @@ +BEGIN { + $| = 1; print "1..1\n"; + $Business::OnlinePayment::HTTPS::skip_NetSSLeay=1; + $Business::OnlinePayment::HTTPS::skip_NetSSLeay=1; +} + +print "ok 1 # Skipped: No way to get a decline response out of test account"; +exit; + +eval "use Crypt::SSLeay;"; +if ( $@ ) { + print "ok 1 # Skipped: Crypt::SSLeay is not installed\n"; exit; +} + +use Business::OnlinePayment; + +my $tx = new Business::OnlinePayment("TransactionCentral"); + +$tx->content( + type => 'VISA', + login => '10011', + password => 'KK48NPYEJHMAH6DK', #regkey + action => 'Normal Authorization', + amount => '32.32', + #card_number => '4012000000001', + card_number => '4342424242424242', + expiration => '08/06', + cvv2 => '420', + name => 'Tofu Beast', + address => '123 Anystreet', + city => 'Anywhere', + state => 'UT', + zip => '84058', + country => 'US', + email => 'ivan-transactioncentral-test@420.am', +); +$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 index 0000000..f813030 --- /dev/null +++ b/t/crypt_credit_card.t @@ -0,0 +1,49 @@ +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("TransactionCentral"); + +#$Business::OnlinePayment::HTTPS::DEBUG = 1; +#$Business::OnlinePayment::HTTPS::DEBUG = 1; +#$Business::OnlinePayment::TransactionCentral::DEBUG = 1; +#$Business::OnlinePayment::TransactionCentral::DEBUG = 1; + +$tx->content( + type => 'VISA', + login => '10011', + password => 'KK48NPYEJHMAH6DK', #regkey + action => 'Normal Authorization', + description => 'Business::OnlinePayment::TransactionCentral test', + amount => '54.01', + card_number => '4012000000001', + expiration => '08/06', + cvv2 => '420', + name => 'Tofu Beast', + address => '123 Anystreet', + city => 'Anywhere', + state => 'UT', + zip => '84058', + country => 'US', + email => 'ivan-transactioncentral-test@420.am', +); +$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 index 0000000..6976366 --- /dev/null +++ b/t/crypt_load.t @@ -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::TransactionCentral; +$loaded = 1; +print "ok 1\n"; diff --git a/t/load.t b/t/load.t new file mode 100644 index 0000000..d45dfff --- /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::TransactionCentral; +$loaded = 1; +print "ok 1\n"; -- 2.11.0