From 19985dbb8c0aa66dc4bf7905abc1148de909097d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20Luka=20=C5=A0ijanec?= Date: Tue, 11 Jan 2022 12:35:47 +0100 Subject: prvi-commit --- vendor/paypal/paypal-checkout-sdk/.gitignore | 2 + vendor/paypal/paypal-checkout-sdk/LICENSE | 86 ++++++++ vendor/paypal/paypal-checkout-sdk/README.md | 169 +++++++++++++++ vendor/paypal/paypal-checkout-sdk/composer.json | 35 +++ vendor/paypal/paypal-checkout-sdk/composer.phar | Bin 0 -> 1874955 bytes vendor/paypal/paypal-checkout-sdk/gen.yml | 6 + vendor/paypal/paypal-checkout-sdk/homepage.jpg | Bin 0 -> 165333 bytes vendor/paypal/paypal-checkout-sdk/init | 0 .../lib/PayPalCheckoutSdk/Core/AccessToken.php | 25 +++ .../PayPalCheckoutSdk/Core/AccessTokenRequest.php | 27 +++ .../Core/AuthorizationInjector.php | 51 +++++ .../Core/FPTIInstrumentationInjector.php | 16 ++ .../lib/PayPalCheckoutSdk/Core/GzipInjector.php | 14 ++ .../PayPalCheckoutSdk/Core/PayPalEnvironment.php | 23 ++ .../PayPalCheckoutSdk/Core/PayPalHttpClient.php | 27 +++ .../Core/ProductionEnvironment.php | 16 ++ .../PayPalCheckoutSdk/Core/RefreshTokenRequest.php | 19 ++ .../PayPalCheckoutSdk/Core/SandboxEnvironment.php | 16 ++ .../lib/PayPalCheckoutSdk/Core/UserAgent.php | 52 +++++ .../lib/PayPalCheckoutSdk/Core/Version.php | 8 + .../Orders/OrdersAuthorizeRequest.php | 37 ++++ .../Orders/OrdersCaptureRequest.php | 37 ++++ .../Orders/OrdersCreateRequest.php | 31 +++ .../PayPalCheckoutSdk/Orders/OrdersGetRequest.php | 26 +++ .../Orders/OrdersPatchRequest.php | 26 +++ .../Orders/OrdersValidateRequest.php | 29 +++ .../Payments/AuthorizationsCaptureRequest.php | 33 +++ .../Payments/AuthorizationsGetRequest.php | 25 +++ .../Payments/AuthorizationsReauthorizeRequest.php | 33 +++ .../Payments/AuthorizationsVoidRequest.php | 25 +++ .../Payments/CapturesGetRequest.php | 25 +++ .../Payments/CapturesRefundRequest.php | 33 +++ .../Payments/RefundsGetRequest.php | 25 +++ vendor/paypal/paypal-checkout-sdk/phpunit.xml | 9 + .../AuthorizeIntentExamples/AuthorizeOrder.php | 61 ++++++ .../AuthorizeIntentExamples/CaptureOrder.php | 55 +++++ .../AuthorizeIntentExamples/CreateOrder.php | 237 +++++++++++++++++++++ .../samples/AuthorizeIntentExamples/RunAll.php | 82 +++++++ .../samples/CaptureIntentExamples/CaptureOrder.php | 60 ++++++ .../samples/CaptureIntentExamples/CreateOrder.php | 178 ++++++++++++++++ .../samples/CaptureIntentExamples/RunAll.php | 74 +++++++ .../paypal-checkout-sdk/samples/ErrorSample.php | 94 ++++++++ .../paypal-checkout-sdk/samples/GetOrder.php | 54 +++++ .../paypal-checkout-sdk/samples/PatchOrder.php | 82 +++++++ .../paypal-checkout-sdk/samples/PayPalClient.php | 35 +++ .../paypal-checkout-sdk/samples/RefundOrder.php | 60 ++++++ .../tests/Orders/OrdersAuthorizeTest.php | 26 +++ .../tests/Orders/OrdersCaptureTest.php | 26 +++ .../tests/Orders/OrdersCreateTest.php | 69 ++++++ .../tests/Orders/OrdersGetTest.php | 48 +++++ .../tests/Orders/OrdersPatchTest.php | 73 +++++++ .../paypal-checkout-sdk/tests/TestHarness.php | 24 +++ vendor/paypal/paypalhttp/.gitattributes | 7 + vendor/paypal/paypalhttp/.gitignore | 32 +++ vendor/paypal/paypalhttp/.travis.yml | 16 ++ vendor/paypal/paypalhttp/CHANGELOG.md | 2 + vendor/paypal/paypalhttp/CONTRIBUTING.md | 10 + vendor/paypal/paypalhttp/LICENSE | 23 ++ vendor/paypal/paypalhttp/README.md | 76 +++++++ vendor/paypal/paypalhttp/Rakefile | 2 + vendor/paypal/paypalhttp/composer.json | 23 ++ vendor/paypal/paypalhttp/lib/PayPalHttp/Curl.php | 57 +++++ .../paypal/paypalhttp/lib/PayPalHttp/Encoder.php | 114 ++++++++++ .../paypalhttp/lib/PayPalHttp/Environment.php | 18 ++ .../paypalhttp/lib/PayPalHttp/HttpClient.php | 231 ++++++++++++++++++++ .../paypalhttp/lib/PayPalHttp/HttpException.php | 23 ++ .../paypalhttp/lib/PayPalHttp/HttpRequest.php | 42 ++++ .../paypalhttp/lib/PayPalHttp/HttpResponse.php | 34 +++ .../paypalhttp/lib/PayPalHttp/IOException.php | 13 ++ .../paypal/paypalhttp/lib/PayPalHttp/Injector.php | 19 ++ .../paypalhttp/lib/PayPalHttp/Serializer.php | 29 +++ .../paypalhttp/lib/PayPalHttp/Serializer/Form.php | 46 ++++ .../lib/PayPalHttp/Serializer/FormPart.php | 25 +++ .../paypalhttp/lib/PayPalHttp/Serializer/Json.php | 38 ++++ .../lib/PayPalHttp/Serializer/Multipart.php | 134 ++++++++++++ .../paypalhttp/lib/PayPalHttp/Serializer/Text.php | 38 ++++ vendor/paypal/paypalhttp/phpunit.xml | 10 + 77 files changed, 3386 insertions(+) create mode 100644 vendor/paypal/paypal-checkout-sdk/.gitignore create mode 100644 vendor/paypal/paypal-checkout-sdk/LICENSE create mode 100644 vendor/paypal/paypal-checkout-sdk/README.md create mode 100644 vendor/paypal/paypal-checkout-sdk/composer.json create mode 100644 vendor/paypal/paypal-checkout-sdk/composer.phar create mode 100644 vendor/paypal/paypal-checkout-sdk/gen.yml create mode 100644 vendor/paypal/paypal-checkout-sdk/homepage.jpg create mode 100644 vendor/paypal/paypal-checkout-sdk/init create mode 100644 vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Core/AccessToken.php create mode 100644 vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Core/AccessTokenRequest.php create mode 100644 vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Core/AuthorizationInjector.php create mode 100644 vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Core/FPTIInstrumentationInjector.php create mode 100644 vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Core/GzipInjector.php create mode 100644 vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Core/PayPalEnvironment.php create mode 100644 vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Core/PayPalHttpClient.php create mode 100644 vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Core/ProductionEnvironment.php create mode 100644 vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Core/RefreshTokenRequest.php create mode 100644 vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Core/SandboxEnvironment.php create mode 100644 vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Core/UserAgent.php create mode 100644 vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Core/Version.php create mode 100644 vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Orders/OrdersAuthorizeRequest.php create mode 100644 vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Orders/OrdersCaptureRequest.php create mode 100644 vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Orders/OrdersCreateRequest.php create mode 100644 vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Orders/OrdersGetRequest.php create mode 100644 vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Orders/OrdersPatchRequest.php create mode 100644 vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Orders/OrdersValidateRequest.php create mode 100644 vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Payments/AuthorizationsCaptureRequest.php create mode 100644 vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Payments/AuthorizationsGetRequest.php create mode 100644 vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Payments/AuthorizationsReauthorizeRequest.php create mode 100644 vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Payments/AuthorizationsVoidRequest.php create mode 100644 vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Payments/CapturesGetRequest.php create mode 100644 vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Payments/CapturesRefundRequest.php create mode 100644 vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Payments/RefundsGetRequest.php create mode 100644 vendor/paypal/paypal-checkout-sdk/phpunit.xml create mode 100644 vendor/paypal/paypal-checkout-sdk/samples/AuthorizeIntentExamples/AuthorizeOrder.php create mode 100644 vendor/paypal/paypal-checkout-sdk/samples/AuthorizeIntentExamples/CaptureOrder.php create mode 100644 vendor/paypal/paypal-checkout-sdk/samples/AuthorizeIntentExamples/CreateOrder.php create mode 100644 vendor/paypal/paypal-checkout-sdk/samples/AuthorizeIntentExamples/RunAll.php create mode 100644 vendor/paypal/paypal-checkout-sdk/samples/CaptureIntentExamples/CaptureOrder.php create mode 100644 vendor/paypal/paypal-checkout-sdk/samples/CaptureIntentExamples/CreateOrder.php create mode 100644 vendor/paypal/paypal-checkout-sdk/samples/CaptureIntentExamples/RunAll.php create mode 100644 vendor/paypal/paypal-checkout-sdk/samples/ErrorSample.php create mode 100644 vendor/paypal/paypal-checkout-sdk/samples/GetOrder.php create mode 100644 vendor/paypal/paypal-checkout-sdk/samples/PatchOrder.php create mode 100644 vendor/paypal/paypal-checkout-sdk/samples/PayPalClient.php create mode 100644 vendor/paypal/paypal-checkout-sdk/samples/RefundOrder.php create mode 100644 vendor/paypal/paypal-checkout-sdk/tests/Orders/OrdersAuthorizeTest.php create mode 100644 vendor/paypal/paypal-checkout-sdk/tests/Orders/OrdersCaptureTest.php create mode 100644 vendor/paypal/paypal-checkout-sdk/tests/Orders/OrdersCreateTest.php create mode 100644 vendor/paypal/paypal-checkout-sdk/tests/Orders/OrdersGetTest.php create mode 100644 vendor/paypal/paypal-checkout-sdk/tests/Orders/OrdersPatchTest.php create mode 100644 vendor/paypal/paypal-checkout-sdk/tests/TestHarness.php create mode 100644 vendor/paypal/paypalhttp/.gitattributes create mode 100644 vendor/paypal/paypalhttp/.gitignore create mode 100644 vendor/paypal/paypalhttp/.travis.yml create mode 100644 vendor/paypal/paypalhttp/CHANGELOG.md create mode 100644 vendor/paypal/paypalhttp/CONTRIBUTING.md create mode 100644 vendor/paypal/paypalhttp/LICENSE create mode 100644 vendor/paypal/paypalhttp/README.md create mode 100644 vendor/paypal/paypalhttp/Rakefile create mode 100644 vendor/paypal/paypalhttp/composer.json create mode 100644 vendor/paypal/paypalhttp/lib/PayPalHttp/Curl.php create mode 100644 vendor/paypal/paypalhttp/lib/PayPalHttp/Encoder.php create mode 100644 vendor/paypal/paypalhttp/lib/PayPalHttp/Environment.php create mode 100644 vendor/paypal/paypalhttp/lib/PayPalHttp/HttpClient.php create mode 100644 vendor/paypal/paypalhttp/lib/PayPalHttp/HttpException.php create mode 100644 vendor/paypal/paypalhttp/lib/PayPalHttp/HttpRequest.php create mode 100644 vendor/paypal/paypalhttp/lib/PayPalHttp/HttpResponse.php create mode 100644 vendor/paypal/paypalhttp/lib/PayPalHttp/IOException.php create mode 100644 vendor/paypal/paypalhttp/lib/PayPalHttp/Injector.php create mode 100644 vendor/paypal/paypalhttp/lib/PayPalHttp/Serializer.php create mode 100644 vendor/paypal/paypalhttp/lib/PayPalHttp/Serializer/Form.php create mode 100644 vendor/paypal/paypalhttp/lib/PayPalHttp/Serializer/FormPart.php create mode 100644 vendor/paypal/paypalhttp/lib/PayPalHttp/Serializer/Json.php create mode 100644 vendor/paypal/paypalhttp/lib/PayPalHttp/Serializer/Multipart.php create mode 100644 vendor/paypal/paypalhttp/lib/PayPalHttp/Serializer/Text.php create mode 100644 vendor/paypal/paypalhttp/phpunit.xml (limited to 'vendor/paypal') diff --git a/vendor/paypal/paypal-checkout-sdk/.gitignore b/vendor/paypal/paypal-checkout-sdk/.gitignore new file mode 100644 index 0000000..4c36e38 --- /dev/null +++ b/vendor/paypal/paypal-checkout-sdk/.gitignore @@ -0,0 +1,2 @@ +.idea/ +vendor/ diff --git a/vendor/paypal/paypal-checkout-sdk/LICENSE b/vendor/paypal/paypal-checkout-sdk/LICENSE new file mode 100644 index 0000000..67d9ac3 --- /dev/null +++ b/vendor/paypal/paypal-checkout-sdk/LICENSE @@ -0,0 +1,86 @@ +The PayPal Node SDK is released under the following license: + + Copyright (c) 2013-2019 PAYPAL, INC. + + SDK LICENSE + + NOTICE TO USER: PayPal, Inc. is providing the Software and Documentation for use under the terms of + this Agreement. Any use, reproduction, modification or distribution of the Software or Documentation, + or any derivatives or portions hereof, constitutes your acceptance of this Agreement. + + As used in this Agreement, "PayPal" means PayPal, Inc. "Software" means the software code accompanying + this agreement. "Documentation" means the documents, specifications and all other items accompanying + this Agreement other than the Software. + + 1. LICENSE GRANT Subject to the terms of this Agreement, PayPal hereby grants you a non-exclusive, + worldwide, royalty free license to use, reproduce, prepare derivative works from, publicly display, + publicly perform, distribute and sublicense the Software for any purpose, provided the copyright notice + below appears in a conspicuous location within the source code of the distributed Software and this + license is distributed in the supporting documentation of the Software you distribute. Furthermore, + you must comply with all third party licenses in order to use the third party software contained in the + Software. + + Subject to the terms of this Agreement, PayPal hereby grants you a non-exclusive, worldwide, royalty free + license to use, reproduce, publicly display, publicly perform, distribute and sublicense the Documentation + for any purpose. You may not modify the Documentation. + + No title to the intellectual property in the Software or Documentation is transferred to you under the + terms of this Agreement. You do not acquire any rights to the Software or the Documentation except as + expressly set forth in this Agreement. + + If you choose to distribute the Software in a commercial product, you do so with the understanding that + you agree to defend, indemnify and hold harmless PayPal and its suppliers against any losses, damages and + costs arising from the claims, lawsuits or other legal actions arising out of such distribution. You may + distribute the Software in object code form under your own license, provided that your license agreement: + + (a) complies with the terms and conditions of this license agreement; + + (b) effectively disclaims all warranties and conditions, express or implied, on behalf of PayPal; + + (c) effectively excludes all liability for damages on behalf of PayPal; + + (d) states that any provisions that differ from this Agreement are offered by you alone and not PayPal; and + + (e) states that the Software is available from you or PayPal and informs licensees how to obtain it in a + reasonable manner on or through a medium customarily used for software exchange. + + 2. DISCLAIMER OF WARRANTY + PAYPAL LICENSES THE SOFTWARE AND DOCUMENTATION TO YOU ONLY ON AN "AS IS" BASIS WITHOUT WARRANTIES OR CONDITIONS + OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY WARRANTIES OR CONDITIONS OF TITLE, + NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. PAYPAL MAKES NO WARRANTY THAT THE + SOFTWARE OR DOCUMENTATION WILL BE ERROR-FREE. Each user of the Software or Documentation is solely responsible + for determining the appropriateness of using and distributing the Software and Documentation and assumes all + risks associated with its exercise of rights under this Agreement, including but not limited to the risks and + costs of program errors, compliance with applicable laws, damage to or loss of data, programs, or equipment, + and unavailability or interruption of operations. Use of the Software and Documentation is made with the + understanding that PayPal will not provide you with any technical or customer support or maintenance. Some + states or jurisdictions do not allow the exclusion of implied warranties or limitations on how long an implied + warranty may last, so the above limitations may not apply to you. To the extent permissible, any implied + warranties are limited to ninety (90) days. + + + 3. LIMITATION OF LIABILITY + PAYPAL AND ITS SUPPLIERS SHALL NOT BE LIABLE FOR LOSS OR DAMAGE ARISING OUT OF THIS AGREEMENT OR FROM THE USE + OF THE SOFTWARE OR DOCUMENTATION. IN NO EVENT WILL PAYPAL OR ITS SUPPLIERS BE LIABLE TO YOU OR ANY THIRD PARTY + FOR ANY DIRECT, INDIRECT, CONSEQUENTIAL, INCIDENTAL, OR SPECIAL DAMAGES INCLUDING LOST PROFITS, LOST SAVINGS, + COSTS, FEES, OR EXPENSES OF ANY KIND ARISING OUT OF ANY PROVISION OF THIS AGREEMENT OR THE USE OR THE INABILITY + TO USE THE SOFTWARE OR DOCUMENTATION, HOWEVER CAUSED AND UNDER ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + STRICT LIABILITY OR TORT INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + PAYPAL'S AGGREGATE LIABILITY AND THAT OF ITS SUPPLIERS UNDER OR IN CONNECTION WITH THIS AGREEMENT SHALL BE + LIMITED TO THE AMOUNT PAID BY YOU FOR THE SOFTWARE AND DOCUMENTATION. + + 4. TRADEMARK USAGE + PayPal is a trademark PayPal, Inc. in the United States and other countries. Such trademarks may not be used + to endorse or promote any product unless expressly permitted under separate agreement with PayPal. + + 5. TERM + Your rights under this Agreement shall terminate if you fail to comply with any of the material terms or + conditions of this Agreement and do not cure such failure in a reasonable period of time after becoming + aware of such noncompliance. If all your rights under this Agreement terminate, you agree to cease use + and distribution of the Software and Documentation as soon as reasonably practicable. + + 6. GOVERNING LAW AND JURISDICTION. This Agreement is governed by the statutes and laws of the State of + California, without regard to the conflicts of law principles thereof. If any part of this Agreement is + found void and unenforceable, it will not affect the validity of the balance of the Agreement, which shall + remain valid and enforceable according to its terms. Any dispute arising out of or related to this Agreement + shall be brought in the courts of Santa Clara County, California, USA. diff --git a/vendor/paypal/paypal-checkout-sdk/README.md b/vendor/paypal/paypal-checkout-sdk/README.md new file mode 100644 index 0000000..d8aedc0 --- /dev/null +++ b/vendor/paypal/paypal-checkout-sdk/README.md @@ -0,0 +1,169 @@ +# REST API SDK for PHP V2 + +![Home Image](homepage.jpg) + +__Welcome to PayPal PHP SDK__. This repository contains PayPal's PHP SDK and samples for [v2/checkout/orders](https://developer.paypal.com/docs/api/orders/v2/) and [v2/payments](https://developer.paypal.com/docs/api/payments/v2/) APIs. + +This is a part of the next major PayPal SDK. It includes a simplified interface to only provide simple model objects and blueprints for HTTP calls. This repo currently contains functionality for PayPal Checkout APIs which includes [Orders V2](https://developer.paypal.com/docs/api/orders/v2/) and [Payments V2](https://developer.paypal.com/docs/api/payments/v2/). + +Please refer to the [PayPal Checkout Integration Guide](https://developer.paypal.com/docs/checkout/) for more information. Also refer to [Setup your SDK](https://developer.paypal.com/docs/checkout/reference/server-integration/setup-sdk/) for additional information about setting up the SDK's. + +## Prerequisites + +PHP 5.6 and above + +An environment which supports TLS 1.2 (see the TLS-update site for more information) + +## Usage + +### Binaries + +It is not mandatory to fork this repository for using the PayPal SDK. You can refer [PayPal Checkout Server SDK](https://developer.paypal.com/docs/checkout/reference/server-integration) for configuring and working with SDK without forking this code. + +For contirbuting or referrring the samples, You can fork/refer this repository. + +### Setting up 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. + +```php +require __DIR__ . '/vendor/autoload.php'; +use PayPalCheckoutSdk\Core\PayPalHttpClient; +use PayPalCheckoutSdk\Core\SandboxEnvironment; +// Creating an environment +$clientId = "<>"; +$clientSecret = "<>"; + +$environment = new SandboxEnvironment($clientId, $clientSecret); +$client = new PayPalHttpClient($environment); +``` + +## Examples +### Creating an Order +#### Code: +```php +// Construct a request object and set desired parameters +// Here, OrdersCreateRequest() creates a POST request to /v2/checkout/orders +use PayPalCheckoutSdk\Orders\OrdersCreateRequest; +$request = new OrdersCreateRequest(); +$request->prefer('return=representation'); +$request->body = [ + "intent" => "CAPTURE", + "purchase_units" => [[ + "reference_id" => "test_ref_id1", + "amount" => [ + "value" => "100.00", + "currency_code" => "USD" + ] + ]], + "application_context" => [ + "cancel_url" => "https://example.com/cancel", + "return_url" => "https://example.com/return" + ] + ]; + +try { + // Call API with your client and get a response for your call + $response = $client->execute($request); + + // If call returns body in response, you can get the deserialized version from the result attribute of the response + print_r($response); +}catch (HttpException $ex) { + echo $ex->statusCode; + print_r($ex->getMessage()); +} +``` +#### Example Output: +``` +Status Code: 201 +Id: 8GB67279RC051624C +Intent: CAPTURE +Gross_amount: + Currency_code: USD + Value: 100.00 +Purchase_units: + 1: + Amount: + Currency_code: USD + Value: 100.00 +Create_time: 2018-08-06T23:34:31Z +Links: + 1: + Href: https://api.sandbox.paypal.com/v2/checkout/orders/8GB67279RC051624C + Rel: self + Method: GET + 2: + Href: https://www.sandbox.paypal.com/checkoutnow?token=8GB67279RC051624C + Rel: approve + Method: GET + 3: + Href: https://api.sandbox.paypal.com/v2/checkout/orders/8GB67279RC051624C/capture + Rel: capture + Method: POST +Status: CREATED +``` + +## Capturing an Order +Before capture, Order should be approved by the buyer using the approval URL returned in the create order response. +### Code to Execute: +```php +use PayPalCheckoutSdk\Orders\OrdersCaptureRequest; +// Here, OrdersCaptureRequest() creates a POST request to /v2/checkout/orders +// $response->result->id gives the orderId of the order created above +$request = new OrdersCaptureRequest("APPROVED-ORDER-ID"); +$request->prefer('return=representation'); +try { + // Call API with your client and get a response for your call + $response = $client->execute($request); + + // If call returns body in response, you can get the deserialized version from the result attribute of the response + print_r($response); +}catch (HttpException $ex) { + echo $ex->statusCode; + print_r($ex->getMessage()); +} +``` + +#### Example Output: +``` +Status Code: 201 +Id: 8GB67279RC051624C +Create_time: 2018-08-06T23:39:11Z +Update_time: 2018-08-06T23:39:11Z +Payer: + Name: + Given_name: test + Surname: buyer + Email_address: test-buyer@paypal.com + Payer_id: KWADC7LXRRWCE + Phone: + Phone_number: + National_number: 408-411-2134 + Address: + Country_code: US +Links: + 1: + Href: https://api.sandbox.paypal.com/v2/checkout/orders/3L848818A2897925Y + Rel: self + Method: GET +Status: COMPLETED +``` + +## Running tests + +To run integration tests using your client id and secret, clone this repository and run the following command: +```sh +$ composer install +$ CLIENT_ID=YOUR_SANDBOX_CLIENT_ID CLIENT_SECRET=OUR_SANDBOX_CLIENT_SECRET composer integration +``` + +## Samples + +You can start off by trying out [creating and capturing an order](/samples/CaptureIntentExamples/RunAll.php) + +To try out different samples for both create and authorize intent check [this link](/samples) + +Note: Update the `PayPalClient.php` with your sandbox client credentials or pass your client credentials as environment variable whie executing the samples. + + +## License +Code released under [SDK LICENSE](LICENSE) diff --git a/vendor/paypal/paypal-checkout-sdk/composer.json b/vendor/paypal/paypal-checkout-sdk/composer.json new file mode 100644 index 0000000..0676fb4 --- /dev/null +++ b/vendor/paypal/paypal-checkout-sdk/composer.json @@ -0,0 +1,35 @@ +{ + "name": "paypal/paypal-checkout-sdk", + "description": "PayPal's PHP SDK for Checkout REST APIs", + "keywords": ["paypal", "payments", "rest", "sdk", "orders", "checkout"], + "type": "library", + "license": "https://github.com/paypal/Checkout-PHP-SDK/blob/master/LICENSE", + "homepage": "http://github.com/paypal/Checkout-PHP-SDK/", + "require": { + "paypal/paypalhttp": "1.0.0" + }, + "authors": [ + { + "name": "PayPal", + "homepage": "https://github.com/paypal/Checkout-PHP-SDK/contributors" + } + ], + "require-dev": { + "phpunit/phpunit": "^5.7" + }, + "autoload": { + "psr-4": { + "PayPalCheckoutSdk\\": "lib/PayPalCheckoutSdk", + "Sample\\":"samples/" + } + }, + "autoload-dev": { + "psr-4": { + "Test\\":"tests/" + } + }, + "scripts": { + "unit": "phpunit --testsuite unit", + "integration": "phpunit --testsuite integration" + } +} diff --git a/vendor/paypal/paypal-checkout-sdk/composer.phar b/vendor/paypal/paypal-checkout-sdk/composer.phar new file mode 100644 index 0000000..801b9a9 Binary files /dev/null and b/vendor/paypal/paypal-checkout-sdk/composer.phar differ diff --git a/vendor/paypal/paypal-checkout-sdk/gen.yml b/vendor/paypal/paypal-checkout-sdk/gen.yml new file mode 100644 index 0000000..b6f3f79 --- /dev/null +++ b/vendor/paypal/paypal-checkout-sdk/gen.yml @@ -0,0 +1,6 @@ +--- +projectName: PayPalCheckoutSdk +language: php +sourcePath: lib/PayPalCheckoutSdk +testPath: tests +apiVersioning: false diff --git a/vendor/paypal/paypal-checkout-sdk/homepage.jpg b/vendor/paypal/paypal-checkout-sdk/homepage.jpg new file mode 100644 index 0000000..9b7aa61 Binary files /dev/null and b/vendor/paypal/paypal-checkout-sdk/homepage.jpg differ diff --git a/vendor/paypal/paypal-checkout-sdk/init b/vendor/paypal/paypal-checkout-sdk/init new file mode 100644 index 0000000..e69de29 diff --git a/vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Core/AccessToken.php b/vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Core/AccessToken.php new file mode 100644 index 0000000..b6f1d2d --- /dev/null +++ b/vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Core/AccessToken.php @@ -0,0 +1,25 @@ +token = $token; + $this->tokenType = $tokenType; + $this->expiresIn = $expiresIn; + $this->createDate = time(); + } + + public function isExpired() + { + return time() >= $this->createDate + $this->expiresIn; + } +} \ No newline at end of file diff --git a/vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Core/AccessTokenRequest.php b/vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Core/AccessTokenRequest.php new file mode 100644 index 0000000..5c3e26e --- /dev/null +++ b/vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Core/AccessTokenRequest.php @@ -0,0 +1,27 @@ +headers["Authorization"] = "Basic " . $environment->authorizationString(); + $body = [ + "grant_type" => "client_credentials" + ]; + + if (!is_null($refreshToken)) + { + $body["grant_type"] = "refresh_token"; + $body["refresh_token"] = $refreshToken; + } + + $this->body = $body; + $this->headers["Content-Type"] = "application/x-www-form-urlencoded"; + } +} + diff --git a/vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Core/AuthorizationInjector.php b/vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Core/AuthorizationInjector.php new file mode 100644 index 0000000..0b38bba --- /dev/null +++ b/vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Core/AuthorizationInjector.php @@ -0,0 +1,51 @@ +client = $client; + $this->environment = $environment; + $this->refreshToken = $refreshToken; + } + + public function inject($request) + { + if (!$this->hasAuthHeader($request) && !$this->isAuthRequest($request)) + { + if (is_null($this->accessToken) || $this->accessToken->isExpired()) + { + $this->accessToken = $this->fetchAccessToken(); + } + $request->headers['Authorization'] = 'Bearer ' . $this->accessToken->token; + } + } + + private function fetchAccessToken() + { + $accessTokenResponse = $this->client->execute(new AccessTokenRequest($this->environment, $this->refreshToken)); + $accessToken = $accessTokenResponse->result; + return new AccessToken($accessToken->access_token, $accessToken->token_type, $accessToken->expires_in); + } + + private function isAuthRequest($request) + { + return $request instanceof AccessTokenRequest || $request instanceof RefreshTokenRequest; + } + + private function hasAuthHeader(HttpRequest $request) + { + return array_key_exists("Authorization", $request->headers); + } +} diff --git a/vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Core/FPTIInstrumentationInjector.php b/vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Core/FPTIInstrumentationInjector.php new file mode 100644 index 0000000..898a750 --- /dev/null +++ b/vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Core/FPTIInstrumentationInjector.php @@ -0,0 +1,16 @@ +headers["sdk_name"] = "Checkout SDK"; + $request->headers["sdk_version"] = "1.0.1"; + $request->headers["sdk_tech_stack"] = "PHP " . PHP_VERSION; + $request->headers["api_integration_type"] = "PAYPALSDK"; + } +} diff --git a/vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Core/GzipInjector.php b/vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Core/GzipInjector.php new file mode 100644 index 0000000..202b6b1 --- /dev/null +++ b/vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Core/GzipInjector.php @@ -0,0 +1,14 @@ +headers["Accept-Encoding"] = "gzip"; + } +} diff --git a/vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Core/PayPalEnvironment.php b/vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Core/PayPalEnvironment.php new file mode 100644 index 0000000..252864b --- /dev/null +++ b/vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Core/PayPalEnvironment.php @@ -0,0 +1,23 @@ +clientId = $clientId; + $this->clientSecret = $clientSecret; + } + + public function authorizationString() + { + return base64_encode($this->clientId . ":" . $this->clientSecret); + } +} + diff --git a/vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Core/PayPalHttpClient.php b/vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Core/PayPalHttpClient.php new file mode 100644 index 0000000..3b3c205 --- /dev/null +++ b/vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Core/PayPalHttpClient.php @@ -0,0 +1,27 @@ +refreshToken = $refreshToken; + $this->authInjector = new AuthorizationInjector($this, $environment, $refreshToken); + $this->addInjector($this->authInjector); + $this->addInjector(new GzipInjector()); + $this->addInjector(new FPTIInstrumentationInjector()); + } + + public function userAgent() + { + return UserAgent::getValue(); + } +} + diff --git a/vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Core/ProductionEnvironment.php b/vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Core/ProductionEnvironment.php new file mode 100644 index 0000000..20a47b2 --- /dev/null +++ b/vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Core/ProductionEnvironment.php @@ -0,0 +1,16 @@ +headers["Authorization"] = "Basic " . $environment->authorizationString(); + $this->headers["Content-Type"] = "application/x-www-form-urlencoded"; + $this->body = [ + "grant_type" => "authorization_code", + "code" => $authorizationCode + ]; + } +} diff --git a/vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Core/SandboxEnvironment.php b/vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Core/SandboxEnvironment.php new file mode 100644 index 0000000..92c1f7a --- /dev/null +++ b/vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Core/SandboxEnvironment.php @@ -0,0 +1,16 @@ +path = str_replace("{order_id}", urlencode($orderId), $this->path); + $this->headers["Content-Type"] = "application/json"; + } + + + public function payPalClientMetadataId($payPalClientMetadataId) + { + $this->headers["PayPal-Client-Metadata-Id"] = $payPalClientMetadataId; + } + public function payPalRequestId($payPalRequestId) + { + $this->headers["PayPal-Request-Id"] = $payPalRequestId; + } + public function prefer($prefer) + { + $this->headers["Prefer"] = $prefer; + } +} diff --git a/vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Orders/OrdersCaptureRequest.php b/vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Orders/OrdersCaptureRequest.php new file mode 100644 index 0000000..8af8a60 --- /dev/null +++ b/vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Orders/OrdersCaptureRequest.php @@ -0,0 +1,37 @@ +path = str_replace("{order_id}", urlencode($orderId), $this->path); + $this->headers["Content-Type"] = "application/json"; + } + + + public function payPalClientMetadataId($payPalClientMetadataId) + { + $this->headers["PayPal-Client-Metadata-Id"] = $payPalClientMetadataId; + } + public function payPalRequestId($payPalRequestId) + { + $this->headers["PayPal-Request-Id"] = $payPalRequestId; + } + public function prefer($prefer) + { + $this->headers["Prefer"] = $prefer; + } +} diff --git a/vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Orders/OrdersCreateRequest.php b/vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Orders/OrdersCreateRequest.php new file mode 100644 index 0000000..0d9f5a9 --- /dev/null +++ b/vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Orders/OrdersCreateRequest.php @@ -0,0 +1,31 @@ +headers["Content-Type"] = "application/json"; + } + + + public function payPalPartnerAttributionId($payPalPartnerAttributionId) + { + $this->headers["PayPal-Partner-Attribution-Id"] = $payPalPartnerAttributionId; + } + public function prefer($prefer) + { + $this->headers["Prefer"] = $prefer; + } +} diff --git a/vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Orders/OrdersGetRequest.php b/vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Orders/OrdersGetRequest.php new file mode 100644 index 0000000..3d1c8f1 --- /dev/null +++ b/vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Orders/OrdersGetRequest.php @@ -0,0 +1,26 @@ +path = str_replace("{order_id}", urlencode($orderId), $this->path); + $this->headers["Content-Type"] = "application/json"; + } + + + +} diff --git a/vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Orders/OrdersPatchRequest.php b/vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Orders/OrdersPatchRequest.php new file mode 100644 index 0000000..4313c42 --- /dev/null +++ b/vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Orders/OrdersPatchRequest.php @@ -0,0 +1,26 @@ +path = str_replace("{order_id}", urlencode($orderId), $this->path); + $this->headers["Content-Type"] = "application/json"; + } + + + +} diff --git a/vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Orders/OrdersValidateRequest.php b/vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Orders/OrdersValidateRequest.php new file mode 100644 index 0000000..0a68f90 --- /dev/null +++ b/vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Orders/OrdersValidateRequest.php @@ -0,0 +1,29 @@ +path = str_replace("{order_id}", urlencode($orderId), $this->path); + $this->headers["Content-Type"] = "application/json"; + } + + + public function payPalClientMetadataId($payPalClientMetadataId) + { + $this->headers["PayPal-Client-Metadata-Id"] = $payPalClientMetadataId; + } +} diff --git a/vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Payments/AuthorizationsCaptureRequest.php b/vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Payments/AuthorizationsCaptureRequest.php new file mode 100644 index 0000000..68d5e81 --- /dev/null +++ b/vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Payments/AuthorizationsCaptureRequest.php @@ -0,0 +1,33 @@ +path = str_replace("{authorization_id}", urlencode($authorizationId), $this->path); + $this->headers["Content-Type"] = "application/json"; + } + + + public function payPalRequestId($payPalRequestId) + { + $this->headers["PayPal-Request-Id"] = $payPalRequestId; + } + public function prefer($prefer) + { + $this->headers["Prefer"] = $prefer; + } +} diff --git a/vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Payments/AuthorizationsGetRequest.php b/vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Payments/AuthorizationsGetRequest.php new file mode 100644 index 0000000..e088224 --- /dev/null +++ b/vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Payments/AuthorizationsGetRequest.php @@ -0,0 +1,25 @@ +path = str_replace("{authorization_id}", urlencode($authorizationId), $this->path); + $this->headers["Content-Type"] = "application/json"; + } + + +} diff --git a/vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Payments/AuthorizationsReauthorizeRequest.php b/vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Payments/AuthorizationsReauthorizeRequest.php new file mode 100644 index 0000000..7547ece --- /dev/null +++ b/vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Payments/AuthorizationsReauthorizeRequest.php @@ -0,0 +1,33 @@ +path = str_replace("{authorization_id}", urlencode($authorizationId), $this->path); + $this->headers["Content-Type"] = "application/json"; + } + + + public function payPalRequestId($payPalRequestId) + { + $this->headers["PayPal-Request-Id"] = $payPalRequestId; + } + public function prefer($prefer) + { + $this->headers["Prefer"] = $prefer; + } +} diff --git a/vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Payments/AuthorizationsVoidRequest.php b/vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Payments/AuthorizationsVoidRequest.php new file mode 100644 index 0000000..f5c0f74 --- /dev/null +++ b/vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Payments/AuthorizationsVoidRequest.php @@ -0,0 +1,25 @@ +path = str_replace("{authorization_id}", urlencode($authorizationId), $this->path); + $this->headers["Content-Type"] = "application/json"; + } + + +} diff --git a/vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Payments/CapturesGetRequest.php b/vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Payments/CapturesGetRequest.php new file mode 100644 index 0000000..5b9b335 --- /dev/null +++ b/vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Payments/CapturesGetRequest.php @@ -0,0 +1,25 @@ +path = str_replace("{capture_id}", urlencode($captureId), $this->path); + $this->headers["Content-Type"] = "application/json"; + } + + +} diff --git a/vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Payments/CapturesRefundRequest.php b/vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Payments/CapturesRefundRequest.php new file mode 100644 index 0000000..7624c6b --- /dev/null +++ b/vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Payments/CapturesRefundRequest.php @@ -0,0 +1,33 @@ +path = str_replace("{capture_id}", urlencode($captureId), $this->path); + $this->headers["Content-Type"] = "application/json"; + } + + + public function payPalRequestId($payPalRequestId) + { + $this->headers["PayPal-Request-Id"] = $payPalRequestId; + } + public function prefer($prefer) + { + $this->headers["Prefer"] = $prefer; + } +} diff --git a/vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Payments/RefundsGetRequest.php b/vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Payments/RefundsGetRequest.php new file mode 100644 index 0000000..cdf1b8a --- /dev/null +++ b/vendor/paypal/paypal-checkout-sdk/lib/PayPalCheckoutSdk/Payments/RefundsGetRequest.php @@ -0,0 +1,25 @@ +path = str_replace("{refund_id}", urlencode($refundId), $this->path); + $this->headers["Content-Type"] = "application/json"; + } + + +} diff --git a/vendor/paypal/paypal-checkout-sdk/phpunit.xml b/vendor/paypal/paypal-checkout-sdk/phpunit.xml new file mode 100644 index 0000000..4e64bcb --- /dev/null +++ b/vendor/paypal/paypal-checkout-sdk/phpunit.xml @@ -0,0 +1,9 @@ + + + + + + ./tests/ + + + diff --git a/vendor/paypal/paypal-checkout-sdk/samples/AuthorizeIntentExamples/AuthorizeOrder.php b/vendor/paypal/paypal-checkout-sdk/samples/AuthorizeIntentExamples/AuthorizeOrder.php new file mode 100644 index 0000000..06cc775 --- /dev/null +++ b/vendor/paypal/paypal-checkout-sdk/samples/AuthorizeIntentExamples/AuthorizeOrder.php @@ -0,0 +1,61 @@ +body = self::buildRequestBody(); + + $client = PayPalClient::client(); + $response = $client->execute($request); + if ($debug) + { + print "Status Code: {$response->statusCode}\n"; + print "Status: {$response->result->status}\n"; + print "Order ID: {$response->result->id}\n"; + print "Authorization ID: {$response->result->purchase_units[0]->payments->authorizations[0]->id}\n"; + print "Links:\n"; + foreach($response->result->links as $link) + { + print "\t{$link->rel}: {$link->href}\tCall Type: {$link->method}\n"; + } + print "Authorization Links:\n"; + foreach($response->result->purchase_units[0]->payments->authorizations[0]->links as $link) + { + print "\t{$link->rel}: {$link->href}\tCall Type: {$link->method}\n"; + } + // To toggle printing the whole response body comment/uncomment below line + echo json_encode($response->result, JSON_PRETTY_PRINT), "\n"; + } + return $response; + } +} + +/** + * This is an driver function which invokes authorize order. + */ +if (!count(debug_backtrace())) +{ + AuthorizeOrder::authorizeOrder('1U242387CB956380X', true); +} \ No newline at end of file diff --git a/vendor/paypal/paypal-checkout-sdk/samples/AuthorizeIntentExamples/CaptureOrder.php b/vendor/paypal/paypal-checkout-sdk/samples/AuthorizeIntentExamples/CaptureOrder.php new file mode 100644 index 0000000..9dffd38 --- /dev/null +++ b/vendor/paypal/paypal-checkout-sdk/samples/AuthorizeIntentExamples/CaptureOrder.php @@ -0,0 +1,55 @@ +body = self::buildRequestBody(); + $client = PayPalClient::client(); + $response = $client->execute($request); + + if ($debug) + { + print "Status Code: {$response->statusCode}\n"; + print "Status: {$response->result->status}\n"; + print "Capture ID: {$response->result->id}\n"; + print "Links:\n"; + foreach($response->result->links as $link) + { + print "\t{$link->rel}: {$link->href}\tCall Type: {$link->method}\n"; + } + // To toggle printing the whole response body comment/uncomment below line + echo json_encode($response->result, JSON_PRETTY_PRINT), "\n"; + } + return $response; + } +} + +/** + * Driver function for invoking the capture flow. + */ +if (!count(debug_backtrace())) +{ + CaptureOrder::captureOrder('18A38324BV5456924', true); +} \ No newline at end of file diff --git a/vendor/paypal/paypal-checkout-sdk/samples/AuthorizeIntentExamples/CreateOrder.php b/vendor/paypal/paypal-checkout-sdk/samples/AuthorizeIntentExamples/CreateOrder.php new file mode 100644 index 0000000..e8f96ce --- /dev/null +++ b/vendor/paypal/paypal-checkout-sdk/samples/AuthorizeIntentExamples/CreateOrder.php @@ -0,0 +1,237 @@ + 'AUTHORIZE', + 'application_context' => + array( + 'return_url' => 'https://example.com/return', + 'cancel_url' => 'https://example.com/cancel', + 'brand_name' => 'EXAMPLE INC', + 'locale' => 'en-US', + 'landing_page' => 'BILLING', + 'shipping_preference' => 'SET_PROVIDED_ADDRESS', + 'user_action' => 'PAY_NOW', + ), + 'purchase_units' => + array( + 0 => + array( + 'reference_id' => 'PUHF', + 'description' => 'Sporting Goods', + 'custom_id' => 'CUST-HighFashions', + 'soft_descriptor' => 'HighFashions', + 'amount' => + array( + 'currency_code' => 'USD', + 'value' => '220.00', + 'breakdown' => + array( + 'item_total' => + array( + 'currency_code' => 'USD', + 'value' => '180.00', + ), + 'shipping' => + array( + 'currency_code' => 'USD', + 'value' => '20.00', + ), + 'handling' => + array( + 'currency_code' => 'USD', + 'value' => '10.00', + ), + 'tax_total' => + array( + 'currency_code' => 'USD', + 'value' => '20.00', + ), + 'shipping_discount' => + array( + 'currency_code' => 'USD', + 'value' => '10.00', + ), + ), + ), + 'items' => + array( + 0 => + array( + 'name' => 'T-Shirt', + 'description' => 'Green XL', + 'sku' => 'sku01', + 'unit_amount' => + array( + 'currency_code' => 'USD', + 'value' => '90.00', + ), + 'tax' => + array( + 'currency_code' => 'USD', + 'value' => '10.00', + ), + 'quantity' => '1', + 'category' => 'PHYSICAL_GOODS', + ), + 1 => + array( + 'name' => 'Shoes', + 'description' => 'Running, Size 10.5', + 'sku' => 'sku02', + 'unit_amount' => + array( + 'currency_code' => 'USD', + 'value' => '45.00', + ), + 'tax' => + array( + 'currency_code' => 'USD', + 'value' => '5.00', + ), + 'quantity' => '2', + 'category' => 'PHYSICAL_GOODS', + ), + ), + 'shipping' => + array( + 'method' => 'United States Postal Service', + 'name' => + array( + 'full_name' => 'John Doe', + ), + 'address' => + array( + 'address_line_1' => '123 Townsend St', + 'address_line_2' => 'Floor 6', + 'admin_area_2' => 'San Francisco', + 'admin_area_1' => 'CA', + 'postal_code' => '94107', + 'country_code' => 'US', + ), + ), + ), + ), + ); + } + + /** + * Setting up the JSON request body for creating the Order with minimum request body. The Intent in the + * request body should be set as "AUTHORIZE" for authorize intent flow. + * + */ + private static function buildMinimumRequestBody() + { + return array( + 'intent' => 'AUTHORIZE', + 'application_context' => + array( + 'return_url' => 'https://example.com/return', + 'cancel_url' => 'https://example.com/cancel' + ), + 'purchase_units' => + array( + 0 => + array( + 'amount' => + array( + 'currency_code' => 'USD', + 'value' => '220.00' + ) + ) + ) + ); + } + + /** + * This is the sample function which can be used to create an order. It uses the + * JSON body returned by buildRequestBody() to create an new Order. + */ + public static function createOrder($debug=false) + { + $request = new OrdersCreateRequest(); + $request->headers["prefer"] = "return=representation"; + $request->body = CreateOrder::buildRequestBody(); + + $client = PayPalClient::client(); + $response = $client->execute($request); + if ($debug) + { + print "Status Code: {$response->statusCode}\n"; + print "Status: {$response->result->status}\n"; + print "Order ID: {$response->result->id}\n"; + print "Intent: {$response->result->intent}\n"; + print "Links:\n"; + foreach($response->result->links as $link) + { + print "\t{$link->rel}: {$link->href}\tCall Type: {$link->method}\n"; + } + + print "Gross Amount: {$response->result->purchase_units[0]->amount->currency_code} {$response->result->purchase_units[0]->amount->value}\n"; + + // To toggle printing the whole response body comment/uncomment below line + echo json_encode($response->result, JSON_PRETTY_PRINT), "\n"; + } + + + return $response; + } + + /** + * This is the sample function which can be used to create an order. It uses the + * JSON body returned by buildMinimumRequestBody() to create an new Order. + */ + public static function createOrderWithMinimumBody($debug=false) + { + $request = new OrdersCreateRequest(); + $request->headers["prefer"] = "return=representation"; + $request->body = CreateOrder::buildMinimumRequestBody(); + + $client = PayPalClient::client(); + $response = $client->execute($request); + if ($debug) + { + print "Order With Minimum Body\n"; + print "Status Code: {$response->statusCode}\n"; + print "Status: {$response->result->status}\n"; + print "Order ID: {$response->result->id}\n"; + print "Intent: {$response->result->intent}\n"; + print "Links:\n"; + foreach($response->result->links as $link) + { + print "\t{$link->rel}: {$link->href}\tCall Type: {$link->method}\n"; + } + + print "Gross Amount: {$response->result->purchase_units[0]->amount->currency_code} {$response->result->purchase_units[0]->amount->value}\n"; + + // To toggle printing the whole response body comment/uncomment below line + echo json_encode($response->result, JSON_PRETTY_PRINT), "\n"; + } + + + return $response; + } +} + + + +if (!count(debug_backtrace())) +{ + CreateOrder::createOrder(true); + CreateOrder::createOrderWithMinimumBody(true); +} \ No newline at end of file diff --git a/vendor/paypal/paypal-checkout-sdk/samples/AuthorizeIntentExamples/RunAll.php b/vendor/paypal/paypal-checkout-sdk/samples/AuthorizeIntentExamples/RunAll.php new file mode 100644 index 0000000..708be9d --- /dev/null +++ b/vendor/paypal/paypal-checkout-sdk/samples/AuthorizeIntentExamples/RunAll.php @@ -0,0 +1,82 @@ +statusCode == 201) +{ + $orderId = $order->result->id; + print "Links:\n"; + for ($i = 0; $i < count($order->result->links); ++$i) + { + $link = $order->result->links[$i]; + print "\t{$link->rel}: {$link->href}\tCall Type: {$link->method}\n"; + } + print "Created Successfully\n"; + print "Copy approve link and paste it in browser. Login with buyer account and follow the instructions.\nOnce approved hit enter...\n"; +} +else { + exit(1); +} + +$handle = fopen ("php://stdin","r"); +$line = fgets($handle); +fclose($handle); + +print "Authorizing Order...\n"; +$response = AuthorizeOrder::authorizeOrder($orderId); +$authId = ""; + +if ($response->statusCode == 201) +{ + print "Authorized Successfully\n"; + $authId = $response->result->purchase_units[0]->payments->authorizations[0]->id; +} +else { + exit(1); +} + +print "\nCapturing Order...\n"; +$response = CaptureOrder::captureOrder($authId); +if ($response->statusCode == 201) +{ + print "Captured Successfully\n"; + print "Status Code: {$response->statusCode}\n"; + print "Status: {$response->result->status}\n"; + $captureId = $response->result->id; + print "Capture ID: {$captureId}\n"; + print "Links:\n"; + for ($i = 0; $i < count($response->result->links); ++$i){ + $link = $response->result->links[$i]; + print "\t{$link->rel}: {$link->href}\tCall Type: {$link->method}\n"; + } +} +else { + exit(1); +} + +print "\nRefunding Order...\n"; +$response = RefundOrder::refundOrder($captureId); +if ($response->statusCode == 201) +{ + print "Refunded Successfully\n"; + print "Status Code: {$response->statusCode}\n"; + print "Status: {$response->result->status}\n"; + print "Refund ID: {$response->result->id}\n"; + print "Links:\n"; + for ($i = 0; $i < count($response->result->links); ++$i){ + $link = $response->result->links[$i]; + print "\t{$link->rel}: {$link->href}\tCall Type: {$link->method}\n"; + } +} +else { + exit(1); +} diff --git a/vendor/paypal/paypal-checkout-sdk/samples/CaptureIntentExamples/CaptureOrder.php b/vendor/paypal/paypal-checkout-sdk/samples/CaptureIntentExamples/CaptureOrder.php new file mode 100644 index 0000000..931d5d9 --- /dev/null +++ b/vendor/paypal/paypal-checkout-sdk/samples/CaptureIntentExamples/CaptureOrder.php @@ -0,0 +1,60 @@ +execute($request); + if ($debug) + { + print "Status Code: {$response->statusCode}\n"; + print "Status: {$response->result->status}\n"; + print "Order ID: {$response->result->id}\n"; + print "Links:\n"; + foreach($response->result->links as $link) + { + print "\t{$link->rel}: {$link->href}\tCall Type: {$link->method}\n"; + } + print "Capture Ids:\n"; + foreach($response->result->purchase_units as $purchase_unit) + { + foreach($purchase_unit->payments->captures as $capture) + { + print "\t{$capture->id}"; + } + } + // To toggle printing the whole response body comment/uncomment below line + echo json_encode($response->result, JSON_PRETTY_PRINT), "\n"; + } + + return $response; + } +} + +/** + * This is the driver function which invokes the captureOrder function with + * Approved Order Id to capture the order payment. + */ +if (!count(debug_backtrace())) +{ + CaptureOrder::captureOrder('0F105083N67049335', true); +} \ No newline at end of file diff --git a/vendor/paypal/paypal-checkout-sdk/samples/CaptureIntentExamples/CreateOrder.php b/vendor/paypal/paypal-checkout-sdk/samples/CaptureIntentExamples/CreateOrder.php new file mode 100644 index 0000000..37a8e63 --- /dev/null +++ b/vendor/paypal/paypal-checkout-sdk/samples/CaptureIntentExamples/CreateOrder.php @@ -0,0 +1,178 @@ + 'CAPTURE', + 'application_context' => + array( + 'return_url' => 'https://example.com/return', + 'cancel_url' => 'https://example.com/cancel', + 'brand_name' => 'EXAMPLE INC', + 'locale' => 'en-US', + 'landing_page' => 'BILLING', + 'shipping_preference' => 'SET_PROVIDED_ADDRESS', + 'user_action' => 'PAY_NOW', + ), + 'purchase_units' => + array( + 0 => + array( + 'reference_id' => 'PUHF', + 'description' => 'Sporting Goods', + 'custom_id' => 'CUST-HighFashions', + 'soft_descriptor' => 'HighFashions', + 'amount' => + array( + 'currency_code' => 'USD', + 'value' => '220.00', + 'breakdown' => + array( + 'item_total' => + array( + 'currency_code' => 'USD', + 'value' => '180.00', + ), + 'shipping' => + array( + 'currency_code' => 'USD', + 'value' => '20.00', + ), + 'handling' => + array( + 'currency_code' => 'USD', + 'value' => '10.00', + ), + 'tax_total' => + array( + 'currency_code' => 'USD', + 'value' => '20.00', + ), + 'shipping_discount' => + array( + 'currency_code' => 'USD', + 'value' => '10.00', + ), + ), + ), + 'items' => + array( + 0 => + array( + 'name' => 'T-Shirt', + 'description' => 'Green XL', + 'sku' => 'sku01', + 'unit_amount' => + array( + 'currency_code' => 'USD', + 'value' => '90.00', + ), + 'tax' => + array( + 'currency_code' => 'USD', + 'value' => '10.00', + ), + 'quantity' => '1', + 'category' => 'PHYSICAL_GOODS', + ), + 1 => + array( + 'name' => 'Shoes', + 'description' => 'Running, Size 10.5', + 'sku' => 'sku02', + 'unit_amount' => + array( + 'currency_code' => 'USD', + 'value' => '45.00', + ), + 'tax' => + array( + 'currency_code' => 'USD', + 'value' => '5.00', + ), + 'quantity' => '2', + 'category' => 'PHYSICAL_GOODS', + ), + ), + 'shipping' => + array( + 'method' => 'United States Postal Service', + 'name' => + array( + 'full_name' => 'John Doe', + ), + 'address' => + array( + 'address_line_1' => '123 Townsend St', + 'address_line_2' => 'Floor 6', + 'admin_area_2' => 'San Francisco', + 'admin_area_1' => 'CA', + 'postal_code' => '94107', + 'country_code' => 'US', + ), + ), + ), + ), + ); + } + + /** + * This is the sample function which can be sued to create an order. It uses the + * JSON body returned by buildRequestBody() to create an new Order. + */ + public static function createOrder($debug=false) + { + $request = new OrdersCreateRequest(); + $request->headers["prefer"] = "return=representation"; + $request->body = self::buildRequestBody(); + + $client = PayPalClient::client(); + $response = $client->execute($request); + if ($debug) + { + print "Status Code: {$response->statusCode}\n"; + print "Status: {$response->result->status}\n"; + print "Order ID: {$response->result->id}\n"; + print "Intent: {$response->result->intent}\n"; + print "Links:\n"; + foreach($response->result->links as $link) + { + print "\t{$link->rel}: {$link->href}\tCall Type: {$link->method}\n"; + } + // To toggle printing the whole response body comment/uncomment below line + echo json_encode($response->result, JSON_PRETTY_PRINT), "\n"; + } + + + return $response; + } +} + + +/** + * This is the driver function which invokes the createOrder function to create + * an sample order. + */ +if (!count(debug_backtrace())) +{ + CreateOrder::createOrder(true); +} + + + diff --git a/vendor/paypal/paypal-checkout-sdk/samples/CaptureIntentExamples/RunAll.php b/vendor/paypal/paypal-checkout-sdk/samples/CaptureIntentExamples/RunAll.php new file mode 100644 index 0000000..e576ff0 --- /dev/null +++ b/vendor/paypal/paypal-checkout-sdk/samples/CaptureIntentExamples/RunAll.php @@ -0,0 +1,74 @@ +statusCode == 201) +{ + $orderId = $order->result->id; + print "Links:\n"; + for ($i = 0; $i < count($order->result->links); ++$i) + { + $link = $order->result->links[$i]; + print "\t{$link->rel}: {$link->href}\tCall Type: {$link->method}\n"; + } + print "Created Successfully\n"; + print "Copy approve link and paste it in browser. Login with buyer account and follow the instructions.\nOnce approved hit enter...\n"; +} +else { + exit(1); +} + +$handle = fopen ("php://stdin","r"); +$line = fgets($handle); +fclose($handle); + +print "Capturing Order...\n"; +$response = CaptureOrder::captureOrder($orderId); +if ($response->statusCode == 201) +{ + print "Captured Successfully\n"; + print "Status Code: {$response->statusCode}\n"; + print "Status: {$response->result->status}\n"; + print "Order ID: {$response->result->id}\n"; + print "Links:\n"; + for ($i = 0; $i < count($response->result->links); ++$i){ + $link = $response->result->links[$i]; + print "\t{$link->rel}: {$link->href}\tCall Type: {$link->method}\n"; + } + foreach($response->result->purchase_units as $purchase_unit) + { + foreach($purchase_unit->payments->captures as $capture) + { + $captureId = $capture->id; + } + } +} +else { + exit(1); +} + +print "\nRefunding Order...\n"; +$response = RefundOrder::refundOrder($captureId); +if ($response->statusCode == 201) +{ + print "Refunded Successfully\n"; + print "Status Code: {$response->statusCode}\n"; + print "Status: {$response->result->status}\n"; + print "Refund ID: {$response->result->id}\n"; + print "Links:\n"; + for ($i = 0; $i < count($response->result->links); ++$i){ + $link = $response->result->links[$i]; + print "\t{$link->rel}: {$link->href}\tCall Type: {$link->method}\n"; + } +} +else { + exit(1); +} diff --git a/vendor/paypal/paypal-checkout-sdk/samples/ErrorSample.php b/vendor/paypal/paypal-checkout-sdk/samples/ErrorSample.php new file mode 100644 index 0000000..8daf96b --- /dev/null +++ b/vendor/paypal/paypal-checkout-sdk/samples/ErrorSample.php @@ -0,0 +1,94 @@ + $val) + { + $pretty .= $pre . ucfirst($key) .": "; + if (strcmp(gettype($val), "array") == 0){ + $pretty .= "\n"; + $sno = 1; + foreach ($val as $value) + { + $pretty .= $pre . "\t" . $sno++ . ":\n"; + $pretty .= self::prettyPrint($value, $pre . "\t\t"); + } + } + else { + $pretty .= $val . "\n"; + } + } + return $pretty; + } + + /** + * Body has no required parameters (intent, purchase_units) + */ + public static function createError1() + { + $request = new OrdersCreateRequest(); + $request->body = "{}"; + print "Request Body: {}\n\n"; + + print "Response:\n"; + try{ + $client = PayPalClient::client(); + $response = $client->execute($request); + } + catch(HttpException $exception){ + $message = json_decode($exception->getMessage(), true); + print "Status Code: {$exception->statusCode}\n"; + print(self::prettyPrint($message)); + } + } + + /** + * Body has invalid parameter value for intent + */ + public static function createError2() + { + $request = new OrdersCreateRequest(); + $request->body = array ( + 'intent' => 'INVALID', + 'purchase_units' => + array ( + 0 => + array ( + 'amount' => + array ( + 'currency_code' => 'USD', + 'value' => '100.00', + ), + ), + ), + ); + print "Request Body:\n" . json_encode($request->body, JSON_PRETTY_PRINT) . "\n\n"; + + try{ + $client = PayPalClient::client(); + $response = $client->execute($request); + } + catch(HttpException $exception){ + print "Response:\n"; + $message = json_decode($exception->getMessage(), true); + print "Status Code: {$exception->statusCode}\n"; + print(self::prettyPrint($message)); + } + + } +} + +print "Calling createError1 (Body has no required parameters (intent, purchase_units))\n"; +ErrorSample::createError1(); + +print "\n\nCalling createError2 (Body has invalid parameter value for intent)\n"; +ErrorSample::createError2(); diff --git a/vendor/paypal/paypal-checkout-sdk/samples/GetOrder.php b/vendor/paypal/paypal-checkout-sdk/samples/GetOrder.php new file mode 100644 index 0000000..f89ac9d --- /dev/null +++ b/vendor/paypal/paypal-checkout-sdk/samples/GetOrder.php @@ -0,0 +1,54 @@ +execute(new OrdersGetRequest($orderId)); + /** + * Enable below line to print complete response as JSON. + */ + //print json_encode($response->result); + print "Status Code: {$response->statusCode}\n"; + print "Status: {$response->result->status}\n"; + print "Order ID: {$response->result->id}\n"; + print "Intent: {$response->result->intent}\n"; + print "Links:\n"; + foreach($response->result->links as $link) + { + print "\t{$link->rel}: {$link->href}\tCall Type: {$link->method}\n"; + } + + print "Gross Amount: {$response->result->purchase_units[0]->amount->currency_code} {$response->result->purchase_units[0]->amount->value}\n"; + + // To toggle printing the whole response body comment/uncomment below line + echo json_encode($response->result, JSON_PRETTY_PRINT), "\n"; + } +} + +/** + * This is the driver function which invokes the getOrder function to retrieve + * an sample order. + * + * To get the correct Order id, we are using the createOrder to create new order + * and then we are using the newly created order id. + */ +if (!count(debug_backtrace())) +{ + $createdOrder = CreateOrder::createOrder()->result; + GetOrder::getOrder($createdOrder ->id); +} \ No newline at end of file diff --git a/vendor/paypal/paypal-checkout-sdk/samples/PatchOrder.php b/vendor/paypal/paypal-checkout-sdk/samples/PatchOrder.php new file mode 100644 index 0000000..cba8152 --- /dev/null +++ b/vendor/paypal/paypal-checkout-sdk/samples/PatchOrder.php @@ -0,0 +1,82 @@ + + array ( + 'op' => 'replace', + 'path' => '/intent', + 'value' => 'CAPTURE', + ), + 1 => + array ( + 'op' => 'replace', + 'path' => '/purchase_units/@reference_id==\'PUHF\'/amount', + 'value' => + array ( + 'currency_code' => 'USD', + 'value' => '200.00', + 'breakdown' => + array ( + 'item_total' => + array ( + 'currency_code' => 'USD', + 'value' => '180.00', + ), + 'tax_total' => + array ( + 'currency_code' => 'USD', + 'value' => '20.00', + ), + ), + ), + ), + ); + } + + public static function patchOrder($orderId) + { + + $client = PayPalClient::client(); + + $request = new OrdersPatchRequest($orderId); + $request->body = PatchOrder::buildRequestBody(); + $client->execute($request); + + $response = $client->execute(new OrdersGetRequest($orderId)); + + print "Status Code: {$response->statusCode}\n"; + print "Status: {$response->result->status}\n"; + print "Order ID: {$response->result->id}\n"; + print "Intent: {$response->result->intent}\n"; + print "Links:\n"; + foreach($response->result->links as $link) + { + print "\t{$link->rel}: {$link->href}\tCall Type: {$link->method}\n"; + } + + print "Gross Amount: {$response->result->purchase_units[0]->amount->currency_code} {$response->result->purchase_units[0]->amount->value}\n"; + + // To toggle printing the whole response body comment/uncomment below line + echo json_encode($response->result, JSON_PRETTY_PRINT), "\n"; + } +} + +if (!count(debug_backtrace())) +{ + print "Before PATCH:\n"; + $createdOrder = CreateOrder::createOrder(true)->result; + print "\nAfter PATCH (Changed Intent and Amount):\n"; + PatchOrder::patchOrder($createdOrder->id); +} \ No newline at end of file diff --git a/vendor/paypal/paypal-checkout-sdk/samples/PayPalClient.php b/vendor/paypal/paypal-checkout-sdk/samples/PayPalClient.php new file mode 100644 index 0000000..397b8d2 --- /dev/null +++ b/vendor/paypal/paypal-checkout-sdk/samples/PayPalClient.php @@ -0,0 +1,35 @@ +>"; + $clientSecret = getenv("CLIENT_SECRET") ?: "<>"; + return new SandboxEnvironment($clientId, $clientSecret); + } +} diff --git a/vendor/paypal/paypal-checkout-sdk/samples/RefundOrder.php b/vendor/paypal/paypal-checkout-sdk/samples/RefundOrder.php new file mode 100644 index 0000000..fc9428f --- /dev/null +++ b/vendor/paypal/paypal-checkout-sdk/samples/RefundOrder.php @@ -0,0 +1,60 @@ + + array( + 'value' => '20.00', + 'currency_code' => 'USD' + ) + ); + } + + /** + * This function can be used to preform refund on the capture. + */ + public static function refundOrder($captureId, $debug=false) + { + $request = new CapturesRefundRequest($captureId); + $request->body = self::buildRequestBody(); + $client = PayPalClient::client(); + $response = $client->execute($request); + + if ($debug) + { + print "Status Code: {$response->statusCode}\n"; + print "Status: {$response->result->status}\n"; + print "Order ID: {$response->result->id}\n"; + print "Links:\n"; + foreach($response->result->links as $link) + { + print "\t{$link->rel}: {$link->href}\tCall Type: {$link->method}\n"; + } + // To toggle printing the whole response body comment/uncomment below line + echo json_encode($response->result, JSON_PRETTY_PRINT), "\n"; + } + return $response; + } +} + +/** + * This is the driver function which invokes the refund capture function with + * Capture Id to perform refund on capture. + */ +if (!count(debug_backtrace())) +{ + RefundOrder::refundOrder('8XL09935J2224701N', true); +} diff --git a/vendor/paypal/paypal-checkout-sdk/tests/Orders/OrdersAuthorizeTest.php b/vendor/paypal/paypal-checkout-sdk/tests/Orders/OrdersAuthorizeTest.php new file mode 100644 index 0000000..981ce26 --- /dev/null +++ b/vendor/paypal/paypal-checkout-sdk/tests/Orders/OrdersAuthorizeTest.php @@ -0,0 +1,26 @@ +markTestSkipped("Need an approved Order ID to execute this test."); + $request = new OrdersAuthorizeRequest('ORDER-ID'); + $request->body = $this->buildRequestBody(); + + $client = TestHarness::client(); + $response = $client->execute($request); + $this->assertEquals(201, $response->statusCode); + $this->assertNotNull($response->result); + } +} diff --git a/vendor/paypal/paypal-checkout-sdk/tests/Orders/OrdersCaptureTest.php b/vendor/paypal/paypal-checkout-sdk/tests/Orders/OrdersCaptureTest.php new file mode 100644 index 0000000..683f70c --- /dev/null +++ b/vendor/paypal/paypal-checkout-sdk/tests/Orders/OrdersCaptureTest.php @@ -0,0 +1,26 @@ +markTestSkipped("Need an approved Order ID to execute this test."); + $request = new OrdersCaptureRequest('ORDER-ID'); + + $client = TestHarness::client(); + $response = $client->execute($request); + $this->assertEquals(201, $response->statusCode); + $this->assertNotNull($response->result); + } +} diff --git a/vendor/paypal/paypal-checkout-sdk/tests/Orders/OrdersCreateTest.php b/vendor/paypal/paypal-checkout-sdk/tests/Orders/OrdersCreateTest.php new file mode 100644 index 0000000..d2d6dad --- /dev/null +++ b/vendor/paypal/paypal-checkout-sdk/tests/Orders/OrdersCreateTest.php @@ -0,0 +1,69 @@ + "CAPTURE", + "purchase_units" => [[ + "reference_id" => "test_ref_id1", + "amount" => [ + "value" => "100.00", + "currency_code" => "USD" + ] + ]], + "redirect_urls" => [ + "cancel_url" => "https://example.com/cancel", + "return_url" => "https://example.com/return" + ] + ]; + } + + public static function create($client) { + $request = new OrdersCreateRequest(); + $request->prefer("return=representation"); + $request->body = self::buildRequestBody(); + return $client->execute($request); + } + + public function testOrdersCreateRequest() + { + $client = TestHarness::client(); + $response = self::create($client); + $this->assertEquals(201, $response->statusCode); + $this->assertNotNull($response->result); + + $createdOrder = $response->result; + $this->assertNotNull($createdOrder->id); + $this->assertNotNull($createdOrder->purchase_units); + $this->assertEquals(1, count($createdOrder->purchase_units)); + $firstPurchaseUnit = $createdOrder->purchase_units[0]; + $this->assertEquals("test_ref_id1", $firstPurchaseUnit->reference_id); + $this->assertEquals("USD", $firstPurchaseUnit->amount->currency_code); + $this->assertEquals("100.00", $firstPurchaseUnit->amount->value); + + $this->assertNotNull($createdOrder->create_time); + $this->assertNotNull($createdOrder->links); + $foundApproveUrl = false; + foreach ($createdOrder->links as $link) { + if ("approve" === $link->rel) { + $foundApproveUrl = true; + $this->assertNotNull($link->href); + $this->assertEquals("GET", $link->method); + } + } + $this->assertTrue($foundApproveUrl); + $this->assertEquals("CREATED", $createdOrder->status); + } +} diff --git a/vendor/paypal/paypal-checkout-sdk/tests/Orders/OrdersGetTest.php b/vendor/paypal/paypal-checkout-sdk/tests/Orders/OrdersGetTest.php new file mode 100644 index 0000000..12fb9b0 --- /dev/null +++ b/vendor/paypal/paypal-checkout-sdk/tests/Orders/OrdersGetTest.php @@ -0,0 +1,48 @@ +result->id); + $response = $client->execute($request); + $this->assertEquals(200, $response->statusCode); + $this->assertNotNull($response->result); + + $createdOrder = $response->result; + $this->assertNotNull($createdOrder->id); + $this->assertNotNull($createdOrder->purchase_units); + $this->assertEquals(1, count($createdOrder->purchase_units)); + $firstPurchaseUnit = $createdOrder->purchase_units[0]; + $this->assertEquals("test_ref_id1", $firstPurchaseUnit->reference_id); + $this->assertEquals("USD", $firstPurchaseUnit->amount->currency_code); + $this->assertEquals("100.00", $firstPurchaseUnit->amount->value); + + $this->assertNotNull($createdOrder->create_time); + $this->assertNotNull($createdOrder->links); + $foundApproveUrl = false; + foreach ($createdOrder->links as $link) { + if ("approve" === $link->rel) { + $foundApproveUrl = true; + $this->assertNotNull($link->href); + $this->assertEquals("GET", $link->method); + } + } + $this->assertTrue($foundApproveUrl); + $this->assertEquals("CREATED", $createdOrder->status); + } +} diff --git a/vendor/paypal/paypal-checkout-sdk/tests/Orders/OrdersPatchTest.php b/vendor/paypal/paypal-checkout-sdk/tests/Orders/OrdersPatchTest.php new file mode 100644 index 0000000..1eaa307 --- /dev/null +++ b/vendor/paypal/paypal-checkout-sdk/tests/Orders/OrdersPatchTest.php @@ -0,0 +1,73 @@ + "add", + "path" => "/purchase_units/@reference_id=='test_ref_id1'/description", + "value" => "added_description" + ], + [ + "op" => "replace", + "path" => "/purchase_units/@reference_id=='test_ref_id1'/amount", + "value" => [ + "currency_code" => "USD", + "value" => "200.00" + ] + ] + ]; + } + + public function testOrdersPatchRequest() + { + $client = TestHarness::client(); + $createdOrder = OrdersCreateTest::create($client); + + $request = new OrdersPatchRequest($createdOrder->result->id); + $request->body = $this->buildRequestBody(); + $response = $client->execute($request); + $this->assertEquals(204, $response->statusCode); + + $request = new OrdersGetRequest($createdOrder->result->id); + $response = $client->execute($request); + $this->assertEquals(200, $response->statusCode); + $this->assertNotNull($response->result); + + $createdOrder = $response->result; + $this->assertNotNull($createdOrder->id); + $this->assertNotNull($createdOrder->purchase_units); + $this->assertEquals(1, count($createdOrder->purchase_units)); + $firstPurchaseUnit = $createdOrder->purchase_units[0]; + $this->assertEquals("test_ref_id1", $firstPurchaseUnit->reference_id); + $this->assertEquals("USD", $firstPurchaseUnit->amount->currency_code); + $this->assertEquals("200.00", $firstPurchaseUnit->amount->value); + $this->assertEquals("added_description", $firstPurchaseUnit->description); + + $this->assertNotNull($createdOrder->create_time); + $this->assertNotNull($createdOrder->links); + $foundApproveUrl = false; + foreach ($createdOrder->links as $link) { + if ("approve" === $link->rel) { + $foundApproveUrl = true; + $this->assertNotNull($link->href); + $this->assertEquals("GET", $link->method); + } + } + $this->assertTrue($foundApproveUrl); + $this->assertEquals("CREATED", $createdOrder->status); + } +} diff --git a/vendor/paypal/paypal-checkout-sdk/tests/TestHarness.php b/vendor/paypal/paypal-checkout-sdk/tests/TestHarness.php new file mode 100644 index 0000000..66b4abe --- /dev/null +++ b/vendor/paypal/paypal-checkout-sdk/tests/TestHarness.php @@ -0,0 +1,24 @@ +>"; + $clientSecret = getenv("CLIENT_SECRET") ?: "<>"; + return new SandboxEnvironment($clientId, $clientSecret); + } +} diff --git a/vendor/paypal/paypalhttp/.gitattributes b/vendor/paypal/paypalhttp/.gitattributes new file mode 100644 index 0000000..ec6c2f5 --- /dev/null +++ b/vendor/paypal/paypalhttp/.gitattributes @@ -0,0 +1,7 @@ +tests/ export-ignore +.idea/ export-ignore +.github/ export-ignore +.releasinator.rb export-ignore +Gemfile export-ignore +Gemfile.lock export-ignore + diff --git a/vendor/paypal/paypalhttp/.gitignore b/vendor/paypal/paypalhttp/.gitignore new file mode 100644 index 0000000..2efb91f --- /dev/null +++ b/vendor/paypal/paypalhttp/.gitignore @@ -0,0 +1,32 @@ +.DS_Store +/vendor/ +composer.phar +composer.lock + +# User-specific stuff: +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/dictionaries + +.idea/codeStyles/Project.xml +.idea/codeStyles/codeStyleConfig.xml +.idea/* + +# Sensitive or high-churn files: +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.xml +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml + +## File-based project format: +*.iws +.idea/*.iml +.idea/vcs.xml +.idea/php.xml +.idea/php-test-framework.xml +.idea/modules.xml +__files/* +mappings/* diff --git a/vendor/paypal/paypalhttp/.travis.yml b/vendor/paypal/paypalhttp/.travis.yml new file mode 100644 index 0000000..4fddbb9 --- /dev/null +++ b/vendor/paypal/paypalhttp/.travis.yml @@ -0,0 +1,16 @@ +sudo: false +language: php +php: +- 5.6 +- 7.0 +- 7.1 +- hhvm +matrix: + allow_failures: + - php: hhvm + fast_finish: true +before_script: +- composer self-update +- composer install --dev +script: +- vendor/bin/phpunit diff --git a/vendor/paypal/paypalhttp/CHANGELOG.md b/vendor/paypal/paypalhttp/CHANGELOG.md new file mode 100644 index 0000000..f55b907 --- /dev/null +++ b/vendor/paypal/paypalhttp/CHANGELOG.md @@ -0,0 +1,2 @@ +## 1.0.0 +- First release diff --git a/vendor/paypal/paypalhttp/CONTRIBUTING.md b/vendor/paypal/paypalhttp/CONTRIBUTING.md new file mode 100644 index 0000000..3810a58 --- /dev/null +++ b/vendor/paypal/paypalhttp/CONTRIBUTING.md @@ -0,0 +1,10 @@ +# Contribute to the PayPal PHP HttpClient + +### *Pull requests are welcome!* + +General Guidelines +------------------ + +* **Code style.** Please follow local code style. Ask if you're unsure. +* **No warnings.** All generated code must compile without warnings. + diff --git a/vendor/paypal/paypalhttp/LICENSE b/vendor/paypal/paypalhttp/LICENSE new file mode 100644 index 0000000..c689d74 --- /dev/null +++ b/vendor/paypal/paypalhttp/LICENSE @@ -0,0 +1,23 @@ +Copyright (c) 2009-2016 PayPal, Inc. + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the "Software"), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + diff --git a/vendor/paypal/paypalhttp/README.md b/vendor/paypal/paypalhttp/README.md new file mode 100644 index 0000000..c4bc958 --- /dev/null +++ b/vendor/paypal/paypalhttp/README.md @@ -0,0 +1,76 @@ +## PayPal HttpClient + +PayPalHttp is a generic HTTP Client. + +In it's simplest form, an [`HttpClient`](lib/PayPalHttp/HttpClient.php) exposes an `execute` method which takes an [HTTP request](lib/PayPalHttp/HttpRequest.php), executes it against the domain described in an [Environment](lib/PayPalHttp/Environment.php), and returns an [HTTP response](lib/PayPalHttp/HttpResponse.php). + +### Environment + +An [`Environment`](./lib/PayPalHttp/environment.rb) describes a domain that hosts a REST API, against which an `HttpClient` will make requests. `Environment` is a simple interface that wraps one method, `baseUrl`. + +```php +$env = new Environment('https://example.com'); +``` + +### Requests + +HTTP requests contain all the information needed to make an HTTP request against the REST API. Specifically, one request describes a path, a verb, any path/query/form parameters, headers, attached files for upload, and body data. + +### Responses + +HTTP responses contain information returned by a server in response to a request as described above. They are simple objects which contain a status code, headers, and any data returned by the server. + +```php +$request = new HttpRequest("/path", "GET"); +$request->body[] = "some data"; + +$response = $client->execute($req); + +$statusCode = $response->statusCode; +$headers = $response->headers; +$data = $response->result; +``` + +### Injectors + +Injectors are blocks that can be used for executing arbitrary pre-flight logic, such as modifying a request or logging data. Injectors are attached to an `HttpClient` using the `addInjector` method. + +The `HttpClient` executes its injectors in a first-in, first-out order, before each request. + +```php +class LogInjector implements Injector +{ + public function inject($httpRequest) + { + // Do some logging here + } +} + +$logInjector = new LogInjector(); +$client = new HttpClient($environment); +$client->addInjector($logInjector); +... +``` + +### Error Handling + +`HttpClient#execute` may throw an `Exception` if something went wrong during the course of execution. If the server returned a non-200 response, [IOException](lib/PayPalHttp/IOException.php) will be thrown, that will contain a status code and headers you can use for debugging. + +```php +try +{ + $client->execute($req); +} +catch (HttpException $e) +{ + $statusCode = $e->response->statusCode; + $headers = $e->response->headers; + $body = $e->response->result; +} +``` + +## License +PayPalHttp-PHP is open source and available under the MIT license. See the [LICENSE](./LICENSE) file for more information. + +## Contributing +Pull requests and issues are welcome. Please see [CONTRIBUTING.md](./CONTRIBUTING.md) for more details. diff --git a/vendor/paypal/paypalhttp/Rakefile b/vendor/paypal/paypalhttp/Rakefile new file mode 100644 index 0000000..33a443c --- /dev/null +++ b/vendor/paypal/paypalhttp/Rakefile @@ -0,0 +1,2 @@ +spec = Gem::Specification.find_by_name 'releasinator' +load "#{spec.gem_dir}/lib/tasks/releasinator.rake" diff --git a/vendor/paypal/paypalhttp/composer.json b/vendor/paypal/paypalhttp/composer.json new file mode 100644 index 0000000..05728a3 --- /dev/null +++ b/vendor/paypal/paypalhttp/composer.json @@ -0,0 +1,23 @@ +{ + "name": "paypal/paypalhttp", + "type": "library", + "license": "MIT", + "authors": [ + { + "name": "PayPal", + "homepage": "https://github.com/paypal/paypalhttp_php/contributors" + } + ], + "require": { + "ext-curl": "*" + }, + "require-dev": { + "phpunit/phpunit": "^5.7", + "wiremock-php/wiremock-php": "1.43.2" + }, + "autoload": { + "psr-4": { + "PayPalHttp\\": "lib/PayPalHttp" + } + } +} diff --git a/vendor/paypal/paypalhttp/lib/PayPalHttp/Curl.php b/vendor/paypal/paypalhttp/lib/PayPalHttp/Curl.php new file mode 100644 index 0000000..08e6eaf --- /dev/null +++ b/vendor/paypal/paypalhttp/lib/PayPalHttp/Curl.php @@ -0,0 +1,57 @@ +curl = $curl; + } + + public function setOpt($option, $value) + { + curl_setopt($this->curl, $option, $value); + return $this; + } + + public function close() + { + curl_close($this->curl); + return $this; + } + + public function exec() + { + return curl_exec($this->curl); + } + + public function errNo() + { + return curl_errno($this->curl); + } + + public function getInfo($option) + { + return curl_getinfo($this->curl, $option); + } + + public function error() + { + return curl_error($this->curl); + } +} diff --git a/vendor/paypal/paypalhttp/lib/PayPalHttp/Encoder.php b/vendor/paypal/paypalhttp/lib/PayPalHttp/Encoder.php new file mode 100644 index 0000000..b7158a7 --- /dev/null +++ b/vendor/paypal/paypalhttp/lib/PayPalHttp/Encoder.php @@ -0,0 +1,114 @@ +serializers[] = new Json(); + $this->serializers[] = new Text(); + $this->serializers[] = new Multipart(); + $this->serializers[] = new Form(); + } + + + + public function serializeRequest(HttpRequest $request) + { + if (!array_key_exists('content-type', $request->headers)) { + $message = "HttpRequest does not have Content-Type header set"; + echo $message; + throw new \Exception($message); + } + + $contentType = $request->headers['content-type']; + /** @var Serializer $serializer */ + $serializer = $this->serializer($contentType); + + if (is_null($serializer)) { + $message = sprintf("Unable to serialize request with Content-Type: %s. Supported encodings are: %s", $contentType, implode(", ", $this->supportedEncodings())); + echo $message; + throw new \Exception($message); + } + + if (!(is_string($request->body) || is_array($request->body))) { + $message = "Body must be either string or array"; + echo $message; + throw new \Exception($message); + } + + $serialized = $serializer->encode($request); + + if (array_key_exists("content-encoding", $request->headers) && $request->headers["content-encoding"] === "gzip") { + $serialized = gzencode($serialized); + } + return $serialized; + } + + + public function deserializeResponse($responseBody, $headers) + { + + if (!array_key_exists('content-type', $headers)) { + $message = "HTTP response does not have Content-Type header set"; + echo $message; + throw new \Exception($message); + } + + $contentType = $headers['content-type']; + /** @var Serializer $serializer */ + $serializer = $this->serializer($contentType); + + if (is_null($serializer)) { + throw new \Exception(sprintf("Unable to deserialize response with Content-Type: %s. Supported encodings are: %s", $contentType, implode(", ", $this->supportedEncodings()))); + } + + if (array_key_exists("content-encoding", $headers) && $headers["content-encoding"] === "gzip") { + $responseBody = gzdecode($responseBody); + } + + return $serializer->decode($responseBody); + } + + private function serializer($contentType) + { + /** @var Serializer $serializer */ + foreach ($this->serializers as $serializer) { + try { + if (preg_match($serializer->contentType(), $contentType) == 1) { + return $serializer; + } + } catch (\Exception $ex) { + $message = sprintf("Error while checking content type of %s: %s", get_class($serializer), $ex->getMessage()); + echo $message; + throw new \Exception($message, $ex->getCode(), $ex); + } + } + + return NULL; + } + + private function supportedEncodings() + { + $values = []; + /** @var Serializer $serializer */ + foreach ($this->serializers as $serializer) { + $values[] = $serializer->contentType(); + } + return $values; + } +} diff --git a/vendor/paypal/paypalhttp/lib/PayPalHttp/Environment.php b/vendor/paypal/paypalhttp/lib/PayPalHttp/Environment.php new file mode 100644 index 0000000..4eb0ce0 --- /dev/null +++ b/vendor/paypal/paypalhttp/lib/PayPalHttp/Environment.php @@ -0,0 +1,18 @@ +environment = $environment; + $this->encoder = new Encoder(); + $this->curlCls = Curl::class; + } + + /** + * Injectors are blocks that can be used for executing arbitrary pre-flight logic, such as modifying a request or logging data. + * Executed in first-in first-out order. + * + * @param Injector $inj + */ + public function addInjector(Injector $inj) + { + $this->injectors[] = $inj; + } + + /** + * The method that takes an HTTP request, serializes the request, makes a call to given environment, and deserialize response + * + * @param $httpRequest HttpRequest + * @return HttpResponse + */ + public function execute(HttpRequest $httpRequest) + { + $requestCpy = clone $httpRequest; + $curl = new Curl(); + + foreach ($this->injectors as $inj) { + $inj->inject($requestCpy); + } + + $url = $this->environment->baseUrl() . $requestCpy->path; + $formattedHeaders = $this->prepareHeaders($requestCpy->headers); + if (!array_key_exists("user-agent", $formattedHeaders)) { + $requestCpy->headers["user-agent"] = $this->userAgent(); + } + + $body = ""; + if (!is_null($requestCpy->body)) { + $rawHeaders = $requestCpy->headers; + $requestCpy->headers = $formattedHeaders; + $body = $this->encoder->serializeRequest($requestCpy); + $requestCpy->headers = $this->mapHeaders($rawHeaders,$requestCpy->headers); + } + + $curl->setOpt(CURLOPT_URL, $url); + $curl->setOpt(CURLOPT_CUSTOMREQUEST, $requestCpy->verb); + $curl->setOpt(CURLOPT_HTTPHEADER, $this->serializeHeaders($requestCpy->headers)); + $curl->setOpt(CURLOPT_RETURNTRANSFER, 1); + $curl->setOpt(CURLOPT_HEADER, 0); + + if (!is_null($requestCpy->body)) { + $curl->setOpt(CURLOPT_POSTFIELDS, $body); + } + + if (strpos($this->environment->baseUrl(), "https://") === 0) { + $curl->setOpt(CURLOPT_SSL_VERIFYPEER, true); + $curl->setOpt(CURLOPT_SSL_VERIFYHOST, 2); + } + + if ($caCertPath = $this->getCACertFilePath()) { + $curl->setOpt(CURLOPT_CAINFO, $caCertPath); + } + + $response = $this->parseResponse($curl); + $curl->close(); + + return $response; + } + + /** + * Returns an array representing headers with their keys + * to be lower case + * @param $headers + * @return array + */ + public function prepareHeaders($headers){ + return array_change_key_case($headers); + } + + /** + * Returns an array representing headers with their key in + * original cases and updated values + * @param $rawHeaders + * @param $formattedHeaders + * @return array + */ + public function mapHeaders($rawHeaders, $formattedHeaders){ + $rawHeadersKey = array_keys($rawHeaders); + foreach ($rawHeadersKey as $array_key) { + if(array_key_exists(strtolower($array_key), $formattedHeaders)){ + $rawHeaders[$array_key] = $formattedHeaders[strtolower($array_key)]; + } + } + return $rawHeaders; + } + + /** + * Returns default user-agent + * + * @return string + */ + public function userAgent() + { + return "PayPalHttp-PHP HTTP/1.1"; + } + + /** + * Return the filepath to your custom CA Cert if needed. + * @return string + */ + protected function getCACertFilePath() + { + return null; + } + + protected function setCurl(Curl $curl) + { + $this->curl = $curl; + } + + protected function setEncoder(Encoder $encoder) + { + $this->encoder = $encoder; + } + + private function serializeHeaders($headers) + { + $headerArray = []; + if ($headers) { + foreach ($headers as $key => $val) { + $headerArray[] = $key . ": " . $val; + } + } + + return $headerArray; + } + + private function parseResponse($curl) + { + $headers = []; + $curl->setOpt(CURLOPT_HEADERFUNCTION, + function($curl, $header) use (&$headers) + { + $len = strlen($header); + + $k = ""; + $v = ""; + + $this->deserializeHeader($header, $k, $v); + $headers[$k] = $v; + + return $len; + }); + + $responseData = $curl->exec(); + $statusCode = $curl->getInfo(CURLINFO_HTTP_CODE); + $errorCode = $curl->errNo(); + $error = $curl->error(); + + if ($errorCode > 0) { + throw new IOException($error, $errorCode); + } + + $body = $responseData; + + if ($statusCode >= 200 && $statusCode < 300) { + $responseBody = NULL; + + if (!empty($body)) { + $responseBody = $this->encoder->deserializeResponse($body, $this->prepareHeaders($headers)); + } + + return new HttpResponse( + $errorCode === 0 ? $statusCode : $errorCode, + $responseBody, + $headers + ); + } else { + throw new HttpException($body, $statusCode, $headers); + } + } + + private function deserializeHeader($header, &$key, &$value) + { + if (strlen($header) > 0) { + if (empty($header) || strpos($header, ':') === false) { + return NULL; + } + + list($k, $v) = explode(":", $header); + $key = trim($k); + $value = trim($v); + } + } +} diff --git a/vendor/paypal/paypalhttp/lib/PayPalHttp/HttpException.php b/vendor/paypal/paypalhttp/lib/PayPalHttp/HttpException.php new file mode 100644 index 0000000..5f4d2db --- /dev/null +++ b/vendor/paypal/paypalhttp/lib/PayPalHttp/HttpException.php @@ -0,0 +1,23 @@ +statusCode = $statusCode; + $this->headers = $headers; + } +} diff --git a/vendor/paypal/paypalhttp/lib/PayPalHttp/HttpRequest.php b/vendor/paypal/paypalhttp/lib/PayPalHttp/HttpRequest.php new file mode 100644 index 0000000..89b7480 --- /dev/null +++ b/vendor/paypal/paypalhttp/lib/PayPalHttp/HttpRequest.php @@ -0,0 +1,42 @@ +path = $path; + $this->verb = $verb; + $this->body = NULL; + $this->headers = []; + } +} diff --git a/vendor/paypal/paypalhttp/lib/PayPalHttp/HttpResponse.php b/vendor/paypal/paypalhttp/lib/PayPalHttp/HttpResponse.php new file mode 100644 index 0000000..ef8fb35 --- /dev/null +++ b/vendor/paypal/paypalhttp/lib/PayPalHttp/HttpResponse.php @@ -0,0 +1,34 @@ +statusCode = $statusCode; + $this->headers = $headers; + $this->result = $body; + } +} diff --git a/vendor/paypal/paypalhttp/lib/PayPalHttp/IOException.php b/vendor/paypal/paypalhttp/lib/PayPalHttp/IOException.php new file mode 100644 index 0000000..7bfc91c --- /dev/null +++ b/vendor/paypal/paypalhttp/lib/PayPalHttp/IOException.php @@ -0,0 +1,13 @@ +body) || !$this->isAssociative($request->body)) + { + throw new \Exception("HttpRequest body must be an associative array when Content-Type is: " . $request->headers["Content-Type"]); + } + + return http_build_query($request->body); + } + + /** + * @param $body + * @return mixed + * @throws \Exception as multipart does not support deserialization. + */ + public function decode($body) + { + throw new \Exception("CurlSupported does not support deserialization"); + } + + private function isAssociative(array $array) + { + return array_values($array) !== $array; + } +} diff --git a/vendor/paypal/paypalhttp/lib/PayPalHttp/Serializer/FormPart.php b/vendor/paypal/paypalhttp/lib/PayPalHttp/Serializer/FormPart.php new file mode 100644 index 0000000..3779a9b --- /dev/null +++ b/vendor/paypal/paypalhttp/lib/PayPalHttp/Serializer/FormPart.php @@ -0,0 +1,25 @@ +value = $value; + $this->headers = array_merge([], $headers); + } + + public function getValue() + { + return $this->value; + } + + public function getHeaders() + { + return $this->headers; + } +} diff --git a/vendor/paypal/paypalhttp/lib/PayPalHttp/Serializer/Json.php b/vendor/paypal/paypalhttp/lib/PayPalHttp/Serializer/Json.php new file mode 100644 index 0000000..3f66314 --- /dev/null +++ b/vendor/paypal/paypalhttp/lib/PayPalHttp/Serializer/Json.php @@ -0,0 +1,38 @@ +body; + if (is_string($body)) { + return $body; + } + if (is_array($body)) { + return json_encode($body); + } + throw new \Exception("Cannot serialize data. Unknown type"); + } + + public function decode($data) + { + return json_decode($data); + } +} diff --git a/vendor/paypal/paypalhttp/lib/PayPalHttp/Serializer/Multipart.php b/vendor/paypal/paypalhttp/lib/PayPalHttp/Serializer/Multipart.php new file mode 100644 index 0000000..a420205 --- /dev/null +++ b/vendor/paypal/paypalhttp/lib/PayPalHttp/Serializer/Multipart.php @@ -0,0 +1,134 @@ +body) || !$this->isAssociative($request->body)) + { + throw new \Exception("HttpRequest body must be an associative array when Content-Type is: " . $request->headers["content-type"]); + } + $boundary = "---------------------" . md5(mt_rand() . microtime()); + $contentTypeHeader = $request->headers["content-type"]; + $request->headers["content-type"] = "{$contentTypeHeader}; boundary={$boundary}"; + + $value_params = []; + $file_params = []; + + $disallow = ["\0", "\"", "\r", "\n"]; + + $body = []; + + foreach ($request->body as $k => $v) { + $k = str_replace($disallow, "_", $k); + if (is_resource($v)) { + $file_params[] = $this->prepareFilePart($k, $v, $boundary); + } else if ($v instanceof FormPart) { + $value_params[] = $this->prepareFormPart($k, $v, $boundary); + } else { + $value_params[] = $this->prepareFormField($k, $v, $boundary); + } + } + + $body = array_merge($value_params, $file_params); + + // add boundary for each parameters + array_walk($body, function (&$part) use ($boundary) { + $part = "--{$boundary}" . self::LINEFEED . "{$part}"; + }); + + // add final boundary + $body[] = "--{$boundary}--"; + $body[] = ""; + + return implode(self::LINEFEED, $body); + } + + public function decode($data) + { + throw new \Exception("Multipart does not support deserialization"); + } + + private function isAssociative(array $array) + { + return array_values($array) !== $array; + } + + private function prepareFormField($partName, $value, $boundary) + { + return implode(self::LINEFEED, [ + "Content-Disposition: form-data; name=\"{$partName}\"", + "", + filter_var($value), + ]); + } + + private function prepareFilePart($partName, $file, $boundary) + { + $fileInfo = new finfo(FILEINFO_MIME_TYPE); + $filePath = stream_get_meta_data($file)['uri']; + $data = file_get_contents($filePath); + $mimeType = $fileInfo->buffer($data); + + $splitFilePath = explode(DIRECTORY_SEPARATOR, $filePath); + $filePath = end($splitFilePath); + $disallow = ["\0", "\"", "\r", "\n"]; + $filePath = str_replace($disallow, "_", $filePath); + return implode(self::LINEFEED, [ + "Content-Disposition: form-data; name=\"{$partName}\"; filename=\"{$filePath}\"", + "Content-Type: {$mimeType}", + "", + $data, + ]); + } + + private function prepareFormPart($partName, $formPart, $boundary) + { + $contentDisposition = "Content-Disposition: form-data; name=\"{$partName}\""; + + $partHeaders = $formPart->getHeaders(); + $formattedheaders = array_change_key_case($partHeaders); + if (array_key_exists("content-type", $formattedheaders)) { + if ($formattedheaders["content-type"] === "application/json") { + $contentDisposition .= "; filename=\"{$partName}.json\""; + } + $tempRequest = new HttpRequest('/', 'POST'); + $tempRequest->headers = $formattedheaders; + $tempRequest->body = $formPart->getValue(); + $encoder = new Encoder(); + $partValue = $encoder->serializeRequest($tempRequest); + } else { + $partValue = $formPart->getValue(); + } + + $finalPartHeaders = []; + foreach ($partHeaders as $k => $v) { + $finalPartHeaders[] = "{$k}: {$v}"; + } + + $body = array_merge([$contentDisposition], $finalPartHeaders, [""], [$partValue]); + + return implode(self::LINEFEED, $body); + } +} diff --git a/vendor/paypal/paypalhttp/lib/PayPalHttp/Serializer/Text.php b/vendor/paypal/paypalhttp/lib/PayPalHttp/Serializer/Text.php new file mode 100644 index 0000000..e2ce0ca --- /dev/null +++ b/vendor/paypal/paypalhttp/lib/PayPalHttp/Serializer/Text.php @@ -0,0 +1,38 @@ +body; + if (is_string($body)) { + return $body; + } + if (is_array($body)) { + return json_encode($body); + } + return implode(" ", $body); + } + + public function decode($data) + { + return $data; + } +} diff --git a/vendor/paypal/paypalhttp/phpunit.xml b/vendor/paypal/paypalhttp/phpunit.xml new file mode 100644 index 0000000..ea84278 --- /dev/null +++ b/vendor/paypal/paypalhttp/phpunit.xml @@ -0,0 +1,10 @@ + + + + + + ./tests/unit + + + + -- cgit v1.2.3