payments/stripe: Remove apply coupon from generate invoice command

Remove the command to apply free tier coupons from the generate invoices
command. Applying free tier coupons should instead be done outside the
normal time window for invoice generation to save time during the
invoicing cycle.

Change-Id: If8fecc558411d5a6fff9d5689143d72f3b709e55
This commit is contained in:
dlamarmorgan 2023-04-25 08:48:17 -07:00
parent 3cd79d987d
commit b89e0e0272
2 changed files with 6 additions and 17 deletions

View File

@ -828,9 +828,9 @@ func (service *Service) CreateBalanceInvoiceItems(ctx context.Context) (err erro
return errGrp.Err()
}
// GenerateInvoices performs all tasks necessary to generate Stripe invoices.
// This is equivalent to invoking ApplyFreeTierCoupons, PrepareInvoiceProjectRecords,
// InvoiceApplyProjectRecords, and CreateInvoices in order.
// GenerateInvoices performs tasks necessary to generate Stripe invoices.
// This is equivalent to invoking PrepareInvoiceProjectRecords, InvoiceApplyProjectRecords,
// and CreateInvoices in order.
func (service *Service) GenerateInvoices(ctx context.Context, period time.Time) (err error) {
defer mon.Task()(&ctx)(&err)
@ -838,9 +838,6 @@ func (service *Service) GenerateInvoices(ctx context.Context, period time.Time)
Description string
Exec func(context.Context, time.Time) error
}{
{"Applying free tier coupons", func(ctx context.Context, _ time.Time) error {
return service.ApplyFreeTierCoupons(ctx)
}},
{"Preparing invoice project records", service.PrepareInvoiceProjectRecords},
{"Applying invoice project records", service.InvoiceApplyProjectRecords},
{"Creating invoices", service.CreateInvoices},

View File

@ -520,17 +520,6 @@ func TestService_GenerateInvoice(t *testing.T) {
require.NoError(t, payments.StripeService.GenerateInvoices(ctx, start))
// ensure free tier coupon was applied
cusID, err := satellite.DB.StripeCoinPayments().Customers().GetCustomerID(ctx, user.ID)
require.NoError(t, err)
params := &stripe.CustomerParams{Params: stripe.Params{Context: ctx}}
stripeUser, err := payments.StripeClient.Customers().Get(cusID, params)
require.NoError(t, err)
require.NotNil(t, stripeUser.Discount)
require.NotNil(t, stripeUser.Discount.Coupon)
require.Equal(t, payments.StripeService.StripeFreeTierCouponID, stripeUser.Discount.Coupon.ID)
// ensure project record was generated
err = satellite.DB.StripeCoinPayments().ProjectRecords().Check(ctx, proj.ID, start, end)
require.ErrorIs(t, stripe1.ErrProjectRecordExists, err)
@ -539,6 +528,9 @@ func TestService_GenerateInvoice(t *testing.T) {
require.NotNil(t, rec)
require.NoError(t, err)
// validate generated invoices
cusID, err := satellite.DB.StripeCoinPayments().Customers().GetCustomerID(ctx, user.ID)
require.NoError(t, err)
invoice, hasInvoice := getCustomerInvoice(ctx, payments.StripeClient, cusID)
invoiceItems := getCustomerInvoiceItems(ctx, payments.StripeClient, cusID)