summaryrefslogtreecommitdiff
path: root/FS/FS
diff options
context:
space:
mode:
authormark <mark>2011-07-22 19:19:57 +0000
committermark <mark>2011-07-22 19:19:57 +0000
commit4d910ef2038bbc29e73a40ec66591ac48355a5ba (patch)
treefca484f693e03297b1f9d5455ce0f9987a78dd94 /FS/FS
parent8dba5cb96454bf8ec81333ebac381180731396f1 (diff)
EFT Canada batch format and scripts, #13628
Diffstat (limited to 'FS/FS')
-rw-r--r--FS/FS/Conf.pm10
-rw-r--r--FS/FS/cust_pay_batch.pm18
-rw-r--r--FS/FS/pay_batch/eft_canada.pm63
3 files changed, 84 insertions, 7 deletions
diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm
index 9953ea54b..36d3bbdce 100644
--- a/FS/FS/Conf.pm
+++ b/FS/FS/Conf.pm
@@ -3122,7 +3122,8 @@ and customer address. Include units.',
'description' => 'Fixed (unchangeable) format for electronic check batches.',
'type' => 'select',
'select_enum' => [ 'csv-td_canada_trust-merchant_pc_batch', 'BoM', 'PAP',
- 'paymentech', 'ach-spiritone', 'RBC', 'td_eft1464'
+ 'paymentech', 'ach-spiritone', 'RBC', 'td_eft1464',
+ 'eft_canada'
]
},
@@ -3183,6 +3184,13 @@ and customer address. Include units.',
},
{
+ 'key' => 'batchconfig-eft_canada',
+ 'section' => 'billing',
+ 'description' => 'Configuration for EFT Canada batching, four lines: 1. SFTP username, 2. SFTP password, 3. Transaction code, 4. Number of days to delay process date.',
+ 'type' => 'textarea',
+ },
+
+ {
'key' => 'payment_history-years',
'section' => 'UI',
'description' => 'Number of years of payment history to show by default. Currently defaults to 2.',
diff --git a/FS/FS/cust_pay_batch.pm b/FS/FS/cust_pay_batch.pm
index 171ec9fcf..f5e6a4bf1 100644
--- a/FS/FS/cust_pay_batch.pm
+++ b/FS/FS/cust_pay_batch.pm
@@ -300,26 +300,32 @@ sub approve {
return;
}
-=item decline
+=item decline [ REASON ]
Decline this payment. This will replace the existing record with the
same paybatchnum, set its status to 'Declined', and run collection events
as appropriate. This should only be called from the batch import process.
+REASON is a string description of the decline reason, defaulting to
+'Returned payment'.
+
=cut
sub decline {
my $new = shift;
- my $conf = new FS::Conf;
+ my $reason = shift || 'Returned payment';
+ #my $conf = new FS::Conf;
my $paybatchnum = $new->paybatchnum;
my $old = qsearchs('cust_pay_batch', { paybatchnum => $paybatchnum })
or return "paybatchnum $paybatchnum not found";
if ( $old->status ) {
# Handle the case where payments are rejected after the batch has been
- # approved. Only if manual approval is enabled.
- if ( $conf->exists('batch-manual_approval')
- and lc($old->status) eq 'approved' ) {
+ # approved. FS::pay_batch::import_results won't allow results to be
+ # imported to a closed batch unless batch-manual_approval is enabled,
+ # so we don't check it here.
+# if ( $conf->exists('batch-manual_approval') and
+ if ( lc($old->status) eq 'approved' ) {
# Void the payment
my $cust_pay = qsearchs('cust_pay', {
custnum => $new->custnum,
@@ -329,7 +335,7 @@ sub decline {
# should never happen...
return "failed to revoke paybatchnum $paybatchnum, payment not found";
}
- $cust_pay->void('Returned payment');
+ $cust_pay->void($reason);
}
else {
# normal case: refuse to do anything
diff --git a/FS/FS/pay_batch/eft_canada.pm b/FS/FS/pay_batch/eft_canada.pm
new file mode 100644
index 000000000..0e4161034
--- /dev/null
+++ b/FS/FS/pay_batch/eft_canada.pm
@@ -0,0 +1,63 @@
+package FS::pay_batch::eft_canada;
+
+use strict;
+use vars qw(@ISA %import_info %export_info $name);
+use FS::Record 'qsearch';
+use FS::Conf;
+use FS::cust_pay_batch;
+use Date::Format 'time2str';
+use Time::Local 'timelocal';
+
+my $conf;
+my $origid;
+
+$name = 'eft_canada';
+
+%import_info = ( filetype => 'NONE' ); # see FS/bin/freeside-eftca-download
+
+my ($trans_code, $process_date);
+
+%export_info = (
+ init => sub {
+ my $conf = shift;
+ my @config = $conf->config('batchconfig-eft_canada');
+ # SFTP login, password, trans code, delay time
+ my $process_delay;
+ ($trans_code, $process_delay) = @config[2,3];
+ $process_delay ||= 1; # days
+ $process_date = time2str('%D', time + ($process_delay * 86400));
+ },
+ delimiter => '', # avoid blank lines for header/footer
+ # EFT Upload Specification for .CSV Files, Rev. 2.0
+ # not a true CSV format--strings aren't quoted, so be careful
+ row => sub {
+ my ($cust_pay_batch, $pay_batch) = @_;
+ my @fields;
+ # company + empty or first + last
+ my $company = sprintf('%.64s', $cust_pay_batch->cust_main->company);
+ if ( $company ) {
+ push @fields, $company, ''
+ }
+ else {
+ push @fields, map { sprintf('%.64s', $_) }
+ $cust_pay_batch->first, $cust_pay_batch->last;
+ }
+ my ($account, $aba) = split('@', $cust_pay_batch->payinfo);
+ # standard format for Canadian bank ID
+ $aba =~ /^0(\d{3})(\d{5})$/
+ or die "invalid routing number '$aba'\n";
+ push @fields, sprintf('%05s', $2),
+ sprintf('%03s', $1),
+ sprintf('%012s', $account),
+ sprintf('%.02f', $cust_pay_batch->amount);
+ # DB = debit
+ push @fields, 'DB', $trans_code, $process_date;
+ push @fields, $cust_pay_batch->paybatchnum; # reference
+ # strip illegal characters that might occur in customer name
+ s/[,|']//g foreach @fields; # better substitution for these?
+ return join(',', @fields) . "\n";
+ },
+
+);
+
+1;