satellite/{console,accountfreeze}: reduce payment retries
This change limits payment attempts to 1. Card updates when billing frozen/warned 2. Right before billing freezing a warned account. Issue: https://github.com/storj/storj-private/issues/457 Change-Id: Ic6d5c649cdac38d5c3b7365e20a4ceb3b6199ee8
This commit is contained in:
parent
6d03b92ea6
commit
32b7b80666
@ -174,6 +174,10 @@ func (p *Payments) triggerAttemptPayment(ctx context.Context) (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
if freezes.BillingFreeze == nil && freezes.BillingWarning == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
err = p.service.Payments().AttemptPayOverdueInvoices(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -194,29 +194,6 @@ func (chore *Chore) attemptBillingFreezeWarn(ctx context.Context) {
|
||||
continue
|
||||
}
|
||||
|
||||
// try to pay the invoice before freezing/warning.
|
||||
err = chore.payments.Invoices().AttemptPayOverdueInvoices(ctx, userID)
|
||||
if err == nil {
|
||||
infoLog("Ignoring invoice; Payment attempt successful")
|
||||
|
||||
if freezes.BillingWarning != nil {
|
||||
err = chore.freezeService.BillingUnWarnUser(ctx, userID)
|
||||
if err != nil {
|
||||
errorLog("Could not remove billing warning event", err)
|
||||
}
|
||||
}
|
||||
if freezes.BillingFreeze != nil {
|
||||
err = chore.freezeService.BillingUnfreezeUser(ctx, userID)
|
||||
if err != nil {
|
||||
errorLog("Could not remove billing freeze event", err)
|
||||
}
|
||||
}
|
||||
|
||||
continue
|
||||
} else {
|
||||
errorLog("Could not attempt payment", err)
|
||||
}
|
||||
|
||||
if freezes.BillingFreeze != nil {
|
||||
if chore.nowFn().Sub(freezes.BillingFreeze.CreatedAt) > chore.config.BillingFreezeGracePeriod {
|
||||
if user.Status == console.PendingDeletion {
|
||||
@ -284,6 +261,22 @@ func (chore *Chore) attemptBillingFreezeWarn(ctx context.Context) {
|
||||
infoLog("Ignoring invoice; payment already made")
|
||||
continue
|
||||
}
|
||||
|
||||
// try to pay the invoice before freezing.
|
||||
err = chore.payments.Invoices().AttemptPayOverdueInvoices(ctx, userID)
|
||||
if err == nil {
|
||||
infoLog("Ignoring invoice; Payment attempt successful")
|
||||
|
||||
err = chore.freezeService.BillingUnWarnUser(ctx, userID)
|
||||
if err != nil {
|
||||
errorLog("Could not remove billing warning event", err)
|
||||
}
|
||||
|
||||
continue
|
||||
} else {
|
||||
errorLog("Could not attempt payment", err)
|
||||
}
|
||||
|
||||
err = chore.freezeService.BillingFreezeUser(ctx, userID)
|
||||
if err != nil {
|
||||
errorLog("Could not billing freeze account", err)
|
||||
@ -368,11 +361,6 @@ func (chore *Chore) attemptBillingUnfreezeUnwarn(ctx context.Context) {
|
||||
continue
|
||||
}
|
||||
if len(invoices) > 0 {
|
||||
// try to pay the invoices.
|
||||
err = chore.payments.Invoices().AttemptPayOverdueInvoices(ctx, event.UserID)
|
||||
if err != nil {
|
||||
errorLog("Could not attempt payment", err)
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -328,12 +328,24 @@ func TestAutoFreezeChore(t *testing.T) {
|
||||
|
||||
chore.Loop.TriggerWait()
|
||||
|
||||
freezes, err := service.GetAll(ctx, user.ID)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, freezes.BillingWarning)
|
||||
require.Nil(t, freezes.BillingFreeze)
|
||||
require.Nil(t, freezes.ViolationFreeze)
|
||||
|
||||
chore.TestSetNow(func() time.Time {
|
||||
// current date is now after billing warn grace period
|
||||
return time.Now().AddDate(0, 0, 50)
|
||||
})
|
||||
chore.Loop.TriggerWait()
|
||||
|
||||
// Payment should have succeeded in the chore.
|
||||
failed, err = invoicesDB.ListFailed(ctx, nil)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 0, len(failed))
|
||||
|
||||
freezes, err := service.GetAll(ctx, user.ID)
|
||||
freezes, err = service.GetAll(ctx, user.ID)
|
||||
require.NoError(t, err)
|
||||
require.Nil(t, freezes.BillingWarning)
|
||||
require.Nil(t, freezes.BillingFreeze)
|
||||
|
Loading…
Reference in New Issue
Block a user