1 package Business::BatchPayment::Paymentech;
10 Business::BatchPayment::Paymentech - Chase Paymentech XML batch format.
18 See L<Business::BatchPayment> for general usage notes.
22 use Business::BatchPayment;
24 my @items = Business::BatchPayment::Item->new( ... );
26 my $processor = Business::BatchPayment->processor('Paymentech',
27 merchantID => '123456',
35 my $result = $processor->submit(@items);
39 Requires L<Net::SFTP::Foreign> and ssh (for file transfer) and the zip and
40 unzip programs. Unlikely to work on non-Unix systems.
42 =head2 PROCESSOR ATTRIBUTES
46 =item login - the username to use for SFTP, and in the "userID" tag
48 =item password - the password for SFTP, and for creating zip files
50 =item merchantID - your 6- or 12-digit Paymentech merchant ID
52 =item bin - your BIN: 000001 or 000002
54 =item terminalID - your 3-digit terminal ID
56 =item industryType - your 2-letter industry type code
62 use File::Temp qw(tempdir);
68 with 'Business::BatchPayment::Processor';
69 with 'Business::BatchPayment::TestMode';
71 # could have some validation on all of these
72 has [ qw(merchantID terminalID bin industryType login password) ] => (
78 has 'fileDateTime' => (
82 DateTime->now->strftime('%Y%m%d%H%M%S')
87 'personal checking' => 'C',
88 'personal savings' => 'S',
89 'business checking' => 'X',
90 'business savings' => 'X',
93 sub default_transport {
95 Business::BatchPayment::Paymentech::Transport->new(
96 login => $self->login,
97 password => $self->password,
98 put_path => $self->fileDateTime,
99 debug => $self->debug,
100 test_mode => $self->test_mode,
108 # not doing anything with batch_id
109 my $items = $batch->items;
110 my $num_items = scalar @$items;
113 my $xml = XML::Writer->new(
118 $xml->startTag('transRequest', RequestCount => $num_items + 1);
119 $xml->startTag('batchFileID');
120 $xml->dataElement(userID => $self->login);
121 $xml->dataElement(fileDateTime => $self->fileDateTime);
122 $xml->dataElement(fileID => $self->fileDateTime);
123 $xml->endTag('batchFileID');
126 foreach my $item (@$items) {
127 if ( $item->action eq 'payment' ) {
128 $xml->startTag('newOrder', BatchRequestNo => $count);
130 industryType => $self->industryType,
133 merchantID => $self->merchantID,
134 terminalID => $self->terminalID,
136 if ($item->payment_type eq 'CC') {
138 ccAccountNum => $item->card_number,
139 ccExp => $item->expiration,
142 elsif ( $item->payment_type eq 'ECHECK' ) {
145 ecpCheckRT => $item->routing_code,
146 ecpCheckDDA => $item->account_number,
147 ecpBankAcctType => $BankAcctType{ $item->account_type },
148 ecpDelvMethod => 'A',
152 die "payment type ".$item->type." not supported";
155 avsZip => $item->zip,
156 avsAddress1 => substr($item->address, 0, 30),
157 avsAddress2 => substr($item->address2, 0, 30),
158 avsCity => substr($item->city, 0, 20),
159 avsState => $item->state,
160 avsName => substr($item->first_name .' '. $item->last_name, 0, 30),
161 avsCountryCode => $item->country,
162 orderID => $item->tid,
163 amount => int( $item->amount * 100 ),
166 my $key = shift @order;
167 my $value = shift @order;
168 $xml->dataElement($key, $value);
170 $xml->endTag('newOrder');
171 } # if action eq 'payment'
173 die "action ".$item->action." not supported";
179 $xml->startTag('endOfDay', 'BatchRequestNo', $count);
180 $xml->dataElement('bin' => $self->bin);
181 $xml->dataElement('merchantID' => $self->merchantID);
182 $xml->dataElement('terminalID' => $self->terminalID);
183 $xml->endTag('endOfDay');
185 $xml->endTag('transRequest');
194 my $tree = XML::Simple::XMLin($input, KeepRoot => 1);
195 my $newOrderResp = $tree->{transResponse}->{newOrderResp};
196 die "can't find <transResponse><newOrderResp> in input"
197 unless defined $newOrderResp;
199 $newOrderResp = [ $newOrderResp ] if ref($newOrderResp) ne 'ARRAY';
201 foreach my $resp (@$newOrderResp) {
202 my ($mon, $day, $year, $hour, $min, $sec) =
203 $resp->{respDateTime} =~ /^(..)(..)(....)(..)(..)(..)$/;
204 my $dt = DateTime->new(
213 my $item = Business::BatchPayment->create(Item =>
214 tid => $resp->{orderID},
216 authorization => $resp->{authorizationCode},
217 order_number => $resp->{txRefNum},
218 approved => ($resp->{approvalStatus} == 1),
219 error_message => $resp->{procStatusMessage},
224 return Business::BatchPayment->create(Batch => items => $items);
230 package Business::BatchPayment::Paymentech::Transport;
232 use File::Temp qw( tempdir );
233 use File::Slurp qw( read_file write_file );
235 use Moose::Util::TypeConstraints;
236 extends 'Business::BatchPayment::Transport::SFTP';
237 with 'Business::BatchPayment::TestMode';
242 $self->test_mode ? 'orbitalbatchvar.paymentech.net'
243 : 'orbitalbatch.paymentech.net'
250 where { !defined($_) or ( -d $_ and -w $_ ) },
251 message { "can't write to '$_'" };
253 has 'archive_to' => (
258 # batch content passed as an argument
264 my $tmpdir = tempdir( CLEANUP => 1 );
265 my $filename = $self->put_path; # also the value of the fileId tag
266 my $archive_dir = $self->archive_to;
268 warn "Writing temp file to $tmpdir/$filename.xml.\n" if $self->debug;
269 write_file("$tmpdir/$filename.xml", $content);
271 warn "Creating zip file.\n" if $self->debug;
276 "$tmpdir/$filename.zip",
277 "$tmpdir/$filename.xml",
279 unshift @args, '-q' unless $self->debug;
280 system('zip', @args);
281 die "failed to create zip file" if (! -f "$tmpdir/$filename.zip");
283 warn "Uploading.\n" if $self->debug;
284 $self->put("$tmpdir/$filename.zip", "$filename.zip");
291 my $tmpdir = tempdir( CLEANUP => 1 );
292 my $ls_info = $self->ls('.', wanted => qr/_resp\.zip$/);
293 my $archive_dir = $self->archive_to;
295 foreach (@$ls_info) {
296 my $filename = $_->{filename}; # still ends in _resp
297 $filename =~ s/\.zip$//;
298 warn "Retrieving $filename.zip\n" if $self->debug;
299 $self->get("$filename.zip", "$tmpdir/$filename.zip");
304 "$tmpdir/$filename.zip",
308 unshift @args, '-q' unless $self->debug;
309 system('unzip', @args);
310 if (! -f "$tmpdir/$filename.xml") {
311 warn "failed to extract $filename.xml from $filename.zip\n";
314 my $content = read_file("$tmpdir/$filename.xml");
315 if ( $archive_dir ) {
316 warn "Copying $tmpdir/$filename.xml to archive dir $archive_dir\n";
317 write_file("$archive_dir/$filename.xml", $content);
319 push @batches, $content;
326 'info_compat' => '0.01',
327 'gateway_name' => 'Paymentech',
328 'gateway_url' => 'http://www.chasepaymentech.com/',
329 'module_version' => $VERSION,
330 'supported_types' => [ qw( CC ECHECK ) ],
331 'token_support' => 0,
332 'test_transaction' => 1,
333 'supported_actions' => [ 'Payment' ],
339 Mark Wells, C<< <mark at freeside.biz> >>
343 Relying on external zip/unzip is awkward.
347 You can find documentation for this module with the perldoc command.
349 perldoc Business::BatchPayment::Paymentech
351 Commercial support is available from Freeside Internet Services, Inc.
353 L<http://www.freeside.biz>
355 =head1 ACKNOWLEDGEMENTS
357 =head1 LICENSE AND COPYRIGHT
359 Copyright 2012 Mark Wells.
361 This program is free software; you can redistribute it and/or modify it
362 under the terms of either: the GNU General Public License as published
363 by the Free Software Foundation; or the Artistic License.
365 See http://dev.perl.org/licenses/ for more information.
370 1; # End of Business::BatchPayment::Paymentech