Update examples

This commit is contained in:
Madison 2026-05-25 14:41:44 -05:00
parent 2e3fe8d7d2
commit 9aa8f2206a
3 changed files with 44 additions and 12 deletions

View File

@ -133,9 +133,20 @@ To sell a product, generate a checkout URL and redirect the user to it. The `cre
For team purchases, call `createCheckoutUrl` on the team object instead:
```typescript
const team = user.useTeam(teamId);
const checkoutUrl = await team.createCheckoutUrl({ productId });
```tsx
function TeamPurchaseButton({ teamId, productId }: { teamId: string, productId: string }) {
const user = useUser({ or: "redirect" });
const team = user.useTeam(teamId);
return (
<button onClick={async () => {
const checkoutUrl = await team.createCheckoutUrl({ productId });
window.location.href = checkoutUrl;
}}>
Purchase team plan
</button>
);
}
```
<Info>

View File

@ -126,10 +126,20 @@ export default function UpgradeButton() {
Team plans work the same way when you call the methods on a team object:
```typescript
const team = user.useTeam(teamId);
await team.switchSubscription({
fromProductId: "prod_team_pro",
toProductId: "prod_team_enterprise",
});
```tsx
function TeamUpgradeButton({ teamId }: { teamId: string }) {
const user = useUser({ or: "redirect" });
const team = user.useTeam(teamId);
return (
<button onClick={async () => {
await team.switchSubscription({
fromProductId: "prod_team_pro",
toProductId: "prod_team_enterprise",
});
}}>
Upgrade team plan
</button>
);
}
```

View File

@ -155,9 +155,20 @@ Generate a checkout URL from the user or team that will own the purchase:
For team purchases, call `createCheckoutUrl` on the team object:
```typescript
const team = user.useTeam(teamId);
const checkoutUrl = await team.createCheckoutUrl({ productId: "prod_team_plan" });
```tsx
function TeamPurchaseButton({ teamId }: { teamId: string }) {
const user = useUser({ or: "redirect" });
const team = user.useTeam(teamId);
return (
<button onClick={async () => {
const checkoutUrl = await team.createCheckoutUrl({ productId: "prod_team_plan" });
window.location.href = checkoutUrl;
}}>
Purchase team plan
</button>
);
}
```
<Info>