Author: Abbas Can Ovacık
This project demonstrates a simple Stripe payment integration using PHP, Docker, and Stripe.js. It allows users to enter billing and card details, process payments, and handle 3D Secure authentication.
- Stripe Elements for secure card input
- Billing address and contact information collection
- Payment processing via Stripe PaymentIntents API
- 3D Secure (authentication) support
- SweetAlert2 integration for elegant success/error notifications
- Phone number input masking with Inputmask
- Enhanced payment status handling with detailed feedback
- Dockerized PHP 8.2 + Apache environment
- ✨ SweetAlert2 Integration: Replaced basic HTML notifications with elegant, user-friendly alerts
- 📱 Phone Input Masking: Added automatic phone number formatting (+1 (999) 999-9999)
- 🔧 Enhanced Error Handling: Improved payment status feedback with detailed error messages
- 🌐 Internationalization: All UI messages and alerts in English
- 🎨 Better UX: Form automatically resets after successful payment
public/— Main web application filescard-payment.html— Payment form UI with Stripe Elements integrationpayment.js— Stripe.js integration, form handling, and SweetAlert2 notificationspayment.css— Styling for the payment formcreate.php— Backend endpoint to create Stripe PaymentIntentcomplete.php— Endpoint to handle post-payment status validationcomplete.html— Payment completion pagecomplete.js— Client-side completion handlingstatus.php— Payment status check endpointpublic_key.php— Endpoint to expose the Stripe publishable key securely
secrets.php— Loads Stripe secret key and publishable key from environment (.env).env— Environment variables (Stripe keys, etc.) - Not tracked in git.env.example— Environment variables templatecomposer.json/composer.lock— PHP dependencies (Stripe PHP SDK)Dockerfile— PHP 8.2 + Apache setupdocker-compose.yml— Development environment orchestrationLICENSE— MIT License
- Clone the repository
- Configure Stripe keys
- Copy
.env.exampleto.envand fill in your Stripe keys:STRIPE_SECRET_KEY=sk_test_xxx STRIPE_PUBLISHABLE_KEY=pk_test_xxx
secrets.phpwill automatically load keys from.envpublic/public_key.phpexposes only the publishable key to frontend
- Copy
- Install dependencies
- Run:
docker compose run --rm composer install
- Run:
- Start the application
- Run:
docker compose up -d
- Access the app at
http://localhost:8080
- Run:
- Open
http://localhost:8080/card-payment.htmlin your browser - Enter billing and card details (phone number is automatically formatted)
- Submit the form to process payment
- If 3D Secure is required, you will be redirected for authentication
- Payment status will be displayed via SweetAlert2 notification
- For testing, use Stripe test card:
4242 4242 4242 4242with any future expiry date and CVC
- Never expose your Stripe secret key publicly
public_key.phpis used to expose only the publishable key- This example is for educational and test purposes only
- For production, ensure PCI compliance and secure key management
This project is licensed under the MIT License - see the LICENSE file for details.
Copyright (c) 2026–present Abbas Can Ovacık
- Stripe PHP SDK - Server-side payment processing
- Stripe.js & Elements - Secure client-side card input
- Stripe PaymentIntents API - Payment handling
- Stripe Test Cards
- SweetAlert2 - Beautiful alert notifications
- Inputmask - Phone number formatting
- Docker - Containerization