@@ -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
@@ -148,6 +153,47 @@ sub _garden_subscription {
148
153
}
149
154
}
150
155
156
+ sub _garden_subscription_renew {
157
+ my ( $self , $args ) = @_ ;
158
+
159
+ my $integration = $self -> get_integration;
160
+
161
+ my $is_free = $integration -> IsAddressFree( $args -> {attributes }{uprn } );
162
+
163
+ if ( $is_free -> {IsFree } eq ' False' ) {
164
+ my $res = $integration -> Renew( {
165
+ CustomerExternalReference => $args -> {attributes }{customer_external_ref },
166
+ ServiceContractUPRN => $args -> {attributes }{uprn },
167
+ WasteContainerQuantity => int ( $args -> {attributes }{new_containers } ) || 1,
168
+ PaymentReference => $args -> {attributes }{PaymentCode },
169
+ PaymentMethodCode =>
170
+ PAYMENT_METHOD_MAPPING-> { $args -> {attributes }{payment_method } },
171
+ } );
172
+
173
+ # Expected response:
174
+ # {
175
+ # Id: int,
176
+ # Address: string,
177
+ # ServiceContractStatus: string,
178
+ # WasteContainerType: string,
179
+ # WasteContainerQuantity: int,
180
+ # StartDate: string,
181
+ # EndDate: string,
182
+ # ReminderDate: string,
183
+ # }
184
+ my $request = $self -> new_request(
185
+ service_request_id => $res -> {Id }, # TODO Is this correct?
186
+ );
187
+
188
+ return $request ;
189
+
190
+ } else {
191
+ die ' UPRN '
192
+ . $args -> {attributes }{uprn }
193
+ . ' does not have a subscription to be renewed, or is invalid' ;
194
+ }
195
+ }
196
+
151
197
sub _garden_subscription_cancel {
152
198
my ( $self , $args ) = @_ ;
153
199
0 commit comments