PayPal REST API client for Laravel and standalone PHP.
PayPal REST API client for Laravel and standalone PHP.
A PayPal REST API package for Laravel, also usable as a standalone PHP client without any framework.
Supports: PHP 8.2–8.5 · Laravel 12 / 13
Disclaimer: This package is an independent community project and is not affiliated with, endorsed by, or supported by PayPal, Inc. "PayPal" is a registered trademark of PayPal, Inc. Use this package at your own risk; no warranty is provided beyond what the MIT license covers.
| Version | PayPal API | PayPal Deprecation | PHP | Laravel | Maintained |
|---|---|---|---|---|---|
| v1.0 | Classic NVP/SOAP (Express Checkout, Adaptive Payments) | Deprecated since 2017, no firm sunset date | 5.6+ | 5.1+ | ❌ |
| v2.0 | REST v1 Payments + v2 Orders | /v1/payments sunset Jan 2027 |
7.2+ | 6+ | ❌ |
| v3.0 | REST v2 Orders + v2 Subscriptions | Current | 7.4+ | 6–12 | ❌ |
| v3.1 | REST v2 Orders + v2 Subscriptions | Current | 8.2+ | 12–13 | ✅ |
setClient()timeout, connect_timeout, max_retries in configwithExceptions() for PayPalApiExceptionverifyWebHookLocally() with in-memory cert caching, no API roundtripgenerateClientToken() for one-click guest checkoutgetCaptureIdFromOrder() — extract capture/transaction ID from order responsesPayPal is sunsetting the v1 Payments REST API (/v1/payments/payment) in January 2027. If your integration uses the old create-payment → redirect → execute-payment flow, or the classic Billing Agreements API (/v1/billing-agreements/), you need to migrate before then.
This package already uses Orders v2 and Subscriptions v2 throughout. The migration notes below are for callers who built custom flows against the legacy endpoints or who were previously using the Express Checkout helpers from older versions.
| Old (v1 Payments — being sunset) | New (Orders v2) |
|---|---|
POST /v1/payments/payment → redirect → POST /v1/payments/payment/{id}/execute |
createOrder() → redirect → capturePaymentOrder() |
…| Old (v1 Billing Agreements — being sunset) | New (Subscriptions v2) |
|---|---|
createBillingAgreementToken() → createBillingAgreement() |
addProductById() → addBillingPlanById() → setupSubscription() |
// New subscriptions flow
$response = $provider->addProductById('PROD-XYAB12ABSB7868434')
->addBillingPlanById('P-5ML4271244454362WXNWU5NQ')
->setReturnAndCancelUrl('https://example.com/success', 'https://example.com/cancel')
->setupSubscription('John Doe', '[email protected]');
// Redirect the buyer to: $response['links'][href where rel === 'approve']See the Subscription Helpers section for creating plans programmatically.
composer require srmklive/paypalPublish the config file:
php artisan vendor:publish --provider "Srmklive\PayPal\Providers\PayPalServiceProvider"The package has no hard dependency on Laravel — you can use it in any PHP project:
composer require srmklive/paypalInstantiate the client and pass your credentials directly via setApiCredentials(). No service provider or .env file needed:
…The facade and php artisan vendor:publish are Laravel-only conveniences; everything else works identically.
Add to your .env:
PAYPAL_MODE=sandbox
PAYPAL_SANDBOX_CLIENT_ID=
PAYPAL_SANDBOX_CLIENT_SECRET=
PAYPAL_LIVE_CLIENT_ID=
PAYPAL_LIVE_CLIENT_SECRET=
PAYPAL_LIVE_APP_ID=
# Optional — shown with defaults
PAYPAL_TIMEOUT=30
PAYPAL_CONNECT_TIMEOUT=10
PAYPAL_MAX_RETRIES=2The published config/paypal.php:
…use Srmklive\PayPal\Services\PayPal as PayPalClient;
$provider = new PayPalClient;
// Or via facade
$provider = \PayPal::setProvider();setClient() accepts any PSR-18 ClientInterface, so you can swap out Guzzle for Symfony HttpClient, Buzz, or any other compliant implementation:
use Symfony\Component\HttpClient\Psr18Client;
$provider->setClient(new Psr18Client());Pass null (or call with no argument) to restore the default Guzzle client with the configured timeout and retry middleware.
Note: The built-in retry middleware runs only on the default Guzzle client. When you inject a custom client, handle retries in that client's own middleware stack.
The default Guzzle client automatically retries failed requests up to max_retries times (default: 2) for:
Retry-After header is read and honoured when presentThe delay between attempts uses exponential backoff (500 ms → 1 s → 2 s → 4 s, capped at 8 s) unless a Retry-After header overrides it. Set max_retries to 0 to disable retries entirely.
$provider->setApiCredentials([
'mode' => 'live',
'live' => [
'client_id' => 'PAYPAL_LIVE_CLIENT_ID',
'client_secret' => 'PAYPAL_LIVE_CLIENT_SECRET',
'app_id' => 'PAYPAL_LIVE_APP_ID',
],
'payment_action' => 'Sale',
'currency' => 'USD',
'notify_url' => 'https://your-site.com/paypal/notify',
'locale' => 'en_US',
'validate_ssl' => true,
]);Call this before any API method:
$provider->getAccessToken();$provider->setCurrency('EUR');PayPal uses the PayPal-Partner-Attribution-Id header to attribute transactions to a partner or platform. Set it once after initialisation — it persists for the lifetime of the provider instance:
$provider->setPartnerAttributionId('YourPlatform_SP');All subsequent API calls will include the header automatically.
By default, API errors are returned as an array with an error key:
$response = $provider->showOrderDetails('bad-id');
if (isset($response['error'])) {
// $response['error'] is the decoded PayPal error object or a plain string
}Opt in to exceptions with withExceptions(). All API errors will then throw PayPalApiException instead:
use Srmklive\PayPal\Exceptions\PayPalApiException;
$provider->withExceptions();
try {
$order = $provider->showOrderDetails('bad-id');
} catch (PayPalApiException $e) {
$e->getHttpStatus(); // HTTP status code: 400, 401, 404, 422, 500, etc. (0 for network errors)
$e->getMessage(); // JSON-encoded error string
$e->getPayPalError(); // decoded array (e.g. ['name' => 'RESOURCE_NOT_FOUND', ...])
// or a plain string for non-JSON errors
}Call withoutExceptions() to revert to silent mode. Both methods are fluent.
PayPal Fastlane is a one-click guest checkout experience that pre-fills shipping and payment details for returning PayPal customers, typically delivering ~50% higher conversion on guest checkout flows.
Server role: generate a client token and handle Orders v2 create/capture. The Fastlane UI is rendered entirely by the PayPal JS SDK on the client.
$provider->getAccessToken();
$result = $provider->generateClientToken();
// $result['client_token'] — pass this to your frontend// Create
$order = $provider->createOrder([
'intent' => 'CAPTURE',
'purchase_units' => [
['amount' => ['currency_code' => 'USD', 'value' => '49.99']],
],
'payment_source' => [
'card' => [
'single_use_token' => $singleUseToken, // from Fastlane.FastlaneCardComponent
],
],
]);
// Capture
$capture = $provider->capturePaymentOrder($order['id']);
// Extract the transaction/capture ID
$captureId = $provider->getCaptureIdFromOrder($capture);Pay Upon Invoice (Rechnungskauf) lets buyers in Germany and Austria pay after receiving goods. PayPal collects the payment and the merchant is paid upfront.
Requirements: DE/AT merchant account, buyer name, email, date of birth, phone number, and billing address.
…A fluent helper API for creating subscriptions without manually building plan/product payloads.
addPlanTrialPricing()andsetReturnAndCancelUrl()are optional. Return/cancel URLs require real domains (notlocalhost).
$response = $provider->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE')
->addPlanTrialPricing('DAY', 7)
->addDailyPlan('Demo Plan', 'Demo Plan', 1.50)
->setReturnAndCancelUrl('https://example.com/paypal-success', 'https://example.com/paypal-cancel')
->setupSubscription('John Doe', '[email protected]', '2025-01-01');…$response = $provider->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE')
->addCustomPlan('Demo Plan', 'Demo Plan', 150, 'MONTH', 3)
->setReturnAndCancelUrl('https://example.com/paypal-success', 'https://example.com/paypal-cancel')
->setupSubscription('John Doe', '[email protected]', '2025-01-01');$response = $provider->addProductById('PROD-XYAB12ABSB7868434')
->addBillingPlanById('P-5ML4271244454362WXNWU5NQ')
->setReturnAndCancelUrl('https://eNo open issues yet, or sync has not completed.