From b89e0e0272b1a1bd73d374212d17f71e31bbf781 Mon Sep 17 00:00:00 2001 From: dlamarmorgan Date: Tue, 25 Apr 2023 08:48:17 -0700 Subject: [PATCH] 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 --- satellite/payments/stripe/service.go | 9 +++------ satellite/payments/stripe/service_test.go | 14 +++----------- 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/satellite/payments/stripe/service.go b/satellite/payments/stripe/service.go index d8f430d17..8c64a0677 100644 --- a/satellite/payments/stripe/service.go +++ b/satellite/payments/stripe/service.go @@ -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}, diff --git a/satellite/payments/stripe/service_test.go b/satellite/payments/stripe/service_test.go index 06ea1f0f7..7d2fc1f9a 100644 --- a/satellite/payments/stripe/service_test.go +++ b/satellite/payments/stripe/service_test.go @@ -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)