Skip to content

Commit

Permalink
[Waste] Add option to force a DD renewal.
Browse files Browse the repository at this point in the history
Sometimes we get new subscriptions through that should be renewals. If
that's the case then we need to treat the payment as a renewal,
regardless of what the payment is listed as.
  • Loading branch information
chrismytton authored and davea committed Nov 1, 2023
1 parent f11d15b commit fd80da8
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
6 changes: 5 additions & 1 deletion bin/fixmystreet.com/waste-reconcile-dd
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ my ($opts, $usage) = describe_options(
['verbose|v', 'more verbose output'],
['cobrand=s', 'which cobrand to fetch events for'],
['help|h', "print usage message and exit" ],
['reference=s', 'only look at direct debits with this reference'],
['force-renewal', 'when run with --reference, force the direct debit to be a renewal'],
);
$usage->die if $opts->help;
$usage->die unless $opts->cobrand;

my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker($opts->cobrand)->new;
$cobrand->waste_reconcile_direct_debits({
verbose => $opts->verbose
verbose => $opts->verbose,
reference => $opts->reference,
force_renewal => $opts->force_renewal,
});
11 changes: 11 additions & 0 deletions perllib/FixMyStreet/Roles/DDProcessor.pm
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ sub waste_reconcile_direct_debits {
$payment = DDPayment->new({ data => $payment, cobrand => $self });
next unless $payment->date;

# If there's a `reference` key in $params then we only want to look at
# payments that match that reference.
next if $params->{reference} && $payment->payer ne $params->{reference};

$self->log( "looking at payment " . $payment->payer );
$self->log( "payment date: " . $payment->date );

Expand All @@ -93,6 +97,11 @@ sub waste_reconcile_direct_debits {

$self->log( "category: $category ($type)" );

if ( $params->{reference} && $params->{force_renewal} ) {
$self->log( "Overriding type $type to renew" );
$type = $self->waste_subscription_types->{Renew};

Check warning on line 102 in perllib/FixMyStreet/Roles/DDProcessor.pm

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/Roles/DDProcessor.pm#L101-L102

Added lines #L101 - L102 were not covered by tests
}

my ($uprn, $rs) = $self->_process_reference($payment->payer);
next unless $rs;
$rs = $rs->search({ category => 'Garden Subscription' });
Expand Down Expand Up @@ -206,6 +215,8 @@ sub waste_reconcile_direct_debits {
$payment = DDCancelPayment->new({ data => $payment, cobrand => $self });
next unless $payment->date;

next if $params->{reference} && $payment->payer ne $params->{reference};

$self->log("looking at payment " . $payment->payer);

my ($uprn, $rs) = $self->_process_reference($payment->payer);
Expand Down
32 changes: 32 additions & 0 deletions t/cobrand/bromley_waste.t
Original file line number Diff line number Diff line change
Expand Up @@ -1475,6 +1475,38 @@ subtest 'check direct debit reconcilliation' => sub {
$ad_hoc_skipped->discard_changes;
is $ad_hoc_skipped->state, 'unconfirmed', "ad hoc report not confirmed on second run";

warnings_are {
$c->waste_reconcile_direct_debits({ reference => $hidden_ref });
} [
"\n",
"looking at payment $hidden_ref\n",
"payment date: 16/03/2021\n",
"category: Garden Subscription (1)\n",
"extra query is {payerReference: $hidden_ref\n",
"is a new/ad hoc\n",
"looking at potential match " . $hidden->id . "\n",
"potential match is a dd payment\n",
"potential match type is 1\n",
"found matching report " . $hidden->id . " with state hidden\n",
"no matching record found for Garden Subscription payment with id $hidden_ref\n",
"done looking at payment $hidden_ref\n",
], "warns if given reference";

$hidden->update({ state => 'fixed - council' });
warnings_are {
$c->waste_reconcile_direct_debits({ reference => $hidden_ref, force_renewal => 1 });
} [
"\n",
"looking at payment $hidden_ref\n",
"payment date: 16/03/2021\n",
"category: Garden Subscription (1)\n",
"Overriding type 1 to renew\n",
"extra query is {payerReference: $hidden_ref\n",
"is a renewal\n",
"looking at potential match " . $hidden->id . " with state fixed - council\n",
"is a matching new report\n",
"no matching service to renew for $hidden_ref\n",
], "gets past the first stage if forced renewal";
};

};
Expand Down

0 comments on commit fd80da8

Please sign in to comment.