Skip to content

[Usage-based] Update credit prices, calculation, and Stripe product IDs #10801

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

Merged
merged 2 commits into from
Jun 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .werft/jobs/build/payment/stripe-configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ data:
config: >
{
"usageProductPriceIds": {
"EUR": "price_1LAyjSGadRXm50o3MO7CNyVU",
"USD": "price_1LAyjSGadRXm50o3tkwZe1N2"
"EUR": "price_1LD8cQGadRXm50o30QwBU9aY",
"USD": "price_1LD8cQGadRXm50o3ftnIiUZL"
}
}
4 changes: 3 additions & 1 deletion components/usage/pkg/stripe/stripe.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package stripe
import (
"encoding/json"
"fmt"
"math"
"os"
"strings"

Expand Down Expand Up @@ -111,6 +112,7 @@ func queriesForCustomersWithTeamIds(teamIds []string) []string {
}

// workspaceSecondsToCredits converts seconds (of workspace usage) into Stripe credits.
// (1 credit = 6 minutes, rounded up)
func workspaceSecondsToCredits(seconds int64) int64 {
return (seconds + 59) / 60
return int64(math.Ceil(float64(seconds) / (60 * 6)))
}
17 changes: 11 additions & 6 deletions components/usage/pkg/stripe/stripe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,20 +105,25 @@ func TestWorkspaceSecondsToCreditsCalcuation(t *testing.T) {
Seconds: 60,
ExpectedCredits: 1,
},
{
Name: "61 seconds",
Seconds: 61,
ExpectedCredits: 2,
},
{
Name: "90 seconds",
Seconds: 90,
ExpectedCredits: 1,
},
{
Name: "6 minutes",
Seconds: 360,
ExpectedCredits: 1,
},
{
Name: "6 minutes and 1 second",
Seconds: 361,
ExpectedCredits: 2,
},
{
Name: "1 hour",
Seconds: 3600,
ExpectedCredits: 60,
ExpectedCredits: 10,
},
}

Expand Down