Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 3 commits
  • 7 files changed
  • 0 commit comments
  • 1 contributor
21 lib/Moonpig/Role/Consumer/ByTime.pm
View
@@ -289,21 +289,21 @@ sub _predicted_shortfall {
my $funds = $self->expected_funds({ include_unpaid_charges => 1 });
# Next, figure out how long that money will last us.
- my $estimated_remaining_funded_lifetime =
- $self->_estimated_remaining_funded_lifetime({ amount => $funds,
- ignore_partial_charge_periods => 0,
- });
+ my $erfl = $self->_estimated_remaining_funded_lifetime({
+ amount => $funds,
+ ignore_partial_charge_periods => 0,
+ });
# Next, figure out long we think it *should* last us.
my $want_to_live = $self->want_to_live;
- my $shortfall = $want_to_live - $estimated_remaining_funded_lifetime;
+ my $shortfall = $want_to_live - $erfl;
return $shortfall;
}
sub _replacement_chain_expiration_date {
my ($self, $opts) = @_;
- $opts->{include_expected_funds} //= 0;
+
$opts->{ignore_partial_charge_periods} //= 1;
return($self->expiration_date +
@@ -313,7 +313,7 @@ sub _replacement_chain_expiration_date {
sub _replacement_chain_lifetime {
my ($self, $_opts) = @_;
my $opts = { %$_opts };
- $opts->{include_expected_funds} //= 0;
+ $opts->{include_unpaid_charges} //= 0;
my @chain = $self->replacement_chain;
@@ -330,7 +330,7 @@ sub _replacement_chain_lifetime {
return (sumof {
$_->_estimated_remaining_funded_lifetime({
amount => $_->expected_funds({
- include_unpaid_charges => $opts->{include_expected_funds},
+ include_unpaid_charges => $opts->{include_unpaid_charges},
}),
ignore_partial_charge_periods => 1,
})
@@ -359,7 +359,8 @@ sub _estimated_remaining_funded_lifetime {
Moonpig::X->throw("can't compute remaining lifetime on inactive consumer")
if $args->{must_be_active} && ! $self->is_active;
- my $each_charge = $self->calculate_total_charge_amount_on( Moonpig->env->now ) + $charge_adjustment;
+ my $each_charge = $self->calculate_total_charge_amount_on( Moonpig->env->now )
+ + $charge_adjustment;
Moonpig::X->throw("can't compute funded lifetime of negative-cost consumer")
if $each_charge < 0;
@@ -425,7 +426,7 @@ sub _maybe_send_psync_quote {
# NEW date is the one caused by the service upgrade, which will
# PERSIST if the user DOES NOT pay the invoice
new_expiration_date => $self->replacement_chain_expiration_date({
- include_expected_funds => 1,
+ include_unpaid_charges => 1,
}),
};
2  lib/Moonpig/Role/Consumer/ByUsage.pm
View
@@ -185,7 +185,7 @@ sub _replacement_chain_expiration_date {
my $amount = sumof {
$_->expected_funds({
- include_unpaid_charges => $opt->{include_expected_funds}
+ include_unpaid_charges => $opt->{include_unpaid_charges}
});
} ($self, @chain);
2  lib/Moonpig/Role/Consumer/FixedExpiration.pm
View
@@ -87,7 +87,7 @@ sub _replacement_chain_expiration_date {
= $exp_date + $consumer->_estimated_remaining_funded_lifetime(
{
amount => $consumer->expected_funds({
- include_unpaid_charges => $arg->{include_expected_funds},
+ include_unpaid_charges => $arg->{include_unpaid_charges},
}),
ignore_partial_charge_periods => 1,
}
6 lib/Moonpig/Role/Consumer/PredictsExpiration.pm
View
@@ -20,7 +20,7 @@ requires 'expiration_date'; # Time, predicted exp date
publish replacement_chain_expiration_date => {
-http_method => 'get',
- include_expected_funds => OptionalStickBool,
+ include_unpaid_charges => OptionalStickBool,
} => sub {
my ($self, $_opts) = @_;
my $opts = { %$_opts };
@@ -30,6 +30,8 @@ publish replacement_chain_expiration_date => {
Moonpig::X->throw("can't compute chain expiration date for non-head");
}
+ $opts->{include_unpaid_charges} //= 0;
+
return $self->_replacement_chain_expiration_date($opts);
};
@@ -41,7 +43,7 @@ PARTIAL_PACK {
return try {
return { } unless $self->is_active;
my $exp_date = $self->replacement_chain_expiration_date({
- include_expected_funds => 0,
+ include_unpaid_charges => 0,
});
return { replacement_chain_expiration_date => $exp_date };
} catch {
2  t/consumer/b5g1.t
View
@@ -102,7 +102,7 @@ test 'signup for five, get one free' => sub {
{
my ($head) = $ledger->active_consumers;
my $exp = $head->replacement_chain_expiration_date({
- include_expected_funds => 0,
+ include_unpaid_charges => 0,
});
my $days = ($exp - $head->activated_at) / 86_400;
4 t/consumer/predicts_expiration.t
View
@@ -33,9 +33,9 @@ test "replacement_chain_expiration_date" => sub {
is($d->expected_funds({include_unpaid_charges => 1}),
dollars(100), "d has \$100 unpaid charges");
};
- is($c->replacement_chain_expiration_date({ include_expected_funds => 0 }),
+ is($c->replacement_chain_expiration_date({ include_unpaid_charges => 0 }),
jan(3), "chain will expire on Jan 3 unless charges are paid");
- is($c->replacement_chain_expiration_date({ include_expected_funds => 1 }),
+ is($c->replacement_chain_expiration_date({ include_unpaid_charges => 1 }),
jan(5), "chain will expire on Jan 5 if charges are paid");
});
};
6 t/web/import.t
View
@@ -67,7 +67,7 @@ test "import a ledger via the web" => sub {
ok($guid, "created ledger via post ($guid)");
my $consumer_guid = $result->{active_xids}{$xid}{guid};
- my $url = sprintf '/ledger/by-guid/%s/consumers/guid/%s/%s?include_expected_funds=0',
+ my $url = sprintf '/ledger/by-guid/%s/consumers/guid/%s/%s?include_unpaid_charges=0',
$guid,
$consumer_guid,
'replacement_chain_expiration_date';
@@ -103,7 +103,7 @@ test "import a ledger via the web" => sub {
# the round_up option to ignore_partial_charge_periods as per 20120605
# comments elsewhere.
my $exp_date = $consumers[0]->replacement_chain_expiration_date(
- { include_expected_funds => 0 });
+ { include_unpaid_charges => 0 });
cmp_ok(
abs($exp_date - $expected_expiration_date), '<', 86_400,
@@ -131,7 +131,7 @@ test "import a ledger via the web" => sub {
sub {
my ($ledger) = @_;
my $exp_date = ($ledger->active_consumers)[0]
- ->replacement_chain_expiration_date({ include_expected_funds => 0 });
+ ->replacement_chain_expiration_date({ include_unpaid_charges => 0 });
my $last = $ledger->consumer_collection->find_by_guid({ guid => $consumer_guid });
$last = $last->replacement while $last->has_replacement;

No commit comments for this range

Something went wrong with that request. Please try again.