W
Wasp11mo ago
until

Payment for Credits / Credit Balance System

Hello, Im currently going over the documentation and will try to create some stuff using the Open SaaS. Can anyone point me in the right direction to have payments turn into credits? The idea would be to have a credit system running where each user buys credits and then uses thoses credits to run apps. Thank you, great job on this!!
23 Replies
Vinny (@Wasp)
Vinny (@Wasp)11mo ago
when creating a stripe product, you can choose a normal one-time payment for a product (instead of a subscription) and then when the payment goes through, you give that user +30 credits
until
untilOP11mo ago
Will try, I understand the mechanics, just not much of a developer myself.
Vinny (@Wasp)
Vinny (@Wasp)11mo ago
here is a link to the lines in the code where we gave an example of Crediting a user with a product payment instead of a subscription: https://github.com/wasp-lang/open-saas/blob/main/app/src/server/webhooks/stripe.ts#L66-L82
GitHub
open-saas/app/src/server/webhooks/stripe.ts at main · wasp-lang/ope...
A free, open-source SaaS app starter for React & Node.js with superpowers. Production-ready. Community-driven. - wasp-lang/open-saas
until
untilOP11mo ago
Having issues with windows wsl but managed to boot everything in a vm, will try to work it this way.
Vinny (@Wasp)
Vinny (@Wasp)11mo ago
DEV Community
Supercharge your Windows Development: The Ultimate Guide to WSL 🚀📟
Hi! I’m Boris! I’m a software engineer working professionally in insurance, teaching other...
until
untilOP11mo ago
yeah having an issue where it cant install a distro, tried every trick in the book
matijash
matijash11mo ago
huh that's tricky. Let us know what's the exact error and maybe somebody will have an idea
until
untilOP11mo ago
any documentation explaining what exactly I need to configure on Stripe to achieve this? Credits is exactly what I need
MEE6
MEE611mo ago
Wohooo @until, you just became a Waspeteer level 1!
until
untilOP11mo ago
ended up creating a vm to circumvent this
Vinny (@Wasp)
Vinny (@Wasp)11mo ago
Stripe themselves have great documentation.
until
untilOP11mo ago
Yeah I've created a few products just unsure on where I configure productID X to be the one that lets the users buy credits on wasp side @Vinny (@Wasp) I've created a CREDITS_PRICE_ID in the .env file. I've then replaced subscripton_price_id places with credits_price_id and commented this: // if (line_items?.data[0]?.price?.id === process.env.SUBSCRIPTION_PRICE_ID) { // console.log('Subscription purchased '); // await context.entities.User.updateMany({ // where: { // stripeId: userStripeId, // }, // data: { // hasPaid: true, // datePaid: new Date(), // }, // }); // } Im getting the following console error: [Server!] Error: You must provide at least one recurring price in subscription mode when using prices. I understand this but I wanted the app to run solely on non-subscription credits. (I do not mind running a subscription model on the side, just dont want it to be mandatory). What do I have to change? Regarding the following on main.wasp operations: action stripeCreditsPayment { fn: import { stripeCreditsPayment } from "@server/actions.js", entities: [User] } Do I need to uncomment this? Ok almost got it. Changed method to "payment". Credits not incrementing on user though Tried a new install, didnt change a thing, users dont get any sort of credit increment
Vinny (@Wasp)
Vinny (@Wasp)11mo ago
Make sure you’re running the stripe cli and that you’re receiving events to the webhook Check “stripe testing” in the open SaaS docs
matijash
matijash11mo ago
@Vinny (@Wasp) would code in coverlettergpt.xyz be a good example to check out? aha I see now it is using monthly subscription
Vinny (@Wasp)
Vinny (@Wasp)11mo ago
No. It’s set up the same way
until
untilOP11mo ago
Yeah I checked it and the events are showing up. I think I'm going to do a whole new install and go from there Ok the payment does change the status of the user to a subscription based planned. Now I will be trying credits I'll be enabling this: // action stripeCreditsPayment { // fn: import { stripeCreditsPayment } from "@server/actions.js", // entities: [User] // } // action updateUser { // fn: import { updateUser } from "@server/actions.js", // entities: [User] // } Removing "Disabled:True" from this: { name: 'Credits', id: 'credits', href: '', price: '$2.95', description: 'Buy credits to use for your projects.', features: ['10 credits', 'Use them any time', 'No expiration date'], disabled: true, }, and enabling this: /** * and here is an example of handling a different type of product * make sure to configure it in the Stripe dashboard first! */ // if (line_items?.data[0]?.price?.id === process.env.CREDITS_PRICE_ID) { // console.log('Credits purchased: '); // await context.entities.User.updateMany({ // where: { // stripeId: userStripeId, // }, // data: { // credits: { // increment: 10, // }, // }, // }); // } Also added a one off payment id to the env file as CREDITS_PRICE_ID Cant seem to make it work
MEE6
MEE611mo ago
Wohooo @until, you just became a Waspeteer level 2!
Vinny (@Wasp)
Vinny (@Wasp)11mo ago
can you share the error youre getting?
until
untilOP11mo ago
actually not getting any error, it just ignores the one off payment of credits and always redirects to the subscription mode (which works fine) no matter what button I click
Vinny (@Wasp)
Vinny (@Wasp)11mo ago
Are you importing the correct action on the client? e.g. stripeCreditsPayment?
until
untilOP11mo ago
I managed to make it work by adding the following await context.entities.User.update({ where: { id: context.user.id, }, data: { checkoutSessionId: session?.id ?? null, stripeId: customer.id ?? null, // Added credits increment here credits: { increment: 10, }, }, }); But I did this by basically replacing the subscription mode :/ Now I need to get both to work ^^ I'm very new at this.
Vinny (@Wasp)
Vinny (@Wasp)11mo ago
ok interesting. I geuss there is no session.id nor customer.id being passed on that event
until
untilOP11mo ago
oh I just added the increment of credits the rest was the same changed the stripe method to payment and used a one off payment stripe product id now I want to have both options in but one thing at a time I guess
Want results from more Discord servers?
Add your server