1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
package FS::pay_batch::td_canada_trust;
# Formerly known as csv-td_canada_trust-merchant_pc_batch,
# which I'm sure we can all agree is both a terrible name
# and an illegal Perl identifier.
use strict;
use vars qw(@ISA %import_info %export_info $name);
use Time::Local 'timelocal';
use FS::Conf;
my $conf;
my ($origid, $datacenter, $typecode, $shortname, $longname, $mybank, $myacct);
$name = 'csv-td_canada_trust-merchant_pc_batch';
%import_info = (
'filetype' => 'CSV',
'fields' => [
'paybatchnum',
'paid',
'', # card type
'_date',
'time',
'payinfo',
'', # expiry date
'', # auth number
'type', # transaction type
'result', # processing result
'', # terminal ID
],
'hook' => sub {
my $hash = shift;
my $date = $hash->{'_date'};
my $time = $hash->{'time'};
$hash->{'paid'} = sprintf("%.2f", $hash->{'paid'} / 100);
$hash->{'_date'} = timelocal( substr($time, 4, 2),
substr($time, 2, 2),
substr($time, 0, 2),
substr($date, 6, 2),
substr($date, 4, 2)-1,
substr($date, 0, 4)-1900 );
},
'approved' => sub {
my $hash = shift;
$hash->{'type'} eq '0' && $hash->{'result'} == 3
},
'declined' => sub {
my $hash = shift;
$hash->{'type'} eq '0' && ( $hash->{'result'} == 4
|| $hash->{'result'} == 5 )
},
'end_condition' => sub {
my $hash = shift;
$hash->{'type'} eq '0BC';
},
'end_hook' => sub {
my ($hash, $total) = @_;
$total = sprintf("%.2f", $total);
my $batch_total = sprintf("%.2f", $hash->{'paybatchnum'} / 100);
return "Our total $total does not match bank total $batch_total!"
if $total != $batch_total;
},
);
%export_info = (
init => sub {
$conf = shift;
},
# no header
row => sub {
my ($cust_pay_batch, $pay_batch) = @_;
return join(',',
'',
'',
'',
'',
$cust_pay_batch->payinfo,
expdate($cust_pay_batch->exp),
$cust_pay_batch->amount,
$cust_pay_batch->paybatchnum
);
},
# no footer
);
sub expdate {
my $exp = shift;
$exp =~ /^\d{2}(\d{2})[\/\-](\d+)[\/\-]\d+$/;
my ($mon, $y) = ($2, $1);
if($conf->exists('batch-increment_expiration')) {
my ($curmon, $curyear) = (localtime(time))[4,5];
$curmon++;
$curyear -= 100;
$y++ while $y < $curyear || ($y == $curyear && $mon < $curmon);
}
$mon = "0$mon" if $mon =~ /^\d$/;
$y = "0$y" if $y =~ /^\d$/;
return "$mon$y";
}
1;
|