phpjuice / paypal-checkout-sdk
Paypal Checkout SDK
Installs: 1 397
Dependents: 1
Suggesters: 0
Security: 0
Stars: 17
Watchers: 3
Forks: 0
Open Issues: 3
Requires
- php: ^7.2
- guzzlehttp/guzzle: ^7.0
- guzzlehttp/psr7: ^1.6
Requires (Dev)
- phpstan/phpstan: ^0.11.5
- phpunit/phpunit: ^9.0
- squizlabs/php_codesniffer: ^3.4
This package is auto-updated.
Last update: 2021-02-10 11:52:09 UTC
README
PayPal Checkout SDK is a wrapper around the V2 Paypal rest API.
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
Usage
PayPal Checkout SDK is designed to simplify using the new paypal checkout api in your app.
Setup Credentials
Get client ID and client secret by going to https://developer.paypal.com/developer/applications and generating a REST API app. Get Client ID and Secret from there.
Setup a Paypal Client
Inorder to communicate with paypal platform we need to setup a client first :
- Create a client with sandbox environment :
// import namespace use PayPal\Checkout\Environment\SandboxEnvironment; use PayPal\Checkout\Http\PayPalClient; // client id and client secret retrieved from paypal $clientId = "<<PAYPAL-CLIENT-ID>>"; $clientSecret = "<<PAYPAL-CLIENT-SECRET>>"; // create a new sandbox environment $environment = new SandboxEnvironment($clientId, $clientSecret); // create a new client $client = new PayPalClient($environment);
- Create a client with production environment :
// import namespace use PayPal\Checkout\Environment\ProductionEnvironment; use PayPal\Checkout\Http\PayPalClient; // client id and client secret retrieved from paypal $clientId = "<<PAYPAL-CLIENT-ID>>"; $clientSecret = "<<PAYPAL-CLIENT-SECRET>>"; // create a new sandbox environment $environment = new ProductionEnvironment($clientId, $clientSecret); // create a new client $client = new PayPalClient($environment);
Create a new Order
// import namespace use PayPal\Checkout\Http\OrderCreateRequest; use PayPal\Checkout\Orders\Item; use PayPal\Checkout\Orders\Order; use PayPal\Checkout\Orders\PurchaseUnit; // create a purchase unit with the total amount $purchase_unit = new PurchaseUnit('USD', 100.00); // create a new item $item = new Item('Item 1', 'USD', 100.00, 1); // add item to purchase unit $purchase_unit->addItem($item); // create a new order with intent to capture a payment $order = new Order('CAPTURE'); // add a purchase unit to order $order->addPurchaseUnit($purchase_unit); // create an order create http request $request = new OrderCreateRequest($order); // send request to paypal $response = $client->send($request); // parse result $result = json_decode((string) $response->getBody()); echo $result->id; // id of the created order
Change log
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
license. Please see the Licence for more information.