Skip to content

Commit 3224ece

Browse files
committed
[stripe] When creating a Subscription, don't specify a custom billing cycle anchor date - let it go from date to date instead
1 parent 2dfe73d commit 3224ece

File tree

3 files changed

+0
-22
lines changed

3 files changed

+0
-22
lines changed

components/server/ee/src/user/stripe-service.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,12 @@ export class StripeService {
154154
taxInformation: customer.tax,
155155
});
156156
}
157-
const startOfNextMonth = new Date(new Date().toISOString().slice(0, 7) + "-01"); // First day of this month (YYYY-MM-01)
158-
startOfNextMonth.setMonth(startOfNextMonth.getMonth() + 1); // Add one month
159157

160158
await reportStripeOutcome("subscriptions_create", () => {
161159
return this.getStripe().subscriptions.create({
162160
customer: customer.id,
163161
items: [{ price: priceId }],
164162
automatic_tax: { enabled: isAutomaticTaxSupported },
165-
billing_cycle_anchor: Math.round(startOfNextMonth.getTime() / 1000),
166163
});
167164
});
168165
}

components/usage/pkg/stripe/stripe.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,6 @@ func (c *Client) CreateSubscription(ctx context.Context, customerID string, pric
338338
return nil, fmt.Errorf("no priceID specified")
339339
}
340340

341-
startOfNextMonth := getStartOfNextMonth(time.Now())
342-
343341
params := &stripe.SubscriptionParams{
344342
Customer: stripe.String(customerID),
345343
Items: []*stripe.SubscriptionItemsParams{
@@ -350,7 +348,6 @@ func (c *Client) CreateSubscription(ctx context.Context, customerID string, pric
350348
AutomaticTax: &stripe.SubscriptionAutomaticTaxParams{
351349
Enabled: stripe.Bool(isAutomaticTaxSupported),
352350
},
353-
BillingCycleAnchor: stripe.Int64(startOfNextMonth.Unix()),
354351
}
355352

356353
subscription, err := c.sc.Subscriptions.New(params)
@@ -361,15 +358,6 @@ func (c *Client) CreateSubscription(ctx context.Context, customerID string, pric
361358
return subscription, err
362359
}
363360

364-
func getStartOfNextMonth(t time.Time) time.Time {
365-
currentYear, currentMonth, _ := t.Date()
366-
367-
firstOfMonth := time.Date(currentYear, currentMonth, 1, 0, 0, 0, 0, time.UTC)
368-
startOfNextMonth := firstOfMonth.AddDate(0, 1, 0)
369-
370-
return startOfNextMonth
371-
}
372-
373361
func (c *Client) SetDefaultPaymentForCustomer(ctx context.Context, customerID string, setupIntentId string) (*stripe.Customer, error) {
374362
if customerID == "" {
375363
return nil, fmt.Errorf("no customerID specified")

components/usage/pkg/stripe/stripe_test.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ package stripe
77
import (
88
"fmt"
99
"testing"
10-
"time"
1110

1211
"github.com/gitpod-io/gitpod/usage/pkg/db"
1312

@@ -91,9 +90,3 @@ func TestCustomerQueriesForTeamIds_MultipleQueries(t *testing.T) {
9190
})
9291
}
9392
}
94-
95-
func TestStartOfNextMonth(t *testing.T) {
96-
ts := time.Date(2022, 10, 1, 0, 0, 0, 0, time.UTC)
97-
98-
require.Equal(t, time.Date(2022, 11, 1, 0, 0, 0, 0, time.UTC), getStartOfNextMonth(ts))
99-
}

0 commit comments

Comments
 (0)