@@ -49,6 +49,7 @@ has agile => (
49
49
50
50
use constant SERVICE_TO_SUB_MAPPING => {
51
51
garden_subscription => \&_garden_subscription,
52
+ garden_subscription_renew => \&_garden_subscription_renew,
52
53
garden_subscription_cancel => \&_garden_subscription_cancel,
53
54
};
54
55
@@ -92,7 +93,11 @@ sub post_service_request {
92
93
$self -> logger-> debug(
93
94
" post_service_request arguments: " . encode_json($args ) );
94
95
95
- my $sub = SERVICE_TO_SUB_MAPPING-> {$service -> service_code};
96
+ # Garden Subscription may be a 'renew' type
97
+ my $lookup = $service -> service_code;
98
+ $lookup .= " _$args ->{attributes}{type}" if $args -> {attributes }{type };
99
+
100
+ my $sub = SERVICE_TO_SUB_MAPPING-> {$lookup };
96
101
97
102
die ' Service \' ' . $service -> service_code . ' \' not handled' unless $sub ;
98
103
@@ -120,7 +125,7 @@ sub _garden_subscription {
120
125
TitleCode => ' Default' ,
121
126
CustomerExternalReference => ' ' ,
122
127
ServiceContractUPRN => $args -> {attributes }{uprn },
123
- WasteContainerQuantity => int ( $args -> {attributes }{new_containers } ) || 1,
128
+ WasteContainerQuantity => int ( $args -> {attributes }{total_containers } ) || 1,
124
129
AlreadyHasBinQuantity => int ( $args -> {attributes }{current_containers } ) || 0,
125
130
PaymentReference => $args -> {attributes }{PaymentCode },
126
131
PaymentMethodCode =>
@@ -129,9 +134,8 @@ sub _garden_subscription {
129
134
# Used for FMS report ID
130
135
ActionReference => $args -> {attributes }{fixmystreet_id },
131
136
132
- # TODO
133
- DirectDebitDate => ' ' ,
134
- DirectDebitReference => ' ' ,
137
+ DirectDebitDate => $args -> {attributes }{direct_debit_start_date } // ' ' ,
138
+ DirectDebitReference => $args -> {attributes }{direct_debit_reference } // ' ' ,
135
139
} );
136
140
137
141
# Expected response:
@@ -153,6 +157,51 @@ sub _garden_subscription {
153
157
}
154
158
}
155
159
160
+ sub _garden_subscription_renew {
161
+ my ( $self , $args ) = @_ ;
162
+
163
+ my $integration = $self -> get_integration;
164
+
165
+ my $is_free = $integration -> IsAddressFree( $args -> {attributes }{uprn } );
166
+
167
+ if ( $is_free -> {IsFree } eq ' False' ) {
168
+ my $res = $integration -> Renew( {
169
+ CustomerExternalReference => $args -> {attributes }{customer_external_ref },
170
+ ServiceContractUPRN => $args -> {attributes }{uprn },
171
+ WasteContainerQuantity => int ( $args -> {attributes }{total_containers } ) || 1,
172
+ AlreadyHasBinQuantity => int ( $args -> {attributes }{current_containers } ) || 0,
173
+ PaymentReference => $args -> {attributes }{PaymentCode },
174
+ PaymentMethodCode =>
175
+ PAYMENT_METHOD_MAPPING-> { $args -> {attributes }{payment_method } },
176
+
177
+ DirectDebitDate => $args -> {attributes }{direct_debit_start_date } // ' ' ,
178
+ DirectDebitReference => $args -> {attributes }{direct_debit_reference } // ' ' ,
179
+ } );
180
+
181
+ # Expected response:
182
+ # {
183
+ # Id: int,
184
+ # Address: string,
185
+ # ServiceContractStatus: string,
186
+ # WasteContainerType: string,
187
+ # WasteContainerQuantity: int,
188
+ # StartDate: string,
189
+ # EndDate: string,
190
+ # ReminderDate: string,
191
+ # }
192
+ my $request = $self -> new_request(
193
+ service_request_id => $res -> {Id }, # TODO Is this correct?
194
+ );
195
+
196
+ return $request ;
197
+
198
+ } else {
199
+ die ' UPRN '
200
+ . $args -> {attributes }{uprn }
201
+ . ' does not have a subscription to be renewed, or is invalid' ;
202
+ }
203
+ }
204
+
156
205
sub _garden_subscription_cancel {
157
206
my ( $self , $args ) = @_ ;
158
207
0 commit comments