Stripe Payment Integration in Core PHP (No Composer, cURL Method)

php dev.to

How to Integrate Stripe Payment in Core PHP (No Composer, No SDK, Using cURL)

This article is part of our "Simple Integration Series."

If you’ve tried integrating Stripe before, you’ve probably noticed one thing—most tutorials are complex.

They use frameworks, SDKs, or multiple files.

👉 In this guide, we’ll do the opposite.

We will integrate Stripe using:

Core PHP
Single-file setup
No Composer
No Stripe SDK
Only cURL

Perfect for beginners and quick projects.

✅ What You’ll Learn
How to integrate Stripe using pure PHP
How to create a Checkout session using cURL
How Stripe authentication works
How to verify payment status
Common mistakes to avoid


  1. Requirements

Before starting, make sure you have:

PHP 7 or higher
cURL enabled in PHP
A Stripe account
Your Stripe API Secret Key (sk_test_...)


  1. Important Note

We are not using Stripe’s official PHP library here.

Instead, we directly call Stripe APIs using cURL, which:

Reduces setup complexity
Gives more control
Works without Composer

👉 This is ideal for simple projects.


  1. Create Stripe Checkout Session (Single File)

Create a file like payment.php:

<?php

$secret_key = "sk_test_xxxxxxxxxxxxx";

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://api.stripe.com/v1/checkout/sessions");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);

// Authentication
curl_setopt($ch, CURLOPT_USERPWD, $secret_key . ":");

// Payment Data
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query([
'success_url' => 'http://localhost/success.php?session_id={CHECKOUT_SESSION_ID}',
'cancel_url' => 'http://localhost/cancel.php',
'mode' => 'payment',

'line_items[0][price_data][currency]' => 'usd',
'line_items[0][price_data][product_data][name]' => 'Test Product',
'line_items[0][price_data][unit_amount]' => 5000,
'line_items[0][quantity]' => 1,
Enter fullscreen mode Exit fullscreen mode

]));

$response = curl_exec($ch);
curl_close($ch);

$result = json_decode($response, true);

// Redirect user to Stripe Checkout
header("Location: " . $result['url']);
exit;
🔍 Explanation (Simple)
CURLOPT_USERPWD → Auth using your secret key
POSTFIELDS → Sends payment data
unit_amount → Amount in cents (5000 = $50)
line_items → Product details
Response → Contains Checkout URL


  1. Success Page (Verify Payment)

Create success.php:

<?php

$session_id = $_GET['session_id'];
$secret_key = "sk_test_xxxxxxxxxxxxx";

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://api.stripe.com/v1/checkout/sessions/" . $session_id);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, $secret_key . ":");

$response = curl_exec($ch);
curl_close($ch);

$data = json_decode($response, true);

echo "

Payment Status: " . $data['payment_status'] . "

";
  1. Optional: Debugging (Recommended)

If something doesn’t work, add:

echo "

";
print_r($result);
exit;

👉 This helps you see the full Stripe response.


  1. Common Mistakes to Avoid

❌ Forgetting : after secret key in cURL authentication
❌ Using live key in test mode
❌ Not converting amount into cents
❌ cURL not enabled in PHP
❌ Missing session_id in success URL


  1. When Should You Use This Method?

This simple approach is best for:

✔ Learning Stripe basics
✔ Small projects
✔ Quick payment integrations
✔ Testing ideas

⚠ When NOT to Use

For large-scale or production-heavy apps:

Use Stripe SDK
Implement webhooks properly
Add security layers


  1. Optional: Store Payment in MySQL (Simple Idea)

You can store:

session_id
amount
payment_status

👉 Keep it simple:

Create one table
Insert data after success

  1. Test Cards (Quick Reference)

Use these in Stripe Test Mode:

Successful payment: 4242 4242 4242 4242
Requires authentication: 4000 0025 0000 3155
Payment fails: 4000 0000 0000 9995

👉 Use any future expiry and random CVC.


  1. Conclusion

Stripe integration doesn’t have to be complicated.

In this guide, we:

Used pure PHP
Avoided Composer and SDK
Built a working payment flow in a single file

👉 Simple, fast, and effective.

🚀 Need Help with Stripe Integration?

We build simple and scalable payment systems using Stripe.

✔ SaaS billing systems
✔ Marketplace & split payments
✔ Custom Stripe integrations

👉 Contact us to get your Stripe integration done professionally.

Source: dev.to

arrow_back Back to Tutorials