A simple PHP application demonstrating Magpie Checkout integration for digital art sales using Magpie PHP SDK.
- Clean, responsive product display page
- Integration with Picsum Photos for random product images
- Magpie payment processing with checkout session creation
- Error handling and user-friendly error messages
- Success page after payment completion
- Mobile-responsive design
- PHP 7.4 or higher
- Composer for dependency management
- Web server (Apache, Nginx, or PHP built-in server)
- Magpie account with API credentials
-
Clone or download this repository
git clone <repository-url> cd sample-magpie-php
-
Install dependencies using Composer
composer install
-
Configure environment variables
cp .env.example .env
Edit the
.envfile and add your Magpie API credentials:MAGPIE_SECRET_KEY=your_magpie_secret_key_here APP_ENV=development APP_DEBUG=true
-
Sign up for a Magpie account
- Visit https://dashboard.magpie.im
- Create a new account or log in to your existing account
-
Create a new application
- Navigate to your Magpie dashboard
- Go to "Developers", under "API Keys" section
-
Get your API credentials
- Copy your Secret Key (used for server-side operations)
- Important: Keep your secret key secure and never expose it in client-side code
php -S localhost:8000Then open your browser and visit: http://localhost:8000
- Configure your web server to serve the application directory
- Ensure the web server has read permissions for all files
- Make sure the
.envfile is not publicly accessible
sample-magpie-php/
├── composer.json # Composer configuration
├── .env.example # Environment variables template
├── .env # Your environment variables (not in git)
├── index.php # Main product page
├── checkout.php # Checkout session handler
├── success.php # Payment success page
├── vendor/ # Composer dependencies
└── README.md # This file
-
Product Display (
index.php)- Shows a digital art product with random image from Picsum
- Displays product name, artist, and price (PHP 1.00)
- Contains a "Buy Now" button that submits to checkout.php
-
Checkout Processing (
checkout.php)- Validates environment configuration
- Creates a Magpie Checkout Session with product details
- Redirects user to Magpie's secure Checkout page
- Handles errors and redirects back with error messages
-
Success Page (
success.php)- Displays confirmation after successful payment
- Provides link back to the main store
The application includes comprehensive error handling:
- Configuration errors: Missing or invalid API credentials
- Session creation errors: Failed to create Magpie Checkout Session
- Network errors: API communication issues
Errors are logged to PHP error log and user-friendly messages are displayed.
- Environment variables are used for sensitive API credentials
.envfile should not be committed to version control- Server-side validation of all payment data
- Proper error handling without exposing sensitive information
- HTTPS should be used in production
Edit the product details in index.php:
- Update the product name, artist, and price
- Modify the image source or use a static image
- Adjust the styling as needed
The CSS is embedded in the HTML files for simplicity. You can:
- Extract CSS to separate files
- Add CSS frameworks like Bootstrap or Tailwind
- Customize colors, fonts, and layout
Consider adding:
- Multiple products with a database
- User accounts and order history
- Email notifications
- Inventory management
- Discount codes
-
"Configuration error" message
- Check that
.envfile exists and has correct credentials - Verify Magpie API keys are valid
- Ensure environment variables are loading correctly
- Check that
-
"Failed to create checkout session" message
- Verify your Magpie account is active
- Check API credential permissions
- Review server error logs for detailed error messages
-
Composer dependencies not loading
- Run
composer installto install dependencies - Check that Composer is installed correctly
- Verify the custom repository URL is accessible
- Run
Enable debug mode in .env:
APP_DEBUG=trueThis will provide more detailed error messages during development.
For issues with:
- Magpie API: Contact Magpie support or check their documentation
- This application: Check the error logs and verify your configuration
- PHP/Composer: Refer to official PHP and Composer documentation
This sample application is provided as-is for demonstration purposes.