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
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
This SDK includes comprehensive working examples to get you started quickly:
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
- 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
Get client ID and client secret from PayPal Developer Console:
- Create a new REST API app
- Copy Client ID and Client Secret
Get API keys from Stripe Dashboard:
- Copy Secret Key (starts with
sk_
) - Copy Publishable Key (starts with
pk_
)
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'
]);
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 returns approval URL for customer
foreach ($responseData['links'] as $link) {
if ($link['rel'] === 'approve') {
echo "Customer Approval URL: " . $link['href'];
break;
}
}
// Stripe returns client_secret for frontend integration
echo "Client Secret: " . $responseData['client_secret'];
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);
Retrieve order/payment details:
// Get order details (works for both providers)
$detailsResponse = $paymentProvider->showOrder($orderId);
$details = json_decode($detailsResponse->getBody(), true);
Complete basic usage examples demonstrating:
- PayPal and Stripe payment creation
- Order details retrieval
- Dynamic provider selection
- Error handling patterns
Focused PayPal example showing:
- Proper PayPal order structure
- JSON output for debugging
- Comprehensive error handling
- Working PayPal implementation
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
Dedicated refund examples including:
- Full and partial refund processing
- Advanced refund request configuration
- Multi-provider refund testing
- Production-ready refund patterns
- 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
Please see the changelog for more information on what has changed recently.
Please see CONTRIBUTING.md for details and a todo list.
If you discover any security related issues, please email author instead of using the issue tracker.
Please see the LICENSE file for more information.