| 1 | package Business::NAB::BPAY::Payments::Results; | ||||||||||
| 2 | 1 | $Business::NAB::BPAY::Payments::Results::VERSION = '0.11'; | |||||||||
| 3 | =head1 NAME | ||||||||||
| 4 | |||||||||||
| 5 | Business::NAB::BPAY::Payments::Results | ||||||||||
| 6 | |||||||||||
| 7 | =head1 SYNOPSIS | ||||||||||
| 8 | |||||||||||
| 9 | use Business::NAB::BPAY::Payments::Results; | ||||||||||
| 10 | |||||||||||
| 11 | my $Payments = Business::NAB::BPAY::Payments::Results->new_from_file( | ||||||||||
| 12 | "/path/to/bpay/payments/batch/file_response.bpb", | ||||||||||
| 13 | ); | ||||||||||
| 14 | |||||||||||
| 15 | # parse | ||||||||||
| 16 | my $Header = $Payments->header_record->[0]; | ||||||||||
| 17 | |||||||||||
| 18 | foreach my $Payment ( $Payments->detail_record->@* ) { | ||||||||||
| 19 | ... | ||||||||||
| 20 | } | ||||||||||
| 21 | |||||||||||
| 22 | my $Trailer = $Payments->trailer_record->[0]; | ||||||||||
| 23 | |||||||||||
| 24 | # create | ||||||||||
| 25 | $Payments->to_file( | ||||||||||
| 26 | "/path/to/bpay/payments/batch/file_output_results.bpb", | ||||||||||
| 27 | $separator, # defaults to "\r\n" | ||||||||||
| 28 | ); | ||||||||||
| 29 | |||||||||||
| 30 | |||||||||||
| 31 | =head1 DESCRIPTION | ||||||||||
| 32 | |||||||||||
| 33 | Class for parsing / creating a NAB BPAY batch payments response files | ||||||||||
| 34 | |||||||||||
| 35 | All methods and attributes are inherited from | ||||||||||
| 36 | L<Business::NAB::BPAY::Payments> | ||||||||||
| 37 | |||||||||||
| 38 | =cut | ||||||||||
| 39 | |||||||||||
| 40 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 41 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 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 | extends 'Business::NAB::BPAY::Payments'; | |||||||||
| 46 | 1 | ▶ | no warnings qw/ experimental::signatures /; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 47 | |||||||||||
| 48 | 1 | ▶ | use Business::NAB::BPAY::Payments::Results::TrailerRecord; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 49 | |||||||||||
| 50 | # we have long namespaces and use them multiple times so have | ||||||||||
| 51 | # normalised them out into the $parent and @subclasses below | ||||||||||
| 52 | 1 | my $parent = 'Business::NAB::BPAY::Payments::Results'; | |||||||||
| 53 | |||||||||||
| 54 | 1 | my @subclasses = ( | |||||||||
| 55 | qw/ | ||||||||||
| 56 | HeaderRecord | ||||||||||
| 57 | DetailRecord | ||||||||||
| 58 | TrailerRecord | ||||||||||
| 59 | / | ||||||||||
| 60 | ); | ||||||||||
| 61 | |||||||||||
| 62 | 1 | __PACKAGE__->load_attributes( $parent, @subclasses ); | |||||||||
| 63 | |||||||||||
| 64 | 1 | ▶ | sub new_from_file ( $class, $file ) { | ||||||||
|
Subroutine
new_from_file: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 65 | |||||||||||
| 66 | 1 | my $self = $class->new; | |||||||||
| 67 | |||||||||||
| 68 | 1 | return $self->SUPER::new_from_file( | |||||||||
| 69 | $file, $parent | ||||||||||
| 70 | ); | ||||||||||
| 71 | } | ||||||||||
| 72 | |||||||||||
| 73 | 3 | ▶ | sub to_file ( $self, $file, $sep = "\r\n" ) { | ||||||||
|
Subroutine
to_file: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||
| 74 | |||||||||||
| 75 | 3 | ▶ | if ( !$self->trailer_record->[ 0 ] ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 76 | |||||||||||
| 77 | my ( | ||||||||||
| 78 | 1 | $total_value, $total_value_success, $total_value_failed, | |||||||||
| 79 | $total_count, $total_count_success, $total_count_failed, | ||||||||||
| 80 | ) = ( 0, 0, 0, 0, 0, 0 ); | ||||||||||
| 81 | |||||||||||
| 82 | 1 | foreach my $Detail ( $self->detail_record->@* ) { | |||||||||
| 83 | 5 | $total_value += $Detail->amount; | |||||||||
| 84 | 5 | $total_count++; | |||||||||
| 85 | |||||||||||
| 86 | 5 | ▶ | if ( $Detail->is_successful ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 87 | 2 | $total_value_success += $Detail->amount; | |||||||||
| 88 | 2 | $total_count_success++; | |||||||||
| 89 | } else { | ||||||||||
| 90 | 3 | $total_value_failed += $Detail->amount; | |||||||||
| 91 | 3 | $total_count_failed++; | |||||||||
| 92 | } | ||||||||||
| 93 | } | ||||||||||
| 94 | |||||||||||
| 95 | 1 | my $TrailerRecord = Business::NAB::BPAY::Payments::Results::TrailerRecord->new( | |||||||||
| 96 | total_value_of_payments => $total_value, | ||||||||||
| 97 | total_number_of_payments => $total_count, | ||||||||||
| 98 | total_value_of_successful_payments => $total_value_success, | ||||||||||
| 99 | total_number_of_successful_payments => $total_count_success, | ||||||||||
| 100 | total_value_of_declined_payments => $total_value_failed, | ||||||||||
| 101 | total_number_of_declined_payments => $total_count_failed, | ||||||||||
| 102 | ); | ||||||||||
| 103 | |||||||||||
| 104 | 1 | $self->add_trailer_record( $TrailerRecord ); | |||||||||
| 105 | } | ||||||||||
| 106 | |||||||||||
| 107 | 3 | return $self->SUPER::to_file( $file, $sep ); | |||||||||
| 108 | } | ||||||||||
| 109 | |||||||||||
| 110 | =head1 SEE ALSO | ||||||||||
| 111 | |||||||||||
| 112 | L<Business::NAB::Types> | ||||||||||
| 113 | |||||||||||
| 114 | L<Business::NAB::BPAY::Payments> | ||||||||||
| 115 | |||||||||||
| 116 | L<Business::NAB::BPAY::Payments::Results::HeaderRecord> | ||||||||||
| 117 | |||||||||||
| 118 | L<Business::NAB::BPAY::Payments::Results::DetailRecord> | ||||||||||
| 119 | |||||||||||
| 120 | L<Business::NAB::BPAY::Payments::Results::TrailerRecord> | ||||||||||
| 121 | |||||||||||
| 122 | =cut | ||||||||||
| 123 | |||||||||||
| 124 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||