forked from LiveCarta/PayPal-PHP-Server-SDK
Compare commits
7 Commits
0.5.2
...
initialize
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f465f0920c | ||
|
|
7d36472b6e | ||
|
|
1522ab5293 | ||
|
|
eb2608f55a | ||
|
|
b8521e83cc | ||
|
|
f423f69aee | ||
|
|
b20aa829db |
10
.codegenignore
Normal file
10
.codegenignore
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
tests/E2E/**
|
||||||
|
tests/UnitTests/**
|
||||||
|
tests/ClientFactory.php
|
||||||
|
tests/WebDriverUtilities.php
|
||||||
|
tests/bootstrap.php
|
||||||
|
tests/Controllers/BaseTestController.php
|
||||||
|
.gitignore
|
||||||
|
.github/**
|
||||||
|
phpunit.xml
|
||||||
|
selenium.jar
|
||||||
46
.github/workflows/test-runner.yml
vendored
Normal file
46
.github/workflows/test-runner.yml
vendored
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
name: Tests
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
name: Running all tests
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Set up PHP
|
||||||
|
uses: shivammathur/setup-php@v2
|
||||||
|
with:
|
||||||
|
php-version: '8.2'
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: |
|
||||||
|
composer install
|
||||||
|
composer require php-webdriver/webdriver --dev
|
||||||
|
composer require phpunit/phpunit --dev
|
||||||
|
|
||||||
|
- name: Run Lint Tests
|
||||||
|
run: composer lint
|
||||||
|
|
||||||
|
- name: Run Analyzer Tests
|
||||||
|
run: composer analyze
|
||||||
|
|
||||||
|
- name: Set up Java 11
|
||||||
|
uses: actions/setup-java@v3
|
||||||
|
with:
|
||||||
|
java-version: '11'
|
||||||
|
distribution: 'temurin'
|
||||||
|
|
||||||
|
- name: Run Selenium Server
|
||||||
|
run: java -jar selenium.jar standalone &
|
||||||
|
|
||||||
|
- name: Run tests
|
||||||
|
run: ./vendor/bin/phpunit --testdox
|
||||||
|
env:
|
||||||
|
CLIENT_ID: ${{ secrets.CLIENT_ID }}
|
||||||
|
CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }}
|
||||||
|
EMAIL: ${{ secrets.EMAIL }}
|
||||||
|
PASSWORD: ${{ secrets.PASSWORD }}
|
||||||
4
LICENSE
4
LICENSE
@@ -1,8 +1,8 @@
|
|||||||
The PayPal Server SDK is released under the following license:
|
The PayPal Server SDK is released under the following license:
|
||||||
|
|
||||||
Copyright (c) 2024 PAYPAL, INC.
|
Copyright (c) 2024 PAYPAL, INC.
|
||||||
|
|
||||||
SDK LICENSE
|
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.
|
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.
|
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.
|
||||||
|
|||||||
49
README.md
49
README.md
@@ -3,22 +3,7 @@
|
|||||||
|
|
||||||
## Introduction
|
## Introduction
|
||||||
|
|
||||||
### ⚠️ Beta Release Notice
|
An order represents a payment between two or more parties. Use the Orders API to create, update, retrieve, authorize, and capture orders., Call the Payments API to authorize payments, capture authorized payments, refund payments that have already been captured, and show payment information. Use the Payments API in conjunction with the <a href="/docs/api/orders/v2/">Orders API</a>. For more information, see the <a href="/docs/checkout/">PayPal Checkout Overview</a>., The Payment Method Tokens API saves payment methods so payers don't have to enter details for future transactions. Payers can check out faster or pay without being present after they agree to save a payment method.<br><br>The API associates a payment method with a temporary setup token. Pass the setup token to the API to exchange the setup token for a permanent token.<br><br>The permanent token represents a payment method that's saved to the vault. This token can be used repeatedly for checkout or recurring transactions such as subscriptions.<br><br>The Payment Method Tokens API is available in the US only.
|
||||||
|
|
||||||
This version is considered a **beta release**. While we have done our best to ensure stability and functionality, there may still be bugs, incomplete features, or breaking changes in future updates.
|
|
||||||
|
|
||||||
#### Important Notes
|
|
||||||
|
|
||||||
- **Available Features:** This SDK currently contains only 3 of PayPal's API endpoints. Additional endpoints and functionality will be added in the future.
|
|
||||||
- **API Changes:** Expect potential changes in APIs and features as we finalize the product.
|
|
||||||
|
|
||||||
### Information
|
|
||||||
|
|
||||||
The PayPal Server SDK provides integration access to the PayPal REST APIs. The API endpoints are divided into distinct controllers:
|
|
||||||
|
|
||||||
- Orders Controller: <a href="https://developer.paypal.com/docs/api/orders/v2/">Orders API v2</a>
|
|
||||||
- Payments Controller: <a href="https://developer.paypal.com/docs/api/payments/v2/">Payments API v2</a>
|
|
||||||
- Vault Controller: <a href="https://developer.paypal.com/docs/api/payment-tokens/v3/">Payment Method Tokens API v3</a> *Available in the US only.*
|
|
||||||
|
|
||||||
Find out more here: [https://developer.paypal.com/docs/api/orders/v2/](https://developer.paypal.com/docs/api/orders/v2/)
|
Find out more here: [https://developer.paypal.com/docs/api/orders/v2/](https://developer.paypal.com/docs/api/orders/v2/)
|
||||||
|
|
||||||
@@ -27,23 +12,23 @@ Find out more here: [https://developer.paypal.com/docs/api/orders/v2/](https://d
|
|||||||
Run the following command to install the package and automatically add the dependency to your composer.json file:
|
Run the following command to install the package and automatically add the dependency to your composer.json file:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
composer require "paypal/paypal-server-sdk:0.5.2"
|
composer require "paypal/paypal-server-sdk:0.5.1"
|
||||||
```
|
```
|
||||||
|
|
||||||
Or add it to the composer.json file manually as given below:
|
Or add it to the composer.json file manually as given below:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
"require": {
|
"require": {
|
||||||
"paypal/paypal-server-sdk": "0.5.2"
|
"paypal/paypal-server-sdk": "0.5.1"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
You can also view the package at:
|
You can also view the package at:
|
||||||
https://packagist.org/packages/paypal/paypal-server-sdk#0.5.2
|
https://packagist.org/packages/paypal/paypal-server-sdk#0.5.1
|
||||||
|
|
||||||
## Initialize the API Client
|
## Initialize the API Client
|
||||||
|
|
||||||
**_Note:_** Documentation for the client can be found [here.](https://www.github.com/paypal/PayPal-PHP-Server-SDK/tree/0.5.2/doc/client.md)
|
**_Note:_** Documentation for the client can be found [here.](https://www.github.com/paypal/PayPal-PHP-Server-SDK/tree/0.5.1/doc/client.md)
|
||||||
|
|
||||||
The following parameters are configurable for the API Client:
|
The following parameters are configurable for the API Client:
|
||||||
|
|
||||||
@@ -59,8 +44,8 @@ The following parameters are configurable for the API Client:
|
|||||||
| `retryOnTimeout` | `bool` | Whether to retry on request timeout.<br>*Default*: `true` |
|
| `retryOnTimeout` | `bool` | Whether to retry on request timeout.<br>*Default*: `true` |
|
||||||
| `httpStatusCodesToRetry` | `array` | Http status codes to retry against.<br>*Default*: `408, 413, 429, 500, 502, 503, 504, 521, 522, 524` |
|
| `httpStatusCodesToRetry` | `array` | Http status codes to retry against.<br>*Default*: `408, 413, 429, 500, 502, 503, 504, 521, 522, 524` |
|
||||||
| `httpMethodsToRetry` | `array` | Http methods to retry against.<br>*Default*: `'GET', 'PUT'` |
|
| `httpMethodsToRetry` | `array` | Http methods to retry against.<br>*Default*: `'GET', 'PUT'` |
|
||||||
| `loggingConfiguration` | [`LoggingConfigurationBuilder`](https://www.github.com/paypal/PayPal-PHP-Server-SDK/tree/0.5.2/doc/logging-configuration-builder.md) | Represents the logging configurations for API calls |
|
| `loggingConfiguration` | [`LoggingConfigurationBuilder`](https://www.github.com/paypal/PayPal-PHP-Server-SDK/tree/0.5.1/doc/logging-configuration-builder.md) | Represents the logging configurations for API calls |
|
||||||
| `clientCredentialsAuth` | [`ClientCredentialsAuth`](https://www.github.com/paypal/PayPal-PHP-Server-SDK/tree/0.5.2/doc/auth/oauth-2-client-credentials-grant.md) | The Credentials Setter for OAuth 2 Client Credentials Grant |
|
| `clientCredentialsAuth` | [`ClientCredentialsAuth`](https://www.github.com/paypal/PayPal-PHP-Server-SDK/tree/0.5.1/doc/auth/oauth-2-client-credentials-grant.md) | The Credentials Setter for OAuth 2 Client Credentials Grant |
|
||||||
|
|
||||||
The API client can be initialized as follows:
|
The API client can be initialized as follows:
|
||||||
|
|
||||||
@@ -105,20 +90,20 @@ The SDK can be configured to use a different environment for making API calls. A
|
|||||||
|
|
||||||
This API uses the following authentication schemes.
|
This API uses the following authentication schemes.
|
||||||
|
|
||||||
* [`Oauth2 (OAuth 2 Client Credentials Grant)`](https://www.github.com/paypal/PayPal-PHP-Server-SDK/tree/0.5.2/doc/auth/oauth-2-client-credentials-grant.md)
|
* [`Oauth2 (OAuth 2 Client Credentials Grant)`](https://www.github.com/paypal/PayPal-PHP-Server-SDK/tree/0.5.1/doc/auth/oauth-2-client-credentials-grant.md)
|
||||||
|
|
||||||
## List of APIs
|
## List of APIs
|
||||||
|
|
||||||
* [Orders](https://www.github.com/paypal/PayPal-PHP-Server-SDK/tree/0.5.2/doc/controllers/orders.md)
|
* [Orders](https://www.github.com/paypal/PayPal-PHP-Server-SDK/tree/0.5.1/doc/controllers/orders.md)
|
||||||
* [Payments](https://www.github.com/paypal/PayPal-PHP-Server-SDK/tree/0.5.2/doc/controllers/payments.md)
|
* [Payments](https://www.github.com/paypal/PayPal-PHP-Server-SDK/tree/0.5.1/doc/controllers/payments.md)
|
||||||
* [Vault](https://www.github.com/paypal/PayPal-PHP-Server-SDK/tree/0.5.2/doc/controllers/vault.md)
|
* [Vault](https://www.github.com/paypal/PayPal-PHP-Server-SDK/tree/0.5.1/doc/controllers/vault.md)
|
||||||
|
|
||||||
## Classes Documentation
|
## Classes Documentation
|
||||||
|
|
||||||
* [ApiException](https://www.github.com/paypal/PayPal-PHP-Server-SDK/tree/0.5.2/doc/api-exception.md)
|
* [ApiException](https://www.github.com/paypal/PayPal-PHP-Server-SDK/tree/0.5.1/doc/api-exception.md)
|
||||||
* [HttpRequest](https://www.github.com/paypal/PayPal-PHP-Server-SDK/tree/0.5.2/doc/http-request.md)
|
* [HttpRequest](https://www.github.com/paypal/PayPal-PHP-Server-SDK/tree/0.5.1/doc/http-request.md)
|
||||||
* [HttpResponse](https://www.github.com/paypal/PayPal-PHP-Server-SDK/tree/0.5.2/doc/http-response.md)
|
* [HttpResponse](https://www.github.com/paypal/PayPal-PHP-Server-SDK/tree/0.5.1/doc/http-response.md)
|
||||||
* [LoggingConfigurationBuilder](https://www.github.com/paypal/PayPal-PHP-Server-SDK/tree/0.5.2/doc/logging-configuration-builder.md)
|
* [LoggingConfigurationBuilder](https://www.github.com/paypal/PayPal-PHP-Server-SDK/tree/0.5.1/doc/logging-configuration-builder.md)
|
||||||
* [RequestLoggingConfigurationBuilder](https://www.github.com/paypal/PayPal-PHP-Server-SDK/tree/0.5.2/doc/request-logging-configuration-builder.md)
|
* [RequestLoggingConfigurationBuilder](https://www.github.com/paypal/PayPal-PHP-Server-SDK/tree/0.5.1/doc/request-logging-configuration-builder.md)
|
||||||
* [ResponseLoggingConfigurationBuilder](https://www.github.com/paypal/PayPal-PHP-Server-SDK/tree/0.5.2/doc/response-logging-configuration-builder.md)
|
* [ResponseLoggingConfigurationBuilder](https://www.github.com/paypal/PayPal-PHP-Server-SDK/tree/0.5.1/doc/response-logging-configuration-builder.md)
|
||||||
|
|
||||||
|
|||||||
16
phpunit.xml
Normal file
16
phpunit.xml
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" bootstrap="tests/bootstrap.php" colors="true" processIsolation="false" stopOnError="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.3/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
|
||||||
|
<testsuites>
|
||||||
|
<testsuite name="SDK Test Suite">
|
||||||
|
<directory suffix="Test.php">./tests</directory>
|
||||||
|
</testsuite>
|
||||||
|
</testsuites>
|
||||||
|
<php>
|
||||||
|
<env name="SYMFONY_DEPRECATIONS_HELPER" value="disabled"/>
|
||||||
|
</php>
|
||||||
|
<source>
|
||||||
|
<include>
|
||||||
|
<directory suffix=".php">src</directory>
|
||||||
|
</include>
|
||||||
|
</source>
|
||||||
|
</phpunit>
|
||||||
BIN
selenium.jar
Normal file
BIN
selenium.jar
Normal file
Binary file not shown.
@@ -62,7 +62,7 @@ class PaypalServerSDKClient implements ConfigurationInterface
|
|||||||
->converter(new CompatibilityConverter())
|
->converter(new CompatibilityConverter())
|
||||||
->jsonHelper(ApiHelper::getJsonHelper())
|
->jsonHelper(ApiHelper::getJsonHelper())
|
||||||
->apiCallback($this->config['httpCallback'] ?? null)
|
->apiCallback($this->config['httpCallback'] ?? null)
|
||||||
->userAgent('PayPal REST API PHP SDK, Version: 0.5.2, on OS {os-info}')
|
->userAgent('PayPal REST API PHP SDK, Version: 0.5.1, on OS {os-info}')
|
||||||
->serverUrls(self::ENVIRONMENT_MAP[$this->getEnvironment()], Server::DEFAULT_)
|
->serverUrls(self::ENVIRONMENT_MAP[$this->getEnvironment()], Server::DEFAULT_)
|
||||||
->authManagers(['Oauth2' => $this->clientCredentialsAuthManager])
|
->authManagers(['Oauth2' => $this->clientCredentialsAuthManager])
|
||||||
->loggingConfiguration($loggingConfiguration)
|
->loggingConfiguration($loggingConfiguration)
|
||||||
|
|||||||
58
tests/ClientFactory.php
Normal file
58
tests/ClientFactory.php
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* PaypalServerSDKLib
|
||||||
|
*
|
||||||
|
* This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ).
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PaypalServerSDKLib\Tests;
|
||||||
|
|
||||||
|
use Core\Types\CallbackCatcher;
|
||||||
|
use PaypalServerSDKLib\Authentication\ClientCredentialsAuthCredentialsBuilder;
|
||||||
|
use PaypalServerSDKLib\Environment;
|
||||||
|
use PaypalServerSDKLib\PaypalServerSDKClient;
|
||||||
|
use PaypalServerSDKLib\PaypalServerSDKClientBuilder;
|
||||||
|
|
||||||
|
class ClientFactory
|
||||||
|
{
|
||||||
|
public static function create(CallbackCatcher $httpCallback): PaypalServerSDKClient
|
||||||
|
{
|
||||||
|
$clientBuilder = PaypalServerSDKClientBuilder::init();
|
||||||
|
$clientBuilder = self::addConfigurationFromEnvironment($clientBuilder);
|
||||||
|
$clientBuilder = self::addTestConfiguration($clientBuilder);
|
||||||
|
return $clientBuilder->httpCallback($httpCallback)->build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function addTestConfiguration(PaypalServerSDKClientBuilder $builder): PaypalServerSDKClientBuilder
|
||||||
|
{
|
||||||
|
return $builder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function addConfigurationFromEnvironment(
|
||||||
|
PaypalServerSDKClientBuilder $builder
|
||||||
|
): PaypalServerSDKClientBuilder {
|
||||||
|
$timeout = '10000';
|
||||||
|
$environment = Environment::SANDBOX;
|
||||||
|
$oAuthClientId = getenv('CLIENT_ID');
|
||||||
|
$oAuthClientSecret = getenv('CLIENT_SECRET');
|
||||||
|
|
||||||
|
if (!empty($timeout) && \is_numeric($timeout)) {
|
||||||
|
$builder->timeout(intval($timeout));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($environment)) {
|
||||||
|
$builder->environment($environment);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($oAuthClientId) && !empty($oAuthClientSecret)) {
|
||||||
|
$builder->clientCredentialsAuthCredentials(
|
||||||
|
ClientCredentialsAuthCredentialsBuilder::init($oAuthClientId, $oAuthClientSecret)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $builder;
|
||||||
|
}
|
||||||
|
}
|
||||||
36
tests/Controllers/BaseTestController.php
Normal file
36
tests/Controllers/BaseTestController.php
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* PaypalServerSDKLib
|
||||||
|
*
|
||||||
|
* This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ).
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PaypalServerSDKLib\Tests\Controllers;
|
||||||
|
|
||||||
|
use Core\TestCase\CoreTestCase;
|
||||||
|
use Core\Types\CallbackCatcher;
|
||||||
|
use PaypalServerSDKLib\PaypalServerSDKClient;
|
||||||
|
use PaypalServerSDKLib\Tests\ClientFactory;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
class BaseTestController extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var CallbackCatcher Callback
|
||||||
|
*/
|
||||||
|
protected static $callbackCatcher;
|
||||||
|
|
||||||
|
protected function newTestCase($result): CoreTestCase
|
||||||
|
{
|
||||||
|
return new CoreTestCase($this, self::$callbackCatcher, $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static function getClient(): PaypalServerSDKClient
|
||||||
|
{
|
||||||
|
self::$callbackCatcher = new CallbackCatcher();
|
||||||
|
return ClientFactory::create(self::$callbackCatcher);
|
||||||
|
}
|
||||||
|
}
|
||||||
203
tests/E2E/AddShippingTrackerInformationToOrderFlowTest.php
Normal file
203
tests/E2E/AddShippingTrackerInformationToOrderFlowTest.php
Normal file
@@ -0,0 +1,203 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* PaypalServerSDKLib
|
||||||
|
*
|
||||||
|
* This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ).
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PaypalServerSDKLib\Tests\E2E;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use PaypalServerSDKLib\Controllers\OrdersController;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\AmountWithBreakdownBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\OrderRequestBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\OrderTrackerItemBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\OrderTrackerRequestBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\PatchBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\PaymentSourceBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\PayPalWalletBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\PayPalWalletExperienceContextBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\PurchaseUnitRequestBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\UniversalProductCodeBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\CheckoutPaymentIntent;
|
||||||
|
use PaypalServerSDKLib\Models\Order;
|
||||||
|
use PaypalServerSDKLib\Models\PatchOp;
|
||||||
|
use PaypalServerSDKLib\Models\PayPalExperienceLandingPage;
|
||||||
|
use PaypalServerSDKLib\Models\ShipmentCarrier;
|
||||||
|
use PaypalServerSDKLib\Models\UPCType;
|
||||||
|
use PaypalServerSDKLib\Tests\Controllers\BaseTestController;
|
||||||
|
use PaypalServerSDKLib\Tests\WebDriverUtilities;
|
||||||
|
|
||||||
|
class AddShippingTrackerInformationToOrderFlowTest extends BaseTestController
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var OrdersController OrdersController instance
|
||||||
|
*/
|
||||||
|
protected static $ordersController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setup test class
|
||||||
|
*/
|
||||||
|
public static function setUpBeforeClass(): void
|
||||||
|
{
|
||||||
|
$client = parent::getClient();
|
||||||
|
self::$ordersController = $client->getOrdersController();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCreateOrder(): Order
|
||||||
|
{
|
||||||
|
$request = [
|
||||||
|
'body' => OrderRequestBuilder::init(
|
||||||
|
CheckoutPaymentIntent::CAPTURE,
|
||||||
|
[
|
||||||
|
PurchaseUnitRequestBuilder::init(
|
||||||
|
AmountWithBreakdownBuilder::init(
|
||||||
|
'USD',
|
||||||
|
'100.00'
|
||||||
|
)->build()
|
||||||
|
)
|
||||||
|
->referenceId('d9f80740-38f0-11e8-b467-0ed5f89f718b')
|
||||||
|
->build()
|
||||||
|
]
|
||||||
|
)
|
||||||
|
->paymentSource(
|
||||||
|
PaymentSourceBuilder::init()
|
||||||
|
->paypal(
|
||||||
|
PayPalWalletBuilder::init()
|
||||||
|
->experienceContext(
|
||||||
|
PayPalWalletExperienceContextBuilder::init()
|
||||||
|
->locale('en-US')
|
||||||
|
->returnUrl('https://example.com/returnUrl')
|
||||||
|
->cancelUrl('https://example.com/cancelUrl')
|
||||||
|
->landingPage(PayPalExperienceLandingPage::LOGIN)
|
||||||
|
->build()
|
||||||
|
)
|
||||||
|
->build()
|
||||||
|
)
|
||||||
|
->build()
|
||||||
|
)
|
||||||
|
->build()
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = self::$ordersController->ordersCreate($request);
|
||||||
|
|
||||||
|
$this->assertTrue($response->isSuccess());
|
||||||
|
$this->assertEquals(200, $response->getStatusCode());
|
||||||
|
|
||||||
|
return $response->getResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testCreateOrder
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function testCompletePayment(Order $orderDetail): void
|
||||||
|
{
|
||||||
|
$links = $orderDetail->getLinks();
|
||||||
|
$url = null;
|
||||||
|
if (isset($links)) {
|
||||||
|
$url = $links[1]->getHref();
|
||||||
|
}
|
||||||
|
$this->assertNotNull($url);
|
||||||
|
WebDriverUtilities::completePayment($url ?? '');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testCreateOrder
|
||||||
|
* @depends testCompletePayment
|
||||||
|
*/
|
||||||
|
public function testCaptureOrder(Order $orderDetail): Order
|
||||||
|
{
|
||||||
|
$request = [
|
||||||
|
'id' => $orderDetail->getId(),
|
||||||
|
'payPalRequestId' => strval(rand(1, 99999999999)),
|
||||||
|
'prefer' => 'return=representation'
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = self::$ordersController->ordersCapture($request);
|
||||||
|
|
||||||
|
$this->assertTrue($response->isSuccess());
|
||||||
|
$this->assertEquals(201, $response->getStatusCode());
|
||||||
|
|
||||||
|
return $response->getResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testCaptureOrder
|
||||||
|
*/
|
||||||
|
public function testCreateOrderTrack(Order $captureDetail): Order
|
||||||
|
{
|
||||||
|
$purchaseUnits = $captureDetail->getPurchaseUnits();
|
||||||
|
$captureId = null;
|
||||||
|
if (isset($purchaseUnits)) {
|
||||||
|
$captures = $purchaseUnits[0]->getPayments()->getCaptures();
|
||||||
|
if (isset($captures)) {
|
||||||
|
$captureId = $captures[0]->getId();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->assertNotNull($captureId);
|
||||||
|
$request = [
|
||||||
|
'id' => $captureDetail->getId(),
|
||||||
|
'body' => OrderTrackerRequestBuilder::init($captureId ?? '')
|
||||||
|
->trackingNumber('443844607820')
|
||||||
|
->carrier(ShipmentCarrier::FEDEX)
|
||||||
|
->notifyPayer(false)
|
||||||
|
->items(
|
||||||
|
[
|
||||||
|
OrderTrackerItemBuilder::init()
|
||||||
|
->name('T-Shirt')
|
||||||
|
->quantity('1')
|
||||||
|
->sku('sku02')
|
||||||
|
->url('https://www.example.com/example')
|
||||||
|
->imageUrl('https://www.example.com/example.jpg')
|
||||||
|
->upc(UniversalProductCodeBuilder::init(UPCType::UPCA, 'upc001')->build())
|
||||||
|
->build()
|
||||||
|
]
|
||||||
|
)
|
||||||
|
->build(),
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = self::$ordersController->ordersTrackCreate($request);
|
||||||
|
|
||||||
|
$this->assertTrue($response->isSuccess());
|
||||||
|
$this->assertEquals(201, $response->getStatusCode());
|
||||||
|
|
||||||
|
return $response->getResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testCreateOrderTrack
|
||||||
|
*/
|
||||||
|
public function testUpdateOrderTrack(Order $shippingOrder): void
|
||||||
|
{
|
||||||
|
$purchaseUnits = $shippingOrder->getPurchaseUnits();
|
||||||
|
$trackerId = null;
|
||||||
|
if (isset($purchaseUnits)) {
|
||||||
|
$trackers = $purchaseUnits[0]->getShipping()->getTrackers();
|
||||||
|
if (isset($trackers)) {
|
||||||
|
$trackerId = $trackers[0]->getId();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->assertNotNull($trackerId);
|
||||||
|
$request = [
|
||||||
|
'id' => $shippingOrder->getId(),
|
||||||
|
'trackerId' => $trackerId ?? '',
|
||||||
|
'body' => [
|
||||||
|
PatchBuilder::init(
|
||||||
|
PatchOp::REPLACE
|
||||||
|
)
|
||||||
|
->path('/notify_payer')
|
||||||
|
->value(true)
|
||||||
|
->build()
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = self::$ordersController->ordersTrackersPatch($request);
|
||||||
|
|
||||||
|
$this->assertTrue($response->isSuccess());
|
||||||
|
$this->assertEquals(204, $response->getStatusCode());
|
||||||
|
}
|
||||||
|
}
|
||||||
220
tests/E2E/AuthenticationMultiStepFlowTest.php
Normal file
220
tests/E2E/AuthenticationMultiStepFlowTest.php
Normal file
@@ -0,0 +1,220 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* PaypalServerSDKLib
|
||||||
|
*
|
||||||
|
* This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ).
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PaypalServerSDKLib\Tests\E2E;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use PaypalServerSDKLib\Controllers\OrdersController;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\AddressBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\AmountBreakdownBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\AmountWithBreakdownBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\CardAttributesBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\CardExperienceContextBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\CardRequestBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\CardVerificationBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\ItemBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\MoneyBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\OrderCaptureRequestBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\OrderCaptureRequestPaymentSourceBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\OrderRequestBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\PurchaseUnitRequestBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\CardVerificationMethod;
|
||||||
|
use PaypalServerSDKLib\Models\CheckoutPaymentIntent;
|
||||||
|
use PaypalServerSDKLib\Models\Order;
|
||||||
|
use PaypalServerSDKLib\Tests\Controllers\BaseTestController;
|
||||||
|
use PaypalServerSDKLib\Tests\WebDriverUtilities;
|
||||||
|
|
||||||
|
class AuthenticationMultiStepFlowTest extends BaseTestController
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var OrdersController OrdersController instance
|
||||||
|
*/
|
||||||
|
protected static $ordersController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setup test class
|
||||||
|
*/
|
||||||
|
public static function setUpBeforeClass(): void
|
||||||
|
{
|
||||||
|
$client = parent::getClient();
|
||||||
|
self::$ordersController = $client->getOrdersController();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCreateOrder(): Order
|
||||||
|
{
|
||||||
|
$request = [
|
||||||
|
'body' => OrderRequestBuilder::init(
|
||||||
|
CheckoutPaymentIntent::CAPTURE,
|
||||||
|
[
|
||||||
|
PurchaseUnitRequestBuilder::init(
|
||||||
|
AmountWithBreakdownBuilder::init(
|
||||||
|
'USD',
|
||||||
|
'10.00'
|
||||||
|
)
|
||||||
|
->breakdown(
|
||||||
|
AmountBreakdownBuilder::init()
|
||||||
|
->itemTotal(
|
||||||
|
MoneyBuilder::init(
|
||||||
|
'USD',
|
||||||
|
'10.00'
|
||||||
|
)->build()
|
||||||
|
)->build()
|
||||||
|
)->build()
|
||||||
|
)
|
||||||
|
->description('Camera Shop')
|
||||||
|
->customId('testcustom_id')
|
||||||
|
->invoiceId('invoice_number_' . rand(1, 99999999999))
|
||||||
|
->items([
|
||||||
|
ItemBuilder::init(
|
||||||
|
'Levis 501 Selvedge STF',
|
||||||
|
MoneyBuilder::init(
|
||||||
|
'USD',
|
||||||
|
'5.00'
|
||||||
|
)->build(),
|
||||||
|
'1'
|
||||||
|
)
|
||||||
|
->tax(MoneyBuilder::init(
|
||||||
|
'USD',
|
||||||
|
'0.00'
|
||||||
|
)->build())
|
||||||
|
->sku('5158936')
|
||||||
|
->build(),
|
||||||
|
ItemBuilder::init(
|
||||||
|
'T-Shirt',
|
||||||
|
MoneyBuilder::init(
|
||||||
|
'USD',
|
||||||
|
'5.00'
|
||||||
|
)->build(),
|
||||||
|
'1'
|
||||||
|
)
|
||||||
|
->tax(MoneyBuilder::init(
|
||||||
|
'USD',
|
||||||
|
'0.00'
|
||||||
|
)->build())
|
||||||
|
->sku('1457432')
|
||||||
|
->build()
|
||||||
|
])
|
||||||
|
->build()
|
||||||
|
]
|
||||||
|
)->build(),
|
||||||
|
'payPalRequestId' => strval(rand(1, 99999999999)),
|
||||||
|
'payPalPartnerAttributionId' => 'PayPal-Partner-Attribution-Id',
|
||||||
|
'payPalClientMetadataId' => 'PayPal-Client-Metadata-Id',
|
||||||
|
'prefer' => 'return=representation'
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = self::$ordersController->ordersCreate($request);
|
||||||
|
|
||||||
|
$this->assertTrue($response->isSuccess());
|
||||||
|
$this->assertEquals(201, $response->getStatusCode());
|
||||||
|
|
||||||
|
return $response->getResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testCreateOrder
|
||||||
|
*/
|
||||||
|
public function testCaptureOrder(Order $orderDetail): ?string
|
||||||
|
{
|
||||||
|
$request = [
|
||||||
|
'id' => $orderDetail->getId(),
|
||||||
|
'prefer' => 'return=representation',
|
||||||
|
'body' => OrderCaptureRequestBuilder::init()
|
||||||
|
->paymentSource(
|
||||||
|
OrderCaptureRequestPaymentSourceBuilder::init()
|
||||||
|
->card(
|
||||||
|
CardRequestBuilder::init()
|
||||||
|
->name('John Doe')
|
||||||
|
->number('4868719460707704')
|
||||||
|
->expiry('2027-02')
|
||||||
|
->billingAddress(
|
||||||
|
AddressBuilder::init(
|
||||||
|
'US'
|
||||||
|
)
|
||||||
|
->addressLine1('2211 N First Street')
|
||||||
|
->adminArea1('CA')
|
||||||
|
->adminArea2('San Jose')
|
||||||
|
->postalCode('95131')
|
||||||
|
->build()
|
||||||
|
)
|
||||||
|
->attributes(
|
||||||
|
CardAttributesBuilder::init()
|
||||||
|
->verification(
|
||||||
|
CardVerificationBuilder::init()
|
||||||
|
->method(CardVerificationMethod::SCA_ALWAYS)
|
||||||
|
->build()
|
||||||
|
)
|
||||||
|
->build()
|
||||||
|
)
|
||||||
|
->experienceContext(CardExperienceContextBuilder::init()
|
||||||
|
->returnUrl('https://example.com/returnUrl')
|
||||||
|
->cancelUrl('https://example.com/cancelUrl')
|
||||||
|
->build())
|
||||||
|
->build()
|
||||||
|
)
|
||||||
|
->build()
|
||||||
|
)
|
||||||
|
->build()
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = self::$ordersController->ordersCapture($request);
|
||||||
|
|
||||||
|
// TODO: Verify status 422, as its currently considered as a success case
|
||||||
|
$this->assertTrue($response->isError());
|
||||||
|
$this->assertEquals(422, $response->getStatusCode());
|
||||||
|
|
||||||
|
return $response->getResult()['links'][0]->href;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testCaptureOrder
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function testCompleteHeliosVerification(?string $href): void
|
||||||
|
{
|
||||||
|
$this->assertNotNull($href);
|
||||||
|
WebDriverUtilities::completeHeliosVerification($href ?? '');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testCreateOrder
|
||||||
|
* @depends testCompleteHeliosVerification
|
||||||
|
*/
|
||||||
|
public function testCaptureOrderAgain(Order $orderDetail): void
|
||||||
|
{
|
||||||
|
$request = [
|
||||||
|
'id' => $orderDetail->getId(),
|
||||||
|
'payPalRequestId' => strval(rand(1, 99999999999)),
|
||||||
|
'prefer' => 'return=representation'
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = self::$ordersController->ordersCapture($request);
|
||||||
|
|
||||||
|
$this->assertTrue($response->isSuccess());
|
||||||
|
$this->assertEquals(201, $response->getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testCreateOrder
|
||||||
|
* @depends testCaptureOrderAgain
|
||||||
|
*/
|
||||||
|
public function testGetOrderDetails(Order $orderDetail): void
|
||||||
|
{
|
||||||
|
$request = [
|
||||||
|
'id' => $orderDetail->getId()
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = self::$ordersController->ordersGet($request);
|
||||||
|
|
||||||
|
$this->assertTrue($response->isSuccess());
|
||||||
|
$this->assertEquals(200, $response->getStatusCode());
|
||||||
|
$this->assertEquals('COMPLETED', $response->getResult()->getStatus());
|
||||||
|
}
|
||||||
|
}
|
||||||
205
tests/E2E/AuthenticationSingleStepFlowTest.php
Normal file
205
tests/E2E/AuthenticationSingleStepFlowTest.php
Normal file
@@ -0,0 +1,205 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* PaypalServerSDKLib
|
||||||
|
*
|
||||||
|
* This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ).
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PaypalServerSDKLib\Tests\E2E;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use PaypalServerSDKLib\Controllers\OrdersController;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\AddressBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\AmountBreakdownBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\AmountWithBreakdownBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\CardAttributesBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\CardExperienceContextBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\CardRequestBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\CardVerificationBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\ItemBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\MoneyBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\OrderRequestBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\PaymentSourceBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\PurchaseUnitRequestBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\CardVerificationMethod;
|
||||||
|
use PaypalServerSDKLib\Models\CheckoutPaymentIntent;
|
||||||
|
use PaypalServerSDKLib\Models\Order;
|
||||||
|
use PaypalServerSDKLib\Tests\Controllers\BaseTestController;
|
||||||
|
use PaypalServerSDKLib\Tests\WebDriverUtilities;
|
||||||
|
|
||||||
|
class AuthenticationSingleStepFlowTest extends BaseTestController
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var OrdersController OrdersController instance
|
||||||
|
*/
|
||||||
|
protected static $ordersController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setup test class
|
||||||
|
*/
|
||||||
|
public static function setUpBeforeClass(): void
|
||||||
|
{
|
||||||
|
$client = parent::getClient();
|
||||||
|
self::$ordersController = $client->getOrdersController();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCreateOrder(): Order
|
||||||
|
{
|
||||||
|
$request = [
|
||||||
|
'body' => OrderRequestBuilder::init(
|
||||||
|
CheckoutPaymentIntent::CAPTURE,
|
||||||
|
[
|
||||||
|
PurchaseUnitRequestBuilder::init(
|
||||||
|
AmountWithBreakdownBuilder::init(
|
||||||
|
'USD',
|
||||||
|
'10.00'
|
||||||
|
)
|
||||||
|
->breakdown(
|
||||||
|
AmountBreakdownBuilder::init()
|
||||||
|
->itemTotal(
|
||||||
|
MoneyBuilder::init(
|
||||||
|
'USD',
|
||||||
|
'10.00'
|
||||||
|
)->build()
|
||||||
|
)->build()
|
||||||
|
)->build()
|
||||||
|
)
|
||||||
|
->description('Camera Shop')
|
||||||
|
->customId('testcustom_id')
|
||||||
|
->invoiceId('invoice_number_' . rand(1, 99999999999))
|
||||||
|
->items([
|
||||||
|
ItemBuilder::init(
|
||||||
|
'Levis 501 Selvedge STF',
|
||||||
|
MoneyBuilder::init(
|
||||||
|
'USD',
|
||||||
|
'5.00'
|
||||||
|
)->build(),
|
||||||
|
'1'
|
||||||
|
)
|
||||||
|
->tax(MoneyBuilder::init(
|
||||||
|
'USD',
|
||||||
|
'0.00'
|
||||||
|
)->build())
|
||||||
|
->sku('5158936')
|
||||||
|
->build(),
|
||||||
|
ItemBuilder::init(
|
||||||
|
'T-Shirt',
|
||||||
|
MoneyBuilder::init(
|
||||||
|
'USD',
|
||||||
|
'5.00'
|
||||||
|
)->build(),
|
||||||
|
'1'
|
||||||
|
)
|
||||||
|
->tax(MoneyBuilder::init(
|
||||||
|
'USD',
|
||||||
|
'0.00'
|
||||||
|
)->build())
|
||||||
|
->sku('1457432')
|
||||||
|
->build()
|
||||||
|
])
|
||||||
|
->build()
|
||||||
|
]
|
||||||
|
)
|
||||||
|
->paymentSource(
|
||||||
|
PaymentSourceBuilder::init()
|
||||||
|
->card(
|
||||||
|
CardRequestBuilder::init()
|
||||||
|
->name('John Doe')
|
||||||
|
->number('4868719995056080')
|
||||||
|
->expiry('2027-02')
|
||||||
|
->billingAddress(
|
||||||
|
AddressBuilder::init(
|
||||||
|
'US'
|
||||||
|
)
|
||||||
|
->addressLine1('2211 N First Street')
|
||||||
|
->adminArea1('CA')
|
||||||
|
->adminArea2('San Jose')
|
||||||
|
->postalCode('95131')
|
||||||
|
->build()
|
||||||
|
)
|
||||||
|
->attributes(
|
||||||
|
CardAttributesBuilder::init()
|
||||||
|
->verification(
|
||||||
|
CardVerificationBuilder::init()
|
||||||
|
->method(CardVerificationMethod::SCA_ALWAYS)
|
||||||
|
->build()
|
||||||
|
)
|
||||||
|
->build()
|
||||||
|
)
|
||||||
|
->experienceContext(CardExperienceContextBuilder::init()
|
||||||
|
->returnUrl('https://example.com/returnUrl')
|
||||||
|
->cancelUrl('https://example.com/cancelUrl')
|
||||||
|
->build())
|
||||||
|
->build()
|
||||||
|
)
|
||||||
|
->build()
|
||||||
|
)
|
||||||
|
->build(),
|
||||||
|
'payPalRequestId' => strval(rand(1, 99999999999)),
|
||||||
|
'payPalPartnerAttributionId' => 'PayPal-Partner-Attribution-Id',
|
||||||
|
'payPalClientMetadataId' => 'PayPal-Client-Metadata-Id',
|
||||||
|
'prefer' => 'return=representation'
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = self::$ordersController->ordersCreate($request);
|
||||||
|
|
||||||
|
$this->assertTrue($response->isSuccess());
|
||||||
|
$this->assertEquals(201, $response->getStatusCode());
|
||||||
|
|
||||||
|
return $response->getResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testCreateOrder
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function testCompleteHeliosVerification(Order $orderDetail): void
|
||||||
|
{
|
||||||
|
$links = $orderDetail->getLinks();
|
||||||
|
$url = null;
|
||||||
|
if (isset($links)) {
|
||||||
|
$url = $links[1]->getHref();
|
||||||
|
}
|
||||||
|
$this->assertNotNull($url);
|
||||||
|
WebDriverUtilities::completeHeliosVerification($url ?? '');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testCreateOrder
|
||||||
|
* @depends testCompleteHeliosVerification
|
||||||
|
*/
|
||||||
|
public function testCaptureOrder(Order $orderDetail): void
|
||||||
|
{
|
||||||
|
$request = [
|
||||||
|
'id' => $orderDetail->getId(),
|
||||||
|
'payPalRequestId' => strval(rand(1, 99999999999)),
|
||||||
|
'prefer' => 'return=representation'
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = self::$ordersController->ordersCapture($request);
|
||||||
|
|
||||||
|
$this->assertTrue($response->isSuccess());
|
||||||
|
$this->assertEquals(201, $response->getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testCreateOrder
|
||||||
|
* @depends testCaptureOrder
|
||||||
|
*/
|
||||||
|
public function getOrderDetails(Order $orderDetail): void
|
||||||
|
{
|
||||||
|
$request = [
|
||||||
|
'id' => $orderDetail->getId()
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = self::$ordersController->ordersGet($request);
|
||||||
|
|
||||||
|
$this->assertTrue($response->isSuccess());
|
||||||
|
$this->assertEquals(200, $response->getStatusCode());
|
||||||
|
$this->assertNotNull($response->getResult()->getPaymentSource());
|
||||||
|
$this->assertEquals('COMPLETED', $response->getResult()->getStatus());
|
||||||
|
}
|
||||||
|
}
|
||||||
232
tests/E2E/AuthorizeAndCaptureFlowTest.php
Normal file
232
tests/E2E/AuthorizeAndCaptureFlowTest.php
Normal file
@@ -0,0 +1,232 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* PaypalServerSDKLib
|
||||||
|
*
|
||||||
|
* This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ).
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PaypalServerSDKLib\Tests\E2E;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use PaypalServerSDKLib\Controllers\OrdersController;
|
||||||
|
use PaypalServerSDKLib\Controllers\PaymentsController;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\AmountBreakdownBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\AmountWithBreakdownBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\ItemBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\MoneyBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\OrderRequestBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\PaymentSourceBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\PayPalWalletBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\PayPalWalletExperienceContextBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\PurchaseUnitRequestBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\CapturedPayment;
|
||||||
|
use PaypalServerSDKLib\Models\CheckoutPaymentIntent;
|
||||||
|
use PaypalServerSDKLib\Models\Order;
|
||||||
|
use PaypalServerSDKLib\Models\OrderAuthorizeResponse;
|
||||||
|
use PaypalServerSDKLib\Models\PayPalExperienceLandingPage;
|
||||||
|
use PaypalServerSDKLib\Tests\Controllers\BaseTestController;
|
||||||
|
use PaypalServerSDKLib\Tests\WebDriverUtilities;
|
||||||
|
|
||||||
|
class AuthorizeAndCaptureFlowTest extends BaseTestController
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var OrdersController OrdersController instance
|
||||||
|
*/
|
||||||
|
protected static $ordersController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var PaymentsController PaymentsController instance
|
||||||
|
*/
|
||||||
|
protected static $paymentsController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setup test class
|
||||||
|
*/
|
||||||
|
public static function setUpBeforeClass(): void
|
||||||
|
{
|
||||||
|
$client = parent::getClient();
|
||||||
|
self::$ordersController = $client->getOrdersController();
|
||||||
|
self::$paymentsController = $client->getPaymentsController();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCreateOrder(): Order
|
||||||
|
{
|
||||||
|
$request = [
|
||||||
|
'body' => OrderRequestBuilder::init(
|
||||||
|
CheckoutPaymentIntent::AUTHORIZE,
|
||||||
|
[
|
||||||
|
PurchaseUnitRequestBuilder::init(
|
||||||
|
AmountWithBreakdownBuilder::init(
|
||||||
|
'USD',
|
||||||
|
'25.00'
|
||||||
|
)
|
||||||
|
->breakdown(
|
||||||
|
AmountBreakdownBuilder::init()
|
||||||
|
->itemTotal(
|
||||||
|
MoneyBuilder::init(
|
||||||
|
'USD',
|
||||||
|
'25.00'
|
||||||
|
)->build()
|
||||||
|
)
|
||||||
|
->shipping(
|
||||||
|
MoneyBuilder::init(
|
||||||
|
'USD',
|
||||||
|
'0'
|
||||||
|
)->build()
|
||||||
|
)
|
||||||
|
->taxTotal(
|
||||||
|
MoneyBuilder::init(
|
||||||
|
'USD',
|
||||||
|
'0'
|
||||||
|
)->build()
|
||||||
|
)
|
||||||
|
->build()
|
||||||
|
)->build()
|
||||||
|
)
|
||||||
|
->description('Clothing Shop')
|
||||||
|
->items([
|
||||||
|
ItemBuilder::init(
|
||||||
|
'Levis 501',
|
||||||
|
MoneyBuilder::init(
|
||||||
|
'USD',
|
||||||
|
'25.00'
|
||||||
|
)->build(),
|
||||||
|
'1'
|
||||||
|
)
|
||||||
|
->tax(
|
||||||
|
MoneyBuilder::init(
|
||||||
|
'USD',
|
||||||
|
'0.00'
|
||||||
|
)->build()
|
||||||
|
)
|
||||||
|
->sku('5158936')
|
||||||
|
->build()
|
||||||
|
])
|
||||||
|
->build()
|
||||||
|
]
|
||||||
|
)
|
||||||
|
->paymentSource(
|
||||||
|
PaymentSourceBuilder::init()
|
||||||
|
->paypal(
|
||||||
|
PayPalWalletBuilder::init()
|
||||||
|
->experienceContext(
|
||||||
|
PayPalWalletExperienceContextBuilder::init()
|
||||||
|
->locale('en-US')
|
||||||
|
->returnUrl('https://example.com/returnUrl')
|
||||||
|
->cancelUrl('https://example.com/cancelUrl')
|
||||||
|
->landingPage(PayPalExperienceLandingPage::LOGIN)
|
||||||
|
->build()
|
||||||
|
)
|
||||||
|
->build()
|
||||||
|
)
|
||||||
|
->build()
|
||||||
|
)
|
||||||
|
->build()
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = self::$ordersController->ordersCreate($request);
|
||||||
|
|
||||||
|
$this->assertTrue($response->isSuccess());
|
||||||
|
$this->assertEquals(200, $response->getStatusCode());
|
||||||
|
|
||||||
|
return $response->getResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testCreateOrder
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function testCompletePayment(Order $orderDetail): void
|
||||||
|
{
|
||||||
|
$links = $orderDetail->getLinks();
|
||||||
|
$url = null;
|
||||||
|
if (isset($links)) {
|
||||||
|
$url = $links[1]->getHref();
|
||||||
|
}
|
||||||
|
$this->assertNotNull($url);
|
||||||
|
WebDriverUtilities::completePayment($url ?? '');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testCreateOrder
|
||||||
|
* @depends testCompletePayment
|
||||||
|
*/
|
||||||
|
public function testAuthorizeOrder(Order $orderDetail): OrderAuthorizeResponse
|
||||||
|
{
|
||||||
|
$request = [
|
||||||
|
'id' => $orderDetail->getId(),
|
||||||
|
'payPalRequestId' => strval(rand(1, 99999999999)),
|
||||||
|
'prefer' => 'return=representation'
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = self::$ordersController->ordersAuthorize($request);
|
||||||
|
|
||||||
|
$this->assertTrue($response->isSuccess());
|
||||||
|
$this->assertEquals(201, $response->getStatusCode());
|
||||||
|
|
||||||
|
return $response->getResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testAuthorizeOrder
|
||||||
|
*/
|
||||||
|
public function testCaptureAuthorization(OrderAuthorizeResponse $authorizeResponse): CapturedPayment
|
||||||
|
{
|
||||||
|
$purchaseUnits = $authorizeResponse->getPurchaseUnits();
|
||||||
|
$authorizationId = null;
|
||||||
|
if (isset($purchaseUnits)) {
|
||||||
|
$authorizations = $purchaseUnits[0]->getPayments()->getAuthorizations();
|
||||||
|
if (isset($authorizations)) {
|
||||||
|
$authorizationId = $authorizations[0]->getId();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->assertNotNull($authorizationId);
|
||||||
|
$request = [
|
||||||
|
'authorizationId' => $authorizationId,
|
||||||
|
'prefer' => 'return=representation'
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = self::$paymentsController->authorizationsCapture($request);
|
||||||
|
|
||||||
|
$this->assertTrue($response->isSuccess());
|
||||||
|
$this->assertEquals(201, $response->getStatusCode());
|
||||||
|
|
||||||
|
return $response->getResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testAuthorizeOrder
|
||||||
|
*/
|
||||||
|
public function testGetAuthorization(OrderAuthorizeResponse $authorizeResponse): void
|
||||||
|
{
|
||||||
|
$purchaseUnits = $authorizeResponse->getPurchaseUnits();
|
||||||
|
$authorizationId = null;
|
||||||
|
if (isset($purchaseUnits)) {
|
||||||
|
$authorizations = $purchaseUnits[0]->getPayments()->getAuthorizations();
|
||||||
|
if (isset($authorizations)) {
|
||||||
|
$authorizationId = $authorizations[0]->getId();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->assertNotNull($authorizationId);
|
||||||
|
$response = self::$paymentsController->authorizationsGet($authorizationId ?? '');
|
||||||
|
|
||||||
|
$this->assertTrue($response->isSuccess());
|
||||||
|
$this->assertEquals(200, $response->getStatusCode());
|
||||||
|
$this->assertEquals('CAPTURED', $response->getResult()->getStatus());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testCaptureAuthorization
|
||||||
|
*/
|
||||||
|
public function testCapturePayment(CapturedPayment $capturedPayment): void
|
||||||
|
{
|
||||||
|
$response = self::$paymentsController->capturesGet($capturedPayment->getId() ?? '');
|
||||||
|
|
||||||
|
$this->assertTrue($response->isSuccess());
|
||||||
|
$this->assertEquals(200, $response->getStatusCode());
|
||||||
|
$this->assertEquals('COMPLETED', $response->getResult()->getStatus());
|
||||||
|
}
|
||||||
|
}
|
||||||
169
tests/E2E/ConfirmOrderFlowTest.php
Normal file
169
tests/E2E/ConfirmOrderFlowTest.php
Normal file
@@ -0,0 +1,169 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* PaypalServerSDKLib
|
||||||
|
*
|
||||||
|
* This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ).
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PaypalServerSDKLib\Tests\E2E;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use PaypalServerSDKLib\Controllers\OrdersController;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\AmountWithBreakdownBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\ConfirmOrderRequestBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\NameBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\OrderRequestBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\PaymentSourceBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\PayPalWalletBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\PayPalWalletExperienceContextBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\PurchaseUnitRequestBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\CheckoutPaymentIntent;
|
||||||
|
use PaypalServerSDKLib\Models\Order;
|
||||||
|
use PaypalServerSDKLib\Models\PayeePaymentMethodPreference;
|
||||||
|
use PaypalServerSDKLib\Models\PayPalExperienceLandingPage;
|
||||||
|
use PaypalServerSDKLib\Models\PayPalExperienceUserAction;
|
||||||
|
use PaypalServerSDKLib\Models\ShippingPreference;
|
||||||
|
use PaypalServerSDKLib\Tests\Controllers\BaseTestController;
|
||||||
|
use PaypalServerSDKLib\Tests\WebDriverUtilities;
|
||||||
|
|
||||||
|
class ConfirmOrderFlowTest extends BaseTestController
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var OrdersController OrdersController instance
|
||||||
|
*/
|
||||||
|
protected static $ordersController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setup test class
|
||||||
|
*/
|
||||||
|
public static function setUpBeforeClass(): void
|
||||||
|
{
|
||||||
|
$client = parent::getClient();
|
||||||
|
self::$ordersController = $client->getOrdersController();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCreateOrder(): Order
|
||||||
|
{
|
||||||
|
$request = [
|
||||||
|
'body' => OrderRequestBuilder::init(
|
||||||
|
CheckoutPaymentIntent::CAPTURE,
|
||||||
|
[
|
||||||
|
PurchaseUnitRequestBuilder::init(
|
||||||
|
AmountWithBreakdownBuilder::init(
|
||||||
|
'USD',
|
||||||
|
'100.00'
|
||||||
|
)->build()
|
||||||
|
)
|
||||||
|
->referenceId('d9f80740-38f0-11e8-b467-0ed5f89f718b')
|
||||||
|
->build()
|
||||||
|
]
|
||||||
|
)
|
||||||
|
->paymentSource(
|
||||||
|
PaymentSourceBuilder::init()
|
||||||
|
->paypal(
|
||||||
|
PayPalWalletBuilder::init()
|
||||||
|
->experienceContext(
|
||||||
|
PayPalWalletExperienceContextBuilder::init()
|
||||||
|
->locale('en-US')
|
||||||
|
->returnUrl('https://example.com/returnUrl')
|
||||||
|
->cancelUrl('https://example.com/cancelUrl')
|
||||||
|
->landingPage(PayPalExperienceLandingPage::LOGIN)
|
||||||
|
->build()
|
||||||
|
)
|
||||||
|
->build()
|
||||||
|
)
|
||||||
|
->build()
|
||||||
|
)
|
||||||
|
->build(),
|
||||||
|
'payPalRequestId' => strval(rand(1, 99999999999)),
|
||||||
|
'prefer' => 'return=representation'
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = self::$ordersController->ordersCreate($request);
|
||||||
|
|
||||||
|
$this->assertTrue($response->isSuccess());
|
||||||
|
$this->assertEquals(200, $response->getStatusCode());
|
||||||
|
|
||||||
|
return $response->getResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testCreateOrder
|
||||||
|
*/
|
||||||
|
public function testConfirmOrder(Order $orderDetail): Order
|
||||||
|
{
|
||||||
|
$request = [
|
||||||
|
'id' => $orderDetail->getId(),
|
||||||
|
'prefer' => 'return=representation',
|
||||||
|
'body' => ConfirmOrderRequestBuilder::init(
|
||||||
|
PaymentSourceBuilder::init()
|
||||||
|
->paypal(
|
||||||
|
PayPalWalletBuilder::init()
|
||||||
|
->emailAddress('customer@example.com')
|
||||||
|
->name(
|
||||||
|
NameBuilder::init()
|
||||||
|
->givenName('John')
|
||||||
|
->surname('Doe')
|
||||||
|
->build()
|
||||||
|
)
|
||||||
|
->experienceContext(
|
||||||
|
PayPalWalletExperienceContextBuilder::init()
|
||||||
|
->brandName('EXAMPLE INC')
|
||||||
|
->locale('en-US')
|
||||||
|
->shippingPreference(ShippingPreference::SET_PROVIDED_ADDRESS)
|
||||||
|
->returnUrl('https://example.com/returnUrl')
|
||||||
|
->cancelUrl('https://example.com/cancelUrl')
|
||||||
|
->landingPage(PayPalExperienceLandingPage::LOGIN)
|
||||||
|
->userAction(PayPalExperienceUserAction::PAY_NOW)
|
||||||
|
->paymentMethodPreference(PayeePaymentMethodPreference::IMMEDIATE_PAYMENT_REQUIRED)
|
||||||
|
->build()
|
||||||
|
)->build()
|
||||||
|
)->build()
|
||||||
|
)->build()
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = self::$ordersController->ordersConfirm($request);
|
||||||
|
|
||||||
|
$this->assertTrue($response->isSuccess());
|
||||||
|
$this->assertEquals(200, $response->getStatusCode());
|
||||||
|
|
||||||
|
return $response->getResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testConfirmOrder
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function testCompletePayment(Order $orderDetail): void
|
||||||
|
{
|
||||||
|
$links = $orderDetail->getLinks();
|
||||||
|
$url = null;
|
||||||
|
if (isset($links)) {
|
||||||
|
$url = $links[1]->getHref();
|
||||||
|
}
|
||||||
|
$this->assertNotNull($url);
|
||||||
|
WebDriverUtilities::completePayment($url ?? '');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testCreateOrder
|
||||||
|
* @depends testCompletePayment
|
||||||
|
*/
|
||||||
|
public function testCaptureOrder(Order $orderDetail): void
|
||||||
|
{
|
||||||
|
$request = [
|
||||||
|
'id' => $orderDetail->getId(),
|
||||||
|
'payPalRequestId' => strval(rand(1, 99999999999)),
|
||||||
|
'prefer' => 'return=representation'
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = self::$ordersController->ordersCapture($request);
|
||||||
|
|
||||||
|
$this->assertTrue($response->isSuccess());
|
||||||
|
$this->assertEquals(201, $response->getStatusCode());
|
||||||
|
$this->assertEquals('COMPLETED', $response->getResult()->getStatus());
|
||||||
|
}
|
||||||
|
}
|
||||||
210
tests/E2E/PatchOrderFlowTest.php
Normal file
210
tests/E2E/PatchOrderFlowTest.php
Normal file
@@ -0,0 +1,210 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* PaypalServerSDKLib
|
||||||
|
*
|
||||||
|
* This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ).
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PaypalServerSDKLib\Tests\E2E;
|
||||||
|
|
||||||
|
use PaypalServerSDKLib\Controllers\OrdersController;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\AddressBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\AmountBreakdownBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\AmountWithBreakdownBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\ItemBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\MoneyBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\OrderRequestBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\PatchBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\PaymentSourceBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\PayPalWalletBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\PayPalWalletExperienceContextBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\PurchaseUnitRequestBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\ShippingDetailsBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\CheckoutPaymentIntent;
|
||||||
|
use PaypalServerSDKLib\Models\Order;
|
||||||
|
use PaypalServerSDKLib\Models\PatchOp;
|
||||||
|
use PaypalServerSDKLib\Models\PayPalExperienceLandingPage;
|
||||||
|
use PaypalServerSDKLib\Tests\Controllers\BaseTestController;
|
||||||
|
|
||||||
|
class PatchOrderFlowTest extends BaseTestController
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var OrdersController OrdersController instance
|
||||||
|
*/
|
||||||
|
protected static $ordersController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setup test class
|
||||||
|
*/
|
||||||
|
public static function setUpBeforeClass(): void
|
||||||
|
{
|
||||||
|
$client = parent::getClient();
|
||||||
|
self::$ordersController = $client->getOrdersController();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCreateOrder(): Order
|
||||||
|
{
|
||||||
|
$request = [
|
||||||
|
'body' => OrderRequestBuilder::init(
|
||||||
|
CheckoutPaymentIntent::CAPTURE,
|
||||||
|
[
|
||||||
|
PurchaseUnitRequestBuilder::init(
|
||||||
|
AmountWithBreakdownBuilder::init(
|
||||||
|
'USD',
|
||||||
|
'10.00'
|
||||||
|
)
|
||||||
|
->breakdown(
|
||||||
|
AmountBreakdownBuilder::init()
|
||||||
|
->itemTotal(
|
||||||
|
MoneyBuilder::init(
|
||||||
|
'USD',
|
||||||
|
'10.00'
|
||||||
|
)->build()
|
||||||
|
)
|
||||||
|
->shipping(
|
||||||
|
MoneyBuilder::init(
|
||||||
|
'USD',
|
||||||
|
'0.00'
|
||||||
|
)->build()
|
||||||
|
)
|
||||||
|
->taxTotal(
|
||||||
|
MoneyBuilder::init(
|
||||||
|
'USD',
|
||||||
|
'0'
|
||||||
|
)->build()
|
||||||
|
)->build()
|
||||||
|
)->build()
|
||||||
|
)
|
||||||
|
->description('Camera Shop')
|
||||||
|
->items([
|
||||||
|
ItemBuilder::init(
|
||||||
|
'Levis 501 Selvedge STF',
|
||||||
|
MoneyBuilder::init(
|
||||||
|
'USD',
|
||||||
|
'5.00'
|
||||||
|
)->build(),
|
||||||
|
'1'
|
||||||
|
)
|
||||||
|
->tax(MoneyBuilder::init(
|
||||||
|
'USD',
|
||||||
|
'0.00'
|
||||||
|
)->build())
|
||||||
|
->sku('5158936')
|
||||||
|
->build(),
|
||||||
|
ItemBuilder::init(
|
||||||
|
'T-Shirt',
|
||||||
|
MoneyBuilder::init(
|
||||||
|
'USD',
|
||||||
|
'5.00'
|
||||||
|
)->build(),
|
||||||
|
'1'
|
||||||
|
)
|
||||||
|
->tax(MoneyBuilder::init(
|
||||||
|
'USD',
|
||||||
|
'0.00'
|
||||||
|
)->build())
|
||||||
|
->sku('1457432')
|
||||||
|
->build()
|
||||||
|
])
|
||||||
|
->shipping(
|
||||||
|
ShippingDetailsBuilder::init()
|
||||||
|
->address(
|
||||||
|
AddressBuilder::init(
|
||||||
|
'US'
|
||||||
|
)
|
||||||
|
->addressLine1('123 Main Street')
|
||||||
|
->adminArea1('CA')
|
||||||
|
->adminArea2('San Jose')
|
||||||
|
->postalCode('95131')
|
||||||
|
->build()
|
||||||
|
)->build()
|
||||||
|
)->build()
|
||||||
|
]
|
||||||
|
)
|
||||||
|
->paymentSource(
|
||||||
|
PaymentSourceBuilder::init()
|
||||||
|
->paypal(
|
||||||
|
PayPalWalletBuilder::init()
|
||||||
|
->experienceContext(
|
||||||
|
PayPalWalletExperienceContextBuilder::init()
|
||||||
|
->locale('en-US')
|
||||||
|
->returnUrl('https://example.com/returnUrl')
|
||||||
|
->cancelUrl('https://example.com/cancelUrl')
|
||||||
|
->landingPage(PayPalExperienceLandingPage::LOGIN)
|
||||||
|
->build()
|
||||||
|
)
|
||||||
|
->build()
|
||||||
|
)
|
||||||
|
->build()
|
||||||
|
)
|
||||||
|
->build(),
|
||||||
|
'payPalRequestId' => strval(rand(1, 99999999999)),
|
||||||
|
'prefer' => 'return=representation'
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = self::$ordersController->ordersCreate($request);
|
||||||
|
|
||||||
|
$this->assertTrue($response->isSuccess());
|
||||||
|
$this->assertEquals(200, $response->getStatusCode());
|
||||||
|
|
||||||
|
return $response->getResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testCreateOrder
|
||||||
|
*/
|
||||||
|
public function testPatchOrder(Order $orderDetail): void
|
||||||
|
{
|
||||||
|
$request = [
|
||||||
|
'id' => $orderDetail->getId(),
|
||||||
|
'body' => [
|
||||||
|
PatchBuilder::init(
|
||||||
|
PatchOp::REPLACE
|
||||||
|
)
|
||||||
|
->path("/purchase_units/@reference_id==d'default'/shipping/address")
|
||||||
|
->value([
|
||||||
|
'address_line_1' => '1234 Main St',
|
||||||
|
'address_line_2' => 'Floor 6',
|
||||||
|
'admin_area_2' => 'San Francisco',
|
||||||
|
'admin_area_1' => 'CA',
|
||||||
|
'postal_code' => '94107',
|
||||||
|
'country_code' => 'US',
|
||||||
|
])
|
||||||
|
->build()
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = self::$ordersController->ordersPatch($request);
|
||||||
|
|
||||||
|
$this->assertTrue($response->isSuccess());
|
||||||
|
$this->assertEquals(204, $response->getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testCreateOrder
|
||||||
|
* @depends testPatchOrder
|
||||||
|
*/
|
||||||
|
public function testGetOrderDetails(Order $orderDetail): void
|
||||||
|
{
|
||||||
|
$request = [
|
||||||
|
'id' => $orderDetail->getId()
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = self::$ordersController->ordersGet($request);
|
||||||
|
|
||||||
|
$this->assertTrue($response->isSuccess());
|
||||||
|
$this->assertEquals(200, $response->getStatusCode());
|
||||||
|
|
||||||
|
$this->assertEquals(
|
||||||
|
'1234 Main St',
|
||||||
|
$response->getResult()
|
||||||
|
->getPurchaseUnits()[0]
|
||||||
|
->getShipping()
|
||||||
|
->getAddress()
|
||||||
|
->getAddressLine1()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
169
tests/E2E/PaymentMethodWithPurchaseFlowTest.php
Normal file
169
tests/E2E/PaymentMethodWithPurchaseFlowTest.php
Normal file
@@ -0,0 +1,169 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* PaypalServerSDKLib
|
||||||
|
*
|
||||||
|
* This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ).
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PaypalServerSDKLib\Tests\E2E;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use PaypalServerSDKLib\Controllers\OrdersController;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\AddressBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\AmountBreakdownBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\AmountWithBreakdownBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\ItemBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\MoneyBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\OrderRequestBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\PaymentSourceBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\PayPalWalletAttributesBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\PayPalWalletBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\PayPalWalletExperienceContextBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\PayPalWalletVaultInstructionBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\PurchaseUnitRequestBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\ShippingDetailsBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\CheckoutPaymentIntent;
|
||||||
|
use PaypalServerSDKLib\Models\Order;
|
||||||
|
use PaypalServerSDKLib\Models\PayPalPaymentTokenUsageType;
|
||||||
|
use PaypalServerSDKLib\Models\ShippingPreference;
|
||||||
|
use PaypalServerSDKLib\Models\StoreInVaultInstruction;
|
||||||
|
use PaypalServerSDKLib\Tests\Controllers\BaseTestController;
|
||||||
|
use PaypalServerSDKLib\Tests\WebDriverUtilities;
|
||||||
|
|
||||||
|
class PaymentMethodWithPurchaseFlowTest extends BaseTestController
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var OrdersController OrdersController instance
|
||||||
|
*/
|
||||||
|
protected static $ordersController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setup test class
|
||||||
|
*/
|
||||||
|
public static function setUpBeforeClass(): void
|
||||||
|
{
|
||||||
|
$client = parent::getClient();
|
||||||
|
self::$ordersController = $client->getOrdersController();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCreateOrder(): Order
|
||||||
|
{
|
||||||
|
$request = [
|
||||||
|
'body' => OrderRequestBuilder::init(
|
||||||
|
CheckoutPaymentIntent::CAPTURE,
|
||||||
|
[
|
||||||
|
PurchaseUnitRequestBuilder::init(
|
||||||
|
AmountWithBreakdownBuilder::init(
|
||||||
|
'USD',
|
||||||
|
'10.00'
|
||||||
|
)
|
||||||
|
->breakdown(
|
||||||
|
AmountBreakdownBuilder::init()
|
||||||
|
->itemTotal(
|
||||||
|
MoneyBuilder::init(
|
||||||
|
'USD',
|
||||||
|
'10.00'
|
||||||
|
)->build()
|
||||||
|
)
|
||||||
|
->build()
|
||||||
|
)->build()
|
||||||
|
)
|
||||||
|
->description('Camera Shop')
|
||||||
|
->items([
|
||||||
|
ItemBuilder::init(
|
||||||
|
'Camera',
|
||||||
|
MoneyBuilder::init(
|
||||||
|
'USD',
|
||||||
|
'10.00'
|
||||||
|
)->build(),
|
||||||
|
'1'
|
||||||
|
)->build()
|
||||||
|
])
|
||||||
|
->shipping(
|
||||||
|
ShippingDetailsBuilder::init()
|
||||||
|
->address(
|
||||||
|
AddressBuilder::init(
|
||||||
|
'US'
|
||||||
|
)
|
||||||
|
->addressLine1('500 Main Street')
|
||||||
|
->addressLine2('#1000')
|
||||||
|
->adminArea1('CA')
|
||||||
|
->adminArea2('San Jose')
|
||||||
|
->postalCode('95131')
|
||||||
|
->build()
|
||||||
|
)->build()
|
||||||
|
)->build()
|
||||||
|
]
|
||||||
|
)
|
||||||
|
->paymentSource(
|
||||||
|
PaymentSourceBuilder::init()
|
||||||
|
->paypal(
|
||||||
|
PayPalWalletBuilder::init()
|
||||||
|
->attributes(PayPalWalletAttributesBuilder::init()
|
||||||
|
->vault(
|
||||||
|
PayPalWalletVaultInstructionBuilder::init(
|
||||||
|
PayPalPaymentTokenUsageType::MERCHANT
|
||||||
|
)
|
||||||
|
->storeInVault(StoreInVaultInstruction::ON_SUCCESS)
|
||||||
|
->build()
|
||||||
|
)->build())
|
||||||
|
->experienceContext(
|
||||||
|
PayPalWalletExperienceContextBuilder::init()
|
||||||
|
->shippingPreference(ShippingPreference::SET_PROVIDED_ADDRESS)
|
||||||
|
->returnUrl('https://example.com/returnUrl')
|
||||||
|
->cancelUrl('https://example.com/cancelUrl')
|
||||||
|
->build()
|
||||||
|
)
|
||||||
|
->build()
|
||||||
|
)
|
||||||
|
->build()
|
||||||
|
)
|
||||||
|
->build(),
|
||||||
|
'payPalRequestId' => strval(rand(1, 99999999999)),
|
||||||
|
'prefer' => 'return=representation'
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = self::$ordersController->ordersCreate($request);
|
||||||
|
|
||||||
|
$this->assertTrue($response->isSuccess());
|
||||||
|
$this->assertEquals(200, $response->getStatusCode());
|
||||||
|
|
||||||
|
return $response->getResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testCreateOrder
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function testCompletePayment(Order $orderDetail): void
|
||||||
|
{
|
||||||
|
$links = $orderDetail->getLinks();
|
||||||
|
$url = null;
|
||||||
|
if (isset($links)) {
|
||||||
|
$url = $links[1]->getHref();
|
||||||
|
}
|
||||||
|
$this->assertNotNull($url);
|
||||||
|
WebDriverUtilities::completePayment($url ?? '');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testCreateOrder
|
||||||
|
* @depends testCompletePayment
|
||||||
|
*/
|
||||||
|
public function testCaptureOrder(Order $orderDetail): void
|
||||||
|
{
|
||||||
|
$request = [
|
||||||
|
'id' => $orderDetail->getId(),
|
||||||
|
'payPalRequestId' => strval(rand(1, 99999999999)),
|
||||||
|
'prefer' => 'return=representation'
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = self::$ordersController->ordersCapture($request);
|
||||||
|
|
||||||
|
$this->assertTrue($response->isSuccess());
|
||||||
|
$this->assertEquals(201, $response->getStatusCode());
|
||||||
|
}
|
||||||
|
}
|
||||||
231
tests/E2E/PaymentMethodWithoutPurchaseFlowTest.php
Normal file
231
tests/E2E/PaymentMethodWithoutPurchaseFlowTest.php
Normal file
@@ -0,0 +1,231 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* PaypalServerSDKLib
|
||||||
|
*
|
||||||
|
* This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ).
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PaypalServerSDKLib\Tests\E2E;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use PaypalServerSDKLib\Controllers\OrdersController;
|
||||||
|
use PaypalServerSDKLib\Controllers\VaultController;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\AddressBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\AmountBreakdownBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\AmountWithBreakdownBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\ItemBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\MoneyBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\OrderRequestBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\PaymentSourceBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\PaymentTokenRequestBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\PaymentTokenRequestPaymentSourceBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\PayPalWalletBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\PurchaseUnitRequestBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\SetupTokenRequestBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\SetupTokenRequestPaymentSourceBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\ShippingDetailsBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\VaultExperienceContextBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\VaultPayPalWalletRequestBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\VaultTokenRequestBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\CheckoutPaymentIntent;
|
||||||
|
use PaypalServerSDKLib\Models\PaymentTokenResponse;
|
||||||
|
use PaypalServerSDKLib\Models\SetupTokenResponse;
|
||||||
|
use PaypalServerSDKLib\Models\TokenRequestType;
|
||||||
|
use PaypalServerSDKLib\Tests\Controllers\BaseTestController;
|
||||||
|
use PaypalServerSDKLib\Tests\WebDriverUtilities;
|
||||||
|
|
||||||
|
class PaymentMethodWithoutPurchaseFlowTest extends BaseTestController
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var OrdersController OrdersController instance
|
||||||
|
*/
|
||||||
|
protected static $ordersController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var VaultController VaultController instance
|
||||||
|
*/
|
||||||
|
protected static $vaultController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setup test class
|
||||||
|
*/
|
||||||
|
public static function setUpBeforeClass(): void
|
||||||
|
{
|
||||||
|
$client = parent::getClient();
|
||||||
|
self::$ordersController = $client->getOrdersController();
|
||||||
|
self::$vaultController = $client->getVaultController();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCreateSetupToken(): SetupTokenResponse
|
||||||
|
{
|
||||||
|
$request = [
|
||||||
|
'payPalRequestId' => strval(rand(1, 99999999999)),
|
||||||
|
'body' => SetupTokenRequestBuilder::init(
|
||||||
|
SetupTokenRequestPaymentSourceBuilder::init()
|
||||||
|
->paypal(
|
||||||
|
VaultPayPalWalletRequestBuilder::init()
|
||||||
|
->description('Description for PayPal to be shown to PayPal payer')
|
||||||
|
->permitMultiplePaymentTokens(true)
|
||||||
|
->usageType('MERCHANT')
|
||||||
|
->customerType('CONSUMER')
|
||||||
|
->experienceContext(
|
||||||
|
VaultExperienceContextBuilder::init()
|
||||||
|
->returnUrl('https://example.com/returnUrl')
|
||||||
|
->cancelUrl('https://example.com/cancelUrl')
|
||||||
|
->build()
|
||||||
|
)
|
||||||
|
->build()
|
||||||
|
)->build()
|
||||||
|
)->build()
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = self::$vaultController->setupTokensCreate($request);
|
||||||
|
|
||||||
|
$this->assertTrue($response->isSuccess());
|
||||||
|
$this->assertEquals(201, $response->getStatusCode());
|
||||||
|
|
||||||
|
return $response->getResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testCreateSetupToken
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function testSavePaymentMethod(SetupTokenResponse $setupTokenDetail): void
|
||||||
|
{
|
||||||
|
$links = $setupTokenDetail->getLinks();
|
||||||
|
$url = null;
|
||||||
|
if (isset($links)) {
|
||||||
|
$url = $links[1]->getHref();
|
||||||
|
}
|
||||||
|
$this->assertNotNull($url);
|
||||||
|
WebDriverUtilities::savePaymentMethod($url ?? '');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testCreateSetupToken
|
||||||
|
* @depends testSavePaymentMethod
|
||||||
|
*/
|
||||||
|
public function testCreatePaymentToken(SetupTokenResponse $setupTokenResponse): PaymentTokenResponse
|
||||||
|
{
|
||||||
|
$request = [
|
||||||
|
'payPalRequestId' => strval(rand(1, 99999999999)),
|
||||||
|
'body' => PaymentTokenRequestBuilder::init(
|
||||||
|
PaymentTokenRequestPaymentSourceBuilder::init()
|
||||||
|
->token(
|
||||||
|
VaultTokenRequestBuilder::init(
|
||||||
|
$setupTokenResponse->getId() ?? '',
|
||||||
|
TokenRequestType::SETUP_TOKEN
|
||||||
|
)->build()
|
||||||
|
)->build()
|
||||||
|
)->build()
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = self::$vaultController->paymentTokensCreate($request);
|
||||||
|
|
||||||
|
$this->assertTrue($response->isSuccess());
|
||||||
|
$this->assertEquals(201, $response->getStatusCode());
|
||||||
|
|
||||||
|
return $response->getResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testCreatePaymentToken
|
||||||
|
*/
|
||||||
|
public function testCreateOrder(PaymentTokenResponse $paymentToken): void
|
||||||
|
{
|
||||||
|
$request = [
|
||||||
|
'body' => OrderRequestBuilder::init(
|
||||||
|
CheckoutPaymentIntent::CAPTURE,
|
||||||
|
[
|
||||||
|
PurchaseUnitRequestBuilder::init(
|
||||||
|
AmountWithBreakdownBuilder::init(
|
||||||
|
'USD',
|
||||||
|
'10.00'
|
||||||
|
)
|
||||||
|
->breakdown(
|
||||||
|
AmountBreakdownBuilder::init()
|
||||||
|
->itemTotal(
|
||||||
|
MoneyBuilder::init(
|
||||||
|
'USD',
|
||||||
|
'10.00'
|
||||||
|
)->build()
|
||||||
|
)->build()
|
||||||
|
)->build()
|
||||||
|
)
|
||||||
|
->description('Camera Shop')
|
||||||
|
->items([
|
||||||
|
ItemBuilder::init(
|
||||||
|
'Camera',
|
||||||
|
MoneyBuilder::init(
|
||||||
|
'USD',
|
||||||
|
'10.00'
|
||||||
|
)->build(),
|
||||||
|
'1'
|
||||||
|
)->build(),
|
||||||
|
])
|
||||||
|
->shipping(
|
||||||
|
ShippingDetailsBuilder::init()
|
||||||
|
->address(
|
||||||
|
AddressBuilder::init(
|
||||||
|
'US'
|
||||||
|
)
|
||||||
|
->addressLine1('500 Main Street')
|
||||||
|
->addressLine2('#1000')
|
||||||
|
->adminArea1('CA')
|
||||||
|
->adminArea2('San Jose')
|
||||||
|
->postalCode('95131')
|
||||||
|
->build()
|
||||||
|
)->build()
|
||||||
|
)->build()
|
||||||
|
]
|
||||||
|
)
|
||||||
|
->paymentSource(
|
||||||
|
PaymentSourceBuilder::init()
|
||||||
|
->paypal(
|
||||||
|
PayPalWalletBuilder::init()
|
||||||
|
->vaultId($paymentToken->getId())
|
||||||
|
->build()
|
||||||
|
)
|
||||||
|
->build()
|
||||||
|
)
|
||||||
|
->build(),
|
||||||
|
'payPalRequestId' => strval(rand(1, 99999999999)),
|
||||||
|
'prefer' => 'return=representation'
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = self::$ordersController->ordersCreate($request);
|
||||||
|
|
||||||
|
$this->assertTrue($response->isSuccess());
|
||||||
|
$this->assertEquals(201, $response->getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testCreateSetupToken
|
||||||
|
* @depends testCreateOrder
|
||||||
|
*/
|
||||||
|
public function testGetSetupToken(SetupTokenResponse $setupTokenDetail): void
|
||||||
|
{
|
||||||
|
$response = self::$vaultController->setupTokensGet($setupTokenDetail->getId() ?? '');
|
||||||
|
|
||||||
|
$this->assertTrue($response->isSuccess());
|
||||||
|
$this->assertEquals(200, $response->getStatusCode());
|
||||||
|
$this->assertEquals('VAULTED', $response->getResult()->getStatus());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testCreatePaymentToken
|
||||||
|
* @depends testGetSetupToken
|
||||||
|
*/
|
||||||
|
public function testGetPaymentToken(PaymentTokenResponse $paymentToken): void
|
||||||
|
{
|
||||||
|
$response = self::$vaultController->paymentTokensGet($paymentToken->getId() ?? '');
|
||||||
|
|
||||||
|
$this->assertTrue($response->isSuccess());
|
||||||
|
$this->assertEquals(200, $response->getStatusCode());
|
||||||
|
$this->assertNotNull($response);
|
||||||
|
}
|
||||||
|
}
|
||||||
167
tests/E2E/RefundFlowTest.php
Normal file
167
tests/E2E/RefundFlowTest.php
Normal file
@@ -0,0 +1,167 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* PaypalServerSDKLib
|
||||||
|
*
|
||||||
|
* This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ).
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PaypalServerSDKLib\Tests\E2E;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use PaypalServerSDKLib\Controllers\OrdersController;
|
||||||
|
use PaypalServerSDKLib\Controllers\PaymentsController;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\AmountWithBreakdownBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\OrderRequestBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\PaymentSourceBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\PayPalWalletBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\PayPalWalletExperienceContextBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\PurchaseUnitRequestBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\CheckoutPaymentIntent;
|
||||||
|
use PaypalServerSDKLib\Models\Order;
|
||||||
|
use PaypalServerSDKLib\Models\PayPalExperienceLandingPage;
|
||||||
|
use PaypalServerSDKLib\Models\Refund;
|
||||||
|
use PaypalServerSDKLib\Tests\Controllers\BaseTestController;
|
||||||
|
use PaypalServerSDKLib\Tests\WebDriverUtilities;
|
||||||
|
|
||||||
|
class RefundFlowTest extends BaseTestController
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var OrdersController OrdersController instance
|
||||||
|
*/
|
||||||
|
protected static $ordersController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var PaymentsController PaymentsController instance
|
||||||
|
*/
|
||||||
|
protected static $paymentsController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setup test class
|
||||||
|
*/
|
||||||
|
public static function setUpBeforeClass(): void
|
||||||
|
{
|
||||||
|
$client = parent::getClient();
|
||||||
|
self::$ordersController = $client->getOrdersController();
|
||||||
|
self::$paymentsController = $client->getPaymentsController();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCreateOrder(): Order
|
||||||
|
{
|
||||||
|
$request = [
|
||||||
|
'body' => OrderRequestBuilder::init(
|
||||||
|
CheckoutPaymentIntent::CAPTURE,
|
||||||
|
[
|
||||||
|
PurchaseUnitRequestBuilder::init(
|
||||||
|
AmountWithBreakdownBuilder::init(
|
||||||
|
'USD',
|
||||||
|
'100.00'
|
||||||
|
)->build()
|
||||||
|
)
|
||||||
|
->referenceId('d9f80740-38f0-11e8-b467-0ed5f89f718b')
|
||||||
|
->build()
|
||||||
|
]
|
||||||
|
)
|
||||||
|
->paymentSource(
|
||||||
|
PaymentSourceBuilder::init()
|
||||||
|
->paypal(
|
||||||
|
PayPalWalletBuilder::init()
|
||||||
|
->experienceContext(
|
||||||
|
PayPalWalletExperienceContextBuilder::init()
|
||||||
|
->locale('en-US')
|
||||||
|
->returnUrl('https://example.com/returnUrl')
|
||||||
|
->cancelUrl('https://example.com/cancelUrl')
|
||||||
|
->landingPage(PayPalExperienceLandingPage::LOGIN)
|
||||||
|
->build()
|
||||||
|
)
|
||||||
|
->build()
|
||||||
|
)
|
||||||
|
->build()
|
||||||
|
)
|
||||||
|
->build()
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = self::$ordersController->ordersCreate($request);
|
||||||
|
|
||||||
|
$this->assertTrue($response->isSuccess());
|
||||||
|
$this->assertEquals(200, $response->getStatusCode());
|
||||||
|
|
||||||
|
return $response->getResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testCreateOrder
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function testCompletePayment(Order $orderDetail): void
|
||||||
|
{
|
||||||
|
$links = $orderDetail->getLinks();
|
||||||
|
$url = null;
|
||||||
|
if (isset($links)) {
|
||||||
|
$url = $links[1]->getHref();
|
||||||
|
}
|
||||||
|
$this->assertNotNull($url);
|
||||||
|
WebDriverUtilities::completePayment($url ?? '');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testCreateOrder
|
||||||
|
* @depends testCompletePayment
|
||||||
|
*/
|
||||||
|
public function testCaptureOrder(Order $orderDetail): Order
|
||||||
|
{
|
||||||
|
$request = [
|
||||||
|
'id' => $orderDetail->getId(),
|
||||||
|
'payPalRequestId' => strval(rand(1, 99999999999)),
|
||||||
|
'prefer' => 'return=representation'
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = self::$ordersController->ordersCapture($request);
|
||||||
|
|
||||||
|
$this->assertTrue($response->isSuccess());
|
||||||
|
$this->assertEquals(201, $response->getStatusCode());
|
||||||
|
|
||||||
|
return $response->getResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testCaptureOrder
|
||||||
|
*/
|
||||||
|
public function testRefund(Order $captureDetail): Refund
|
||||||
|
{
|
||||||
|
$purchaseUnits = $captureDetail->getPurchaseUnits();
|
||||||
|
$captureId = null;
|
||||||
|
if (isset($purchaseUnits)) {
|
||||||
|
$captures = $purchaseUnits[0]->getPayments()->getCaptures();
|
||||||
|
if (isset($captures)) {
|
||||||
|
$captureId = $captures[0]->getId();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->assertNotNull($captureId);
|
||||||
|
$request = [
|
||||||
|
'captureId' => $captureId,
|
||||||
|
'prefer' => 'return=representation'
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = self::$paymentsController->capturesRefund($request);
|
||||||
|
|
||||||
|
$this->assertTrue($response->isSuccess());
|
||||||
|
$this->assertEquals(201, $response->getStatusCode());
|
||||||
|
|
||||||
|
return $response->getResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testRefund
|
||||||
|
*/
|
||||||
|
public function testGetRefund(Refund $refund): void
|
||||||
|
{
|
||||||
|
$response = self::$paymentsController->refundsGet($refund->getId() ?? '');
|
||||||
|
|
||||||
|
$this->assertTrue($response->isSuccess());
|
||||||
|
$this->assertEquals(200, $response->getStatusCode());
|
||||||
|
$this->assertEquals('COMPLETED', $response->getResult()->getStatus());
|
||||||
|
}
|
||||||
|
}
|
||||||
134
tests/E2E/StandardCheckoutFlowTest.php
Normal file
134
tests/E2E/StandardCheckoutFlowTest.php
Normal file
@@ -0,0 +1,134 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* PaypalServerSDKLib
|
||||||
|
*
|
||||||
|
* This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ).
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PaypalServerSDKLib\Tests\E2E;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use PaypalServerSDKLib\Controllers\OrdersController;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\AmountWithBreakdownBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\OrderRequestBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\PaymentSourceBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\PayPalWalletBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\PayPalWalletExperienceContextBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\PurchaseUnitRequestBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\CheckoutPaymentIntent;
|
||||||
|
use PaypalServerSDKLib\Models\Order;
|
||||||
|
use PaypalServerSDKLib\Models\PayPalExperienceLandingPage;
|
||||||
|
use PaypalServerSDKLib\Tests\Controllers\BaseTestController;
|
||||||
|
use PaypalServerSDKLib\Tests\WebDriverUtilities;
|
||||||
|
|
||||||
|
class StandardCheckoutFlowTest extends BaseTestController
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var OrdersController OrdersController instance
|
||||||
|
*/
|
||||||
|
protected static $ordersController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setup test class
|
||||||
|
*/
|
||||||
|
public static function setUpBeforeClass(): void
|
||||||
|
{
|
||||||
|
$client = parent::getClient();
|
||||||
|
self::$ordersController = $client->getOrdersController();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCreateOrder(): Order
|
||||||
|
{
|
||||||
|
$request = [
|
||||||
|
'body' => OrderRequestBuilder::init(
|
||||||
|
CheckoutPaymentIntent::CAPTURE,
|
||||||
|
[
|
||||||
|
PurchaseUnitRequestBuilder::init(
|
||||||
|
AmountWithBreakdownBuilder::init(
|
||||||
|
'USD',
|
||||||
|
'100.00'
|
||||||
|
)->build()
|
||||||
|
)
|
||||||
|
->referenceId('d9f80740-38f0-11e8-b467-0ed5f89f718b')
|
||||||
|
->build()
|
||||||
|
]
|
||||||
|
)
|
||||||
|
->paymentSource(
|
||||||
|
PaymentSourceBuilder::init()
|
||||||
|
->paypal(
|
||||||
|
PayPalWalletBuilder::init()
|
||||||
|
->experienceContext(
|
||||||
|
PayPalWalletExperienceContextBuilder::init()
|
||||||
|
->locale('en-US')
|
||||||
|
->returnUrl('https://example.com/returnUrl')
|
||||||
|
->cancelUrl('https://example.com/cancelUrl')
|
||||||
|
->landingPage(PayPalExperienceLandingPage::LOGIN)
|
||||||
|
->build()
|
||||||
|
)
|
||||||
|
->build()
|
||||||
|
)
|
||||||
|
->build()
|
||||||
|
)
|
||||||
|
->build()
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = self::$ordersController->ordersCreate($request);
|
||||||
|
|
||||||
|
$this->assertTrue($response->isSuccess());
|
||||||
|
$this->assertEquals(200, $response->getStatusCode());
|
||||||
|
|
||||||
|
return $response->getResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testCreateOrder
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function testCompletePayment(Order $orderDetail): void
|
||||||
|
{
|
||||||
|
$links = $orderDetail->getLinks();
|
||||||
|
$url = null;
|
||||||
|
if (isset($links)) {
|
||||||
|
$url = $links[1]->getHref();
|
||||||
|
}
|
||||||
|
$this->assertNotNull($url);
|
||||||
|
WebDriverUtilities::completePayment($url ?? '');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testCreateOrder
|
||||||
|
* @depends testCompletePayment
|
||||||
|
*/
|
||||||
|
public function testCaptureOrder(Order $orderDetail): void
|
||||||
|
{
|
||||||
|
$request = [
|
||||||
|
'id' => $orderDetail->getId(),
|
||||||
|
'payPalRequestId' => strval(rand(1, 99999999999)),
|
||||||
|
'prefer' => 'return=representation'
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = self::$ordersController->ordersCapture($request);
|
||||||
|
|
||||||
|
$this->assertTrue($response->isSuccess());
|
||||||
|
$this->assertEquals(201, $response->getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testCreateOrder
|
||||||
|
* @depends testCaptureOrder
|
||||||
|
*/
|
||||||
|
public function testGetOrderDetails(Order $orderDetail): void
|
||||||
|
{
|
||||||
|
$request = [
|
||||||
|
'id' => $orderDetail->getId()
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = self::$ordersController->ordersGet($request);
|
||||||
|
|
||||||
|
$this->assertTrue($response->isSuccess());
|
||||||
|
$this->assertEquals(200, $response->getStatusCode());
|
||||||
|
}
|
||||||
|
}
|
||||||
197
tests/E2E/VoidAuthorizationFlowTest.php
Normal file
197
tests/E2E/VoidAuthorizationFlowTest.php
Normal file
@@ -0,0 +1,197 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* PaypalServerSDKLib
|
||||||
|
*
|
||||||
|
* This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ).
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PaypalServerSDKLib\Tests\E2E;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use PaypalServerSDKLib\Controllers\OrdersController;
|
||||||
|
use PaypalServerSDKLib\Controllers\PaymentsController;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\AmountBreakdownBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\AmountWithBreakdownBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\ItemBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\MoneyBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\OrderRequestBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\PaymentSourceBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\PayPalWalletBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\PayPalWalletExperienceContextBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\PurchaseUnitRequestBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\CheckoutPaymentIntent;
|
||||||
|
use PaypalServerSDKLib\Models\Order;
|
||||||
|
use PaypalServerSDKLib\Models\OrderAuthorizeResponse;
|
||||||
|
use PaypalServerSDKLib\Models\PayPalExperienceLandingPage;
|
||||||
|
use PaypalServerSDKLib\Tests\Controllers\BaseTestController;
|
||||||
|
use PaypalServerSDKLib\Tests\WebDriverUtilities;
|
||||||
|
|
||||||
|
class VoidAuthorizationFlowTest extends BaseTestController
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var OrdersController OrdersController instance
|
||||||
|
*/
|
||||||
|
protected static $ordersController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var PaymentsController PaymentsController instance
|
||||||
|
*/
|
||||||
|
protected static $paymentsController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setup test class
|
||||||
|
*/
|
||||||
|
public static function setUpBeforeClass(): void
|
||||||
|
{
|
||||||
|
$client = parent::getClient();
|
||||||
|
self::$ordersController = $client->getOrdersController();
|
||||||
|
self::$paymentsController = $client->getPaymentsController();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCreateOrder(): Order
|
||||||
|
{
|
||||||
|
$request = [
|
||||||
|
'body' => OrderRequestBuilder::init(
|
||||||
|
CheckoutPaymentIntent::AUTHORIZE,
|
||||||
|
[
|
||||||
|
PurchaseUnitRequestBuilder::init(
|
||||||
|
AmountWithBreakdownBuilder::init(
|
||||||
|
'USD',
|
||||||
|
'25.00'
|
||||||
|
)
|
||||||
|
->breakdown(
|
||||||
|
AmountBreakdownBuilder::init()
|
||||||
|
->itemTotal(
|
||||||
|
MoneyBuilder::init(
|
||||||
|
'USD',
|
||||||
|
'25.00'
|
||||||
|
)->build()
|
||||||
|
)
|
||||||
|
->shipping(
|
||||||
|
MoneyBuilder::init(
|
||||||
|
'USD',
|
||||||
|
'0'
|
||||||
|
)->build()
|
||||||
|
)
|
||||||
|
->taxTotal(
|
||||||
|
MoneyBuilder::init(
|
||||||
|
'USD',
|
||||||
|
'0'
|
||||||
|
)->build()
|
||||||
|
)
|
||||||
|
->build()
|
||||||
|
)->build()
|
||||||
|
)
|
||||||
|
->description('Clothing Shop')
|
||||||
|
->items([
|
||||||
|
ItemBuilder::init(
|
||||||
|
'Levis 501',
|
||||||
|
MoneyBuilder::init(
|
||||||
|
'USD',
|
||||||
|
'25.00'
|
||||||
|
)->build(),
|
||||||
|
'1'
|
||||||
|
)
|
||||||
|
->tax(
|
||||||
|
MoneyBuilder::init(
|
||||||
|
'USD',
|
||||||
|
'0.00'
|
||||||
|
)->build()
|
||||||
|
)
|
||||||
|
->sku('5158936')
|
||||||
|
->build()
|
||||||
|
])
|
||||||
|
->build()
|
||||||
|
]
|
||||||
|
)
|
||||||
|
->paymentSource(
|
||||||
|
PaymentSourceBuilder::init()
|
||||||
|
->paypal(
|
||||||
|
PayPalWalletBuilder::init()
|
||||||
|
->experienceContext(
|
||||||
|
PayPalWalletExperienceContextBuilder::init()
|
||||||
|
->locale('en-US')
|
||||||
|
->returnUrl('https://example.com/returnUrl')
|
||||||
|
->cancelUrl('https://example.com/cancelUrl')
|
||||||
|
->landingPage(PayPalExperienceLandingPage::LOGIN)
|
||||||
|
->build()
|
||||||
|
)
|
||||||
|
->build()
|
||||||
|
)
|
||||||
|
->build()
|
||||||
|
)
|
||||||
|
->build(),
|
||||||
|
'payPalRequestId' => strval(rand(1, 99999999999))
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = self::$ordersController->ordersCreate($request);
|
||||||
|
|
||||||
|
$this->assertTrue($response->isSuccess());
|
||||||
|
$this->assertEquals(200, $response->getStatusCode());
|
||||||
|
|
||||||
|
return $response->getResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testCreateOrder
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function testCompletePayment(Order $orderDetail): void
|
||||||
|
{
|
||||||
|
$links = $orderDetail->getLinks();
|
||||||
|
$url = null;
|
||||||
|
if (isset($links)) {
|
||||||
|
$url = $links[1]->getHref();
|
||||||
|
}
|
||||||
|
$this->assertNotNull($url);
|
||||||
|
WebDriverUtilities::completePayment($url ?? '');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testCreateOrder
|
||||||
|
* @depends testCompletePayment
|
||||||
|
*/
|
||||||
|
public function testAuthorizeOrder(Order $orderDetail): OrderAuthorizeResponse
|
||||||
|
{
|
||||||
|
$request = [
|
||||||
|
'id' => $orderDetail->getId(),
|
||||||
|
'payPalRequestId' => strval(rand(1, 99999999999)),
|
||||||
|
'prefer' => 'return=representation'
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = self::$ordersController->ordersAuthorize($request);
|
||||||
|
|
||||||
|
$this->assertTrue($response->isSuccess());
|
||||||
|
$this->assertEquals(201, $response->getStatusCode());
|
||||||
|
|
||||||
|
return $response->getResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testAuthorizeOrder
|
||||||
|
*/
|
||||||
|
public function testCaptureAuthorization(OrderAuthorizeResponse $authorizeResponse): void
|
||||||
|
{
|
||||||
|
$purchaseUnits = $authorizeResponse->getPurchaseUnits();
|
||||||
|
$authorizationId = null;
|
||||||
|
if (isset($purchaseUnits)) {
|
||||||
|
$authorizations = $purchaseUnits[0]->getPayments()->getAuthorizations();
|
||||||
|
if (isset($authorizations)) {
|
||||||
|
$authorizationId = $authorizations[0]->getId();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->assertNotNull($authorizationId);
|
||||||
|
$request = [
|
||||||
|
'authorizationId' => $authorizationId,
|
||||||
|
'prefer' => 'return=representation'
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = self::$paymentsController->authorizationsCapture($request);
|
||||||
|
|
||||||
|
$this->assertTrue($response->isSuccess());
|
||||||
|
$this->assertEquals(201, $response->getStatusCode());
|
||||||
|
}
|
||||||
|
}
|
||||||
209
tests/UnitTests/OrdersControllerTest.php
Normal file
209
tests/UnitTests/OrdersControllerTest.php
Normal file
@@ -0,0 +1,209 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* PaypalServerSDKLib
|
||||||
|
*
|
||||||
|
* This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ).
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PaypalServerSDKLib\Tests\UnitTests;
|
||||||
|
|
||||||
|
use PaypalServerSDKLib\Controllers\OrdersController;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\ConfirmOrderRequestBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\OrderRequestBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\OrderTrackerRequestBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\PatchBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\PaymentSourceBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\CheckoutPaymentIntent;
|
||||||
|
use PaypalServerSDKLib\Models\PatchOp;
|
||||||
|
use PaypalServerSDKLib\Tests\Controllers\BaseTestController;
|
||||||
|
|
||||||
|
class OrdersControllerTest extends BaseTestController
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var OrdersController OrdersController instance
|
||||||
|
*/
|
||||||
|
protected static $controller;
|
||||||
|
private const NON_EXISTENT_ORDER_ID = 'id-4';
|
||||||
|
private const NON_EXISTENT_TRACKER_ID = '5UA89551P20376023-443844607820';
|
||||||
|
private const ALREADY_CAPTURED_ID = '123';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setup test class
|
||||||
|
*/
|
||||||
|
public static function setUpBeforeClass(): void
|
||||||
|
{
|
||||||
|
self::$controller = parent::getClient()->getOrdersController();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testOrdersCreateWithStatus400()
|
||||||
|
{
|
||||||
|
// Parameters for the API call
|
||||||
|
$request = [
|
||||||
|
'body' => OrderRequestBuilder::init(
|
||||||
|
CheckoutPaymentIntent::CAPTURE,
|
||||||
|
[]
|
||||||
|
)->build(),
|
||||||
|
'payPalRequestId' => 'PayPal-Request-Id',
|
||||||
|
'payPalPartnerAttributionId' => 'PayPal-Partner-Attribution-Id2',
|
||||||
|
'payPalClientMetadataId' => 'PayPal-Client-Metadata-Id',
|
||||||
|
'prefer' => 'return=minimal'
|
||||||
|
];
|
||||||
|
// Perform API call
|
||||||
|
$result = self::$controller->ordersCreate($request);
|
||||||
|
|
||||||
|
$headers = [];
|
||||||
|
$headers['Content-Type'] = ['application/json', true];
|
||||||
|
|
||||||
|
// Assert result with expected response
|
||||||
|
$this->assertTrue($result->isError());
|
||||||
|
$this->newTestCase($result->getResult())
|
||||||
|
->expectStatus(400)
|
||||||
|
->allowExtraHeaders()
|
||||||
|
->expectHeaders($headers)
|
||||||
|
->assert();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testOrdersPatchWithStatus400()
|
||||||
|
{
|
||||||
|
// Parameters for the API call
|
||||||
|
$request = [
|
||||||
|
'body' => PatchBuilder::init(
|
||||||
|
PatchOp::ADD
|
||||||
|
)->build(),
|
||||||
|
'id' => self::NON_EXISTENT_ORDER_ID,
|
||||||
|
];
|
||||||
|
// Perform API call
|
||||||
|
$result = self::$controller->ordersPatch($request);
|
||||||
|
|
||||||
|
$headers = [];
|
||||||
|
$headers['Content-Type'] = ['application/json', true];
|
||||||
|
|
||||||
|
// Assert result with expected response
|
||||||
|
$this->assertTrue($result->isError());
|
||||||
|
$this->newTestCase($result->getResult())
|
||||||
|
->expectStatus(400)
|
||||||
|
->allowExtraHeaders()
|
||||||
|
->expectHeaders($headers)
|
||||||
|
->assert();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testOrdersGetWithStatus204()
|
||||||
|
{
|
||||||
|
// Parameters for the API call
|
||||||
|
$request = [
|
||||||
|
'id' => self::NON_EXISTENT_ORDER_ID
|
||||||
|
];
|
||||||
|
// Perform API call
|
||||||
|
$result = self::$controller->ordersPatch($request);
|
||||||
|
|
||||||
|
// Assert result with expected response
|
||||||
|
$this->assertTrue($result->isSuccess());
|
||||||
|
$this->newTestCase($result->getResult())
|
||||||
|
->expectStatus(204)
|
||||||
|
->assert();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testOrdersConfirmWithStatus404()
|
||||||
|
{
|
||||||
|
// Parameters for the API call
|
||||||
|
$request = [
|
||||||
|
'body' => ConfirmOrderRequestBuilder::init(
|
||||||
|
PaymentSourceBuilder::init()->build()
|
||||||
|
)->build(),
|
||||||
|
'id' => self::NON_EXISTENT_ORDER_ID,
|
||||||
|
'prefer' => 'return=minimal'
|
||||||
|
];
|
||||||
|
// Perform API call
|
||||||
|
$result = self::$controller->ordersConfirm($request);
|
||||||
|
|
||||||
|
$headers = [];
|
||||||
|
$headers['Content-Type'] = ['application/json', true];
|
||||||
|
|
||||||
|
// Assert result with expected response
|
||||||
|
$this->assertTrue($result->isError());
|
||||||
|
$this->newTestCase($result->getResult())
|
||||||
|
->expectStatus(404)
|
||||||
|
->allowExtraHeaders()
|
||||||
|
->expectHeaders($headers)
|
||||||
|
->assert();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testOrdersAuthorizeWithStatus404()
|
||||||
|
{
|
||||||
|
// Parameters for the API call
|
||||||
|
$request = [
|
||||||
|
'id' => self::NON_EXISTENT_ORDER_ID,
|
||||||
|
'prefer' => 'return=minimal'
|
||||||
|
];
|
||||||
|
// Perform API call
|
||||||
|
$result = self::$controller->ordersAuthorize($request);
|
||||||
|
|
||||||
|
$headers = [];
|
||||||
|
$headers['Content-Type'] = ['application/json', true];
|
||||||
|
|
||||||
|
// Assert result with expected response
|
||||||
|
$this->assertTrue($result->isError());
|
||||||
|
$this->newTestCase($result->getResult())
|
||||||
|
->expectStatus(404)
|
||||||
|
->allowExtraHeaders()
|
||||||
|
->expectHeaders($headers)
|
||||||
|
->assert();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testOrdersTrackCreateWithStatus404()
|
||||||
|
{
|
||||||
|
// Parameters for the API call
|
||||||
|
$request = [
|
||||||
|
'id' => self::NON_EXISTENT_ORDER_ID,
|
||||||
|
'body' => OrderTrackerRequestBuilder::init(
|
||||||
|
self::ALREADY_CAPTURED_ID
|
||||||
|
)->notifyPayer(false)->build(),
|
||||||
|
];
|
||||||
|
// Perform API call
|
||||||
|
$result = self::$controller->ordersTrackCreate($request);
|
||||||
|
|
||||||
|
$headers = [];
|
||||||
|
$headers['Content-Type'] = ['application/json', true];
|
||||||
|
|
||||||
|
// Assert result with expected response
|
||||||
|
$this->assertTrue($result->isError());
|
||||||
|
$this->newTestCase($result->getResult())
|
||||||
|
->expectStatus(400)
|
||||||
|
->allowExtraHeaders()
|
||||||
|
->expectHeaders($headers)
|
||||||
|
->assert();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testOrdersTrackersPatchWithStatus404()
|
||||||
|
{
|
||||||
|
// Parameters for the API call
|
||||||
|
$request = [
|
||||||
|
'id' => self::NON_EXISTENT_ORDER_ID,
|
||||||
|
'trackerId' => self::NON_EXISTENT_TRACKER_ID,
|
||||||
|
'body' => [
|
||||||
|
PatchBuilder::init(
|
||||||
|
PatchOp::REPLACE
|
||||||
|
)
|
||||||
|
->path('/notify_payer')
|
||||||
|
->value(true)
|
||||||
|
->build()
|
||||||
|
]
|
||||||
|
];
|
||||||
|
// Perform API call
|
||||||
|
$result = self::$controller->ordersTrackersPatch($request);
|
||||||
|
|
||||||
|
$headers = [];
|
||||||
|
$headers['Content-Type'] = ['application/json', true];
|
||||||
|
|
||||||
|
// Assert result with expected response
|
||||||
|
$this->assertTrue($result->isError());
|
||||||
|
$this->newTestCase($result->getResult())
|
||||||
|
->expectStatus(404)
|
||||||
|
->allowExtraHeaders()
|
||||||
|
->expectHeaders($headers)
|
||||||
|
->assert();
|
||||||
|
}
|
||||||
|
}
|
||||||
208
tests/UnitTests/PaymentsControllerTest.php
Normal file
208
tests/UnitTests/PaymentsControllerTest.php
Normal file
@@ -0,0 +1,208 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* PaypalServerSDKLib
|
||||||
|
*
|
||||||
|
* This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ).
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PaypalServerSDKLib\Tests\UnitTests;
|
||||||
|
|
||||||
|
use PaypalServerSDKLib\Controllers\PaymentsController;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\CaptureRequestBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\MoneyBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\RefundRequestBuilder;
|
||||||
|
use PaypalServerSDKLib\Tests\Controllers\BaseTestController;
|
||||||
|
|
||||||
|
class PaymentsControllerTest extends BaseTestController
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var PaymentsController PaymentsController instance
|
||||||
|
*/
|
||||||
|
protected static $controller;
|
||||||
|
private const NON_EXISTENT_AUTHORIZATION_ID = 'authorization_id8';
|
||||||
|
private const NON_EXISTENT_CAPTURE_ID = 'capture_id';
|
||||||
|
private const NON_EXISTENT_REFUND_ID = 'refund_id';
|
||||||
|
private const ALREADY_AUTHORIZED_ID = '3BJ81821K7933911P';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setup test class
|
||||||
|
*/
|
||||||
|
public static function setUpBeforeClass(): void
|
||||||
|
{
|
||||||
|
self::$controller = parent::getClient()->getPaymentsController();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAuthorizationsGetWithStatus404()
|
||||||
|
{
|
||||||
|
// Perform API call
|
||||||
|
$result = self::$controller->authorizationsGet(self::NON_EXISTENT_AUTHORIZATION_ID);
|
||||||
|
|
||||||
|
$headers = [];
|
||||||
|
$headers['Content-Type'] = ['application/json;charset=UTF-8', true];
|
||||||
|
|
||||||
|
// Assert result with expected response
|
||||||
|
$this->assertTrue($result->isError());
|
||||||
|
$this->newTestCase($result->getResult())
|
||||||
|
->expectStatus(404)
|
||||||
|
->allowExtraHeaders()
|
||||||
|
->expectHeaders($headers)
|
||||||
|
->assert();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCapturesGetWithStatus404()
|
||||||
|
{
|
||||||
|
// Perform API call
|
||||||
|
$result = self::$controller->capturesGet(self::NON_EXISTENT_CAPTURE_ID);
|
||||||
|
|
||||||
|
$headers = [];
|
||||||
|
$headers['Content-Type'] = ['application/json;charset=UTF-8', true];
|
||||||
|
|
||||||
|
// Assert result with expected response
|
||||||
|
$this->assertTrue($result->isError());
|
||||||
|
$this->newTestCase($result->getResult())
|
||||||
|
->expectStatus(404)
|
||||||
|
->allowExtraHeaders()
|
||||||
|
->expectHeaders($headers)
|
||||||
|
->assert();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testRefundsGetWithStatus404()
|
||||||
|
{
|
||||||
|
// Perform API call
|
||||||
|
$result = self::$controller->refundsGet(self::NON_EXISTENT_REFUND_ID);
|
||||||
|
|
||||||
|
$headers = [];
|
||||||
|
$headers['Content-Type'] = ['application/json', true];
|
||||||
|
|
||||||
|
// Assert result with expected response
|
||||||
|
$this->assertTrue($result->isError());
|
||||||
|
$this->newTestCase($result->getResult())
|
||||||
|
->expectStatus(404)
|
||||||
|
->allowExtraHeaders()
|
||||||
|
->expectHeaders($headers)
|
||||||
|
->assert();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAuthorizationsCaptureWithStatus404()
|
||||||
|
{
|
||||||
|
// Parameters for the API call
|
||||||
|
$request = [
|
||||||
|
'body' => CaptureRequestBuilder::init()->finalCapture(false)->build(),
|
||||||
|
'authorizationId' => self::NON_EXISTENT_AUTHORIZATION_ID,
|
||||||
|
'prefer' => 'return=minimal'
|
||||||
|
];
|
||||||
|
// Perform API call
|
||||||
|
$result = self::$controller->authorizationsCapture($request);
|
||||||
|
|
||||||
|
$headers = [];
|
||||||
|
$headers['Content-Type'] = ['application/json;charset=UTF-8', true];
|
||||||
|
|
||||||
|
// Assert result with expected response
|
||||||
|
$this->assertTrue($result->isError());
|
||||||
|
$this->newTestCase($result->getResult())
|
||||||
|
->expectStatus(404)
|
||||||
|
->allowExtraHeaders()
|
||||||
|
->expectHeaders($headers)
|
||||||
|
->assert();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAuthorizationsReauthorizeWithStatus404()
|
||||||
|
{
|
||||||
|
// Parameters for the API call
|
||||||
|
$request = [
|
||||||
|
'authorizationId' => self::NON_EXISTENT_AUTHORIZATION_ID,
|
||||||
|
'prefer' => 'return=minimal'
|
||||||
|
];
|
||||||
|
// Perform API call
|
||||||
|
$result = self::$controller->authorizationsReauthorize($request);
|
||||||
|
|
||||||
|
$headers = [];
|
||||||
|
$headers['Content-Type'] = ['application/json;charset=UTF-8', true];
|
||||||
|
|
||||||
|
// Assert result with expected response
|
||||||
|
$this->assertTrue($result->isError());
|
||||||
|
$this->newTestCase($result->getResult())
|
||||||
|
->expectStatus(404)
|
||||||
|
->allowExtraHeaders()
|
||||||
|
->expectHeaders($headers)
|
||||||
|
->assert();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAuthorizationsVoidWithStatus404()
|
||||||
|
{
|
||||||
|
// Parameters for the API call
|
||||||
|
$request = [
|
||||||
|
'authorizationId' => self::NON_EXISTENT_AUTHORIZATION_ID,
|
||||||
|
'prefer' => 'return=minimal'
|
||||||
|
];
|
||||||
|
// Perform API call
|
||||||
|
$result = self::$controller->authorizationsVoid($request);
|
||||||
|
|
||||||
|
$headers = [];
|
||||||
|
$headers['Content-Type'] = ['application/json', true];
|
||||||
|
|
||||||
|
// Assert result with expected response
|
||||||
|
$this->assertTrue($result->isError());
|
||||||
|
$this->newTestCase($result->getResult())
|
||||||
|
->expectStatus(404)
|
||||||
|
->allowExtraHeaders()
|
||||||
|
->expectHeaders($headers)
|
||||||
|
->assert();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAuthorizationsVoidWithStatus422()
|
||||||
|
{
|
||||||
|
// Parameters for the API call
|
||||||
|
$request = [
|
||||||
|
'authorizationId' => self::ALREADY_AUTHORIZED_ID,
|
||||||
|
'prefer' => 'return=minimal'
|
||||||
|
];
|
||||||
|
// Perform API call
|
||||||
|
$result = self::$controller->authorizationsVoid($request);
|
||||||
|
|
||||||
|
$headers = [];
|
||||||
|
$headers['Content-Type'] = ['application/json', true];
|
||||||
|
|
||||||
|
// Assert result with expected response
|
||||||
|
$this->assertTrue($result->isError());
|
||||||
|
$this->newTestCase($result->getResult())
|
||||||
|
->expectStatus(422)
|
||||||
|
->allowExtraHeaders()
|
||||||
|
->expectHeaders($headers)
|
||||||
|
->assert();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCapturesRefundWithStatus404()
|
||||||
|
{
|
||||||
|
// Parameters for the API call
|
||||||
|
$request = [
|
||||||
|
'captureId' => self::NON_EXISTENT_CAPTURE_ID,
|
||||||
|
'prefer' => 'return=minimal',
|
||||||
|
'body' => RefundRequestBuilder::init()
|
||||||
|
->amount(
|
||||||
|
MoneyBuilder::init(
|
||||||
|
'USD',
|
||||||
|
'1.44'
|
||||||
|
)->build()
|
||||||
|
)
|
||||||
|
->noteToPayer('Defective product')
|
||||||
|
->build()
|
||||||
|
];
|
||||||
|
// Perform API call
|
||||||
|
$result = self::$controller->capturesRefund($request);
|
||||||
|
|
||||||
|
$headers = [];
|
||||||
|
$headers['Content-Type'] = ['application/json', true];
|
||||||
|
|
||||||
|
// Assert result with expected response
|
||||||
|
$this->assertTrue($result->isError());
|
||||||
|
$this->newTestCase($result->getResult())
|
||||||
|
->expectStatus(404)
|
||||||
|
->allowExtraHeaders()
|
||||||
|
->expectHeaders($headers)
|
||||||
|
->assert();
|
||||||
|
}
|
||||||
|
}
|
||||||
242
tests/UnitTests/VaultControllerTest.php
Normal file
242
tests/UnitTests/VaultControllerTest.php
Normal file
@@ -0,0 +1,242 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* PaypalServerSDKLib
|
||||||
|
*
|
||||||
|
* This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ).
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PaypalServerSDKLib\Tests\UnitTests;
|
||||||
|
|
||||||
|
use PaypalServerSDKLib\Controllers\VaultController;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\PaymentTokenRequestBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\PaymentTokenRequestPaymentSourceBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\SetupTokenRequestBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\SetupTokenRequestPaymentSourceBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\Builders\VaultTokenRequestBuilder;
|
||||||
|
use PaypalServerSDKLib\Models\TokenRequestType;
|
||||||
|
use PaypalServerSDKLib\Tests\Controllers\BaseTestController;
|
||||||
|
|
||||||
|
class VaultControllerTest extends BaseTestController
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var VaultController OrdersController instance
|
||||||
|
*/
|
||||||
|
protected static $controller;
|
||||||
|
private const NON_EXISTENT_SETUP_TOKEN_ID = 'setup-1';
|
||||||
|
private const NON_EXISTENT_PAYMENT_TOKEN_ID = 'payment-1';
|
||||||
|
private const NON_EXISTENT_CUSTOMER_ID = 'customer-1';
|
||||||
|
private const INVALID_ID = "'dw";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setup test class
|
||||||
|
*/
|
||||||
|
public static function setUpBeforeClass(): void
|
||||||
|
{
|
||||||
|
self::$controller = parent::getClient()->getVaultController();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSetupTokensCreateWithStatus400()
|
||||||
|
{
|
||||||
|
// Parameters for the API call
|
||||||
|
$request = [
|
||||||
|
'payPalRequestId' => '',
|
||||||
|
'body' => SetupTokenRequestBuilder::init(
|
||||||
|
SetupTokenRequestPaymentSourceBuilder::init()->build()
|
||||||
|
)->build()
|
||||||
|
];
|
||||||
|
// Perform API call
|
||||||
|
$result = self::$controller->setupTokensCreate($request);
|
||||||
|
|
||||||
|
$headers = [];
|
||||||
|
$headers['Content-Type'] = ['application/json', true];
|
||||||
|
|
||||||
|
// Assert result with expected response
|
||||||
|
$this->assertTrue($result->isError());
|
||||||
|
$this->newTestCase($result->getResult())
|
||||||
|
->expectStatus(400)
|
||||||
|
->allowExtraHeaders()
|
||||||
|
->expectHeaders($headers)
|
||||||
|
->assert();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPaymentTokensCreateWithStatus404()
|
||||||
|
{
|
||||||
|
// Parameters for the API call
|
||||||
|
$request = [
|
||||||
|
'body' => PaymentTokenRequestBuilder::init(
|
||||||
|
PaymentTokenRequestPaymentSourceBuilder::init()->build()
|
||||||
|
)->build(),
|
||||||
|
'payPalRequestId' => '',
|
||||||
|
];
|
||||||
|
// Perform API call
|
||||||
|
$result = self::$controller->paymentTokensCreate($request);
|
||||||
|
|
||||||
|
$headers = [];
|
||||||
|
$headers['Content-Type'] = ['application/json', true];
|
||||||
|
|
||||||
|
// Assert result with expected response
|
||||||
|
$this->assertTrue($result->isError());
|
||||||
|
$this->newTestCase($result->getResult())
|
||||||
|
->expectStatus(404)
|
||||||
|
->allowExtraHeaders()
|
||||||
|
->expectHeaders($headers)
|
||||||
|
->assert();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPaymentTokensCreateWithStatus400()
|
||||||
|
{
|
||||||
|
// Parameters for the API call
|
||||||
|
$request = [
|
||||||
|
'body' => PaymentTokenRequestBuilder::init(
|
||||||
|
PaymentTokenRequestPaymentSourceBuilder::init()
|
||||||
|
->token(VaultTokenRequestBuilder::init(self::INVALID_ID, TokenRequestType::SETUP_TOKEN)->build())
|
||||||
|
->build()
|
||||||
|
)->build(),
|
||||||
|
'payPalRequestId' => '',
|
||||||
|
];
|
||||||
|
// Perform API call
|
||||||
|
$result = self::$controller->paymentTokensCreate($request);
|
||||||
|
|
||||||
|
$headers = [];
|
||||||
|
$headers['Content-Type'] = ['application/json', true];
|
||||||
|
|
||||||
|
// Assert result with expected response
|
||||||
|
$this->assertTrue($result->isError());
|
||||||
|
$this->newTestCase($result->getResult())
|
||||||
|
->expectStatus(400)
|
||||||
|
->allowExtraHeaders()
|
||||||
|
->expectHeaders($headers)
|
||||||
|
->assert();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSetupTokensGetWithStatus404()
|
||||||
|
{
|
||||||
|
// Perform API call
|
||||||
|
$result = self::$controller->setupTokensGet(self::NON_EXISTENT_SETUP_TOKEN_ID);
|
||||||
|
|
||||||
|
$headers = [];
|
||||||
|
$headers['Content-Type'] = ['application/json', true];
|
||||||
|
|
||||||
|
// Assert result with expected response
|
||||||
|
$this->assertTrue($result->isError());
|
||||||
|
$this->newTestCase($result->getResult())
|
||||||
|
->expectStatus(404)
|
||||||
|
->allowExtraHeaders()
|
||||||
|
->expectHeaders($headers)
|
||||||
|
->assert();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSetupTokensGetWithStatus400()
|
||||||
|
{
|
||||||
|
// Perform API call
|
||||||
|
$result = self::$controller->setupTokensGet(self::INVALID_ID);
|
||||||
|
|
||||||
|
$headers = [];
|
||||||
|
$headers['Content-Type'] = ['application/json', true];
|
||||||
|
|
||||||
|
// Assert result with expected response
|
||||||
|
$this->assertTrue($result->isError());
|
||||||
|
$this->newTestCase($result->getResult())
|
||||||
|
->expectStatus(400)
|
||||||
|
->allowExtraHeaders()
|
||||||
|
->expectHeaders($headers)
|
||||||
|
->assert();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPaymentTokensGetWithStatus404()
|
||||||
|
{
|
||||||
|
// Perform API call
|
||||||
|
$result = self::$controller->paymentTokensGet(self::NON_EXISTENT_PAYMENT_TOKEN_ID);
|
||||||
|
|
||||||
|
$headers = [];
|
||||||
|
$headers['Content-Type'] = ['application/json', true];
|
||||||
|
|
||||||
|
// Assert result with expected response
|
||||||
|
$this->assertTrue($result->isError());
|
||||||
|
$this->newTestCase($result->getResult())
|
||||||
|
->expectStatus(404)
|
||||||
|
->allowExtraHeaders()
|
||||||
|
->expectHeaders($headers)
|
||||||
|
->assert();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPaymentTokensGetWithStatus400()
|
||||||
|
{
|
||||||
|
// Perform API call
|
||||||
|
$result = self::$controller->paymentTokensGet(self::NON_EXISTENT_PAYMENT_TOKEN_ID);
|
||||||
|
|
||||||
|
$headers = [];
|
||||||
|
$headers['Content-Type'] = ['application/json', true];
|
||||||
|
|
||||||
|
// Assert result with expected response
|
||||||
|
$this->assertTrue($result->isError());
|
||||||
|
$this->newTestCase($result->getResult())
|
||||||
|
->expectStatus(404)
|
||||||
|
->allowExtraHeaders()
|
||||||
|
->expectHeaders($headers)
|
||||||
|
->assert();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCustomerPaymentTokensGetWithStatus404()
|
||||||
|
{
|
||||||
|
// Parameters for the API call
|
||||||
|
$request = [
|
||||||
|
'customerId' => self::NON_EXISTENT_CUSTOMER_ID,
|
||||||
|
'pageSize' => 5,
|
||||||
|
'page' => 1,
|
||||||
|
'totalRequired' => false,
|
||||||
|
];
|
||||||
|
// Perform API call
|
||||||
|
$result = self::$controller->customerPaymentTokensGet($request);
|
||||||
|
|
||||||
|
$headers = [];
|
||||||
|
$headers['Content-Type'] = ['application/json', true];
|
||||||
|
|
||||||
|
// Assert result with expected response
|
||||||
|
$this->assertTrue($result->isError());
|
||||||
|
$this->newTestCase($result->getResult())
|
||||||
|
->expectStatus(404)
|
||||||
|
->allowExtraHeaders()
|
||||||
|
->expectHeaders($headers)
|
||||||
|
->assert();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCustomerPaymentTokensGetWithStatus400()
|
||||||
|
{
|
||||||
|
// Parameters for the API call
|
||||||
|
$request = [
|
||||||
|
'customerId' => self::INVALID_ID,
|
||||||
|
'pageSize' => 5,
|
||||||
|
'page' => 1,
|
||||||
|
'totalRequired' => false,
|
||||||
|
];
|
||||||
|
// Perform API call
|
||||||
|
$result = self::$controller->customerPaymentTokensGet($request);
|
||||||
|
|
||||||
|
$headers = [];
|
||||||
|
$headers['Content-Type'] = ['application/json', true];
|
||||||
|
|
||||||
|
// Assert result with expected response
|
||||||
|
$this->assertTrue($result->isError());
|
||||||
|
$this->newTestCase($result->getResult())
|
||||||
|
->expectStatus(400)
|
||||||
|
->allowExtraHeaders()
|
||||||
|
->expectHeaders($headers)
|
||||||
|
->assert();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPaymentTokensDeleteWithStatus204()
|
||||||
|
{
|
||||||
|
// Perform API call
|
||||||
|
$result = self::$controller->paymentTokensDelete(self::NON_EXISTENT_PAYMENT_TOKEN_ID);
|
||||||
|
|
||||||
|
// Assert result with expected response
|
||||||
|
$this->assertTrue($result->isSuccess());
|
||||||
|
$this->newTestCase($result->getResult())
|
||||||
|
->expectStatus(204)
|
||||||
|
->assert();
|
||||||
|
}
|
||||||
|
}
|
||||||
212
tests/WebDriverUtilities.php
Normal file
212
tests/WebDriverUtilities.php
Normal file
@@ -0,0 +1,212 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PaypalServerSDKLib\Tests;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use Facebook\WebDriver\Firefox\FirefoxOptions;
|
||||||
|
use Facebook\WebDriver\Remote\DesiredCapabilities;
|
||||||
|
use Facebook\WebDriver\Remote\RemoteWebDriver;
|
||||||
|
use Facebook\WebDriver\WebDriverBy;
|
||||||
|
use Facebook\WebDriver\WebDriverExpectedCondition;
|
||||||
|
|
||||||
|
class WebDriverUtilities
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static function completePayment(string $checkoutUrl): void
|
||||||
|
{
|
||||||
|
$email = getenv('EMAIL');
|
||||||
|
$pass = getenv('PASSWORD');
|
||||||
|
if (!isset($email) || !isset($pass)) {
|
||||||
|
throw new Exception('EMAIL or PASSWORD environment variable is not set');
|
||||||
|
}
|
||||||
|
|
||||||
|
$driver = self::getWebDriver();
|
||||||
|
$driver->get($checkoutUrl);
|
||||||
|
|
||||||
|
$elements = $driver->findElements(WebDriverBy::cssSelector('#email'));
|
||||||
|
if (count($elements) > 0) {
|
||||||
|
// If not logged in fill in the email
|
||||||
|
$emailField = $elements[0];
|
||||||
|
$emailField->clear();
|
||||||
|
$emailField->sendKeys($email);
|
||||||
|
|
||||||
|
$elements = $driver->findElements(WebDriverBy::cssSelector('#btnNext'));
|
||||||
|
if (count($elements) > 0) {
|
||||||
|
// Click the Next button if found
|
||||||
|
$elements[0]->click();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wait for the login button
|
||||||
|
$driver->wait(50)->until(
|
||||||
|
WebDriverExpectedCondition::visibilityOfElementLocated(
|
||||||
|
WebDriverBy::cssSelector('#btnLogin')
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Fill in password and login
|
||||||
|
$driver->findElement(WebDriverBy::cssSelector('#password'))->sendKeys($pass);
|
||||||
|
$driver->findElement(WebDriverBy::cssSelector('#btnLogin'))->click();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wait for the payment button
|
||||||
|
$driver->wait(50)->until(
|
||||||
|
WebDriverExpectedCondition::visibilityOfElementLocated(
|
||||||
|
WebDriverBy::cssSelector('#payment-submit-btn')
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Click on payment submit button
|
||||||
|
$driver->findElement(WebDriverBy::cssSelector('#payment-submit-btn'))->click();
|
||||||
|
|
||||||
|
// Wait for the return URL
|
||||||
|
$driver->wait(50)->until(
|
||||||
|
WebDriverExpectedCondition::urlContains('https://example.com/returnUrl')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static function savePaymentMethod(string $url): void
|
||||||
|
{
|
||||||
|
$email = getenv('EMAIL');
|
||||||
|
$pass = getenv('PASSWORD');
|
||||||
|
if (!isset($email) || !isset($pass)) {
|
||||||
|
throw new Exception('EMAIL or PASSWORD environment variable is not set');
|
||||||
|
}
|
||||||
|
|
||||||
|
$driver = self::getWebDriver();
|
||||||
|
$driver->get($url);
|
||||||
|
|
||||||
|
$elements = $driver->findElements(WebDriverBy::cssSelector('#email'));
|
||||||
|
if (count($elements) > 0) {
|
||||||
|
// If not logged in fill in the email
|
||||||
|
$emailField = $elements[0];
|
||||||
|
$emailField->sendKeys($email);
|
||||||
|
|
||||||
|
$elements = $driver->findElements(WebDriverBy::cssSelector('#btnNext'));
|
||||||
|
if (count($elements) > 0) {
|
||||||
|
// Click the Next button if found
|
||||||
|
$elements[0]->click();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wait for the login button
|
||||||
|
$driver->wait(50)->until(
|
||||||
|
WebDriverExpectedCondition::visibilityOfElementLocated(
|
||||||
|
WebDriverBy::cssSelector('#btnLogin')
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Fill in password and login
|
||||||
|
$driver->findElement(WebDriverBy::cssSelector('#password'))->sendKeys($pass);
|
||||||
|
$driver->findElement(WebDriverBy::cssSelector('#btnLogin'))->click();
|
||||||
|
}
|
||||||
|
|
||||||
|
usleep(10 * 1000000);
|
||||||
|
|
||||||
|
$elements = $driver->findElements(WebDriverBy::cssSelector('#consentButton'));
|
||||||
|
if (count($elements) > 0) {
|
||||||
|
// Click the Consent button if found
|
||||||
|
$elements[0]->click();
|
||||||
|
} else {
|
||||||
|
// Go back to the previous page
|
||||||
|
$driver->navigate()->back();
|
||||||
|
|
||||||
|
// Wait for the consent button
|
||||||
|
$driver->wait(50)->until(
|
||||||
|
WebDriverExpectedCondition::visibilityOfElementLocated(
|
||||||
|
WebDriverBy::cssSelector('#consentButton')
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Click on consent button
|
||||||
|
$driver->findElement(WebDriverBy::cssSelector('#consentButton'))->click();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wait for the return URL
|
||||||
|
$driver->wait(50)->until(
|
||||||
|
WebDriverExpectedCondition::urlContains('https://example.com/returnUrl')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static function completeHeliosVerification(string $checkoutUrl): void
|
||||||
|
{
|
||||||
|
$driver = self::getWebDriver();
|
||||||
|
$driver->get($checkoutUrl);
|
||||||
|
|
||||||
|
// Wait for the specific PayPal verification URL
|
||||||
|
$driver->wait(50)->until(
|
||||||
|
WebDriverExpectedCondition::urlContains(
|
||||||
|
'https://www.sandbox.paypal.com/webapps/helios?action=verify&flow=3ds'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Wait until the outer iframe loads completely
|
||||||
|
usleep(10 * 1000000); // wait 10 secs
|
||||||
|
|
||||||
|
if (strpos($driver->getCurrentURL(), 'https://example.com/returnUrl') !== false) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Switch to the appropriate iframe
|
||||||
|
$frame = $driver->switchTo()->frame(
|
||||||
|
$driver->findElement(WebDriverBy::cssSelector('iframe[name="threedsIframeV2"]'))
|
||||||
|
);
|
||||||
|
|
||||||
|
$frame = $frame->switchTo()->frame(
|
||||||
|
$driver->findElement(WebDriverBy::tagName('iframe'))
|
||||||
|
);
|
||||||
|
|
||||||
|
// Enter the verification code and submit
|
||||||
|
$frame->findElement(WebDriverBy::cssSelector('input[placeholder=" Enter Code Here"]'))->sendKeys('1234');
|
||||||
|
$submitButton = $frame->findElement(WebDriverBy::cssSelector('input[type="submit"][value="SUBMIT"]'));
|
||||||
|
$driver->executeScript('arguments[0].scrollIntoView(true);', [$submitButton]);
|
||||||
|
if ($submitButton->isDisplayed()) {
|
||||||
|
$submitButton->click();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for the return URL
|
||||||
|
$driver->wait(50)->until(
|
||||||
|
WebDriverExpectedCondition::urlContains('https://example.com/returnUrl')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var RemoteWebDriver
|
||||||
|
*/
|
||||||
|
private static $remoteWebDriver;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
private static function getWebDriver(int $tryCount = 3): RemoteWebDriver
|
||||||
|
{
|
||||||
|
if (!isset(self::$remoteWebDriver)) {
|
||||||
|
$options = new FirefoxOptions();
|
||||||
|
$options->addArguments(['--headless']);
|
||||||
|
|
||||||
|
$capabilities = DesiredCapabilities::firefox();
|
||||||
|
$capabilities->setCapability(FirefoxOptions::CAPABILITY, $options);
|
||||||
|
|
||||||
|
try {
|
||||||
|
self::$remoteWebDriver = RemoteWebDriver::create(
|
||||||
|
'http://localhost:4444',
|
||||||
|
$capabilities,
|
||||||
|
500000,
|
||||||
|
500000
|
||||||
|
);
|
||||||
|
} catch (Exception $exp) {
|
||||||
|
if ($tryCount == 0) {
|
||||||
|
throw $exp;
|
||||||
|
}
|
||||||
|
return self::getWebDriver($tryCount - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return self::$remoteWebDriver;
|
||||||
|
}
|
||||||
|
}
|
||||||
18
tests/bootstrap.php
Normal file
18
tests/bootstrap.php
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* PaypalServerSDKLib
|
||||||
|
*
|
||||||
|
* This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ).
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load the composer's autoload file so that we don't have to require files
|
||||||
|
* manually in our code. Also load helper classes for tests.
|
||||||
|
*/
|
||||||
|
|
||||||
|
$vendor_dir = getenv('COMPOSER_VENDOR_DIR') ?: 'vendor';
|
||||||
|
|
||||||
|
require __DIR__ . '/../' . $vendor_dir . '/autoload.php';
|
||||||
|
require __DIR__ . '/ClientFactory.php';
|
||||||
Reference in New Issue
Block a user