Skip to content

Feat improved billing #1742

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Feat improved billing #1742

wants to merge 6 commits into from

Conversation

grutt
Copy link
Contributor

@grutt grutt commented May 16, 2025

Description

Improvements for usage based billing

Copy link

vercel bot commented May 16, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
hatchet-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 16, 2025 10:03pm
hatchet-v0-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 16, 2025 10:03pm

}),
queryClient.invalidateQueries({
queryKey: ['billing:*'],
queryKey: ['*'],
Copy link
Contributor Author

@grutt grutt May 16, 2025

Choose a reason for hiding this comment

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

@mrkaye97 heads up this doesnt work 🤷

Copy link
Contributor

Choose a reason for hiding this comment

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

which part of it? the wildcard? if yes, I don't think I'd expect it to, there's nothing on this in the docs AFAICT

Copy link
Contributor Author

Choose a reason for hiding this comment

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

interesting... ok then this is a gabe hallucination and not an llm one -- i could have sworn it supported wildcard query keys

Copy link
Contributor

Choose a reason for hiding this comment

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

heh yeah I'm not sure, I thought I'd seen them before too but I was looking in the docs and couldn't find anything. I think maybe the right thing would be to split up the query keys into e.g. ['billing', 'foo'], ['billing', 'bar'], .. and then use 'billing' as the key to invalidate? idk

@@ -85,6 +94,23 @@ func (r *tenantAPIRepository) CreateTenant(ctx context.Context, opts *repository
return nil, err
}

if user != nil {
// add the user as an owner of the tenant
_, err = r.CreateTenantMember(ctx, tenantId, &repository.CreateTenantMemberOpts{
Copy link
Contributor Author

Choose a reason for hiding this comment

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

it makes more sense to me to create a tenant owner on create, without this the hook is racy

Copy link
Contributor

@mrkaye97 mrkaye97 left a comment

Choose a reason for hiding this comment

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

left some comments / questions!

Comment on lines +56 to +58
useEffect(() => {
setShowAnnual(active?.period?.includes('yearly') || false);
}, [active]);
Copy link
Contributor

Choose a reason for hiding this comment

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

I know this was just moved up from below, but I'd think we could get rid of this effect hook and use derived state?

const showAnnual = active?.period?.includes("yearly") || false

@@ -80,7 +80,7 @@ export function PaymentMethods({
<Icon size={24} />
{method.brand.toUpperCase()}
{method.last4 && ` *** *** ${method.last4} `}
{method.expiration && `(Expires {method.expiration})`}
Copy link
Contributor

Choose a reason for hiding this comment

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

😬

Comment on lines +56 to +59
useEffect(() => {
setShowAnnual(active?.period?.includes('yearly') || false);
}, [active]);

Copy link
Contributor

Choose a reason for hiding this comment

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

same here re: derived state

}),
queryClient.invalidateQueries({
queryKey: ['billing:*'],
queryKey: ['*'],
Copy link
Contributor

Choose a reason for hiding this comment

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

which part of it? the wildcard? if yes, I don't think I'd expect it to, there's nothing on this in the docs AFAICT

Comment on lines +20 to +32
let adjusted = priceCents;
for (const coupon of coupons) {
if (coupon.percent) {
adjusted = Math.round(adjusted * (1 - coupon.percent / 100));
}
}

// Then apply fixed-amount coupons
for (const coupon of coupons) {
if (coupon.amount_cents) {
adjusted = Math.max(0, adjusted - coupon.amount_cents);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

would be great to use reduce for these IMO

Comment on lines +39 to +45
func (r *tenantAPIRepository) RegisterCreateCallback(callback repository.UnscopedCallback[*dbsqlc.Tenant]) {
if r.createCallbacks == nil {
r.createCallbacks = make([]repository.UnscopedCallback[*dbsqlc.Tenant], 0)
}

r.createCallbacks = append(r.createCallbacks, callback)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

O_O does Go allow this? Haven't seen this pattern before so I'm curious about it, since this feels a lot more like Java getter/setter patterns to me than Go's no-class approach to things

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants