File Coverage

blib/lib/Business/NAB/AccountInformation/Transaction.pm
Criterion Covered Total %
statement 58 58 100.0
branch 3 4 75.0
condition n/a
subroutine 15 15 100.0
pod 5 5 100.0
total 81 82 98.7


line stmt bran cond sub pod time code
1             package Business::NAB::AccountInformation::Transaction;
2             $Business::NAB::AccountInformation::Transaction::VERSION = '0.03';
3             =head1 NAME
4              
5             Business::NAB::AccountInformation::Transaction
6              
7             =head1 SYNOPSIS
8              
9             use Business::NAB::AccountInformation::Transaction;
10              
11             my $Transaction = Business::NAB::AccountInformation::Transaction->new(
12             transaction_code => $trans_code,
13             amount_minor_units => $amount,
14             funds_type => $funds_type,
15             reference_number => $ref_number,
16             text => $text,
17             );
18              
19             =head1 DESCRIPTION
20              
21             Class for parsing a NAB "Account Information File (NAI/BAI2)" transaction
22             line (type C<16>).
23              
24             =cut
25              
26 3     3   1265907 use strict;
  3         10  
  3         141  
27 3     3   16 use warnings;
  3         9  
  3         267  
28 3     3   43 use feature qw/ signatures state /;
  3         7  
  3         494  
29 3     3   26 use Carp qw/ croak /;
  3         54  
  3         318  
30              
31 3     3   778 use Moose;
  3         604723  
  3         29  
32 3     3   26496 use Moose::Util::TypeConstraints;
  3         9  
  3         65  
33 3     3   9438 no warnings qw/ experimental::signatures /;
  3         9  
  3         195  
34              
35 3     3   1374 use Text::CSV_XS qw/ csv /;
  3         20006  
  3         246  
36 3         2938 use Business::NAB::Types qw/
37             add_max_string_attribute
38 3     3   713 /;
  3         11  
