Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

Stripe: Use Direct API or PHP/Laravel Package?

Premium
8:26

When integrating 3rd-party APIs, you will be lucky if they have a specific PHP/Laravel package. In this lesson, I will show you an example of exactly that.

We will try to integrate Stripe payments with Laravel by building a water park ticket purchasing page.

Water Park Payment Form

We'll explore both approaches: using Laravel's HTTP Client directly with Stripe's API and using their official PHP package.

Let me be honest right away: an official package is almost always a better choice than manually using APIs. In this lesson, I will try to demonstrate why.


What You'll Learn

By the end of this lesson, you will understand how to:

  • Compare HTTP Client approach vs official PHP packages
  • Handle Bearer token authentication in API headers
  • Manage dual API keys (public and private) for payment systems
  • Implement proper exception handling for payment APIs

Structure of Stripe Payment Intent API

Stripe's Payment Intent API is the modern way to handle payments. Here's what a typical request looks like:

Stripe API Documentation

As a result, we should get an object containing the client_secret, which we need to put inside the form for further submission.

Again, we can call this API directly with...

The Full Lesson is Only for Premium Members

Want to access all of our courses? (29 h 46 min)

You also get:

55 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

Comments & Discussion

JV
Johan van den Broek ✓ Link copied!

I had the form url encoding issue before as well with other APIs. Fortunately, the Http facade has a built-in solution.

Try adding ->asForm()

i.e.

$response = Http::withHeaders($headers)->asForm()
->post('https://api.stripe.com/v1/payment_intents', [
'amount' => $amount,
'currency' => $currency,
'automatic_payment_methods' => [
'enabled' => true,
],
'metadata' => [
'order_id' => $orderId ?? uniqid('waterpark_'),
'product' => 'Water Park Ticket',
],
]);
PK
Povilas Korop ✓ Link copied!

Thanks, didn't know that one! Will definitely try in the future.

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.