1 package FS::pay_batch::paymentech;
4 use vars qw(@ISA %import_info %export_info $name);
6 use Date::Format 'time2str';
7 use Date::Parse 'str2time';
12 my ($bin, $merchantID, $terminalID, $username);
17 xmlrow => [ qw(transResponse newOrderResp) ],
29 my ($hash, $oldhash) = @_;
30 my ($mon, $day, $year, $hour, $min, $sec) =
31 $hash->{'_date'} =~ /^(..)(..)(....)(..)(..)(..)$/;
32 $hash->{'_date'} = timelocal($sec, $min, $hour, $day, $mon-1, $year);
33 $hash->{'paid'} = $oldhash->{'amount'};
35 'approved' => sub { my $hash = shift;
36 $hash->{'approvalStatus'}
38 'declined' => sub { my $hash = shift;
39 ! $hash->{'approvalStatus'}
44 'personal checking' => 'C',
45 'personal savings' => 'S',
46 'business checking' => 'X',
47 'business savings' => 'X',
52 # Load this at run time
53 eval "use XML::Writer";
56 ($bin, $terminalID, $merchantID, $username) =
57 $conf->config('batchconfig-paymentech');
59 # Here we do all the work in the header function.
61 my $pay_batch = shift;
62 my @cust_pay_batch = @{(shift)};
65 my $xml = new XML::Writer(OUTPUT => \$output, DATA_MODE => 1, DATA_INDENT => 2);
66 $xml->startTag('transRequest', RequestCount => scalar(@cust_pay_batch) + 1);
67 $xml->startTag('batchFileID');
68 $xml->dataElement(userID => $username);
69 $xml->dataElement(fileDateTime => time2str('%Y%m%d%H%M%S', time));
70 $xml->dataElement(fileID => 'FILEID');
71 $xml->endTag('batchFileID');
73 foreach (@cust_pay_batch) {
74 $xml->startTag('newOrder', BatchRequestNo => $count++);
75 tie my %order, 'Tie::IxHash', (
79 merchantID => $merchantID,
80 terminalID => $terminalID,
81 ($_->payby eq 'CARD') ? (
82 ccAccountNum => $_->payinfo,
83 ccExp => time2str('%m%y', str2time($_->exp))
85 ecpCheckRT => ($_->payinfo =~ /@(\d+)/),
86 ecpCheckDDA => ($_->payinfo =~ /(\d+)@/),
87 ecpBankAcctType => $paytype{lc($_->cust_main->paytype)},
90 avsZip => substr($_->zip, 0, 10),
91 avsAddress1 => substr($_->address1, 0, 30),
92 avsAddress2 => substr($_->address2, 0, 30),
93 avsCity => substr($_->city, 0, 20),
94 avsState => $_->state,
95 avsName => substr($_->first . ' ' . $_->last, 0, 30),
96 avsCountryCode => $_->country,
97 orderID => $_->paybatchnum,
98 amount => $_->amount * 100,
100 foreach my $key (keys %order) {
101 $xml->dataElement($key, $order{$key})
103 $xml->endTag('newOrder');
105 $xml->startTag('endOfDay', BatchRequestNo => $count);
106 $xml->dataElement(bin => $bin);
107 $xml->dataElement(merchantID => $merchantID);
108 $xml->dataElement(terminalID => $terminalID);
109 $xml->endTag('endOfDay');
110 $xml->endTag('transRequest');