Accept a payment with the Payment Element using PHP

แชร์
ฝัง
  • เผยแพร่เมื่อ 5 ส.ค. 2024
  • In this episode, you'll learn how to accept a one-time payment with a custom form using PHP on the server and the Stripe Payment Element on the client. The Payment Element enables you to collect several different payment method types from cards and bank accounts to wallets and buy-now-pay-later payment methods.
    Presenter
    CJ Avilla - Developer Advocate at Stripe - / cjav_dev
    Chapters
    00:00 Introduction
    01:37 Install a sample with the Stripe CLI
    04:00 Enable payment methods in the dashboard
    05:06 Overview of payment flow
    05:31 Create payment intent on the server
    08:00 Collect payment details on the client
    11:22 Submit payment details to Stripe
    13:58 Build a confirmation page
    16:19 Handle webhooks and post-processing events
    19:49 Test your integration with Stripe test cards
    21:15 Conclusion
    Resources
    Accept a payment - stripe.com/docs/payments/acce...
    PaymentIntent API reference - stripe.com/docs/api/payment_i...
    Learn all about webhooks - stripe.com/docs/videos/develo...
    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 #php #payment_element #integration
  • แนวปฏิบัติและการใช้ชีวิต

ความคิดเห็น • 35

  • @sensingturtle
    @sensingturtle 11 หลายเดือนก่อน

    This was a fantastic tutorial. Thank you so much :)

  • @thesigmasystems
    @thesigmasystems 4 หลายเดือนก่อน

    Perfect

  • @timurgafforov8856
    @timurgafforov8856 5 หลายเดือนก่อน +1

    Thanks a lot for the tutorial. Though, it would be nice to have this exact code you've written downloadable. I know there are enough samples provided in GitHub, but it really simplifies when you just have such step-by-step instructions for a downloadable code. One wouldn't have to look for chunks of required code or type them manually. Not critical, but, I think, a valid suggestion.

    • @senju31
      @senju31 10 วันที่ผ่านมา

      I agree.

  • @StripeDev
    @StripeDev  11 หลายเดือนก่อน

    Hey there-good question! You can take a look at how to create charges which will generate a charge ID here: stripe.com/docs/api/charges/create. You'll also find more information on how to retrieve charges using the charge ID a bit further down.

    • @tiydosoft
      @tiydosoft 7 หลายเดือนก่อน

      Hi there,
      This tutorial is really helpfull. I need to know one more think. I want to set the customer name but they maybe a guest user! So how can I do this?
      is there any parameter to add the guest customer name??
      $paymentIntent = $stripe->paymentIntents->create([
      'amount' => $amount,
      'currency' => $currency,
      'automatic_payment_methods' => ['enabled' => true],
      // 'customer' => $customer,
      'description' => $description,
      'receipt_email' => $receipt_email,
      'metadata' => [
      'u_id' => $u_id,
      'o_id' => $o_id,
      ],
      ]);
      Thank you!

  • @MattBarraud
    @MattBarraud 8 หลายเดือนก่อน

    This is a great tutorial, thank you - I do have a question, how do I also add the users name, email and a short description of the payment? I believe I need to create the customer first - then the intent? How does that work in this workflow?

    • @StripeDev
      @StripeDev  8 หลายเดือนก่อน +1

      Hi Matthew-this tutorial specifically covers one-time payments. If you need to add a customer for recurring payments, you can do so through the API or the Dashboard: stripe.com/docs/billing/customer.
      You might find our documentation on getting started helpful for setting up this workflow: stripe.com/docs/payments/accept-a-payment.

  • @chrispaul4090
    @chrispaul4090 ปีที่แล้ว

    Regarding currencies, how do I enable multiple currency option?

    • @StripeDev
      @StripeDev  ปีที่แล้ว

      Hi Chris, have a look at our multiple currency doc here: stripe.com/docs/connect/currencies. Any further questions, feel free to get in touch using support.stripe.com. Thanks.

  • @fustibal
    @fustibal ปีที่แล้ว

    My customer sells tickets in the US for us events and sells tickets in Mexico for MX events. Will the exchange rate be done automatically to dollars if a ticket is sold in Mexico?

    • @StripeDev
      @StripeDev  ปีที่แล้ว

      Hey Mario-are you speaking about Automatic Currency Conversion: support.stripe.com/questions/automatic-currency-conversion-pricing?
      Otherwise, this doc has more information about currency conversions: stripe.com/docs/currencies/conversions.

    • @fustibal
      @fustibal ปีที่แล้ว

      @@StripeDev Yes, this makes sense. What are the requirements to have an elegible account to have ACC enabled?

    • @StripeDev
      @StripeDev  ปีที่แล้ว +1

      This feature is currently limited to beta users, but you can enter in your email at the bottom of this page if you're interested in participating: stripe.com/docs/payments/checkout/present-local-currencies#:~:text=Automatic%20currency%20conversion%20allows%20you,needing%20to%20update%20your%20integration.

    • @fustibal
      @fustibal ปีที่แล้ว

      @@StripeDev Thank you for the fast answers.

  • @jamesr2408
    @jamesr2408 11 หลายเดือนก่อน

    I have test-mode pair of publishable and secret keys, but where to get the webhook secret? Is it generated when creating endpoints? Would that be in test mode or the live? Also in the video, the publishable and secret keys, are in quote marks as in Strings, but not in the generated code.

    • @StripeDev
      @StripeDev  11 หลายเดือนก่อน

      We'd be happy to explain this further. Feel free to chat with us on Discord at stripe.com/go/developer-chat

    • @jamesr2408
      @jamesr2408 11 หลายเดือนก่อน

      @@StripeDev Thanks for the discord link. I will use it in the near future. But for now, having ./stripe login done, the regenerated the started project, and .env was properly populated with the keys in quote marks. As a bonus, the webhook key was there too. THANKS AGAIN.🙂

  • @riddhipanchal9141
    @riddhipanchal9141 ปีที่แล้ว

    Hello, can you guide how can we set Google pay instead of cards ?

    • @StripeDev
      @StripeDev  ปีที่แล้ว

      Hello there. Happy to help you with that. After activating Google Pay on your dashboard here: dashboard.stripe.com/settings/payment_methods, you can follow the steps on this document to set this payment method to your website: stripe.com/docs/google-pay.

  • @jamesr2408
    @jamesr2408 11 หลายเดือนก่อน

    @17.49 the webhook trigger was successful, and the results are evident in the terminal. When I redirect the return_url to webhook.php, upon payment, I get the error: {"error":"Unable to extract timestamp and signatures from header"}. It is unfortunate, that the demo does not show the webhook.php in action. But all the same, thanks a ton for sharing this tutorial.

  • @aliyufari
    @aliyufari 9 หลายเดือนก่อน

    Great, but how can I add input to the form to collect user email and so on. And how to handle that in the back end.

    • @StripeDev
      @StripeDev  9 หลายเดือนก่อน

      Hey there-great question! Could you please elaborate on this so that we can better answer your question?

    • @StripeDev
      @StripeDev  9 หลายเดือนก่อน

      So, we dug a little deeper from what we could grasp out of your question. The email address mentioned here: stripe.com/docs/js/elements_object/create_payment_element#payment_element_create-options-fields-billingDetails-email, if set to `auto` will only show as an input field when the PaymentMethod requires collecting it i.e. it will not always be displayed as an input field.
      What you can try is implementing the input field yourself and passing that in as part of the billing_details when confirming the PaymentIntent or SetupIntent. If you're implementing your own input field to collect the email address, you'll likely want to set it such that the Payment Element never collects the email.
      Alternatively, if you're willing to integrate with Link, you can take a look at this guide: stripe.com/docs/payments/link/add-link-elements-integration?link-integration-type=collect-email&defaultValues-integration-type=same#design-your-integration.

  • @nnnkgjj
    @nnnkgjj ปีที่แล้ว

    can u make video on how to change charge to intent

    • @StripeDev
      @StripeDev  ปีที่แล้ว

      Hey T. We will certainly consider doing another video about it. For now, you can find information on changing a Charge to a Payment Intent in the official Stripe documentation:
      Payment Intents API: stripe.com/docs/payments/payment-intents
      Confirm a Payment Intent: stripe.com/docs/payments/payment-intents/quickstart#confirm-payment-intent
      Capture a Payment Intent: stripe.com/docs/payments/payment-intents/quickstart#capture
      In general, the Payment Intents API is designed to replace the Charges API, so you might also find it helpful to review the following resources for background information:
      Migrating to Payment Intents: stripe.com/docs/payments/payment-intents/migration
      Charge API vs. Payment Intents API: stripe.com/docs/payments/payment-intents/migration/charges

  • @user-yn8tc8ke3f
    @user-yn8tc8ke3f ปีที่แล้ว +1

    Can you share vscode theme name? :)

  • @alpachino468
    @alpachino468 9 หลายเดือนก่อน

    Here's one for you: Using the API, I can get the payment_intent , and I can also get its associated charge for a successful purchase completed via the Stripe Hosted payment url. What I can't do is get the product that either the intent or the charge are associated to - how in the world do I get which charge or intent is associated to a product?

    • @StripeDev
      @StripeDev  9 หลายเดือนก่อน +1

      Hi there, you can do this by retrieving the Session and using expansion stripe.com/docs/expand, to include the 'line_item': stripe.com/docs/api/checkout/sessions/object#checkout_session_object-line_items.
      You can also take a look at this doc for more context: stripe.com/docs/api/checkout/sessions/retrieve.

    • @alpachino468
      @alpachino468 9 หลายเดือนก่อน

      @@StripeDev Awesome, thanks for pointing me in the right direction ❤

    • @StripeDev
      @StripeDev  9 หลายเดือนก่อน

      Happy to help!

  • @bmtamim7818
    @bmtamim7818 11 หลายเดือนก่อน

    I don’t want to redirect them. Just want the charge id for the backend. How can I do this?
    Note: we are using stripe api. We took card data and send to srtipe. In test mood its work. But tomorrow we will live our application and today we just put the live key. And saw stripe sucks. They publish new rule we can't send raw card details. Okay perfect. This message should be with test too. So we aware and took necessary step erliery.
    But they didn’t and we have yo launch it tomorrow and we got this error..now I want to add stripe element but its want redirect url. Our system can't deal with this within one day. So, Stripe put us in trouble.