« NAB/BPAY/Payments/HeaderRecord.pm
↑ Summary
NAB/Australian/DirectEntry/Payments/DescriptiveRecord.pm »
| 1 | package Business::NAB::BPAY::Payments::Results::TrailerRecord; | ||||||||||
| 2 | 2 | $Business::NAB::BPAY::Payments::Results::TrailerRecord::VERSION = '0.11'; | |||||||||
| 3 | =head1 NAME | ||||||||||
| 4 | |||||||||||
| 5 | Business::NAB::BPAY::Payments::TrailerRecord | ||||||||||
| 6 | |||||||||||
| 7 | =head1 SYNOPSIS | ||||||||||
| 8 | |||||||||||
| 9 | use Business::NAB::BPAY::Payments::TrailerRecord; | ||||||||||
| 10 | |||||||||||
| 11 | # parse | ||||||||||
| 12 | my $Trailer = Business::NAB::BPAY::Payments::Results::TrailerRecord | ||||||||||
| 13 | ->new_from_record( $line ); | ||||||||||
| 14 | |||||||||||
| 15 | # create | ||||||||||
| 16 | my $Trailer = Business::NAB::BPAY::Payments::Results::TrailerRecord->new( | ||||||||||
| 17 | total_value_of_payments => 189915, | ||||||||||
| 18 | total_number_of_payments => 5, | ||||||||||
| 19 | total_number_of_successful_payments => 2, | ||||||||||
| 20 | total_value_of_successful_payments => 9914, | ||||||||||
| 21 | total_number_of_declined_payments => 3, | ||||||||||
| 22 | total_value_of_declined_payments => 180001, | ||||||||||
| 23 | ); | ||||||||||
| 24 | |||||||||||
| 25 | my $line = $Trailer->to_record; | ||||||||||
| 26 | |||||||||||
| 27 | =head1 DESCRIPTION | ||||||||||
| 28 | |||||||||||
| 29 | Class for trailer record in the "BPAY Batch User Guide" responses | ||||||||||
| 30 | |||||||||||
| 31 | All methods and attributes are inherited from | ||||||||||
| 32 | L<Business::NAB::BPAY::Payments::TrailerRecord> | ||||||||||
| 33 | |||||||||||
| 34 | =cut | ||||||||||
| 35 | |||||||||||
| 36 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 37 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 38 | 2 | ▶ | use feature qw/ signatures /; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 39 | |||||||||||
| 40 | 2 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 41 | 2 | extends 'Business::NAB::BPAY::Payments::TrailerRecord'; | |||||||||
| 42 | |||||||||||
| 43 | 2 | ▶ | use Carp qw/ croak /; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 44 | |||||||||||
| 45 | 2 | ▶ | no warnings qw/ experimental::signatures /; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 46 | |||||||||||
| 47 | =head1 ATTRIBUTES | ||||||||||
| 48 | |||||||||||
| 49 | Additional attributes are inherited from | ||||||||||
| 50 | L<Business::NAB::BPAY::Payments::HeaderRecord> | ||||||||||
| 51 | |||||||||||
| 52 | =over | ||||||||||
| 53 | |||||||||||
| 54 | =item total_number_of_successful_payments (NAB::Type::PositiveIntOrZero) | ||||||||||
| 55 | |||||||||||
| 56 | =item total_value_of_successful_payments (NAB::Type::PositiveIntOrZero) | ||||||||||
| 57 | |||||||||||
| 58 | =item total_number_of_declined_payments (NAB::Type::PositiveIntOrZero) | ||||||||||
| 59 | |||||||||||
| 60 | =item total_value_of_declined_payments (NAB::Type::PositiveIntOrZero) | ||||||||||
| 61 | |||||||||||
| 62 | =back | ||||||||||
| 63 | |||||||||||
| 64 | =cut | ||||||||||
| 65 | |||||||||||
| 66 | 2 | foreach my $attr ( | |||||||||
| 67 | qw/ | ||||||||||
| 68 | total_value_of_successful_payments | ||||||||||
| 69 | total_value_of_declined_payments | ||||||||||
| 70 | total_number_of_successful_payments | ||||||||||
| 71 | total_number_of_declined_payments | ||||||||||
| 72 | / | ||||||||||
| 73 | ) { | ||||||||||
| 74 | has $attr => ( | ||||||||||
| 75 | is => 'ro', | ||||||||||
| 76 | isa => 'NAB::Type::PositiveIntOrZero', | ||||||||||
| 77 | required => 1, | ||||||||||
| 78 | 20 | ▶ | trigger => sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 79 | 20 | my ( $self, $value, $old_value ) = @_; | |||||||||
| 80 | 20 | $self->{ $attr } = int( $value ); | |||||||||
| 81 | }, | ||||||||||
| 82 | 8 | ); | |||||||||
| 83 | } | ||||||||||
| 84 | |||||||||||
| 85 | 7 | ▶ | sub _pack_template { | ||||||||
|
Subroutine
_pack_template: called CC=1 SCAR=0.0
| |||||||||||
| 86 | 7 | return "A1 A10 A13 A10 A13 A10 A13"; | |||||||||
| 87 | } | ||||||||||
| 88 | |||||||||||
| 89 | 3 | ▶ | sub new_from_record ( $class, $line ) { | ||||||||
|
Subroutine
new_from_record: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 90 | |||||||||||
| 91 | # undef being "this space intentionally left blank" | ||||||||||
| 92 | my ( | ||||||||||
| 93 | 3 | $record_type, | |||||||||
| 94 | $total_successful_number, | ||||||||||
| 95 | $total_successful_value, | ||||||||||
| 96 | $total_declined_number, | ||||||||||
| 97 | $total_declined_value, | ||||||||||
| 98 | $total_transactions, | ||||||||||
| 99 | $total_value, | ||||||||||
| 100 | ) = unpack( $class->_pack_template(), $line ); | ||||||||||
| 101 | |||||||||||
| 102 | 3 | ▶ | if ( $record_type ne '9' ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 103 | 1 | croak( "unsupported record type ($record_type)" ); | |||||||||
| 104 | } | ||||||||||
| 105 | |||||||||||
| 106 | 2 | return $class->new( | |||||||||
| 107 | total_number_of_successful_payments => $total_successful_number, | ||||||||||
| 108 | total_value_of_successful_payments => $total_successful_value, | ||||||||||
| 109 | total_number_of_declined_payments => $total_declined_number, | ||||||||||
| 110 | total_value_of_declined_payments => $total_declined_value, | ||||||||||
| 111 | total_number_of_payments => $total_transactions, | ||||||||||
| 112 | total_value_of_payments => $total_value, | ||||||||||
| 113 | ); | ||||||||||
| 114 | } | ||||||||||
| 115 | |||||||||||
| 116 | 4 | ▶ | sub to_record ( $self ) { | ||||||||
|
Subroutine
to_record: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 117 | |||||||||||
| 118 | 4 | my $record = pack( | |||||||||
| 119 | $self->_pack_template(), | ||||||||||
| 120 | "9", | ||||||||||
| 121 | sprintf( "%010.0f", $self->total_number_of_successful_payments ), | ||||||||||
| 122 | sprintf( "%013.0f", $self->total_value_of_successful_payments ), | ||||||||||
| 123 | sprintf( "%010.0f", $self->total_number_of_declined_payments ), | ||||||||||
| 124 | sprintf( "%013.0f", $self->total_value_of_declined_payments ), | ||||||||||
| 125 | sprintf( "%010.0f", $self->total_number_of_payments ), | ||||||||||
| 126 | sprintf( "%013.0f", $self->total_value_of_payments ), | ||||||||||
| 127 | ); | ||||||||||
| 128 | |||||||||||
| 129 | 4 | return $record; | |||||||||
| 130 | } | ||||||||||
| 131 | |||||||||||
| 132 | =head1 SEE ALSO | ||||||||||
| 133 | |||||||||||
| 134 | L<Business::NAB::Types> | ||||||||||
| 135 | |||||||||||
| 136 | L<Business::NAB::BPAY::Payments::TrailerRecord> | ||||||||||
| 137 | |||||||||||
| 138 | =cut | ||||||||||
| 139 | |||||||||||
| 140 | 2 | __PACKAGE__->meta->make_immutable; | |||||||||