diff options
author | Mark Wells <mark@freeside.biz> | 2013-01-31 20:16:10 -0800 |
---|---|---|
committer | Mark Wells <mark@freeside.biz> | 2013-01-31 20:16:10 -0800 |
commit | 1bd6506437d1329616ee97321187b1868f6a76de (patch) | |
tree | dbb84a141084d8f2ee5839b4124f5ae125d0afd3 /BatchPayment/Batch.pm | |
parent | 0bf7a1ffc63873be09e848b900d89eb23cb99beb (diff) |
changes for cardfortress
Diffstat (limited to 'BatchPayment/Batch.pm')
-rw-r--r-- | BatchPayment/Batch.pm | 58 |
1 files changed, 57 insertions, 1 deletions
diff --git a/BatchPayment/Batch.pm b/BatchPayment/Batch.pm index 0d6176b..16f1738 100644 --- a/BatchPayment/Batch.pm +++ b/BatchPayment/Batch.pm @@ -21,20 +21,42 @@ but usually must be a positive integer, if it's used at all. Processor modules may include C<batch_id> in a reply batch ONLY if it is guaranteed to match the batch_id of a request batch AND all the items in the reply batch come from that request batch. Otherwise, -C<batch_id> must be null. It must always be null when using one-way +C<batch_id> must be undef. It must always be undef when using one-way (receive-only) workflow, since there are no request batches. +=item process_date - The intended processing date for a request batch. +If not set, it will default to the start of the next day; if that's +not what you want, set it explicitly. + =item items - An arrayref of L<Business::BatchPayment::Item> objects included in the batch. +=item num + +If your processor uses C<format_header> and C<format_item>, this will +be set to 0 by C<format_header> and incremented every time C<format_item> +is called. Convenient for formats that require record numbers. + =back +=head1 METHODS + +=over 4 + +=item totals + +Returns a hash containing 'credit_count', 'credit_sum', 'payment_count', +and 'payment_sum'. These are the number of credits, sum of credit amounts, +number of payments, and sum of payment amounts. + =cut package Business::BatchPayment::Batch; use strict; use Moose; +use Moose::Util::TypeConstraints; +use DateTime; has incoming => ( is => 'rw', @@ -59,4 +81,38 @@ has items => ( default => sub { [] }, ); +class_type 'DateTime'; +coerce 'DateTime', from 'Int', via { DateTime->from_epoch($_) }; + +has process_date => ( + is => 'rw', + isa => 'DateTime', + coerce => 1, + default => sub { +# warn "No batch process date set; assuming tomorrow.\n"; + DateTime->today->add(days => 1); + }, +); + +has num => ( + is => 'rw', + isa => 'Maybe[Int]', +); + +sub totals { + my $self = shift; + my %totals = map {$_ => 0} + qw(credit_count credit_sum payment_count payment_sum); + foreach ($self->elements) { + if ($_->action eq 'credit') { + $totals{credit_count}++; + $totals{credit_sum} += $_->amount; + } elsif ( $_->action eq 'payment') { + $totals{payment_count}++; + $totals{payment_sum} += $_->amount; + } + } + %totals; +} + 1; |