File Coverage

blib/lib/Business/NAB/BPAY/Remittance/File/DetailRecord.pm
Criterion Covered Total %
statement 48 49 97.9
branch 1 2 50.0
condition n/a
subroutine 13 13 100.0
pod 5 5 100.0
total 67 69 97.1


line stmt bran cond sub pod time code
1             package Business::NAB::BPAY::Remittance::File::DetailRecord;
2             $Business::NAB::BPAY::Remittance::File::DetailRecord::VERSION = '0.03';
3             =head1 NAME
4              
5             Business::NAB::BPAY::Remittance::File::DetailRecord
6              
7             =head1 SYNOPSIS
8              
9             use Business::NAB::BPAY::Remittance::File::DetailRecord;
10              
11             # parse
12             my $Detail = Business::NAB::BPAY::Remittance::File::DetailRecord;
13             ->new_from_record( $line );
14              
15             # create
16             my $Detail = Business::NAB::BPAY::Remittance::File::DetailRecord->new(
17             biller_code => ...
18             customer_reference_number => ...
19             payment_instruction_type => ...
20             transaction_reference_number => ...
21             original_reference_number => ...
22             error_correction_reason => ...
23             amount => ...
24             payment_date => ...
25             payment_time => ...
26             settlement_date => ...
27             );
28              
29             my $line = $Detail->to_record;
30              
31             =head1 DESCRIPTION
32              
33             Class for detail record in the "BPAY Remittance File"
34              
35             =cut;
36              
37 1     1   753 use strict;
  1         3  
  1         38  
38 1     1   6 use warnings;
  1         2  
  1         165  
39 1     1   7 use feature qw/ signatures /;
  1         2  
  1         137  
40              
41 1     1   6 use Carp qw/ croak /;
  1         1  
  1         62  
42 1     1   5 use Moose;
  1         2  
  1         8  
43 1         68 use Business::NAB::Types qw/
44             add_max_string_attribute
45 1     1   8196 /;
  1         2  
46              
47 1     1   5 no warnings qw/ experimental::signatures /;
  1         3  
  1         630  
48              
49             =head1 ATTRIBUTES
50              
51             =over
52              
53             =item biller_code (Str, max length 10)
54              
55             =item customer_reference_number (Str, max length 20)
56              
57             =item payment_instruction_type (Str, max length 2)
58              
59             =item transaction_reference_number (Str, max length 21)
60              
61             =item original_reference_number (Str, max length 21)
62              
63             =item error_correction_reason (Str, max length 3)
64              
65             =item amount (NAB::Type::PositiveInt)
66              
67             =item payment_date (NAB::Type::StatementDate)
68              
69             =item payment_time (Str, max length 6)
70              
71             =item settlement_date (NAB::Type::StatementDate)
72              
73             =back
74              
75             =cut
76              
77             has [ qw/ amount / ] => (
78             is => 'ro',
79             isa => 'NAB::Type::PositiveInt',
80             required => 1,
81             );
82              
83             has [ qw/ payment_date settlement_date / ] => (
84             is => 'ro',
85             isa => 'NAB::Type::StatementDate',
86             required => 1,
87             coerce => 1,
88             );
89              
90             foreach my $str_attr (
91             'biller_code[10]',
92             'customer_reference_number[20]',
93             'payment_instruction_type[2]',
94             'transaction_reference_number[21]',
95             'original_reference_number[21]',
96             'error_correction_reason[3]',
97             'payment_time[6]',
98             ) {
99             __PACKAGE__->add_max_string_attribute(
100             $str_attr,
101             is => 'ro',
102             required => 1,
103             );
104             }
105              
106             sub _pack_template {
107 48     48   264 return "A2 A10 A20 A2 A21 A21 A3 A12 A8 A6 A8 A106";
108             }
109              
110             =head1 METHODS
111              
112             =head2 new_from_record
113              
114             Returns a new instance of the class with attributes populated from
115             the result of parsing the passed line:
116              
117             my $Record = Business::NAB::BPAY::Remittance::File::DetailRecord
118             ->new_from_record( $line );
119              
120             =cut
121              
122 12     12 1 44 sub new_from_record ( $class, $line ) {
  12         27  
  12         19  
  12         21  
123              
124             # undef being "this space intentionally left blank"
125             my (
126 12         34 $record_type,
127             $biller_code,
128             $customer_reference_number,
129             $payment_instruction_type,
130             $transaction_reference_number,
131             $original_reference_number,
132             $error_correction_reason,
133             $amount,
134             $payment_date,
135             $payment_time,
136             $settlement_date,
137             undef,
138             ) = unpack( $class->_pack_template(), $line );
139              
140 12 50       60 if ( $record_type ne '50' ) {
141 0         0 croak( "unsupported record type ($record_type)" );
142             }
143              
144 12         61 $biller_code =~ s/^0+//;
145 12         37 $amount =~ s/^0+//;
146              
147 12         768 return $class->new(
148             biller_code => $biller_code,
149             customer_reference_number => $customer_reference_number,
150             payment_instruction_type => $payment_instruction_type,
151             transaction_reference_number => $transaction_reference_number,
152             original_reference_number => $original_reference_number,
153             error_correction_reason => $error_correction_reason,
154             amount => $amount,
155             payment_date => $payment_date,
156             payment_time => $payment_time,
157             settlement_date => $settlement_date,
158             );
159             }
160              
161             =head2 to_record
162              
163             Returns a string constructed from the object's attributes, representing
164             the record for use in a batch file:
165              
166             my $line = $Detail->to_record;
167              
168             =cut
169              
170 36     36 1 112 sub to_record ( $self ) {
  36         68  
  36         53  
171              
172 36         96 my $record = pack(
173             $self->_pack_template(),
174             "50",
175             sprintf( "%010d", $self->biller_code ),
176             sprintf( "%-20s", $self->customer_reference_number ),
177             sprintf( "%02d", $self->payment_instruction_type ),
178             sprintf( "%21s", $self->transaction_reference_number ),
179             sprintf( "%21s", $self->original_reference_number ),
180             sprintf( "%03d", $self->error_correction_reason ),
181             sprintf( "%012d", $self->amount ),
182             $self->payment_date->ymd( '' ),
183             $self->payment_time,
184             $self->settlement_date->ymd( '' ),
185             "",
186             );
187              
188 36         994 return $record;
189             }
190              
191             =head2 is_payment
192              
193             =head2 is_correction
194              
195             =head2 is_reversal
196              
197             Boolean check on the record's payment_instruction_type:
198              
199             if ( $Detail->is_payment ) {
200             ...
201             }
202              
203             =cut
204              
205 12     12 1 20 sub is_payment ( $self ) { return $self->payment_instruction_type eq '05' }
  12         24  
  12         26  
  12         38  
206 5     5 1 46 sub is_correction ( $self ) { return $self->payment_instruction_type eq '15' }
  5         9  
  5         9  
  5         13  
207 1     1 1 11 sub is_reversal ( $self ) { return $self->payment_instruction_type eq '25' }
  1         2  
  1         3  
  1         4  
208              
209             =head1 SEE ALSO
210              
211             L<Business::NAB::Types>
212              
213             =cut
214              
215             __PACKAGE__->meta->make_immutable;