Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[usage] Handle customer.subscription.deletedevent from Stripe #13016

Merged
merged 5 commits into from
Sep 16, 2022

Conversation

svenefftinge
Copy link
Member

@svenefftinge svenefftinge commented Sep 15, 2022

Description

When a user cancels their subscription, we get an event from Stripe, which we need to handle in order to update our system.
This PR does

  • introduce CancelSubscription on usage-api
  • add handling for the customer.subscription.deleted event in public-api-server which calls CancelSubscription
  • implementation of CancelSubscription in usage.

Related Issue(s)

See #13010

How to test

Release Notes

NONE

Documentation

Werft options:

  • /werft with-preview
  • /werft with-payment

@werft-gitpod-dev-com
Copy link

started the job as gitpod-build-se-stripe-cancellation.1 because the annotations in the pull request description changed
(with .werft/ from main)

@svenefftinge svenefftinge changed the title Se/stripe-cancellation [usage] Update Cost Center on Stripe cancellation Sep 15, 2022
@svenefftinge svenefftinge added the team: webapp Issue belongs to the WebApp team label Sep 16, 2022
@roboquat roboquat added size/M and removed size/XXL labels Sep 16, 2022
@roboquat roboquat added size/XXL and removed size/M labels Sep 16, 2022
@svenefftinge svenefftinge changed the title [usage] Update Cost Center on Stripe cancellation [usage] Handle customer.subscription.deletedevent form Stripe Sep 16, 2022
@svenefftinge svenefftinge changed the title [usage] Handle customer.subscription.deletedevent form Stripe [usage] Handle customer.subscription.deletedevent from Stripe Sep 16, 2022
Copy link
Member

@easyCZ easyCZ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM in general. Left a couple of comments around readability

/hold

@@ -244,6 +245,19 @@ func (c *Client) GetInvoice(ctx context.Context, invoiceID string) (*stripe.Invo
return invoice, nil
}

func (c *Client) GetAttributionIdForSubscriptionId(ctx context.Context, subscriptionID string) (db.AttributionID, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 135 to 147
// we don't manage stripe billing cycle
costCenter.NextBillingTime = VarcharTime{}
} else if costCenter.BillingStrategy == CostCenter_Other {
// cancelled from stripe reset the spending limit
if costCenter.ID.IsEntity(AttributionEntity_Team) {
costCenter.SpendingLimit = c.cfg.ForTeams
} else {
costCenter.SpendingLimit = c.cfg.ForUsers
}
// see you next month
costCenter.NextBillingTime = NewVarcharTime(now.AddDate(0, 1, 0))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the individual field assignment into a CostCenter object really hurts readability here. The alternative approach is to construct the CostCenter in each branch seperately (with some possible duplication) but making it very explicit what each branch will result in.

Comment on lines +26 to +29
invoiceUpdatedEventType = "invoice.updated"
invoiceFinalizedEventType = "invoice.finalized"
customerCreatedEventType = "customer.created"
customerSubscriptionDeleted = "customer.subscription.deleted"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might make sense to move these as consts in the stripe.go file and re-use in tests

@svenefftinge svenefftinge force-pushed the se/stripe-cancellation branch 3 times, most recently from 1bb1ab3 to be4ee50 Compare September 16, 2022 09:48
@svenefftinge svenefftinge marked this pull request as ready for review September 16, 2022 14:21
@svenefftinge svenefftinge requested a review from a team September 16, 2022 14:21
@svenefftinge
Copy link
Member Author

/unhold

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deployed: webapp Meta team change is running in production deployed Change is completely running in production release-note-none size/XXL team: webapp Issue belongs to the WebApp team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants