Accept a payment - Create a PaymentIntent with Node.js

Поделиться
HTML-код
  • Опубликовано: 29 июл 2024
  • Accepting a one-time payment with a custom form requires two steps. First, creating a PaymentIntent on the server. Second, confirming the payment intent on the client. It's also recommended that you handle fulfillment for a purchase when receiving a webhook notification of successful payment.
    In this video, you'll learn how to create a PaymentIntent on the server using Node.js and how to setup a basic Webhook handler. For part two of this series to confirm a PaymentIntent using a variety of payment methods, watch one of the videos in the playlists for front end frameworks:
    HTML and JavaScript - • stripe-js
    React - • react-stripe-js
    iOS - • stripe-ios
    Android - • stripe-android
    If you'd like to learn how to create a PaymentIntent on the server in another server side language, consider watching one of these episodes:
    Ruby - • Accept a payment - Cre...
    Python - • Video
    PHP - • Accept a payment - Cre...
    Node.js - • Accept a payment - Cre...
    Java - • Accept a payment - Cre...
    Go - • Accept a payment - Cre...
    .NET - • Accept a payment - Cre...
    Resources
    Code: github.com/stripe-samples/acc...
    Documentation: stripe.com/docs/payments/paym...
    How intents work: stripe.com/docs/payments/intents
    Playlist: • stripe-go
    Table of contents
    00:00 Overview
    01:11 Setup the office hours sample
    01:45 Add route to create-payment-intent
    02:12 Create a basic PaymentIntent using the API with stripe-go
    02:45 Test the endpoint with cURL
    03:12 Accept payment method type and currency in request
    04:57 Handle errors
    05:48 Handle webhook notifications
    08:23 Add a config route for fetching publishable keys
    09:00 Recap and conclusion
    Presenter
    CJ Avilla, Developer Advocate at Stripe - / cjav_dev
    Support
    If you have a question, please feel free to reach out to our support team on Discord at stripe.com/go/developer-chat.
    Updates
    Sign up to stay updated with developer news: go.stripe.global/dev-digest
    Feedback
    If you have any feedback about this or other episodes, let us know: forms.gle/VjNqzRhotM2snYo88.
    #Stripe #Payments
  • НаукаНаука

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

  • @danielborges.
    @danielborges. 2 года назад +5

    Hi. It would be nice if in this type of video and in the VS Code extension also cover Stripe using Angular and Firebase Functions.

  • @arunkutz
    @arunkutz 3 года назад +1

    Really Helpful .. Thank you !!

    • @cjav_dev
      @cjav_dev 3 года назад +1

      Happy to hear that, Arun!

  • @aliimranadil2
    @aliimranadil2 Месяц назад

    you are spot on..thank you

  • @sephycai
    @sephycai 2 года назад

    Hi. Is creating payment intent and waiting for web hook to confirm the only way to complete a payment? Does stripe provides any async api that I can call and directly get the final status of the payment?

    • @StripeDev
      @StripeDev  2 года назад

      Hey there, you can retrieve the PaymentIntent object using the API to check up on the status: stripe.com/docs/api/payment_intents/retrieve. However, it's typically recommended to use the webhook event for reconciliation.

  • @transcendcapitalism
    @transcendcapitalism 2 года назад

    Hi! We still have to use Stripe.js to set up the Customer Portal per the docs, right, so some server setup is necessary no mater what, no?

    • @StripeDev
      @StripeDev  2 года назад

      Hi Rachel, that's correct. We also have a video on how to integrate the customer portal: ruclips.net/video/u8H6awDJVpM/видео.html

    • @transcendcapitalism
      @transcendcapitalism 2 года назад

      ​@@StripeDev Thanks for the reply! Yes, I previously watched the video on Customer Portal integration.
      In the above video, CJ's sending us to the relevant front-end tutorial afterward, but for
      Customer Portal integration, I shouldn't need to build out any front-end beyond the 3 lines of code that integrate the payment button on a webpage, right?
      Appreciate the help!

  • @googleaccount7252
    @googleaccount7252 2 года назад

    Hi, can you please explain which window you used to experiment with the curl on 2:35, my terminal is running fine and listening on port 4242 just like yours. But I'm not sure where you were putting that curl... info on. Thank you.

    • @StripeDev
      @StripeDev  2 года назад

      Hey there-the curl command is entered into another terminal. CJ opened a new one in a tab and configured his UI to have both visible. It's the same as opening a new window in your terminal and typing the command there. We hope that helps!

    • @googleaccount7252
      @googleaccount7252 2 года назад

      @@StripeDev Thank you, I got a reply from you on reddit too I think. Anyways, I figured it out but now but when I input the curl command I get an error back and an html page but I'm expecting a json. My js code is identical to his.

    • @StripeDev
      @StripeDev  2 года назад

      What's the error message you're seeing? Which curl command did you use? Which JS code are you referring to? It would be super helpful if you'd shared the request ID, copy and paste the code snippets / cURL command and provide a screenshot of the error you're seeing over email here support.stripe.com/contact/login so we can help you further.

  • @simonaerts2926
    @simonaerts2926 2 года назад

    Any idea why when I write in the terminal: "stripe samples create developer-office-hours tutorial" I have "The sample provided is not currently supported by the CLI: developer-office-hours"? Thank you.

    • @StripeDev
      @StripeDev  2 года назад

      Hey Simon! Just to make sure, have you installed Stripe CLI? See here: stripe.com/docs/stripe-cli for more.

    • @simonaerts2926
      @simonaerts2926 2 года назад

      @@StripeDev Hello! Yes stripe CLI is installed (version: 1.8.11), what's weird is that when I enter 'stripe samples list' ==> 'developer-office-hours' is not in the propositions....

  • @5464654135756
    @5464654135756 Год назад

    I got zsh: command not found: stripe when running stripe samples create developer-office-hours. Can sb tell me how to kick-start?

    • @StripeDev
      @StripeDev  Год назад

      Hi Ben! Have you installed the CLI? If you didn't yet, here is a guide that can help you: stripe.com/docs/stripe-cli#install.

  • @googleaccount7252
    @googleaccount7252 2 года назад

    Hi guys, is it possible to explain why the code on here is different from the sample on github, I'm asking because I've encountered errors I'm unable to solve, so I wanted to make sure I'm using the right code,

    • @StripeDev
      @StripeDev  2 года назад

      Understood-did you get the chance to email that info in to the address we provided i our last response? If so, we'll take a look at it and reach out to you there.

    • @googleaccount7252
      @googleaccount7252 2 года назад

      @@StripeDev Hi, no but I joined your discord server and got some help from your devs, but that still didn't fix the issue. If you still want me to email you I'll do tomorrow.

    • @StripeDev
      @StripeDev  2 года назад

      That would be fantastic!

  • @fdorantesm
    @fdorantesm Год назад

    Thanks. Mmm, How do I use a payment intent to create a charge?

    • @StripeDev
      @StripeDev  Год назад

      Hi Fernando! Check out our documentation here for more guidance: stripe.com/docs/payments/payment-intents#creating-a-paymentintent

  • @kebatake
    @kebatake 2 года назад

    I have a question, i Made exactly What is here, but, when i set an amount of 75 EUR, stripe makes the payment with 0.75, What could be the problem?

    • @kebatake
      @kebatake 2 года назад

      Oh... I have to convert the euro to cents before set the amount right ?

    • @StripeDev
      @StripeDev  2 года назад +1

      Hi Jhon-yes, this is correct. Stripe payments are entered in the smallest unit possible for that currency, so for 75 EUR you'd want to do 7500.

    • @kebatake
      @kebatake 2 года назад

      @@StripeDev i have another question, when i started my one time payment application i saw that they recomend to make the payment intent when the view is rendered, but, it creates a record in the stripe dashboard with the tag "Uncomplete" and for example if you reload the page it will make it again but the previous record will be in uncomplete for ever, would be a best practice if i make this when the payment is submited just before the confirmPayment in order to get the client secret and avoid the uncomplete récord?

    • @StripeDev
      @StripeDev  2 года назад +1

      This would be entirely up to you. Some people like to see how many people are hitting the page and not paying based on the number of incomplete Payment Intents showing up in the Dashboard. Others don't like that, so they defer creation of the Payment Intent until later.

    • @kebatake
      @kebatake 2 года назад

      @@StripeDev thanks !!! You help me a Lot !

  • @johnme60
    @johnme60 2 года назад

    why I can't no longer do this :
    const stripe = require('stripe')('secretkey');
    it says require('stripe') is not function type;
    and it gives undefined on paymentIntents .

    • @StripeDev
      @StripeDev  2 года назад

      Hi John. Could you expand a little on what it is you are trying to do?

    • @oluwafemiakinyemi3332
      @oluwafemiakinyemi3332 2 года назад

      @@StripeDev To create Payment Intent in the frontend.. App.js file. This is the same issue I'm having

  • @uguur
    @uguur Год назад

    Webhook could be heavy for backend I think async api will be better.
    Also how I know userId when I use web hook completed successfully ?

    • @StripeDev
      @StripeDev  Год назад

      Hi there! Can you please explain your question further? What are currently struggling with?

    • @uguur
      @uguur Год назад

      @@StripeDev if I want to use web hook, how I know that which user transactions belongs to owner of transactions user.

    • @StripeDev
      @StripeDev  Год назад

      You can use the event object guide here: stripe.com/docs/webhooks#webhook-endpoint-one.

  • @clamgts
    @clamgts 2 года назад

    I keep getting the error "webhookSecret is not defined" I don't see it being defined anywhere in the code, any idea why I'm getting this error, did you define the secret somewhere higher up?

    • @StripeDev
      @StripeDev  2 года назад +1

      Heya Darren! Could you DM us on Twitter or send us an email so we can troubleshoot this with you? Thank you! twitter.com/stripe, stripe.com/contact.

    • @clamgts
      @clamgts 2 года назад

      @@StripeDev I've dropped you guys a DM with a rundown of the issue.

    • @StripeDev
      @StripeDev  2 года назад

      Thank you!

    • @clamgts
      @clamgts 2 года назад

      @@StripeDev eventually figured it out, thanks for the help!

  • @mdridoy-ef2pw
    @mdridoy-ef2pw 2 года назад

    what if I want to pass complex product data in a paymentIntent?

    • @shadmanmartinpiyal4057
      @shadmanmartinpiyal4057 2 года назад

      pass those data in metadata and in ur stripe webhook function fetch that data to do whatever u want

    • @mdridoy-ef2pw
      @mdridoy-ef2pw 2 года назад

      @@shadmanmartinpiyal4057I have multiple nested data in my product. so I have to stringify it.
      even then stripe has limited how much data I can send.
      this is what they say:
      "You can specify up to 50 keys, with key names up to 40 characters long and values up to 500 characters long. Metadata is useful for storing additional, structured information on an object."
      some product may exceed 500 characters.
      also, I have 10 products, I surely exceed this limit.

    • @shadmanmartinpiyal4057
      @shadmanmartinpiyal4057 2 года назад

      @@mdridoy-ef2pw metadata means just metadata, it could be some ID reference or something. of course metadata will be limited. my suggestion will be to pass some ID reference to a database in metadata and use that Id in stripe webhook to fetch the data that u need.

    • @mdridoy-ef2pw
      @mdridoy-ef2pw 2 года назад

      @@shadmanmartinpiyal4057 the thing is, I may update some product data after a customer orders a product.
      since I am only passing the id, I will fetch the product data in my webhook. but since the product is updated, the customer will no t get what they originally ordered.
      Even though it's a rare case, passing the id is kind of unreliable to me.
      So when they checkout, I create an order with all the data and a paymentStatus of incomplete.
      when I receive the webhook event, I just update the paymentStatus to completed.
      If I don't receive the webhook event in certain period of time, the order gets deleted automatically.
      This way I can be sure that even if I change product data, customer gets exactly what they ordered.

    • @shadmanmartinpiyal4057
      @shadmanmartinpiyal4057 2 года назад

      @@mdridoy-ef2pw then take a snapshot and save that snapshot temporarily in the database, and call that using the passed id in metadata from the webhook. There are many ways to do it. If you are using NoSQL database, i suggest you make a dedicated collection just for these temporary datas. You can delete these temporary data from the webhook if you don't need to keep them anymore.

  • @reece5863
    @reece5863 2 года назад

    WOW

  • @TheJason118511
    @TheJason118511 2 года назад

    thank you for not calling json jason