1 package Business::OnlinePayment::IPaymentTPG;
4 use vars qw($VERSION @ISA);
7 use Business::OnlinePayment;
10 @ISA = qw(Business::OnlinePayment);
16 $self->server('205.137.49.250');
19 $self->build_subs('order_number');
26 my %content = $self->content();
29 my %actions = ('normal authorization' => 'B', #both
30 'authorization only' => 'O', #open
31 'credit' => 'C', #credit
32 'post authorization' => 'S', #sell
34 $content{'action'} = $actions{lc($content{'action'})} || $content{'action'};
36 # stuff it back into %content
37 $self->content(%content);
44 #no warnings; #not 5.005
46 eval "sub $_ { my \$self = shift; if(\@_) { \$self->{$_} = shift; } return \$self->{$_}; }";
51 my($self,@fields) = @_;
53 my %content = $self->content();
55 foreach( grep defined $content{$_}, @fields) { $new{$_} = $content{$_}; }
65 # my %content = $self->content;
67 $self->required_fields(qw( login password
68 action card_number expiration amount ) );
70 my %d = $self->get_fields(qw(
71 login password action card_number expiration amount
72 phone invoice_number zip email
75 $d{expiration} =~ s/\D//g;
77 substr($d{expiration},2,2,'') if length($d{expiration}) == 6;
79 $d{amount} = sprintf("%.2f",$d{amount});
82 my($address1,$address2);
89 ($address1,$address2) = split(/,\s*/, $d{address}, 2); #hmm
94 my $req4 = pack("A4A10A20A1A16A4A10A1",
97 $d{password}, #PASSWORD
109 $opt1 = pack("A4A5A10A10A9A3A40A40A40A40A25A2A25A40A40A4A10A25",
113 $d{invoice_number}, #SEQNO
122 $d{country}, #COUNTRY
123 $d{first_name}, #FIRST_NAME
124 $d{last_name}, #LAST_NAME
126 $d{order_number}, #TRACKING_NO
127 'CRYPT_KEY', #CRYPT_KEY
132 my $sock = new IO::Socket::INET
133 PeerAddr => $self->server,
134 PeerPort => $self->port,
137 or die "can't connect to ". $self->server. ":". $self->port. " : $!";
139 print $sock "000438$req4$opt1"; ; #66 + 372, only one record for now
142 my $num = read $sock, $message_length, 6;
143 die "expected 6 byte MESSAGE_LENGTH response from server, got $num: $!"
146 #34 - only one record for now
147 die "expected MESSAGE_LENGTH 34 from server, got $message_length"
148 unless $message_length == 34;
151 my $read_length = read $sock, $res1, $message_length;
152 die "expected 34 byte RES1 message from server, got $read_length"
153 unless $read_length == 34;
155 my( $segment_id, $response, $tracking_no, $seqno ) =
156 unpack("A4A10A10A10", $res1);
158 die "expected SEGMENT_ID=RES1 from server, got $segment_id"
159 unless $segment_id eq 'RES1';
161 my($result,$mapp,$avs,$card,$ani,$new,$transaction,$cvv2,$ssv,$bin_blocker)=
164 if ( $result =~ /^[127]$/ ) {
165 $self->is_success(1);
166 $self->result_code($response);
167 $self->authorization($tracking_no);
168 $self->order_number($tracking_no);
171 $self->is_success(0);
172 $self->result_code($response);
175 '0' => 'Not available or System Down',
176 '1' => 'Optn Approved',
177 '2' => 'Sell Approved',
178 '3' => 'Open Declined',
179 '4' => 'Sell Decliend',
180 '5' => 'Invalid Message',
181 '6' => 'Closed Merchant Account',
182 '7' => 'Credit Approved',
183 '8' => 'Credit Declined',
189 #'2' => 'Card Limit',
190 '2' => 'Card Over Limit',
193 '4' => 'Card Blocked',
195 '5' => 'Invalid credit card number',
200 my $error = $resultmap{$result};
201 $error .= ": $cardmap{$card}" if $card;
203 $self->error_message($error);
213 Business::OnlinePayment::IPaymentTPG - iPayment TPG backend for Business::OnlinePayment
217 use Business::OnlinePayment;
219 my $tx = new Business::OnlinePayment( 'IPaymentTPG',
224 action => 'Normal Authorization',
225 description => 'Business::OnlinePayment test',
227 invoice_number => '100100',
228 customer_id => 'jsk',
229 first_name => 'Tofu',
230 last_name => 'Beast',
231 address => '123 Anystreet',
235 email => 'ivan-ipaymenttpg@420.am',
236 card_number => '4007000000027',
237 expiration => '09/02',
241 if($tx->is_success()) {
242 print "Card processed successfully: ".$tx->authorization."\n";
244 print "Card was rejected: ".$tx->error_message."\n";
247 =head1 SUPPORTED TRANSACTION TYPES
249 =head2 Visa, MasterCard, American Express, JCB, Discover/Novus, Carte blanche/Diners Club
253 For detailed information see L<Business::OnlinePayment>.
257 Unlike Business::OnlinePayment or pre-3.0 verisons of
258 Business::OnlinePayment::AuthorizeNet, 3.1 requires separate first_name and
263 This module implements the interface documented in
264 https://tpg1.ipaymenttechnologies.com/docs/
268 The documentation lacks specifics on the encryption implementation.
272 Ivan Kohler <ivan-ipaymenttpg@420.am>
276 perl(1), L<Business::OnlinePayment>.