Stripe is the gold standard for online payments and their PHP SDK makes integration straightforward. In this guide, we will walk through a complete integration from installation to handling webhooks in production.
Prerequisites
- PHP 8.1+
- Composer installed
- Stripe account (free to create)
Step 1 — Install the SDK
composer require stripe/stripe-php
Step 2 — Create a Payment Intent
$stripe = new StripeStripeClient(STRIPE_SECRET_KEY);
$intent = $stripe->paymentIntents->create([
"amount" => 2999,
"currency" => "usd",
"automatic_payment_methods" => ["enabled" => true],
]);
Step 3 — Handle the Webhook
Webhooks are essential for confirming payments server-side. Always verify the signature...
Set your webhook URL in the Stripe Dashboard to https://yoursite.com/payment/stripe-webhook.php and listen to payment_intent.succeeded.
Testing
Use test card 4242 4242 4242 4242 with any future expiry and CVV.