How to add a discount code to OpenSaaS Stripe checkout page?
How do I add a discount code field to my payment processing on OpenSaaS when using Stripe?
4 Replies
Hi @AC. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Based on the knowledge sources provided, there isn't specific information about adding a discount code field to the OpenSaaS Stripe checkout page. The documents contain information about Stripe integration with OpenSaaS, including payment processing for subscriptions and one-time payments, but they don't specifically address discount code implementation.
To implement this feature, you would likely need to:
1. Modify the Stripe checkout session creation in the server-side code
2. Add a discount code field to your checkout UI
3. Update your Stripe webhook handler to process the discount
Since OpenSaaS is built with Wasp (which works with React, Node.js, and Prisma), you would need to refer to Stripe's documentation for implementing coupon/discount code functionality and then integrate it into your OpenSaaS application.
I recommend checking the Stripe API documentation for information on how to implement discount codes, and then adapting that to the OpenSaaS codebase. You might also want to look at the server-side code in
src/server/actions.ts
where the Stripe checkout session is created, as that would be the place to add discount code support.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @AC, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist:
Perhaps try again in 15mins?I don't see src/server/actions.ts in OpenSaaS. Do you know where I can find the server-side Stripe code in OpenSaaS?
For anyone else dealing with this - You need to change checkoutUtilts code to this:
export async function createStripeCheckoutSession({
userId,
priceId,
customerId,
mode
}: {
userId: string,
priceId: string;
customerId: string;
mode: StripeMode;
}) {
try {
const sessionConfig: Stripe.Checkout.SessionCreateParams = {
line_items: [
{
price: priceId,
quantity: 1,
},
],
mode: mode,
success_url:
${DOMAIN}/checkout?success=true,
cancel_url:
${DOMAIN}/checkout?canceled=true,
automatic_tax: { enabled: true },
customer_update: {
address: 'auto',
},
customer: customerId,
// Enable promotion codes input field on checkout page
allow_promotion_codes: true
};
return await stripe.checkout.sessions.create(sessionConfig);
} catch (error) {
console.error(error);
throw error;
}
}
I think in this function you'll want to add
to the object in the function call
we answered at the same time haha
Thanks! Haha