39              
40             =head1 ATTRIBUTES
41              
42             =over
43              
44             =item transaction_code (Str, max length 3)
45              
46             =item funds_type (Str, max length 1)
47              
48             =item bank_reference (Str, max length 4096)
49              
50             =item customer_reference (Str, max length 4096)
51              
52             =item text (Str, max length 4096)
53              
54             =item amount_minor_units (NAB::Type::PositiveIntOrZero)
55              
56             =back
57              
58             =cut
59              
60             foreach my $str_attr (
61             'transaction_code[3]',
62             'funds_type[1]',
63             'bank_reference[4096]',
64             'customer_reference[4096]',
65             'text[4096]',
66             ) {
67             __PACKAGE__->add_max_string_attribute(
68             $str_attr,
69             is => 'ro',
70             required => 1,
71             );
72             }
73              
74             has [ qw/ amount_minor_units / ] => (
75             is => 'ro',
76             isa => 'NAB::Type::PositiveIntOrZero',
77             required => 1,
78             );
79              
80             =head1 METHODS
81              
82             =head2 new_from_raw_record
83              
84             Returns a new instance of the class with attributes populated from
85             the result of parsing the passed line:
86              
87             my $Transaction = Business::NAB::AccountInformation::Transaction
88             ::Payments::DescriptiveRecord->new_from_raw_record( $line );
89              
90             =cut
91              
92 3     3 1 19827 sub new_from_raw_record ( $class, $line ) {
  3         7  
  3         7  
  3         5  
93              
94 3 50       17 my $aoa = csv( in => \$line )
95             or croak( Text::CSV->error_diag );
96              
97 3         1491 return $class->new_from_record( $aoa->[ 0 ]->@* );
98             }
99              
100             =head2 new_from_record
101              
102             Returns a new instance of the class with attributes populated from
103             the result of parsing the already parsed line:
104              
105             my $Transaction = Business::NAB::AccountInformation::Transaction
106             ::Payments::DescriptiveRecord->new_from_record( @record );
107              
108             =cut
109              
110 15     15 1 23 sub new_from_record ( $class, @record ) {
  15         22  
  15         35  
  15         18  
111              
112 15         36 my ( $record_type, $trans_code, $amount, $funds_type, $bank_ref, $cust_ref, @text )
113             = @record;
114              
115 15 100       33 if ( $record_type ne '16' ) {
116 1         16 croak( "unsupported record type ($record_type)" );
117             }
118              
119 14         468 return $class->new(
120             transaction_code => $trans_code,
121             amount_minor_units => $amount,
122             funds_type => $funds_type,
123             bank_reference => $bank_ref,
124             customer_reference => $cust_ref,
125             text => join( " ", @text ),
126             );
127             }
128              
129             =head2 is_debit
130              
131             =head2 is_credit
132              
133             Boolean check on the transaction type
134              
135             if ( $Transaction->is_credit ) {
136             ...
137             }
138              
139             =cut
140              
141 1     1 1 2626 sub is_debit ( $self ) {
  1         2  
  1         1  
142 1         5 return $self->_raw_description->[ 0 ] eq 'DR';
143             }
144              
145 1     1 1 324 sub is_credit ( $self ) {
  1         2  
  1         2  
146 1         2 return $self->_raw_description->[ 0 ] eq 'CR';
147             }
148              
149             =head2 description
150              
151             Returns a descriptive string for the transaction type
152              
153             my $description = $Transaction->description;
154              
155             =cut
156              
157 1     1 1 292 sub description ( $self ) {
  1         2  
  1         1  
158 1         4 return $self->_raw_description->[ 1 ];
159             }
160              
161 3     3   4 sub _raw_description ( $self ) {
  3         4  
  3         4  
162              
163 3         63 state %transaction_details_codes = (
164             175 => [ 'CR', 'Cheques' ],
165             195 => [ 'CR', 'Transfer credits' ],
166             238 => [ 'CR', 'Dividend' ],
167             252 => [ 'CR', 'Reversal Entry' ],
168             357 => [ 'CR', 'Credit adjustment' ],
169             399 => [ 'CR', 'Miscellaneous credits' ],
170             475 => [ 'DR', 'Cheques (paid)' ],
171             495 => [ 'DR', 'Transfer debits' ],
172             501 => [ 'DR', 'Automatic drawings' ],
173             512 => [ 'DR', 'Documentary L/C Drawings/Fees' ],
174             555 => [ 'DR', 'Dishonoured cheques' ],
175             564 => [ 'DR', 'Loan fees' ],
176             595 => [ 'DR', 'FlexiPay' ],
177             631 => [ 'DR', 'Debit adjustment' ],
178             654 => [ 'DR', 'Debit Interest' ],
179             699 => [ 'DR', 'Miscellaneous debits' ],
180             905 => [ 'CR', 'Credit Interest' ],
181             906 => [ 'CR', 'National nominees credits' ],
182             910 => [ 'CR', 'Cash' ],
183             911 => [ 'CR', 'Cash/cheques' ],
184             915 => [ 'CR', 'Agent Credits' ],
185             920 => [ 'CR', 'Inter-bank credits' ],
186             925 => [ 'CR', 'Bankcard credits' ],
187             930 => [ 'CR', 'Credit balance transfer' ],
188             935 => [ 'CR', 'Credits summarised' ],
189             936 => [ 'CR', 'EFTPOS' ],
190             938 => [ 'CR', 'NFCA credit transactions' ],
191             950 => [ 'DR', 'Loan establishment fees' ],
192             951 => [ 'DR', 'Account keeping fees' ],
193             952 => [ 'DR', 'Unused limit fees' ],
194             953 => [ 'DR', 'Security fees' ],
195             955 => [ 'DR', 'Charges' ],
196             956 => [ 'DR', 'National nominee debits' ],
197             960 => [ 'DR', 'Stamp duty-cheque book' ],
198             961 => [ 'DR', 'Stamp duty' ],
199             962 => [ 'DR', 'Stamp duty-security' ],
200             970 => [ 'DR', 'State government tax' ],
201             971 => [ 'DR', 'Federal government tax' ],
202             975 => [ 'DR', 'Bankcards' ],
203             980 => [ 'DR', 'Debit balance transfers' ],
204             985 => [ 'DR', 'Debits summarised' ],
205             986 => [ 'DR', 'Cheques summarised' ],
206             987 => [ 'DR', 'Non-cheques summarised' ],
207             988 => [ 'DR', 'NFCA debit transaction' ],
208             );
209              
210 3         11 return $transaction_details_codes{ $self->transaction_code };
211             }
212              
213             =head1 SEE ALSO
214              
215             L<Business::NAB::Types>
216              
217             =cut
218              
219             __PACKAGE__->meta->make_immutable;