Skip to content
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
18 changes: 0 additions & 18 deletions .github/workflows/dependency-review.yml

This file was deleted.

2 changes: 1 addition & 1 deletion agent
Submodule agent updated from 52ea16 to 2f4d61
65 changes: 47 additions & 18 deletions app/dashboard/new/actions/create-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,30 +39,52 @@ export type CreateServerResult =
* Get or create a Stripe Price for a given server type and monthly GBP pence amount.
* Uses a stable lookup_key so repeated calls are idempotent.
*/
const getOrCreateStripePrice = async (
const getOrCreateStripePrices = async (
stripe: Stripe,
serverTypeName: string,
pricePerMonthCents: number
): Promise<string> => {
const lookupKey = `nodebyte-${serverTypeName.toLowerCase()}-monthly`;
const existing = await stripe.prices.list({ lookup_keys: [lookupKey] });
if (existing.data.length > 0) {
return existing.data[0].id;
): Promise<{
introductoryPriceId: string;
usageSubscriptionPriceId: string;
}> => {
const priceKey = `nodebyte-${serverTypeName.toLowerCase()}-${pricePerMonthCents}`;
const [introductoryPrices, usagePrices] = await Promise.all([
stripe.prices.list({ lookup_keys: [`${priceKey}-first-month`] }),
stripe.prices.list({ lookup_keys: [`${priceKey}-usage-base`] }),
]);
if (introductoryPrices.data[0] && usagePrices.data[0]) {
return {
introductoryPriceId: introductoryPrices.data[0].id,
usageSubscriptionPriceId: usagePrices.data[0].id,
};
}
// Create a recurring product + price for this server type
const product = await stripe.products.create({
metadata: { serverType: serverTypeName },
name: `NodeByte — ${serverTypeName} Game Server`,
});
const price = await stripe.prices.create({
currency: "gbp",
lookup_key: lookupKey,
product: product.id,
recurring: { interval: "month" },
transfer_lookup_key: true,
unit_amount: pricePerMonthCents,
});
return price.id;
const [introductoryPrice, usageSubscriptionPrice] = await Promise.all([
introductoryPrices.data[0] ??
stripe.prices.create({
currency: "gbp",
lookup_key: `${priceKey}-first-month`,
product: product.id,
transfer_lookup_key: true,
unit_amount: pricePerMonthCents,
}),
usagePrices.data[0] ??
stripe.prices.create({
currency: "gbp",
lookup_key: `${priceKey}-usage-base`,
product: product.id,
recurring: { interval: "month" },
transfer_lookup_key: true,
unit_amount: 0,
}),
]);
return {
introductoryPriceId: introductoryPrice.id,
usageSubscriptionPriceId: usageSubscriptionPrice.id,
};
};

export const createServer = async (
Expand Down Expand Up @@ -151,7 +173,7 @@ export const createServer = async (
);

const pricePerMonthCents = Math.round(type.pricePerMonth * 100);
const priceId = await getOrCreateStripePrice(
const prices = await getOrCreateStripePrices(
stripe,
type.name,
pricePerMonthCents
Expand All @@ -170,16 +192,23 @@ export const createServer = async (
const session = await stripe.checkout.sessions.create({
cancel_url: `${stripeReturnUrl}/dashboard/new${bypassParam ? `?${bypassParam.slice(1)}` : ""}`,
customer: stripeCustomerId,
line_items: [{ price: priceId, quantity: 1 }],
line_items: [
{ price: prices.introductoryPriceId, quantity: 1 },
{ price: prices.usageSubscriptionPriceId, quantity: 1 },
],
metadata: {
hourlyRateMilliCents: String(location.hourlyPriceMilliCents),
nodebyteServerId: server.id,
nodebyteUserId: user.id,
pricePerMonthCents: String(pricePerMonthCents),
},
mode: "subscription",
subscription_data: {
metadata: {
hourlyRateMilliCents: String(location.hourlyPriceMilliCents),
nodebyteServerId: server.id,
nodebyteUserId: user.id,
pricePerMonthCents: String(pricePerMonthCents),
serverType: type.name,
},
},
Expand Down
7 changes: 6 additions & 1 deletion bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 21 additions & 15 deletions components/ui/accordion.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"use client"
"use client";

import * as React from "react"
import { Accordion as AccordionPrimitive } from "radix-ui"
import * as React from "react";
import { Accordion as AccordionPrimitive } from "radix-ui";

import { cn } from "@/lib/utils"
import { ChevronDownIcon, ChevronUpIcon } from "lucide-react"
import { cn } from "@/lib/utils";
import { ChevronDownIcon, ChevronUpIcon } from "lucide-react";

function Accordion({
className,
Expand All @@ -15,11 +15,11 @@ function Accordion({
data-slot="accordion"
className={cn(
"flex w-full flex-col overflow-hidden rounded-2xl border",
className
className,
)}
{...props}
/>
)
);
}

function AccordionItem({
Expand All @@ -32,7 +32,7 @@ function AccordionItem({
className={cn("not-last:border-b data-open:bg-muted/50", className)}
{...props}
/>
)
);
}

function AccordionTrigger({
Expand All @@ -46,16 +46,22 @@ function AccordionTrigger({
data-slot="accordion-trigger"
className={cn(
"group/accordion-trigger relative flex flex-1 items-start justify-between gap-6 border border-transparent p-4 text-left text-sm font-medium transition-all outline-none hover:underline disabled:pointer-events-none disabled:opacity-50 **:data-[slot=accordion-trigger-icon]:ml-auto **:data-[slot=accordion-trigger-icon]:size-4 **:data-[slot=accordion-trigger-icon]:text-muted-foreground",
className
className,
)}
{...props}
>
{children}
<ChevronDownIcon data-slot="accordion-trigger-icon" className="pointer-events-none shrink-0 group-aria-expanded/accordion-trigger:hidden" />
<ChevronUpIcon data-slot="accordion-trigger-icon" className="pointer-events-none hidden shrink-0 group-aria-expanded/accordion-trigger:inline" />
<ChevronDownIcon
data-slot="accordion-trigger-icon"
className="pointer-events-none shrink-0 group-aria-expanded/accordion-trigger:hidden"
/>
<ChevronUpIcon
data-slot="accordion-trigger-icon"
className="pointer-events-none hidden shrink-0 group-aria-expanded/accordion-trigger:inline"
/>
</AccordionPrimitive.Trigger>
</AccordionPrimitive.Header>
)
);
}

function AccordionContent({
Expand All @@ -72,13 +78,13 @@ function AccordionContent({
<div
className={cn(
"h-(--radix-accordion-content-height) pt-0 pb-4 [&_a]:underline [&_a]:underline-offset-3 [&_a]:hover:text-foreground [&_p:not(:last-child)]:mb-4",
className
className,
)}
>
{children}
</div>
</AccordionPrimitive.Content>
)
);
}

export { Accordion, AccordionItem, AccordionTrigger, AccordionContent }
export { Accordion, AccordionItem, AccordionTrigger, AccordionContent };
Loading