How I implement a credit systems using stripe

Поделиться
HTML-код
  • Опубликовано: 6 авг 2024

Комментарии • 82

  • @monfernape
    @monfernape 10 месяцев назад +3

    Have been avoiding Stripe for years now but you make it very easy to consume. Kudos

  • @rotivanov
    @rotivanov 10 месяцев назад +6

    You are the man!! Thanks a lot for sharing your knowledge. I have learned a lot from you.

  • @alexandrepereira6522
    @alexandrepereira6522 10 месяцев назад +1

    Another incredible video! Thanks Cody

  • @FlorinPop
    @FlorinPop 10 месяцев назад +2

    This is very neat! Thank you for the tutorial!

  • @Tyheir
    @Tyheir 10 месяцев назад +1

    Prisma Transactions would work perfect for that update and decrement scenario.

  • @claudiufarcas
    @claudiufarcas 5 месяцев назад

    Nice presentation, I do believe there is needed also a transaction log (as a User for sure I wish to check/validate/inspect all my transactions.) It is good also for auditing purpose.

  • @user-uj9mh2nd8q
    @user-uj9mh2nd8q 10 месяцев назад +1

    exactly , it will be fantastic if you make a simple tutorial about the stripe credit system , it will be great

  • @orcdev
    @orcdev 7 месяцев назад

    Don't know how I missed this video! This is exactly what I need 😀 Even wanted to ask you on Discord how you implemented token system for your icon generator saas. Thanks Cody!

    • @WebDevCody
      @WebDevCody  7 месяцев назад +1

      All the code is also in my repo as icon generator tutorial I think

    • @orcdev
      @orcdev 7 месяцев назад

      @@WebDevCody just checked, it's there! Thanks!

  • @LM43243
    @LM43243 9 месяцев назад

    Thanks for this mate! Would love to see how you create your saas apps in next, do you have any video going through an app? Have some AI saas ideas in mind but not sure how to start. Cheers

  • @Drainos2006
    @Drainos2006 10 месяцев назад +7

    Great video. Obviously still in development, but you should try moving the payment process as a popup on the pricing page, instead of going to another page then coming back. Paypal do that and it's so annoying for the end user! Keep up the good work. Stripe rocks.

  • @SeibertSwirl
    @SeibertSwirl 10 месяцев назад +6

    Good job bubby!!!

  • @optimbro
    @optimbro 10 месяцев назад

    Very simple to understand now. Thank you.

  • @namanh7665
    @namanh7665 10 месяцев назад

    Thanks for sharing, what's theme icon pack your using btw?

  • @ullaskunder
    @ullaskunder 9 месяцев назад

    please please do make tutorial on this topic, it would be really helpful

  • @trentcox9239
    @trentcox9239 10 месяцев назад

    is there any way for the webhook to interact with the client? ie. if the stripe result detects some kind of fraud or other issue, is it possible to subscribe to events coming from that api to react to?

  • @amorto3420
    @amorto3420 10 месяцев назад +1

    Great video. Another question, Are you creating a product in the Stripe dashboard with 3 different pricing?

  • @DanielClipsTVS
    @DanielClipsTVS 10 месяцев назад

    hey there cody , nice video , may i know how you implemented the nextjs progress bar ?

    • @WebDevCody
      @WebDevCody  10 месяцев назад

      It’s an npm library called nextjs progress bar

  • @sivuyilemagutywa5286
    @sivuyilemagutywa5286 10 месяцев назад

    you should create a browser extention for you new side project

  • @Ethanishful
    @Ethanishful 10 месяцев назад +2

    Was using Prisma and SST in this project difficult to configure. I know on SST discord they kind of discourage using Prisma. Maybe you can do a video on how you set up this project.

    • @WebDevCody
      @WebDevCody  10 месяцев назад +1

      No, it worked easily for me. You just need to put binaryTargets to include Linux arm64 for it to work when deployed to lambda

  • @charliesta.abc123
    @charliesta.abc123 10 месяцев назад

    Around 6:09...don't you want to log that error on the Stripe endpoint? Then return your response. Otherwise you don't know why the error might be an "Unknown Error"

  • @yarapolana
    @yarapolana 9 месяцев назад

    I have a AI service and I was lost on how to price it, this helped me a lot thank you! If you dont want to share this particular code, can you make a separate project/indepth tutorial?

    • @WebDevCody
      @WebDevCody  9 месяцев назад

      I may share the project in a bit

    • @yarapolana
      @yarapolana 9 месяцев назад

      @@WebDevCodyYey looking forward to it

  • @abdullahislam
    @abdullahislam 10 месяцев назад

    Love this!
    With stripe redirect to dashboard - does it wait for the hook to complete applying the credit?
    What if the redirect completes before the hook is finished processing?

    • @WebDevCody
      @WebDevCody  10 месяцев назад

      No, it doesn’t wait. The better solution, which I didn’t implement, would be to redirect to a page which continuously polls until your user has the credits applied and then redirect them to the dashboard.

    • @azzazkhansiddiqui
      @azzazkhansiddiqui 10 месяцев назад

      @@WebDevCody Not Next.js stuff but I've added a pending verification page in Laravel which is shown when webhook is not received yet.

  • @danieljing9319
    @danieljing9319 8 месяцев назад

    how do you handle stripe webhooks run in wrong order issue? I mean sometimes the webhooks may not run in order for example the updated event may complete first and then create event complete second. you might check this on you stripe webhook dashboard.

    • @WebDevCody
      @WebDevCody  8 месяцев назад

      I’m not sure if order makes a differences? I only check for the compete event, and when that comes in I apply credits to the user.

  • @techwithtolu
    @techwithtolu 10 месяцев назад

    How do you design your apps? Do you just have a set of templates you already have and just dive right in? I guess what I really want to know is what’s your process?

    • @WebDevCody
      @WebDevCody  10 месяцев назад

      Design as it how it looks? Or functionality design? Code design? For code I often just reuse code I have in other projects, for design I use a component library and just do stuff until it seems nice, put loaders where necessary, etc

    • @techwithtolu
      @techwithtolu 10 месяцев назад +1

      @@WebDevCody Thanks for your response. I was referring to your UI design but you covered it.

  • @L0rdofIsh01
    @L0rdofIsh01 10 месяцев назад

    Hi Cody, i was wondering if you can do a video on how to think of a project (that not many have been building) using AI. I am trying to think of a side project like yours that you are building an potentially making a small buck but its hard. I was thinking of something with Spotify but no clue...

    • @WebDevCody
      @WebDevCody  10 месяцев назад

      So far I’ve made things I personally needed, such as a way to generate icons for my own side projects, and now a way to generate chapters for my RUclips videos. I’d say find something you’re interested in and see if AI can help fast track the process

  • @azzazkhansiddiqui
    @azzazkhansiddiqui 10 месяцев назад

    I've built a similar system using Laravel but I'm storing the credits as encrypted strings in the database. Is it the right approach or should we store it somewhere else or use a 3rd party service for this on production level?

    • @WebDevCody
      @WebDevCody  10 месяцев назад

      Why are you storing encrypted strings for credits? I’d just use an int

    • @azzazkhansiddiqui
      @azzazkhansiddiqui 10 месяцев назад

      @@WebDevCody For additional security, still I'm worried about it.

  • @abdousfayhi7649
    @abdousfayhi7649 10 месяцев назад

    i also tried implementing this style of credit system with stripe but i ran into an issue i was trying to update ui (credits) and could not i'm nextauth they provide update method to update session client side but i didnt know to trigger update method after the stripe webhook has been called , only solution i came up with is long polling & some state in localstorage which isn't optimal

    • @WebDevCody
      @WebDevCody  10 месяцев назад

      you either need polling, websockets, or server side events to notify users when the stripe webhook finishes

    • @abdousfayhi7649
      @abdousfayhi7649 10 месяцев назад

      yes i thought about those too but the other issue is ran into what if the user isn't logged in when webhook get triggered so i figured might aswell do long polling@@WebDevCody

  • @oliverkidd5160
    @oliverkidd5160 10 месяцев назад

    How are you handling updating the client side total of credits after purchasing and updating prisma? using next auth session update()?

    • @WebDevCody
      @WebDevCody  10 месяцев назад

      On the front end I just make a request to the backend to get the latest amount of credits for the user. I think when stripe redirects you back to your app, you could just tell the ui to refresh credits

    • @abdousfayhi7649
      @abdousfayhi7649 10 месяцев назад

      i ran into the same issue only solution i came up with is long polling , if the payment happens immediately you can add state to redirect url payment=true & on mount check if you've queryParams payment=true & update client session then but if the payment could take couple of days just only solution is long polling with some state in localStorage 'payment=pending" or smth

    • @oliverkidd5160
      @oliverkidd5160 10 месяцев назад

      @@abdousfayhi7649 my solution for something similar was to use stripe elements to host the payment on-site, then if payment fails you can handle things appropriately. web hooks take care of syncing db and if successful simply update the client session with result. Saves any request between the server and client to pull latest credits!

  • @kirilmilanov1096
    @kirilmilanov1096 7 месяцев назад

    Something that may be unrelated but whenever somebody is using the credits, shouldn’t the operation be made transactional mainly due to issues like double charging (race condition where a user might try to invoke this action a few times in parallel)

    • @WebDevCody
      @WebDevCody  7 месяцев назад

      I think it depends on the db default transactions. I believe Postgres by default uses transactions for all writes, so two conditional writes shouldn’t have race conditions

    • @kirilmilanov1096
      @kirilmilanov1096 7 месяцев назад

      I am not sure about that bur my main idea is that even it uses transactions, creating one explicitly would not hurt. Also, even if it did, the default isolation level is read committed which would not be enough for this use case

  • @puneetdhiman5194
    @puneetdhiman5194 10 месяцев назад

    Which service you are using to generate transcripts?

    • @WebDevCody
      @WebDevCody  10 месяцев назад

      I use a library called yt transcripts

  • @nick49302
    @nick49302 10 месяцев назад

    How did you work with videos over 8000 tokens? Assuming you're using GPT-4.

    • @WebDevCody
      @WebDevCody  10 месяцев назад

      I’m using 3.5 turbo, but I may need to switch to 4 or provide an option Gpt4 is 10x more expensive and these videos have huge transcripts, so the cost adds up with 4, but gpt3.5 is very hit and miss on regards to results.
      I haven’t figured out my approach for longer videos. I may have to chunk the transcripts up and process them separate and combine somehow

  • @rico454
    @rico454 10 месяцев назад +1

    7:11 just a general question but should the default value for credits reside in your backend code rather than the database level?
    Ideally, the database shouldn’t have a default value for it so that you’re forced to enter a value, which can be handled in your backend during user creation.
    You can even have it as an environment variable so if that value needed to be changed in the future, you can easily do so.

    • @WebDevCody
      @WebDevCody  10 месяцев назад

      That’s actually how I did it on another project, but was lazy for this one

    • @rico454
      @rico454 10 месяцев назад

      Ahh okay gotcha

  • @versaleyoutubevanced8647
    @versaleyoutubevanced8647 10 месяцев назад

    Great video, but why people don't usually use good practices in Next? Like Clean Architecture, DIP...

    • @WebDevCody
      @WebDevCody  10 месяцев назад +2

      I think certain design patterns are more useful for larger projects with many developers needing to work on the same code base (or projects that expect to be around for many years). For most of the content you see online and youtube, no one is going to apply clean architecture to a project that is maintained by one person; it's basically over engineering in most cases.

    • @versaleyoutubevanced8647
      @versaleyoutubevanced8647 10 месяцев назад

      @@WebDevCody fair enough

  • @tiisetsontsoane5809
    @tiisetsontsoane5809 10 месяцев назад

    Do you do the design yourself, or you outsource?

    • @WebDevCody
      @WebDevCody  10 месяцев назад

      This was all using an existing component library. Everything here is by me

  • @rahim.tn99
    @rahim.tn99 10 месяцев назад +1

    why are you using updateMany instead of update for decrementing user credits

    • @WebDevCody
      @WebDevCody  10 месяцев назад +1

      I'm pretty sure the update command doesn't allow you to check that the user has credits >= 1, but updateMany does

    • @rahim.tn99
      @rahim.tn99 10 месяцев назад

      @@WebDevCody you can use credits: { gte: 1 } with update as you did with updateMany.
      The only difference is update returns a User object while updateMany returns the count of updated records.

    • @rahim.tn99
      @rahim.tn99 10 месяцев назад

      @@WebDevCody My bad 😂 I tested the update method with gte and it threw an error when the gte condition is not met.
      Your usage of updateMany is the correct way since it returns back count.
      Thank you 😊

  • @yaffet97
    @yaffet97 10 месяцев назад

    What´s the vsc theme sir?

    • @WebDevCody
      @WebDevCody  10 месяцев назад

      Bearded theme stained blue

  • @ataadevs
    @ataadevs 10 месяцев назад

    To use stripe, does it need you to have a business open?

    • @WebDevCody
      @WebDevCody  10 месяцев назад +1

      I think so, or a sole proprietorship with your home address

  • @user-mj8qo8sq7o
    @user-mj8qo8sq7o Месяц назад

    >=1, not >1 (i guess.)

  • @TheSocialDeveloper
    @TheSocialDeveloper 10 месяцев назад

    You bought 50 credits but they only got 49

    • @WebDevCody
      @WebDevCody  10 месяцев назад +1

      I bought 50 credits?

    • @TheSocialDeveloper
      @TheSocialDeveloper 10 месяцев назад

      @@WebDevCody I thought so in the video but could be wrong

  • @worldwide6626
    @worldwide6626 6 месяцев назад

    Hi Cody. Is the actions.ts file on the frontend? That means we are sending the number of credits from the frontend? Can a malicious client change the code to change the credit to lower the price of each item?
    Also what have you stored as process.env.PRICE_ID_50?