downgrade moose and CSV requirements
[Business-BatchPayment-KeyBank.git] / KeyBank.pm
1 package Business::BatchPayment::KeyBank;
2
3 use 5.006;
4 use strict;
5 use warnings;
6 our $VERSION = '0.01';
7
8 =head1 NAME
9
10 Business::BatchPayment::KeyBank - Key Bank check lockbox format
11
12 =head1 VERSION
13
14 Version 0.01
15
16 =head1 USAGE
17
18 See L<Business::BatchPayment> for general usage notes.  This is a
19 one-way, non-transport processor; you must supply the file to be 
20 received.
21
22 =head2 SYNOPSIS
23
24 use Business::BatchPayment;
25
26 my $processor = Business::BatchPayment->create( KeyBank =>
27   input => 'mybatch.csv');
28
29 my @items = $processor->receive;
30
31 =head2 PROCESSOR ATTRIBUTES
32
33 None.
34
35 =cut
36
37 use DateTime;
38 use Text::CSV;
39 use Digest::MD5 qw( md5_hex );
40
41 use Moose;
42 with 'Business::BatchPayment::Processor';
43
44 sub incoming { 1 }
45 sub format_item { '' }
46
47 has '_csv' => (
48   is => 'ro',
49   default => sub { Text::CSV->new() },
50 );
51
52 sub parse_batch_id {
53   my ($self, $content) = @_;
54   # we just need it to be unique...
55   return md5_hex($content);
56 }
57
58 sub parse_item {
59   my ($self, $row) = @_;
60   $self->_csv->parse($row);
61   if ( !$self->_csv->status ) {
62     die $self->_csv->error_diag . "\n";
63   }
64   my @f = $self->_csv->fields;
65   foreach (@f) {
66     s/^\s+//;
67     s/\s+$//;
68   }
69   # INVOICEID, ACCOUNT_NUMBER, POSTDATE, AMOUNT, CHECK_NUMBER
70   # date in YYYYMMDD format
71   $f[2] =~ /^(\d{4})(\d{2})(\d{2})$/ or die "bad process date '$f[2]'\n";
72   my $dt = eval { DateTime->new( year => $1, month => $2, day => $3 ) }
73     or die "bad process date '$f[2]'\n";
74
75   my $amount = $f[3] / 100;
76   Business::BatchPayment->create(Item =>
77     action          => 'payment',
78     payment_type    => 'ECHECK',
79     invoice_number  => $f[0],
80     customer_id     => $f[1],
81     payment_date    => $dt,
82     amount          => $amount,
83     check_number    => $f[3],
84     order_number    => $f[3],  #?
85     approved        => 1,
86   );
87 }
88
89 __PACKAGE__->meta->make_immutable;
90
91 =head1 AUTHOR
92
93 Mark Wells, <mark@freeside.biz>
94
95 =head1 SUPPORT
96
97 You can find documentation for this module with the perldoc command.
98
99     perldoc Business::BatchPayment::KeyBank
100
101 Commercial support is available from Freeside Internet Services, Inc.
102
103 L<http://www.freeside.biz>
104
105 =head1 LICENSE AND COPYRIGHT
106
107 Copyright 2012 Mark Wells.
108
109 This program is free software; you can redistribute it and/or modify it
110 under the terms of either: the GNU General Public License as published
111 by the Free Software Foundation; or the Artistic License.
112
113 See http://dev.perl.org/licenses/ for more information.
114
115
116 =cut
117
118 1;