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
- 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_...)
- 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.
- 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,
]));
$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
- 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'] . "
";- Optional: Debugging (Recommended)
If something doesnβt work, add:
echo "
";
print_r($result);
exit;π This helps you see the full Stripe response.
- 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
- 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
- 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
- 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.
- 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.
Top comments (0)