File Coverage

blib/lib/Business/Westpac/PaymentsPlus/Australian/Payment/Import/Remittance.pm
Criterion Covered Total %
statement 38 38 100.0
branch 18 20 90.0
condition 11 12 91.6
subroutine 9 9 100.0
pod 1 3 33.3
total 77 82 93.9


line stmt bran cond sub pod time code
1             package Business::Westpac::PaymentsPlus::Australian::Payment::Import::Remittance;
2              
3             =head1 NAME
4              
5             Business::Westpac::PaymentsPlus::Australian::Payment::Import::Remittance
6              
7             =head1 SYNOPSIS
8              
9             use Business::Westpac::PaymentsPlus::Australian::Payment::Import::Remittance;
10             my $Remittance = Business::Westpac::PaymentsPlus::Australian::Payment::Import::Remittance->new(
11             remittance_delivery_type => 'EMAIL',
12             payee_name => 'Payee 01',
13             addressee_name => 'Addressee 01',
14             street_1 => 'Level 1',
15             street_2 => 'Wallsend Plaza',
16             city => 'Wallsend',
17             state => 'NSW',
18             post_code => '2287',
19             country => 'AU',
20             email => 'test@test.com',
21             remittance_layout_code => 1,
22             return_to_address_identifier => 1,
23             pass_through_data => "Some pass through data",
24             );
25              
26             my @csv = $Header->to_csv;
27              
28             =head1 DESCRIPTION
29              
30             Class for modeling remittance details in the context of Westpac CSV files.
31              
32             =cut
33              
34 2     2   340994 use feature qw/ signatures /;
  2         4  
  2         311  
35              
36 2     2   684 use Moose;
  2         452633  
  2         13  
37 2     2   12842 use Types::Standard qw/ Enum /;
  2         256320  
  2         22  
38             with 'Business::Westpac::Role::CSV';
39 2     2   6017 no warnings qw/ experimental::signatures /;
  2         7  
  2         130  
40              
41 2     2   14 use Carp qw/ croak /;
  2         74  
  2         162  
42 2         2035 use Business::Westpac::Types qw/
43             add_max_string_attribute
44 2     2   618 /;
  2         12  
45              
46             =head1 ATTRIBUTES
47              
48             All attributes are optional, except were stated, and are read only
49              
50             =over
51              
52             =item remittance_delivery_type (Enum, required)
53              
54             One of: POST, POST_RETURN, POST_OS, POST_MULTI, FAX, EMAIL, NONE
55              
56             =item remittance_layout_code (PositiveInt)
57              
58             =item payee_name (Str, max 35 chars, required)
59              
60             =item addressee_name (Str, max 35 chars)
61              
62             =item street_1 (Str, max 35 chars)
63              
64             =item street_2 (Str, max 35 chars)
65              
66             =item street_3 (Str, max 35 chars)
67              
68             =item city (Str, max 40 chars)
69              
70             =item state (Str, max 3 chars)
71              
72             =item post_code (Str, max 9 chars)
73              
74             =item country (Str, max 2 chars)
75              
76             =item fax (Str, max 15 chars)
77              
78             =item email (Str, max 128 chars)
79              
80             =item return_to_address_identifier (Str, max 1 chars)
81              
82             =item pass_through_data (Str, max 120 chars)
83              
84             =back
85              
86             =cut
87              
88 6     6 0 20 sub record_type { 'R' }
89              
90             has 'remittance_delivery_type' => (
91             is => 'ro',
92             isa => Enum[ qw/
93             POST
94             POST_RETURN
95             POST_OS
96             POST_MULTI
97             FAX
98             EMAIL
99             NONE
100             / ],
101             required => 1,
102             );
103              
104             has 'remittance_layout_code' => (
105             is => 'ro',
106             isa => 'PositiveInt',
107             required => 0,
108             );
109              
110             foreach my $str_attr (
111             'PayeeName[35]',
112             ) {
113             __PACKAGE__->add_max_string_attribute(
114             $str_attr,
115             is => 'ro',
116             required => 1,
117             );
118             }
119              
120             foreach my $str_attr (
121             'AddresseeName[35]',
122             ( map { "Street_" . $_ . "[35]" } 1 .. 3 ),
123             'City[40]',
124             'State[3]',
125             'PostCode[9]',
126             'Country[2]',
127             'Fax[15]',
128             'Email[128]',
129             'ReturnToAddressIdentifier[1]',
130             ) {
131             __PACKAGE__->add_max_string_attribute(
132             $str_attr,
133             is => 'ro',
134             required => 0,
135             );
136             }
137              
138             # Pass through data appears on a distinct "Remittance Pass-through record"
139             # (RP) however it can only appear after a Remittance record (R), i.e. this
140             # class. Given the RP line currently *only* contains a single field, the
141             # pass through data, it seems overkill to have an entire distinct class for
142             # it. So for now it's just an attribute on *this* class.
143             __PACKAGE__->add_max_string_attribute(
144             'PassThroughData[120]',
145             is => 'ro',
146             required => 0,
147             );
148              
149             sub BUILD {
150 18     18 0 48 my ( $self ) = @_;
151              
152 18         1362 my $rdt = $self->remittance_delivery_type;
153 18         71 my $error = "is required when remittance_delivery_type is $rdt";
154              
155 18 100 100     160 if (
      100        
156             $rdt eq 'POST'
157             || $rdt eq 'POST_OS'
158             || $rdt eq 'POST_MULTI'
159             ) {
160 11 100       72 $self->_has_street_1 || croak( "street_1 $error" );
161 8 100       97 $self->_has_city || croak( "city $error" );
162              
163 5 50       61 length( $self->city ) <= 25 || croak(
164             "city is limited to 25 chars for remittance_delivery_type of $rdt"
165             );
166              
167 5 50       60 unless ( $rdt eq 'POST_OS' ) {
168 5 100       35 $self->_has_state || croak( "state $error" );
169 3 100       38 $self->_has_post_code || croak( "post_code $error" );
170             }
171             }
172              
173 8 100 66     44 $rdt eq 'FAX' && !$self->_has_fax && croak( "fax $error" );
174 7 100 100     118 $rdt eq 'EMAIL' && !$self->_has_email && croak( "email $error" );
175             }
176              
177             =head1 METHODS
178              
179             =head2 to_csv
180              
181             Convert the attributes to CSV line(s):
182              
183             my @csv = $Header->to_csv;
184              
185             If pass_through_data has content then the CSV will contain
186             multiple lines
187              
188             =cut
189              
190 6     6 1 101 sub to_csv ( $self ) {
  6         14  
  6         12  
191              
192 6         32 my @csv_str = $self->attributes_to_csv(
193             qw/
194             record_type
195             remittance_delivery_type
196             payee_name
197             addressee_name
198             street_1
199             street_2
200             street_3
201             city
202             state
203             post_code
204             country
205             fax
206             email
207             remittance_layout_code
208             return_to_address_identifier
209             /
210             );
211              
212             # add the "Remittance Pass-through record" if present
213 6 100       104 if ( $self->_has_pass_through_data ) {
214 1         11 push( @csv_str, $self->values_to_csv(
215             "RP",$self->pass_through_data
216             ) );
217             }
218              
219 6         86 return @csv_str;
220             }
221              
222             =head1 SEE ALSO
223              
224             L<Business::Westpac::Types>
225              
226             =cut
227              
228             __PACKAGE__->meta->make_immutable;