W
Waspβ€’6mo ago
mb23

How can I offer a free trial?

I'm using the OpenSaaS template and would like to offer a free trial. I can set up a free trial as part of a payment link but haven't found a way to link it to the code. Should I simply use the payment link JS code provided by Stripe and the replace the particular button in the app? πŸ™‚
10 Replies
kapa.ai
kapa.aiβ€’6mo ago
Hi @mb23. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- To offer a free trial with the OpenSaaS template, you can add a trial_period_days field when creating a subscription. This is a feature provided by Stripe, and you can find more details in their documentation (https://docs.stripe.com/api/subscriptions/create#create_subscription-trial_period_days). As for integrating this into your Wasp application, you would need to modify the code where the subscription is created. Unfortunately, the knowledge sources provided do not include specific code examples for this. However, you can find the relevant code in your project and add the trial_period_days field accordingly. Remember to test your changes thoroughly to ensure that the free trial is applied correctly. If you encounter any issues, don't hesitate to ask for help in the Wasp community. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @mb23, 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?
miho
mihoβ€’6mo ago
@Vinny (@Wasp) one for you when you have the time
neogeofun
neogeofunβ€’6mo ago
How you want to offer a free trial is really up to you. AI's answer is okay and you could apply that. Stripe might also provide some APIs for that.
martinsos
martinsosβ€’6mo ago
What OpenSaas already does is a kind of "manual" trial, in the sense that it gives you 3 free credits. If that works for you great, if not, then that is something you will have to figure out on your own, and OpenSaas here gives you the flexibility to do so.
mb23
mb23OPβ€’5mo ago
@martinsos @neogeofun @miho It was really quite easy. Here's the adjusted createStripeCheckoutSession code: export async function createStripeCheckoutSession({ priceId, customerId, mode, }: { priceId: string; customerId: string; mode: 'subscription' | 'payment'; }) { return await stripe.checkout.sessions.create({ 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, ...(mode === 'subscription' && { subscription_data: { trial_settings: { end_behavior: { missing_payment_method: 'cancel', }, }, trial_period_days: 7, }, }), }); }
Vinny (@Wasp)
Vinny (@Wasp)β€’5mo ago
oh this is nice! good to know, thanks. you'd probably have to add a new trial StatusOption and deal with this in the webhook too though
MEE6
MEE6β€’4mo ago
Wohooo @Sherm, you just became a Waspeteer level 7!
Wix
Wixβ€’3mo ago
@kapa.ai where can i adjust the default free credits you get when you sign up
kapa.ai
kapa.aiβ€’3mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- In the OpenSaaS template, the default credits for a new user are set in the signup action. You can find this action in the server/actions.js file. Here is an example of how it might look:
export const signup = async ({ email, password, ...additionalData }) => {
// ... code to handle signup ...

// Set default credits for new user
await context.entities.User.update({
where: { id: context.user.id },
data: {
credits: {
set: YOUR_DESIRED_AMOUNT, // Replace with the number of credits you want to give
},
},
});

// ... rest of the code ...
};
export const signup = async ({ email, password, ...additionalData }) => {
// ... code to handle signup ...

// Set default credits for new user
await context.entities.User.update({
where: { id: context.user.id },
data: {
credits: {
set: YOUR_DESIRED_AMOUNT, // Replace with the number of credits you want to give
},
},
});

// ... rest of the code ...
};
Replace YOUR_DESIRED_AMOUNT with the number of credits you want to give to new users. Please note that the exact code might differ based on your application's setup and the provided knowledge sources do not include specific code examples for this. Make sure to test your changes thoroughly to ensure that the credits are set correctly. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @Wix, 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?
Vinny (@Wasp)
Vinny (@Wasp)β€’3mo ago
you can also just set the default credit number in your schema.prisma file. that's easier
Want results from more Discord servers?
Add your server