Skip to content

Commit

Permalink
fix stripe pricing updates (highlight#7252)
Browse files Browse the repository at this point in the history
## Summary

Fixes two issues
* Plans on non-3-month session retention would apply the session
retention to traces / logs, failing to find a price
* Plans manually subscribed from the startup discount would have a
different product ordering, failing to find the base product.

![Screenshot from 2023-11-30
17-10-18](https://github.com/highlight/highlight/assets/1351531/68821fc5-b1a2-4b6a-a997-7492741f84fe)


## How did you test this change?

Locally testing with stripe test mode.

## Are there any deployment considerations?

No

## Does this work require review from our design team?

No
  • Loading branch information
Vadman97 authored Dec 1, 2023
1 parent 6297549 commit f1983a7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/turbo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
branches: ['main']
pull_request:
types: [opened, reopened, synchronize, assigned, review_requested]
types: [opened, synchronize]

concurrency: ${{ github.workflow }}-${{ github.ref }}
jobs:
Expand Down
17 changes: 13 additions & 4 deletions backend/pricing/pricing.go
Original file line number Diff line number Diff line change
Expand Up @@ -685,8 +685,9 @@ func GetStripePrices(stripeClient *client.API, workspace *model.Workspace, produ
membersLookupKey := string(model.PricingProductTypeMembers)
sessionsLookupKey := GetOverageKey(model.PricingProductTypeSessions, rp, productTier)
errorsLookupKey := GetOverageKey(model.PricingProductTypeErrors, rp, productTier)
logsLookupKey := GetOverageKey(model.PricingProductTypeLogs, rp, productTier)
tracesLookupKey := GetOverageKey(model.PricingProductTypeTraces, rp, productTier)
// logs and traces are only available with three month retention
logsLookupKey := GetOverageKey(model.PricingProductTypeLogs, backend.RetentionPeriodThreeMonths, productTier)
tracesLookupKey := GetOverageKey(model.PricingProductTypeTraces, backend.RetentionPeriodThreeMonths, productTier)

priceListParams := stripe.PriceListParams{}
priceListParams.LookupKeys = []*string{&baseLookupKey, &sessionsLookupKey, &membersLookupKey, &errorsLookupKey, &logsLookupKey, &tracesLookupKey}
Expand Down Expand Up @@ -831,8 +832,16 @@ func (w *Worker) reportUsage(ctx context.Context, workspaceID int, productType *
})) != 1 {
return e.New("STRIPE_INTEGRATION_ERROR cannot report usage - subscription has multiple products")
}
subscriptionItem := subscription.Items.Data[0]
_, productTier, _, interval, _ := GetProductMetadata(subscriptionItem.Price)

baseProductItem, ok := lo.Find(subscription.Items.Data, func(item *stripe.SubscriptionItem) bool {
_, ok := item.Price.Product.Metadata[highlightProductType]
return ok
})
if !ok {
return e.New("STRIPE_INTEGRATION_ERROR cannot report usage - cannot find base product")
}

_, productTier, _, interval, _ := GetProductMetadata(baseProductItem.Price)
if productTier == nil {
return e.New("STRIPE_INTEGRATION_ERROR cannot report usage - product has no tier")
}
Expand Down

0 comments on commit f1983a7

Please sign in to comment.