Westpac/PaymentsPlus/Australian/Payment/Import/File.pm

filter: Statementstmt 100% 63 / 63 Branchbran 100% 6 / 6 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 15 / 15 Podpod 50.0% 1 / 2 totaltotal 98.8% 88 / 89 CC 8 SCAR 8.2
CC
8
Cov
100%
_add_payment_object_to_records
5.0
add_realtime_record
3.0
to_csv
2.0
CRAP 2.3
« Westpac/PaymentsPlus/Australian/Payment/Import/Remittance.pm ↑ Summary Westpac/Types.pm »
1 package Business::Westpac::PaymentsPlus::Australian::Payment::Import::File;
2  
3 =head1 NAME
4  
5 Business::Westpac::PaymentsPlus::Australian::Payment::Import::File
6  
7 =head1 SYNOPSIS
8  
9 my $ImportFile = Business::Westpac::PaymentsPlus::Australian::Payment::Import::File->new(
10 customer_code => 'TESTPAYER',
11 customer_name => 'TESTPAYER',
12 customer_file_reference => 'TESTFILE001',
13 scheduled_date => '26082016',
14 );
15  
16 $ImportFile->add_eft_record(
17 eft => \%eft_details,
18 remittance => \%remittance_details,
19 invoices => [
20 \%invoice_details,
21 \%second_invoice_details,
22 ]
23 );
24  
25 $ImportFile->add_osko_record( ... );
26 $ImportFile->add_cheque_record( ... );
27 $ImportFile->add_bpay_record( ... );
28 $ImportFile->add_realtime_record( ... );
29 $ImportFile->add_remittance_only_record( ... );
30 $ImportFile->add_overseas_telegraphic_transfer_record( ... );
31  
32  
33 =head1 DESCRIPTION
34  
35 This class implements the format as defined by Westpac at https://paymentsplus.westpac.com.au/docs/file-formats/australian-payment-import-csv
36  
37 This class follows the structure and validation rules in the spec,
38 and delegates most of this to the subclasses (SEE ALSO below)
39  
40 =cut
41  
42 1 ▶use feature qw/ signatures /;
Subroutine BEGIN: called CC=1 SCAR=0.0
43  
44 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
45 1 with 'Business::Westpac::Role::CSV';
46 1 ▶no warnings qw/ experimental::signatures /;
Subroutine BEGIN: called CC=1 SCAR=0.0
47  
48 1 ▶use Carp qw/ croak /;
Subroutine BEGIN: called CC=1 SCAR=0.0
49 1 ▶use Module::Load;
Subroutine BEGIN: called CC=1 SCAR=0.0
50  
51 1 ▶use Business::Westpac::Types qw/
Subroutine BEGIN: called CC=1 SCAR=0.0
52 add_max_string_attribute
53 1 /;
54  
55 # we have long namespaces and use them multiple times so have
56 # normalised them out into the $parent and @subclasses below
57 1 my $parent = 'Business::Westpac::PaymentsPlus::Australian::Payment::Import';
58  
59 1 my @subclasses = ( qw/
60 FileHeader
61 Invoice
62 Payment::BPAY
63 Payment::Cheque
64 Payment::EFT
65 Payment::OTT
66 Payment::Osko
67 Payment::RealTime
68 Payment::RemittanceOnly
69 Remittance
70 Trailer
71 / );
72  
73 1 load $parent . "::$_" for @subclasses;
74  
75 has 'records' => (
76 traits => [ 'Array' ],
77 is => 'rw',
78 isa => "ArrayRef[ " .
79 11 join( " | ",map { "${parent}::$_" } @subclasses ) . "
80 ]",
81 1 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
82 1 handles => {
83 _add_record => 'push',
84 },
85 );
86  
87 has 'count' => (
88 traits => [ 'Number' ],
89 is => 'rw',
90 isa => 'Num',
91 1 ▶ default => sub { 0 },
Subroutine __ANON__: called CC=1 SCAR=0.0
92 1 handles => {
93 _add_payment => 'add'
94 },
95 );
96  
97 has 'amount' => (
98 traits => [ 'Number' ],
99 is => 'rw',
100 isa => 'Num',
101 1 ▶ default => sub { 0 },
Subroutine __ANON__: called CC=1 SCAR=0.0
102 1 handles => {
103 _add_amount => 'add'
104 },
105 );
106  
107 1 foreach my $str_attr (
108 'CustomerCode[10]',
109 'CustomerName[40]',
110 'CustomerFileReference[20]',
111 ) {
112 3 __PACKAGE__->add_max_string_attribute(
113 $str_attr,
114 is => 'ro',
115 required => 1,
116 );
117 }
118  
119 1 has 'scheduled_date' => (
120 is => 'ro',
121 isa => 'WestpacDate',
122 required => 1,
123 coerce => 1,
124 handles => {
125 scheduled_csv_date => [ strftime => '%d%m%C%y' ],
126 },
127 );
128  
129 has 'currency' => (
130 is => 'ro',
131 isa => 'Str',
132 required => 0,
133 1 ▶ default => sub { 'AUD' },
Subroutine __ANON__: called CC=1 SCAR=0.0
134 1 );
135  
136 has 'version' => (
137 is => 'ro',
138 isa => 'Str',
139 required => 0,
140 1 ▶ default => sub { '6' },
Subroutine __ANON__: called CC=1 SCAR=0.0
141 1 );
142  
143 1 ▶sub record_type { 'H' }
Subroutine record_type: called CC=1 SCAR=0.0
Pod undocumented
144  
145 =head1 METHODS
146  
147 =head2 to_csv
148  
149 Return an array of CSV lines for output
150  
151 my @csv = $self->to_csv;
152  
153 The returned lines will contain the entire file structure ready for
154 output, including the header and trailers.
155  
156 =cut
157  
158 1 ▶sub to_csv ( $self ) {
Subroutine to_csv: called CC=2 SCAR=6.9
Pod documented
159  
160 # header line
161 1 my @csv = $self->attributes_to_csv( qw/
162 record_type
163 customer_code
164 customer_name
165 customer_file_reference
166 scheduled_csv_date
167 currency
168 version
169 / );
170  
171 # payment records
172 push( @csv,$_->to_csv )
173 1 foreach $self->records->@*;
174  
175 # trailer line
176 1 push(
177 @csv,
178 $self->values_to_csv(
179 'T',$self->count,$self->amount
180 )
181 );
182  
183 1 return @csv;
184 }
185  
186 =head2 add_eft_record (E)
187  
188 =head2 add_osko_record (O)
189  
190 =head2 add_realtime_record (RT)
191  
192 =head2 add_overseas_telegraphic_transfer_record (OTT)
193  
194 =head2 add_bpay_record (B)
195  
196 =head2 add_cheque_record (C)
197  
198 =head2 add_remittance_only_record (RO)
199  
200 Add payment records to the file, optionally adding remittance and invoice
201 records. As per the Westpac spec some record types require remittance
202 and others have them as an option:
203  
204 Type Remittance Invoice
205  
206 E 0..1 0..n
207 O 0..1 0..n
208 RT 0..1 0..n
209 OTT 0..1 0..n
210 B 0..1 0..n
211 C 1 0..n
212 RO 1 0..n
213  
214 Each method expects a hash with the attributes to populate the objects
215 that will be instantiated, with the key names being those used for the
216 method name C<add_${key_name}_record>, for example:
217  
218 $ImportFile->add_eft_record(
219  
220 # refer to Business::Westpac::PaymentsPlus::Australian::Payment::Import::Payment::EFT
221 eft => {
222 payer_payment_reference => 'REF00001',
223 payment_amount => '36.04',
224 recipient_reference => 'REF00001',
225 account_number => '000002',
226 account_name => 'Payee 02',
227 bsb_number => '062-000',
228 funding_bsb_number => '032-000',
229 funding_account_number => '000007',
230 remitter_name => 'Remitter Name',
231 },
232  
233 # optional (in most cases) remittance and invoice lines
234 # refer to Business::Westpac::PaymentsPlus::Australian::Payment::Import::Invoice
235 # and Business::Westpac::PaymentsPlus::Australian::Payment::Import::Remittance
236 remittance => { ... },
237 invoices => [ { ... },{ ... }, ... ],
238 );
239  
240 =cut
241  
242 1 foreach my $payment_type (
243 [ qw/ EFT eft / ],
244 [ qw/ Osko osko / ],
245 [ qw/ RealTime realtime / ],
246 [ qw/ OTT overseas_telegraphic_transfer / ],
247 [ qw/ BPAY bpay / ],
248 [ qw/ Cheque cheque 1 / ],
249 [ qw/ RemittanceOnly remittance_only 1 / ],
250 ) {
251 7 my ( $class,$key_name,$requires_remit ) = $payment_type->@*;
252 7 my $sub = "add_${key_name}_record";
253  
254 __PACKAGE__->meta->add_method(
255 11 ▶ $sub => sub ( $self,%records ) {
Subroutine add_realtime_record: called CC=3 SCAR=11.0
256  
257 11 ▶ if ( $requires_remit ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($requires_remit) 5 6 11
258 5 ▶ $records{remittance} || croak(
Branch: 1 branch
BranchTrueFalseTotal
$records{"remittance"} or croak("$class records must have a remittance") 3 2 5
259 "$class records must have a remittance"
260 );
261 }
262  
263 return $self->_add_payment_object_to_records(
264 9 $class,$records{$key_name},\%records
265 );
266 },
267 7 );
268 }
269  
270 9 ▶sub _add_payment_object_to_records (
Subroutine _add_payment_object_to_records: called CC=5 SCAR=16.1
271 $self,
272 $subclass,
273 $attributes,
274 9 $records = {},
275 ) {
276 9 my $parent = 'Business::Westpac::PaymentsPlus::Australian::Payment::Import';
277 9 my $class = "${parent}::Payment::${subclass}";
278  
279 9 $self->_add_record(
280 my $Record = $class->new( $attributes->%* )
281 );
282  
283 8 $self->_add_payment( 1 );
284 8 $self->_add_amount( $Record->payment_amount );
285  
286 8 ▶ if ( $records->{remittance} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($records->{"remittance"}) 5 3 8
287 5 my $class = "${parent}::Remittance";
288 $self->_add_record(
289 $class->new( $records->{remittance}->%* )
290 5 );
291 }
292  
293 8 ▶ foreach my $invoice ( @{ $records->{invoices} // [] } ) {
Condition100%2/2
$records->{"invoices"} // []
l!l
26
MC/DC100%1/1
$records->{"invoices"} // []
$records->{"invoices"}
Truth table100%2/2
A
A= $records->{"invoices"}
Aresult
11
00
294 3 my $class = "${parent}::Invoice";
295 3 $self->_add_record(
296 $class->new( $invoice->%* )
297 );
298 }
299  
300 8 return $Record;
301 }
302  
303 1 __PACKAGE__->meta->make_immutable;
304  
305 =head1 SEE ALSO
306  
307 Business::Westpac::PaymentsPlus::Australian::Payment::Import...
308  
309 =over 4
310  
311 ::FileHeader
312  
313 ::Invoice
314  
315 ::Payment
316  
317 ::Payment::Cheque
318  
319 ::Payment::EFT
320  
321 ::Payment::Okso
322  
323 ::Payment::OTT
324  
325 ::Payment::RealTime
326  
327 ::Remittance
328  
329 ::Remittance::Only
330  
331 L<Business::Westpac::Types>
332  
333 =back
334  
335 =cut
« Westpac/PaymentsPlus/Australian/Payment/Import/Remittance.pm ↑ Summary Westpac/Types.pm »