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);
69 with 'Business::BatchPayment::Processor';
70 with 'Business::BatchPayment::TestMode';
72 # could have some validation on all of these
73 has [ qw(merchantID terminalID bin industryType login password) ] => (
79 has 'fileDateTime' => (
83 DateTime->now->strftime('%Y%m%d%H%M%S')
88 'personal checking' => 'C',
89 'personal savings' => 'S',
90 'business checking' => 'X',
91 'business savings' => 'X',
94 sub default_transport {
96 Business::BatchPayment::Paymentech::Transport->new(
97 login => $self->login,
98 password => $self->password,
99 put_path => $self->fileDateTime,
100 debug => $self->debug,
101 test_mode => $self->test_mode,
110 my $xml = XML::Writer->new(
115 $self->format_header($batch, $xml);
117 foreach my $item ( @{ $batch->items } ) {
119 $self->format_item($item, $batch, $xml, $count);
122 $self->format_error($item, $_);
125 $self->format_trailer($batch, $xml, $count);
130 my ($self, $batch, $xml) = @_;
131 my $num_items = $batch->count;
133 $xml->startTag('transRequest', RequestCount => $num_items + 1);
134 $xml->startTag('batchFileID');
135 $xml->dataElement(userID => $self->login);
136 $xml->dataElement(fileDateTime => $self->fileDateTime);
137 $xml->dataElement(fileID => $self->fileDateTime);
138 $xml->endTag('batchFileID');
142 my ($self, $item, $batch, $xml, $count) = @_;
143 if ( $item->action eq 'payment' ) {
144 $xml->startTag('newOrder', BatchRequestNo => $count);
146 industryType => $self->industryType,
149 merchantID => $self->merchantID,
150 terminalID => $self->terminalID,
152 if ($item->payment_type eq 'CC') {
154 ccAccountNum => $item->card_number,
155 ccExp => $item->expiration,
158 elsif ( $item->payment_type eq 'ECHECK' ) {
161 ecpCheckRT => $item->routing_code,
162 ecpCheckDDA => $item->account_number,
163 ecpBankAcctType => $BankAcctType{ $item->account_type },
164 ecpDelvMethod => 'A',
168 die "payment type ".$item->type." not supported";
171 avsZip => $item->zip,
172 avsAddress1 => substr($item->address, 0, 30),
173 avsAddress2 => substr($item->address2, 0, 30),
174 avsCity => substr($item->city, 0, 20),
175 avsState => $item->state,
176 avsName => substr($item->first_name .' '. $item->last_name, 0, 30),
177 avsCountryCode => $item->country,
178 orderID => $item->tid,
179 amount => int( $item->amount * 100 ),
182 my $key = shift @order;
183 my $value = shift @order;
184 $xml->dataElement($key, $value);
186 $xml->endTag('newOrder');
187 } # if action eq 'payment'
189 die "action ".$item->action." not supported";
195 my ($self, $batch, $xml, $count) = @_;
196 $xml->startTag('endOfDay', 'BatchRequestNo', $count);
197 $xml->dataElement('bin' => $self->bin);
198 $xml->dataElement('merchantID' => $self->merchantID);
199 $xml->dataElement('terminalID' => $self->terminalID);
200 $xml->endTag('endOfDay');
201 $xml->endTag('transRequest');
207 my $batch = Business::BatchPayment->create('Batch');
209 my $tree = XML::Simple::XMLin($input, KeepRoot => 1);
210 my $newOrderResp = $tree->{transResponse}->{newOrderResp};
211 die "can't find <transResponse><newOrderResp> in input"
212 unless defined $newOrderResp;
214 $newOrderResp = [ $newOrderResp ] if ref($newOrderResp) ne 'ARRAY';
215 foreach my $resp (@$newOrderResp) {
217 $batch->push( $self->parse_item($resp) );
219 # parse_error needs a string representation of the
220 # input data...and if it 's failing because it wasn't valid
221 # XML, we wouldn't get this far.
222 $self->parse_error(XML::Simple::XMLout($resp), $_);
229 my ($self, $resp) = @_;
231 my ($mon, $day, $year, $hour, $min, $sec) =
232 $resp->{respDateTime} =~ /^(..)(..)(....)(..)(..)(..)$/;
233 my $dt = DateTime->new(
242 my $item = Business::BatchPayment->create(Item =>
243 tid => $resp->{orderID},
245 authorization => $resp->{authorizationCode},
246 order_number => $resp->{txRefNum},
247 approved => ($resp->{approvalStatus} == 1),
248 error_message => $resp->{procStatusMessage},
253 package Business::BatchPayment::Paymentech::Transport;
255 use File::Temp qw( tempdir );
256 use File::Slurp qw( read_file write_file );
258 use Moose::Util::TypeConstraints;
259 extends 'Business::BatchPayment::Transport::SFTP';
260 with 'Business::BatchPayment::TestMode';
265 $self->test_mode ? 'orbitalbatchvar.paymentech.net'
266 : 'orbitalbatch.paymentech.net'
273 where { !defined($_) or ( -d $_ and -w $_ ) },
274 message { "can't write to '$_'" };
276 has 'archive_to' => (
281 # batch content passed as an argument
287 my $tmpdir = tempdir( CLEANUP => 1 );
288 my $filename = $self->put_path; # also the value of the fileId tag
289 my $archive_dir = $self->archive_to;
291 warn "Writing temp file to $tmpdir/$filename.xml.\n" if $self->debug;
292 write_file("$tmpdir/$filename.xml", $content);
294 warn "Creating zip file.\n" if $self->debug;
299 "$tmpdir/$filename.zip",
300 "$tmpdir/$filename.xml",
302 unshift @args, '-q' unless $self->debug;
303 system('zip', @args);
304 die "failed to create zip file" if (! -f "$tmpdir/$filename.zip");
306 warn "Uploading.\n" if $self->debug;
307 $self->put("$tmpdir/$filename.zip", "$filename.zip");
314 my $tmpdir = tempdir( CLEANUP => 1 );
315 my $ls_info = $self->ls('.', wanted => qr/_resp\.zip$/);
316 my $archive_dir = $self->archive_to;
318 foreach (@$ls_info) {
319 my $filename = $_->{filename}; # still ends in _resp
320 $filename =~ s/\.zip$//;
321 warn "Retrieving $filename.zip\n" if $self->debug;
322 $self->get("$filename.zip", "$tmpdir/$filename.zip");
327 "$tmpdir/$filename.zip",
331 unshift @args, '-q' unless $self->debug;
332 system('unzip', @args);
333 if (! -f "$tmpdir/$filename.xml") {
334 warn "failed to extract $filename.xml from $filename.zip\n";
337 my $content = read_file("$tmpdir/$filename.xml");
338 if ( $archive_dir ) {
339 warn "Copying $tmpdir/$filename.xml to archive dir $archive_dir\n";
340 write_file("$archive_dir/$filename.xml", $content);
342 push @batches, $content;
349 'info_compat' => '0.01',
350 'gateway_name' => 'Paymentech',
351 'gateway_url' => 'http://www.chasepaymentech.com/',
352 'module_version' => $VERSION,
353 'supported_types' => [ qw( CC ECHECK ) ],
354 'token_support' => 0,
355 'test_transaction' => 1,
356 'supported_actions' => [ 'Payment' ],
362 Mark Wells, C<< <mark at freeside.biz> >>
366 Relying on external zip/unzip is awkward.
370 You can find documentation for this module with the perldoc command.
372 perldoc Business::BatchPayment::Paymentech
374 Commercial support is available from Freeside Internet Services, Inc.
376 L<http://www.freeside.biz>
378 =head1 ACKNOWLEDGEMENTS
380 =head1 LICENSE AND COPYRIGHT
382 Copyright 2012 Mark Wells.
384 This program is free software; you can redistribute it and/or modify it
385 under the terms of either: the GNU General Public License as published
386 by the Free Software Foundation; or the Artistic License.
388 See http://dev.perl.org/licenses/ for more information.
393 1; # End of Business::BatchPayment::Paymentech