createGuestCheckoutSession: publicProcedure
.input(
z.object({
cart: z.array(
z.object({
id: z.string(),
price: z.number(),
image: z.string(),
quantity: z.number().optional(),
})
),
})
)
.mutation(async ({ ctx, input }) => {
const { stripe, req } = ctx;
const lineItems = input.cart.map((product) => ({
price: product.id,
quantity: product.quantity ?? 1,
}));
const checkoutSession = await stripe.checkout.sessions.create({
payment_method_types: ["card"],
mode: "payment",
line_items: lineItems,
success_url: `${baseUrl}/shop?checkoutSuccess=true`,
cancel_url: `${baseUrl}/shop?checkoutCanceled=true`,
});
if (!checkoutSession) {
throw new Error("Could not create checkout session");
}
return { checkoutUrl: checkoutSession.url };
}),
});
createGuestCheckoutSession: publicProcedure
.input(
z.object({
cart: z.array(
z.object({
id: z.string(),
price: z.number(),
image: z.string(),
quantity: z.number().optional(),
})
),
})
)
.mutation(async ({ ctx, input }) => {
const { stripe, req } = ctx;
const lineItems = input.cart.map((product) => ({
price: product.id,
quantity: product.quantity ?? 1,
}));
const checkoutSession = await stripe.checkout.sessions.create({
payment_method_types: ["card"],
mode: "payment",
line_items: lineItems,
success_url: `${baseUrl}/shop?checkoutSuccess=true`,
cancel_url: `${baseUrl}/shop?checkoutCanceled=true`,
});
if (!checkoutSession) {
throw new Error("Could not create checkout session");
}
return { checkoutUrl: checkoutSession.url };
}),
});