| 1 |
package Business::OnlinePayment::TCLink; |
| 2 |
|
| 3 |
use strict; |
| 4 |
use Net::TCLink; |
| 5 |
use Business::OnlinePayment; |
| 6 |
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); |
| 7 |
|
| 8 |
require Exporter; |
| 9 |
|
| 10 |
@ISA = qw(Exporter AutoLoader Business::OnlinePayment); |
| 11 |
@EXPORT = qw(); |
| 12 |
@EXPORT_OK = qw(); |
| 13 |
$VERSION = '1.03'; |
| 14 |
|
| 15 |
sub set_defaults { |
| 16 |
my $self = shift; |
| 17 |
|
| 18 |
# this module uses Net::TCLink for connections to the payment gateway |
| 19 |
$self->server(''); |
| 20 |
$self->port(''); |
| 21 |
$self->path(''); |
| 22 |
|
| 23 |
$self->build_subs('order_number'); |
| 24 |
} |
| 25 |
|
| 26 |
sub map_fields { |
| 27 |
my($self) = @_; |
| 28 |
|
| 29 |
my %content = $self->content(); |
| 30 |
|
| 31 |
# ACTION MAP |
| 32 |
my %actions = ('normal authorization' => 'sale', |
| 33 |
'authorization only' => 'preauth', |
| 34 |
'credit' => 'credit', |
| 35 |
'post authorization' => 'postauth', |
| 36 |
); |
| 37 |
$content{'action'} = $actions{lc($content{'action'})} || $content{'action'}; |
| 38 |
|
| 39 |
# TYPE MAP |
| 40 |
my %types = ('visa' => 'cc', |
| 41 |
'mastercard' => 'cc', |
| 42 |
'american express' => 'cc', |
| 43 |
'discover' => 'cc', |
| 44 |
'novus' => 'cc', |
| 45 |
"diner's club" => 'cc', |
| 46 |
'carte blanche' => 'cc', |
| 47 |
'japan card' => 'cc', |
| 48 |
'enroute' => 'cc', |
| 49 |
'cc' => 'cc', |
| 50 |
'check' => 'ach', |
| 51 |
); |
| 52 |
$content{'type'} = $types{lc($content{'type'})} || $content{'type'}; |
| 53 |
$self->transaction_type($content{'type'}); |
| 54 |
|
| 55 |
# stuff it back into %content |
| 56 |
$self->content(%content); |
| 57 |
} |
| 58 |
|
| 59 |
sub remap_fields { |
| 60 |
my($self,%map) = @_; |
| 61 |
|
| 62 |
my %content = $self->content(); |
| 63 |
foreach(keys %map) { |
| 64 |
$content{$map{$_}} = $content{$_}; |
| 65 |
} |
| 66 |
$self->content(%content); |
| 67 |
} |
| 68 |
|
| 69 |
sub get_fields { |
| 70 |
my($self,@fields) = @_; |
| 71 |
|
| 72 |
my %content = $self->content(); |
| 73 |
my %new = (); |
| 74 |
foreach( grep defined $content{$_}, @fields) { $new{$_} = $content{$_}; } |
| 75 |
return %new; |
| 76 |
} |
| 77 |
|
| 78 |
sub submit { |
| 79 |
my($self) = @_; |
| 80 |
|
| 81 |
$self->map_fields(); |
| 82 |
$self->remap_fields( |
| 83 |
type => 'media', |
| 84 |
login => 'custid', |
| 85 |
password => 'password', |
| 86 |
action => 'action', |
| 87 |
amount => 'amount', |
| 88 |
first_name => 'first_name', |
| 89 |
last_name => 'last_name', |
| 90 |
address => 'address1', |
| 91 |
city => 'city', |
| 92 |
state => 'state', |
| 93 |
zip => 'zip', |
| 94 |
card_number => 'cc', |
| 95 |
expiration => 'exp', |
| 96 |
account_number => 'account', |
| 97 |
routing_code => 'routing', |
| 98 |
country => 'country', |
| 99 |
phone => 'phone', |
| 100 |
email => 'email', |
| 101 |
order_number => 'transid' |
| 102 |
); |
| 103 |
|
| 104 |
if($self->transaction_type() eq "ach") { |
| 105 |
$self->required_fields(qw/type login password action amount first_name |
| 106 |
last_name account_number routing_code/); |
| 107 |
} elsif($self->transaction_type() eq 'cc' ) { |
| 108 |
if ( $self->{_content}->{action} eq 'postauth' ) { |
| 109 |
$self->required_fields(qw/login password action amount order_number |
| 110 |
card_number expiration/); |
| 111 |
} else { |
| 112 |
$self->required_fields(qw/login password action amount first_name |
| 113 |
last_name card_number expiration/); |
| 114 |
} |
| 115 |
} else { |
| 116 |
Carp::croak("TrustCommerce can't handle transaction type: ". |
| 117 |
$self->transaction_type()); |
| 118 |
} |
| 119 |
|
| 120 |
my %params = $self->get_fields(qw/media custid password action amount |
| 121 |
first_name last_name address1 city state |
| 122 |
zip cc exp account routing country phone |
| 123 |
email transid/); |
| 124 |
$params{'demo'} = $self->test_transaction() ? 'y' : 'n'; |
| 125 |
$params{'avs'} = $self->require_avs() ? 'y' : 'n'; |
| 126 |
$params{'name'} = $params{'first_name'} . ' ' . $params{'last_name'}; |
| 127 |
delete $params{'first_name'}; |
| 128 |
delete $params{'last_name'}; |
| 129 |
$params{'amount'} =~ s/\D//g; # strip non-digits |
| 130 |
$params{'cc'} =~ s/\D//g; |
| 131 |
$params{'exp'} =~ s/\D//g; |
| 132 |
$params{'exp'} = '0' . $params{'exp'} if length($params{'exp'}) == 3; |
| 133 |
|
| 134 |
my %results = Net::TCLink::send(\%params); |
| 135 |
|
| 136 |
if($results{'status'} eq 'approved' or $results{'status'} eq 'accepted') { |
| 137 |
$self->is_success(1); |
| 138 |
$self->result_code($results{'status'}); |
| 139 |
$self->authorization($results{'avs'}); |
| 140 |
$self->order_number($results{'transid'}); |
| 141 |
} else { |
| 142 |
$self->is_success(0); |
| 143 |
$self->result_code($results{'status'}); |
| 144 |
|
| 145 |
my $error; |
| 146 |
if ($results{'status'} eq 'decline') { |
| 147 |
if ($results{'declinetype'} eq 'carderror') { |
| 148 |
$error = 'The credit card number is invalid.'; |
| 149 |
} else { |
| 150 |
$error = 'The credit card transaction was declined.'; |
| 151 |
} |
| 152 |
} elsif ($results{'status'} eq 'baddata') { |
| 153 |
$error = 'The transaction data is invalid.'; |
| 154 |
} elsif ($results{'status'} eq 'error') { |
| 155 |
$error = 'There was a network failure during processing.'; |
| 156 |
} |
| 157 |
$self->error_message($error); |
| 158 |
} |
| 159 |
} |
| 160 |
|
| 161 |
1; |
| 162 |
__END__ |
| 163 |
|
| 164 |
=head1 NAME |
| 165 |
|
| 166 |
Business::OnlinePayment::TCLink - TrustCommerce backend for Business::OnlinePayment |
| 167 |
|
| 168 |
=head1 SYNOPSIS |
| 169 |
|
| 170 |
use Business::OnlinePayment; |
| 171 |
|
| 172 |
my $tx = new Business::OnlinePayment("TCLink"); |
| 173 |
$tx->content( |
| 174 |
type => 'VISA', |
| 175 |
login => '99999', |
| 176 |
password => '', |
| 177 |
action => 'Normal Authorization', |
| 178 |
amount => '49.95', |
| 179 |
first_name => 'Dan', |
| 180 |
last_name => 'Helfman', |
| 181 |
address => '123 Anystreet', |
| 182 |
city => 'Anywhere', |
| 183 |
state => 'UT', |
| 184 |
zip => '84058', |
| 185 |
card_number => '4111111111111111', |
| 186 |
expiration => '09/05', |
| 187 |
); |
| 188 |
$tx->submit(); |
| 189 |
|
| 190 |
if($tx->is_success()) { |
| 191 |
print "Card processed successfully: ".$tx->authorization."\n"; |
| 192 |
} else { |
| 193 |
print "Card was rejected: ".$tx->error_message."\n"; |
| 194 |
} |
| 195 |
|
| 196 |
=head1 SUPPORTED TRANSACTION TYPES |
| 197 |
|
| 198 |
=head2 Visa, MasterCard, American Express, Discover, Novus, Diner's Club, |
| 199 |
Carte Blanche, Japan Card, Enroute, CC |
| 200 |
|
| 201 |
Content required: type, login, password, action, amount, first_name, last_name, card_number, expiration. |
| 202 |
|
| 203 |
=head2 Check |
| 204 |
|
| 205 |
Content required: type, login, password, action, amount, first_name, last_name, account_number, routing_code. |
| 206 |
|
| 207 |
=head1 DESCRIPTION |
| 208 |
|
| 209 |
For detailed information see L<Business::OnlinePayment>. |
| 210 |
|
| 211 |
=head1 NOTE |
| 212 |
|
| 213 |
To settle an authorization-only transaction (where you set action to |
| 214 |
'Authorization Only'), submit the transaction id code in the field |
| 215 |
"order_number" with the action set to "Post Authorization". You can get |
| 216 |
the transaction id from the authorization by calling the order_number |
| 217 |
method on the object returned from the authorization. You must also |
| 218 |
submit the amount field with a value less than or equal to the amount |
| 219 |
specified in the original authorization. |
| 220 |
|
| 221 |
=head1 COMPATIBILITY |
| 222 |
|
| 223 |
This module relies on L<Net::TCLink> for interacting with the |
| 224 |
TrustCommerce payment engine. See |
| 225 |
http://www.trustcommerce.com/tclink.html for details. |
| 226 |
|
| 227 |
=head1 AUTHOR |
| 228 |
|
| 229 |
Dan Helfman <[email protected]> |
| 230 |
|
| 231 |
Derived from code by Jason Kohles and Ivan Kohler. |
| 232 |
|
| 233 |
=head1 SEE ALSO |
| 234 |
|
| 235 |
perl(1). L<Business::OnlinePayment>. L<Net::TCLink>. |
| 236 |
|
| 237 |
=cut |
| 238 |
|