shopware / paypal-sdk
SDK to communicate with the PayPal API
Requires
- php-http/discovery: ^1.20
- psr/http-client: ^1.0
- psr/http-client-implementation: ^1.0
- psr/http-factory: ^1.1
- psr/simple-cache: ^3.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.75
- guzzlehttp/psr7: ^2.7
- kubawerlos/php-cs-fixer-custom-fixers: ^3.24
- monolog/monolog: ^3.9
- php-http/guzzle7-adapter: ^1.1
- phpstan/extension-installer: ^1.4
- phpstan/phpstan: ^2.1
- phpstan/phpstan-phpunit: ^2.0
- phpunit/phpunit: ^11.5
- roave/backward-compatibility-check: ^8.13
- symplify/phpstan-rules: ^14.5
- zircote/swagger-php: ^5.0
Suggests
- guzzlehttp/psr7: HTTP client implementation
- php-http/guzzle7-adapter: HTTP client implementation
This package is auto-updated.
Last update: 2025-04-16 08:26:26 UTC
README
PayPal SDK for PHP
A PayPal PHP SDK that allows integration of PayPal services into PHP applications. This SDK provides a simple and easy-to-use interface for working with PayPal's REST APIs, making it easier to accept payments, handle PayPal-related tasks and errors.
Warning
Currently this SDK is an extraction of the implementation within Shopware's PayPal plugin. Only use cases and API responses used within the plugin are covered.
Quick start
Installation
You can install the SDK via Composer. Run the following command in your terminal:
composer require shopware/paypal-sdk
In addition, a PSR client implementation is needed. We recommend Guzzle HTTP or Symfony's HttpClient.
composer require guzzlehttp/psr7 php-http/guzzle7-adapter
The php-http/discovery package is used for this library to discover the PSR client implementation automatically. Have a look at their README to set the client implementation manually. Alternatively you can provide a gateway with a concrete client of your choice.
Usage (Simple)
use Shopware\PayPalSDK\Context\ApiContext; use Shopware\PayPalSDK\Context\CredentialsOAuthContext; use Shopware\PayPalSDK\Gateway\OrderGateway; use Shopware\PayPalSDK\Struct\V2\Order; $context = new ApiContext( new CredentialsOAuthContext('<clientId>', '<clientSecret>'), sandbox: true, ); $orderGateway = new OrderGateway(); $toCreateOrder = new Order(); $toCreateOrder->setPaymentSource(...); $createdOrder = $orderGateway->createOrder($toCreateOrder, $context); $anotherOrder = $orderGateway->getOrder('<orderId>', $context);
Usage (Advanced)
use Shopware\PayPalSDK\Context\ApiContext; use Shopware\PayPalSDK\Context\CredentialsOAuthContext; use Shopware\PayPalSDK\Gateway\TokenGateway; use Shopware\PayPalSDK\Gateway\OrderGateway; use Shopware\PayPalSDK\Struct\V2\Order; $context = new ApiContext( new CredentialsOAuthContext('<clientId>', '<clientSecret>'), sandbox: true, merchantId: '<merchantId>', // optional headers: ['some-additional-header' => 'value'], // optional queryParameters: ['filter' => 'value'], // optional thirdParty: false, // optional ) $client = new Http\Adapter\Guzzle7\Client(new GuzzleHttp\Client([ // some custom options like adding a logger middleware ])); $tokenGateway = new TokenGateway($client); $orderGateway = new OrderGateway($client, $tokenGateway); $toCreateOrder = new Order(); $toCreateOrder->setPaymentSource(...); $createdOrder = $orderGateway->createOrder($toCreateOrder, $context); $anotherOrder = $orderGateway->getOrder('<orderId>', $context);