abdelwahidjobs / payment-checkout-api
Multi-provider PHP SDK for Payment Checkout APIs (PayPal & Stripe)
Installs: 1
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/abdelwahidjobs/payment-checkout-api
Requires
- php: ^8.0 || ^8.2
- ext-json: *
- brick/money: ^0.7
- guzzlehttp/guzzle: ^7.5
- guzzlehttp/psr7: ^2.0
- phpjuice/paypal-http-client: ^1.0
Requires (Dev)
- pestphp/pest: ^1.18
- phpstan/phpstan: ^1.12
- phpunit/phpunit: ^9.5
- squizlabs/php_codesniffer: ^3.7
This package is auto-updated.
Last update: 2026-01-26 11:30:35 UTC
README
This package is an enhanced multi-provider payment SDK that supports both PayPal and Stripe payment processing through a unified interface. It provides a simple, fluent API to create, capture, and refund payments with both sandbox and production environments supported.
Features:
- ✅ Unified interface for PayPal and Stripe payments
- ✅ Complete refund functionality for both providers
- ✅ Order creation and capture
- ✅ Sandbox and production environment support
- ✅ Comprehensive error handling
- ✅ Full working examples included
Installation
PayPal Checkout SDK Package requires PHP 7.4 or higher.
INFO: If you are using an older version of php this package may not function correctly.
The supported way of installing PayPal Checkout SDK package is via Composer.
composer require phpjuice/paypal-checkout-sdk
Quick Start Examples
This SDK includes comprehensive working examples to get you started quickly:
Available Example Files
example_usage.php- Basic usage examples for both PayPal and Stripecorrected_test.php- Corrected PayPal implementation exampleworking_example_with_refunds.php- Complete example with refund functionalityexample_refund_usage.php- Dedicated refund examples and advanced usage
Running the Examples
- Replace credential placeholders with your actual API keys in any example file
- Run:
php example_usage.php(or any other example file) - Follow the output instructions for completing payments
Setup
Credentials Setup
PayPal Credentials
Get client ID and client secret from PayPal Developer Console:
- Create a new REST API app
- Copy Client ID and Client Secret
Stripe Credentials
Get API keys from Stripe Dashboard:
- Copy Secret Key (starts with
sk_) - Copy Publishable Key (starts with
pk_)
Basic Provider Setup
use PayPal\Checkout\Factory\PaymentProviderFactory; // PayPal Provider $paypalProvider = PaymentProviderFactory::create('paypal', 'sandbox', [ 'client_id' => 'your_paypal_client_id', 'client_secret' => 'your_paypal_client_secret' ]); // Stripe Provider $stripeProvider = PaymentProviderFactory::create('stripe', 'sandbox', [ 'secret_key' => 'sk_test_your_stripe_secret_key', 'publishable_key' => 'pk_test_your_stripe_publishable_key' ]);
Usage
Creating Orders (Unified Interface)
The same code works for both PayPal and Stripe providers:
use PayPal\Checkout\Orders\Order; use PayPal\Checkout\Orders\PurchaseUnit; use PayPal\Checkout\Orders\Amount; // Create order (same for both providers) $order = new Order(); $order->setIntent('CAPTURE'); // Create purchase unit $purchaseUnit = new PurchaseUnit(); $purchaseUnit->setAmount(new Amount('100.00', 'USD')); $purchaseUnit->setReferenceId('order-' . time()); $order->addPurchaseUnit($purchaseUnit); // Create payment with either provider $response = $paymentProvider->createOrder($order); $responseData = json_decode($response->getBody(), true); echo "Payment ID: " . $responseData['id'];
PayPal-Specific Usage
// PayPal returns approval URL for customer foreach ($responseData['links'] as $link) { if ($link['rel'] === 'approve') { echo "Customer Approval URL: " . $link['href']; break; } }
Stripe-Specific Usage
// Stripe returns client_secret for frontend integration echo "Client Secret: " . $responseData['client_secret'];
Refund Processing
Both providers support full and partial refunds through a unified interface:
use PayPal\Checkout\Refunds\RefundRequest; // Create refund request $refundRequest = new RefundRequest('25.00', 'USD'); // Partial refund $refundRequest->setInvoiceId('refund-' . time()) ->setNoteToPayer('Refund processed as requested') ->setReason('requested_by_customer'); // Process refund (works with both PayPal capture IDs and Stripe payment intent IDs) $refundResponse = $paymentProvider->refundPayment($paymentId, $refundRequest);
Order Details
Retrieve order/payment details:
// Get order details (works for both providers) $detailsResponse = $paymentProvider->showOrder($orderId); $details = json_decode($detailsResponse->getBody(), true);
Example Files Overview
example_usage.php
Complete basic usage examples demonstrating:
- PayPal and Stripe payment creation
- Order details retrieval
- Dynamic provider selection
- Error handling patterns
corrected_test.php
Focused PayPal example showing:
- Proper PayPal order structure
- JSON output for debugging
- Comprehensive error handling
- Working PayPal implementation
working_example_with_refunds.php
Comprehensive example featuring:
- Multi-provider payment creation (PayPal & Stripe)
- Complete refund functionality for both providers
- Refund request creation and processing
- Summary of all implemented features
example_refund_usage.php
Dedicated refund examples including:
- Full and partial refund processing
- Advanced refund request configuration
- Multi-provider refund testing
- Production-ready refund patterns
Getting Started
- Choose the example file that best matches your needs
- Replace credential placeholders with your actual API keys
- Run:
php filename.php - Follow console output for next steps
Changelog
Please see the changelog for more information on what has changed recently.
Contributing
Please see CONTRIBUTING.md for details and a todo list.
Security
If you discover any security related issues, please email author instead of using the issue tracker.
Credits
License
Please see the LICENSE file for more information.