summaryrefslogtreecommitdiff
path: root/KeyBank.pm
blob: 6c5eafdd9b69b8a3847e2b2964a2a37ed9918809 (plain)
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package Business::BatchPayment::KeyBank;

use 5.006;
use strict;
use warnings;
our $VERSION = '0.01';

=head1 NAME

Business::BatchPayment::KeyBank - Key Bank check lockbox format

=head1 VERSION

Version 0.01

=head1 USAGE

See L<Business::BatchPayment> for general usage notes.  This is a
one-way, non-transport processor; you must supply the file to be 
received.

=head2 SYNOPSIS

use Business::BatchPayment;

my $processor = Business::BatchPayment->create( KeyBank =>
  input => 'mybatch.csv');

my @items = $processor->receive;

=head2 PROCESSOR ATTRIBUTES

None.

=cut

use DateTime;
use Text::CSV_XS;
use Digest::MD5 qw( md5_hex );

use Moose;
with 'Business::BatchPayment::Processor';

sub incoming { 1 }
sub format_item { '' }

has '_csv' => (
  is => 'ro',
  default => sub { Text::CSV_XS->new() },
);

sub parse_batch_id {
  my ($self, $content) = @_;
  # we just need it to be unique...
  return md5_hex($content);
}

sub parse_item {
  my ($self, $row) = @_;
  $self->_csv->parse($row);
  if ( !$self->_csv->status ) {
    die $self->_csv->error_diag . "\n";
  }
  my @f = $self->_csv->fields;
  foreach (@f) {
    s/^\s+//;
    s/\s+$//;
  }
  # INVOICEID, ACCOUNT_NUMBER, POSTDATE, AMOUNT, CHECK_NUMBER
  # date in YYYYMMDD format
  $f[2] =~ /^(\d{4})(\d{2})(\d{2})$/ or die "bad process date '$f[2]'\n";
  my $dt = eval { DateTime->new( year => $1, month => $2, day => $3 ) }
    or die "bad process date '$f[2]'\n";

  my $amount = $f[3] / 100;
  Business::BatchPayment->create(Item =>
    action          => 'payment',
    payment_type    => 'ECHECK',
    invoice_number  => $f[0],
    customer_id     => $f[1],
    payment_date    => $dt,
    amount          => $amount,
    check_number    => $f[3],
    order_number    => $f[3],  #?
    approved        => 1,
  );
}

__PACKAGE__->meta->make_immutable;

=head1 AUTHOR

Mark Wells, <mark@freeside.biz>

=head1 SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc Business::BatchPayment::KeyBank

Commercial support is available from Freeside Internet Services, Inc.

L<http://www.freeside.biz>

=head1 LICENSE AND COPYRIGHT

Copyright 2012 Mark Wells.

This program is free software; you can redistribute it and/or modify it
under the terms of either: the GNU General Public License as published
by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.


=cut

1;