NAB/BPAY/Remittance/File/DetailRecord.pm

filter: Statementstmt 97.4% 38 / 39 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 13 / 13 Podpod 100% 5 / 5 totaltotal 96.6% 57 / 59 CC 2 SCAR 1.4
CC
2
Cov
95%
new_from_record
2.1
BEGIN
1.0
BEGIN
1.0
CRAP 1.2
« NAB/BPAY/Payments/TrailerRecord.pm ↑ Summary NAB/Australian/DirectEntry/Payments/TotalRecord.pm »
1 package Business::NAB::BPAY::Remittance::File::DetailRecord;
2 1 $Business::NAB::BPAY::Remittance::File::DetailRecord::VERSION = '0.11';
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 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 1 ▶use feature qw/ signatures /;
Subroutine BEGIN: called CC=1 SCAR=0.0
40  
41 1 ▶use Carp qw/ croak /;
Subroutine BEGIN: called CC=1 SCAR=0.0
42 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
43 1 ▶use Business::NAB::Types qw/
Subroutine BEGIN: called CC=1 SCAR=0.0
44 add_max_string_attribute
45 1 /;
46  
47 1 ▶no warnings qw/ experimental::signatures /;
Subroutine BEGIN: called CC=1 SCAR=0.0
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 1 has [ qw/ amount / ] => (
78 is => 'ro',
79 isa => 'NAB::Type::PositiveInt',
80 required => 1,
81 );
82  
83 1 has [ qw/ payment_date settlement_date / ] => (
84 is => 'ro',
85 isa => 'NAB::Type::StatementDate',
86 required => 1,
87 coerce => 1,
88 );
89  
90 1 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 7 __PACKAGE__->add_max_string_attribute(
100 $str_attr,
101 is => 'ro',
102 required => 1,
103 );
104 }
105  
106 48 ▶sub _pack_template {
Subroutine _pack_template: called CC=1 SCAR=0.0
107 48 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 ▶sub new_from_record ( $class, $line ) {
Subroutine new_from_record: called CC=2 SCAR=7.2
Pod documented
123  
124 # undef being "this space intentionally left blank"
125 my (
126 12 $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 ▶ if ( $record_type ne '50' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($record_type ne 50) 0 12 12
141 0 croak( "unsupported record type ($record_type)" );
142 }
143  
144 12 $biller_code =~ s/^0+//;
145 12 $amount =~ s/^0+//;
146  
147 12 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 ▶sub to_record ( $self ) {
Subroutine to_record: called CC=1 SCAR=0.0
Pod documented
171  
172 36 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 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 ▶sub is_payment ( $self ) { return $self->payment_instruction_type eq '05' }
Subroutine is_payment: called CC=1 SCAR=0.0
Pod documented
206 5 ▶sub is_correction ( $self ) { return $self->payment_instruction_type eq '15' }
Subroutine is_correction: called CC=1 SCAR=0.0
Pod documented
207 1 ▶sub is_reversal ( $self ) { return $self->payment_instruction_type eq '25' }
Subroutine is_reversal: called CC=1 SCAR=0.0
Pod documented
208  
209 =head1 SEE ALSO
210  
211 L<Business::NAB::Types>
212  
213 =cut
214  
215 1 __PACKAGE__->meta->make_immutable;
« NAB/BPAY/Payments/TrailerRecord.pm ↑ Summary NAB/Australian/DirectEntry/Payments/TotalRecord.pm »