1 package FS::pay_batch::paymentech;
4 use vars qw(@ISA %import_info %export_info $name);
5 use FS::Record 'qsearchs';
7 use Date::Format 'time2str';
8 use Date::Parse 'str2time';
13 my ($bin, $merchantID, $terminalID, $username, $password, $with_recurringInd);
20 xmlrow => [ qw(transResponse newOrderResp) ],
37 # find a gateway configuration that has the same merchantID
38 # as the batch config, if there is one. If not, leave
39 # gateway out entirely.
40 my $merchant = (FS::Conf->new->config('batchconfig-paymentech'))[2];
42 'table' => 'payment_gateway',
43 'addl_from' => ' JOIN payment_gateway_option USING (gatewaynum) ',
44 'hashref' => { disabled => '',
45 optionname => 'merchant_id',
46 optionvalue => $merchant,
49 $gateway = ($g ? $g->gatewaynum . '-' : '') . 'PaymenTech';
51 my ($hash, $oldhash) = @_;
52 my ($mon, $day, $year, $hour, $min, $sec) =
53 $hash->{'_date'} =~ /^(..)(..)(....)(..)(..)(..)$/;
54 $hash->{'_date'} = timelocal($sec, $min, $hour, $day, $mon-1, $year);
55 $hash->{'paid'} = $oldhash->{'amount'};
56 $hash->{'paybatch'} = join(':',
58 $hash->{'authorization'},
59 $hash->{'order_number'},
62 'approved' => sub { my $hash = shift;
63 $hash->{'approvalStatus'}
65 'declined' => sub { my $hash = shift;
66 ! $hash->{'approvalStatus'}
71 'personal checking' => 'C',
72 'personal savings' => 'S',
73 'business checking' => 'X',
74 'business savings' => 'X',
79 # Load this at run time
80 eval "use XML::Writer";
83 ($bin, $terminalID, $merchantID, $username, $password, $with_recurringInd) =
84 $conf->config('batchconfig-paymentech');
86 # Here we do all the work in the header function.
88 my $pay_batch = shift;
89 my @cust_pay_batch = @{(shift)};
92 my $xml = new XML::Writer(OUTPUT => \$output, DATA_MODE => 1, DATA_INDENT => 2);
93 $xml->startTag('transRequest', RequestCount => scalar(@cust_pay_batch) + 1);
94 $xml->startTag('batchFileID');
95 $xml->dataElement(userID => $username);
96 $xml->dataElement(fileDateTime => time2str('%Y%m%d%H%M%S', time));
97 $xml->dataElement(fileID => 'FILEID');
98 $xml->endTag('batchFileID');
100 foreach (@cust_pay_batch) {
101 $xml->startTag('newOrder', BatchRequestNo => $count++);
102 my $status = $_->cust_main->status;
103 tie my %order, 'Tie::IxHash', (
104 industryType => 'EC',
107 merchantID => $merchantID,
108 terminalID => $terminalID,
109 ($_->payby eq 'CARD') ? (
110 ccAccountNum => $_->payinfo,
111 ccExp => $_->expmmyy,
113 ecpCheckRT => ($_->payinfo =~ /@(\d+)/),
114 ecpCheckDDA => ($_->payinfo =~ /(\d+)@/),
115 ecpBankAcctType => $paytype{lc($_->cust_main->paytype)},
116 ecpDelvMethod => 'A',
118 avsZip => substr($_->zip, 0, 10),
119 avsAddress1 => substr($_->address1, 0, 30),
120 avsAddress2 => substr($_->address2, 0, 30),
121 avsCity => substr($_->city, 0, 20),
122 avsState => $_->state,
123 avsName => substr($_->first . ' ' . $_->last, 0, 30),
124 avsCountryCode => $_->country,
125 orderID => $_->paybatchnum,
126 amount => $_->amount * 100,
128 # only do this if recurringInd is enabled in config,
129 # and the customer has at least one non-canceled recurring package
130 if ( $with_recurringInd and $status =~ /^active|suspended|ordered$/ ) {
131 # then send RF if this is the first payment on this payinfo,
133 $order{'recurringInd'} = $_->payinfo_used ? 'RS' : 'RF';
135 foreach my $key (keys %order) {
136 $xml->dataElement($key, $order{$key})
138 $xml->endTag('newOrder');
140 $xml->startTag('endOfDay', BatchRequestNo => $count);
141 $xml->dataElement(bin => $bin);
142 $xml->dataElement(merchantID => $merchantID);
143 $xml->dataElement(terminalID => $terminalID);
144 $xml->endTag('endOfDay');
145 $xml->endTag('transRequest');