Skip to content

Commit

Permalink
[Bromley] Add DD option to renew when no service.
Browse files Browse the repository at this point in the history
Sometimes we get a renewal through but there's no matching service in
the backend. Add an option to push it through with the given quantity.
  • Loading branch information
dracos committed May 3, 2024
1 parent c34f2ee commit 9b81dd6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
2 changes: 2 additions & 0 deletions bin/fixmystreet.com/waste-reconcile-dd
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ my ($opts, $usage) = describe_options(
['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'],
['force-when-missing:i', 'when run with --reference, force a renewal even if no matching service, with this quantity'],
);
$usage->die if $opts->help;
$usage->die unless $opts->cobrand;
Expand All @@ -29,4 +30,5 @@ $cobrand->waste_reconcile_direct_debits({
verbose => $opts->verbose,
reference => $opts->reference,
force_renewal => $opts->force_renewal,
force_when_missing => $opts->force_when_missing,
});
18 changes: 12 additions & 6 deletions perllib/FixMyStreet/Roles/DDProcessor.pm
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ has date => ( is => 'lazy', default => sub { $_[0]->data->{$_[0]->cobrand->payme
has status => ( is => 'lazy', default => sub { $_[0]->data->{$_[0]->cobrand->statusField} } );
has type => ( is => 'lazy', default => sub { $_[0]->data->{$_[0]->cobrand->paymentTypeField} } );
has oneOffRef => ( is => 'lazy', default => sub { $_[0]->data->{$_[0]->cobrand->oneOffReferenceField} } );
has amount => ( is => 'lazy', default => sub { $_[0]->data->{Amount} } );

package DDCancelPayment;
use Moo;
Expand All @@ -19,6 +20,7 @@ has date => ( is => 'lazy', default => sub { $_[0]->data->{$_[0]->cobrand->cance

package FixMyStreet::Roles::DDProcessor;

use utf8;
use Moo::Role;
use Utils;
use JSON::MaybeXS;
Expand Down Expand Up @@ -86,8 +88,7 @@ sub waste_reconcile_direct_debits {
# 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 );
$self->log( "looking at payment " . $payment->payer . " for £" . $payment->amount . " on " . $payment->date );

next unless $self->waste_dd_paid($payment->date);
next unless $payment->status eq $self->paymentTakenCode;
Expand Down Expand Up @@ -147,12 +148,17 @@ sub waste_reconcile_direct_debits {
}
if ( $p ) {
my $service = $self->waste_get_current_garden_sub( $p->get_extra_field_value('property_id') );
unless ($service) {
my $quantity;
if ($service) {
$quantity = $self->waste_get_sub_quantity($service);
} elsif ($params->{reference} && $params->{force_when_missing}) {
$quantity = $params->{force_when_missing};
} else {
$self->log("no matching service to renew for " . $payment->payer);
$self->output_log(1);
next;
}
my $renew = $self->_duplicate_waste_report($p, $uprn, $service, $payment, $dry_run);
my $renew = $self->_duplicate_waste_report($p, $uprn, $quantity, $payment, $dry_run);
$handled = $dry_run ? 1 : $renew->id;
}
# this covers new subscriptions and ad-hoc payments, both of which already have
Expand Down Expand Up @@ -284,12 +290,12 @@ sub _report_matches_payment {
}

sub _duplicate_waste_report {
my ($self, $report, $uprn, $service, $payment, $dry_run) = @_;
my ($self, $report, $uprn, $quantity, $payment, $dry_run) = @_;

my $extra = {
$self->garden_subscription_type_field => $self->waste_subscription_types->{Renew},
uprn => $uprn,
Subscription_Details_Quantity => $self->waste_get_sub_quantity($service),
Subscription_Details_Quantity => $quantity,
LastPayMethod => $self->bin_payment_types->{direct_debit},
PaymentCode => $payment->payer,
payment_method => 'direct_debit',
Expand Down
26 changes: 12 additions & 14 deletions t/cobrand/bromley_waste.t
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use utf8;
use CGI::Simple;
use JSON::MaybeXS;
use Test::MockModule;
Expand Down Expand Up @@ -1421,15 +1422,13 @@ subtest 'check direct debit reconcilliation' => sub {

my $warnings = [
"\n",
"looking at payment GGW554321\n",
"payment date: 16/03/2021\n",
"looking at payment GGW554321 for £10 on 16/03/2021\n",
"category: Garden Subscription (1)\n",
"is a new/ad hoc\n",
"no matching record found for Garden Subscription payment with id GGW554321\n",
"done looking at payment GGW554321\n",
"\n",
"looking at payment $hidden_ref\n",
"payment date: 16/03/2021\n",
"looking at payment $hidden_ref for £10 on 16/03/2021\n",
"category: Garden Subscription (1)\n",
"extra query is {payerReference: $hidden_ref\n",
"is a new/ad hoc\n",
Expand All @@ -1440,24 +1439,21 @@ subtest 'check direct debit reconcilliation' => sub {
"no matching record found for Garden Subscription payment with id $hidden_ref\n",
"done looking at payment $hidden_ref\n",
"\n",
"looking at payment $renewal_nothing_in_echo_ref\n",
"payment date: 16/03/2021\n",
"looking at payment $renewal_nothing_in_echo_ref for £10 on 16/03/2021\n",
"category: Garden Subscription (2)\n",
"extra query is {payerReference: $renewal_nothing_in_echo_ref\n",
"is a renewal\n",
"looking at potential match " . $renewal_nothing_in_echo->id . " with state confirmed\n",
"is a matching new report\n",
"no matching service to renew for $renewal_nothing_in_echo_ref\n",
"\n",
"looking at payment GGW854324\n",
"payment date: 16/03/2021\n",
"looking at payment GGW854324 for £10 on 16/03/2021\n",
"category: Garden Subscription (2)\n",
"is a renewal\n",
"no matching record found for Garden Subscription payment with id GGW854324\n",
"done looking at payment GGW854324\n",
"\n",
"looking at payment $ad_hoc_skipped_ref\n",
"payment date: 16/03/2021\n",
"looking at payment $ad_hoc_skipped_ref for £10 on 16/03/2021\n",
"category: Garden Subscription (1)\n",
"extra query is {payerReference: $ad_hoc_skipped_ref\n",
"is a new/ad hoc\n",
Expand Down Expand Up @@ -1628,8 +1624,7 @@ subtest 'check direct debit reconcilliation' => sub {
$c->waste_reconcile_direct_debits({ reference => $hidden_ref });
} [
"\n",
"looking at payment $hidden_ref\n",
"payment date: 16/03/2021\n",
"looking at payment $hidden_ref for £10 on 16/03/2021\n",
"category: Garden Subscription (1)\n",
"extra query is {payerReference: $hidden_ref\n",
"is a new/ad hoc\n",
Expand All @@ -1646,8 +1641,7 @@ subtest 'check direct debit reconcilliation' => sub {
$c->waste_reconcile_direct_debits({ reference => $hidden_ref, force_renewal => 1 });
} [
"\n",
"looking at payment $hidden_ref\n",
"payment date: 16/03/2021\n",
"looking at payment $hidden_ref for £10 on 16/03/2021\n",
"category: Garden Subscription (1)\n",
"Overriding type 1 to renew\n",
"extra query is {payerReference: $hidden_ref\n",
Expand All @@ -1656,6 +1650,10 @@ subtest 'check direct debit reconcilliation' => sub {
"is a matching new report\n",
"no matching service to renew for $hidden_ref\n",
], "gets past the first stage if forced renewal";

stdout_like {
$c->waste_reconcile_direct_debits({ reference => $renewal_nothing_in_echo_ref, force_when_missing => 1, verbose => 1 });
} qr/looking at payment $renewal_nothing_in_echo_ref for £10 on 16\/03\/2021.*?category: Garden Subscription \(2\).*?is a renewal.*?looking at potential match @{[$renewal_nothing_in_echo->id]}.*?is a matching new report.*?created new confirmed report.*?done looking at payment/s, "creates a renewal if forced to";
};

};
Expand Down

0 comments on commit 9b81dd6

Please sign in to comment.