Force authorization intent when purchasing subscription product

This commit is contained in:
dinamiko 2021-10-05 12:12:19 +02:00
parent d38f24ef2b
commit a592b57848
6 changed files with 88 additions and 343 deletions

322
composer.lock generated
View file

@ -35,10 +35,6 @@
],
"description": "Promoting container interoperability through standard service providers",
"homepage": "https://github.com/container-interop/service-provider",
"support": {
"issues": "https://github.com/container-interop/service-provider/issues",
"source": "https://github.com/container-interop/service-provider/tree/master"
},
"time": "2017-09-20T14:13:36+00:00"
},
{
@ -90,10 +86,6 @@
}
],
"description": "A highly ISP-compliant collection of interfaces that represent maps and lists.",
"support": {
"issues": "https://github.com/Dhii/collections-interface/issues",
"source": "https://github.com/Dhii/collections-interface/tree/v0.3.0-alpha4"
},
"time": "2021-03-09T17:36:34+00:00"
},
{
@ -147,10 +139,6 @@
"PSR-11",
"container"
],
"support": {
"issues": "https://github.com/Dhii/containers/issues",
"source": "https://github.com/Dhii/containers/tree/v0.1.0-alpha1"
},
"time": "2020-09-14T18:27:47+00:00"
},
{
@ -205,10 +193,6 @@
}
],
"description": "Interfaces for working with data containers",
"support": {
"issues": "https://github.com/Dhii/data-container-interface/issues",
"source": "https://github.com/Dhii/data-container-interface/tree/v0.2.1-alpha1"
},
"abandoned": "dhii/collections-interface",
"time": "2019-05-10T14:17:29+00:00"
},
@ -258,10 +242,6 @@
}
],
"description": "Interfaces for most common exceptions",
"support": {
"issues": "https://github.com/Dhii/exception-interface/issues",
"source": "https://github.com/Dhii/exception-interface/tree/develop"
},
"time": "2018-08-29T10:42:04+00:00"
},
{
@ -312,10 +292,6 @@
}
],
"description": "Interfaces for working with factories.",
"support": {
"issues": "https://github.com/Dhii/factory-interface/issues",
"source": "https://github.com/Dhii/factory-interface/tree/master"
},
"abandoned": true,
"time": "2018-08-29T11:15:09+00:00"
},
@ -365,10 +341,6 @@
}
],
"description": "Interfaces for modules",
"support": {
"issues": "https://github.com/Dhii/module-interface/issues",
"source": "https://github.com/Dhii/module-interface/tree/v0.3.0-alpha2"
},
"time": "2021-08-23T08:23:01+00:00"
},
{
@ -411,10 +383,6 @@
}
],
"description": "Interoperability interface for objects that can be cast to string",
"support": {
"issues": "https://github.com/Dhii/stringable-interface/issues",
"source": "https://github.com/Dhii/stringable-interface/tree/master"
},
"abandoned": "symfony/polyfill-php80",
"time": "2017-01-23T15:08:20+00:00"
},
@ -471,10 +439,6 @@
"di",
"wordpress"
],
"support": {
"issues": "https://github.com/Dhii/wp-containers/issues",
"source": "https://github.com/Dhii/wp-containers/tree/v0.1.0-alpha1"
},
"abandoned": "wp-oop/containers",
"time": "2019-05-10T15:04:22+00:00"
},
@ -525,10 +489,6 @@
"container-interop",
"psr"
],
"support": {
"issues": "https://github.com/php-fig/container/issues",
"source": "https://github.com/php-fig/container/tree/master"
},
"time": "2017-02-14T16:28:37+00:00"
},
{
@ -576,9 +536,6 @@
"psr",
"psr-3"
],
"support": {
"source": "https://github.com/php-fig/log/tree/1.1.4"
},
"time": "2021-05-03T11:20:27+00:00"
},
{
@ -619,10 +576,6 @@
}
],
"description": "A polyfill for getallheaders.",
"support": {
"issues": "https://github.com/ralouphie/getallheaders/issues",
"source": "https://github.com/ralouphie/getallheaders/tree/develop"
},
"time": "2019-03-08T08:55:37+00:00"
}
],
@ -669,10 +622,6 @@
"runkit",
"testing"
],
"support": {
"issues": "https://github.com/antecedent/patchwork/issues",
"source": "https://github.com/antecedent/patchwork/tree/2.1.15"
},
"time": "2021-08-22T08:00:13+00:00"
},
{
@ -739,10 +688,6 @@
"test",
"testing"
],
"support": {
"issues": "https://github.com/Brain-WP/BrainMonkey/issues",
"source": "https://github.com/Brain-WP/BrainMonkey"
},
"time": "2020-10-13T17:56:14+00:00"
},
{
@ -809,10 +754,6 @@
"stylecheck",
"tests"
],
"support": {
"issues": "https://github.com/dealerdirect/phpcodesniffer-composer-installer/issues",
"source": "https://github.com/dealerdirect/phpcodesniffer-composer-installer"
},
"time": "2020-12-07T18:04:37+00:00"
},
{
@ -864,24 +805,6 @@
"constructor",
"instantiate"
],
"support": {
"issues": "https://github.com/doctrine/instantiator/issues",
"source": "https://github.com/doctrine/instantiator/tree/1.4.0"
},
"funding": [
{
"url": "https://www.doctrine-project.org/sponsorship.html",
"type": "custom"
},
{
"url": "https://www.patreon.com/phpdoctrine",
"type": "patreon"
},
{
"url": "https://tidelift.com/funding/github/packagist/doctrine%2Finstantiator",
"type": "tidelift"
}
],
"time": "2020-11-10T18:47:58+00:00"
},
{
@ -929,24 +852,20 @@
"keywords": [
"test"
],
"support": {
"issues": "https://github.com/hamcrest/hamcrest-php/issues",
"source": "https://github.com/hamcrest/hamcrest-php/tree/v2.0.1"
},
"time": "2020-07-09T08:09:16+00:00"
},
{
"name": "mockery/mockery",
"version": "1.3.4",
"version": "1.3.5",
"source": {
"type": "git",
"url": "https://github.com/mockery/mockery.git",
"reference": "31467aeb3ca3188158613322d66df81cedd86626"
"reference": "472fa8ca4e55483d55ee1e73c963718c4393791d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/mockery/mockery/zipball/31467aeb3ca3188158613322d66df81cedd86626",
"reference": "31467aeb3ca3188158613322d66df81cedd86626",
"url": "https://api.github.com/repos/mockery/mockery/zipball/472fa8ca4e55483d55ee1e73c963718c4393791d",
"reference": "472fa8ca4e55483d55ee1e73c963718c4393791d",
"shasum": ""
},
"require": {
@ -998,11 +917,7 @@
"test double",
"testing"
],
"support": {
"issues": "https://github.com/mockery/mockery/issues",
"source": "https://github.com/mockery/mockery/tree/1.3.4"
},
"time": "2021-02-24T09:51:00+00:00"
"time": "2021-09-13T15:33:03+00:00"
},
{
"name": "myclabs/deep-copy",
@ -1050,16 +965,6 @@
"object",
"object graph"
],
"support": {
"issues": "https://github.com/myclabs/DeepCopy/issues",
"source": "https://github.com/myclabs/DeepCopy/tree/1.10.2"
},
"funding": [
{
"url": "https://tidelift.com/funding/github/packagist/myclabs/deep-copy",
"type": "tidelift"
}
],
"time": "2020-11-13T09:40:50+00:00"
},
{
@ -1115,10 +1020,6 @@
}
],
"description": "Component for reading phar.io manifest information from a PHP Archive (PHAR)",
"support": {
"issues": "https://github.com/phar-io/manifest/issues",
"source": "https://github.com/phar-io/manifest/tree/master"
},
"time": "2018-07-08T19:23:20+00:00"
},
{
@ -1166,10 +1067,6 @@
}
],
"description": "Library for handling version information and constraints",
"support": {
"issues": "https://github.com/phar-io/version/issues",
"source": "https://github.com/phar-io/version/tree/master"
},
"time": "2018-07-08T19:19:57+00:00"
},
{
@ -1228,10 +1125,6 @@
"phpcs",
"standards"
],
"support": {
"issues": "https://github.com/PHPCompatibility/PHPCompatibility/issues",
"source": "https://github.com/PHPCompatibility/PHPCompatibility"
},
"time": "2019-12-27T09:44:58+00:00"
},
{
@ -1284,10 +1177,6 @@
"polyfill",
"standards"
],
"support": {
"issues": "https://github.com/PHPCompatibility/PHPCompatibilityParagonie/issues",
"source": "https://github.com/PHPCompatibility/PHPCompatibilityParagonie"
},
"time": "2021-02-15T10:24:51+00:00"
},
{
@ -1338,10 +1227,6 @@
"standards",
"wordpress"
],
"support": {
"issues": "https://github.com/PHPCompatibility/PHPCompatibilityWP/issues",
"source": "https://github.com/PHPCompatibility/PHPCompatibilityWP"
},
"time": "2021-07-21T11:09:57+00:00"
},
{
@ -1391,10 +1276,6 @@
"reflection",
"static analysis"
],
"support": {
"issues": "https://github.com/phpDocumentor/ReflectionCommon/issues",
"source": "https://github.com/phpDocumentor/ReflectionCommon/tree/master"
},
"time": "2020-04-27T09:25:28+00:00"
},
{
@ -1447,10 +1328,6 @@
}
],
"description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.",
"support": {
"issues": "https://github.com/phpDocumentor/ReflectionDocBlock/issues",
"source": "https://github.com/phpDocumentor/ReflectionDocBlock/tree/release/4.x"
},
"time": "2019-12-28T18:55:12+00:00"
},
{
@ -1498,10 +1375,6 @@
}
],
"description": "A PSR-5 based resolver of Class names, Types and Structural Element Names",
"support": {
"issues": "https://github.com/phpDocumentor/TypeResolver/issues",
"source": "https://github.com/phpDocumentor/TypeResolver/tree/0.7.2"
},
"time": "2019-08-22T18:11:29+00:00"
},
{
@ -1565,10 +1438,6 @@
"spy",
"stub"
],
"support": {
"issues": "https://github.com/phpspec/prophecy/issues",
"source": "https://github.com/phpspec/prophecy/tree/v1.10.3"
},
"time": "2020-03-05T15:02:03+00:00"
},
{
@ -1632,10 +1501,6 @@
"testing",
"xunit"
],
"support": {
"issues": "https://github.com/sebastianbergmann/php-code-coverage/issues",
"source": "https://github.com/sebastianbergmann/php-code-coverage/tree/master"
},
"time": "2018-10-31T16:06:48+00:00"
},
{
@ -1686,16 +1551,6 @@
"filesystem",
"iterator"
],
"support": {
"issues": "https://github.com/sebastianbergmann/php-file-iterator/issues",
"source": "https://github.com/sebastianbergmann/php-file-iterator/tree/2.0.4"
},
"funding": [
{
"url": "https://github.com/sebastianbergmann",
"type": "github"
}
],
"time": "2021-07-19T06:46:01+00:00"
},
{
@ -1737,10 +1592,6 @@
"keywords": [
"template"
],
"support": {
"issues": "https://github.com/sebastianbergmann/php-text-template/issues",
"source": "https://github.com/sebastianbergmann/php-text-template/tree/1.2.1"
},
"time": "2015-06-21T13:50:34+00:00"
},
{
@ -1790,16 +1641,6 @@
"keywords": [
"timer"
],
"support": {
"issues": "https://github.com/sebastianbergmann/php-timer/issues",
"source": "https://github.com/sebastianbergmann/php-timer/tree/2.1.3"
},
"funding": [
{
"url": "https://github.com/sebastianbergmann",
"type": "github"
}
],
"time": "2020-11-30T08:20:02+00:00"
},
{
@ -1849,16 +1690,6 @@
"keywords": [
"tokenizer"
],
"support": {
"issues": "https://github.com/sebastianbergmann/php-token-stream/issues",
"source": "https://github.com/sebastianbergmann/php-token-stream/tree/3.1.3"
},
"funding": [
{
"url": "https://github.com/sebastianbergmann",
"type": "github"
}
],
"abandoned": true,
"time": "2021-07-26T12:15:06+00:00"
},
@ -1944,10 +1775,6 @@
"testing",
"xunit"
],
"support": {
"issues": "https://github.com/sebastianbergmann/phpunit/issues",
"source": "https://github.com/sebastianbergmann/phpunit/tree/7.5.20"
},
"time": "2020-01-08T08:45:45+00:00"
},
{
@ -1993,16 +1820,6 @@
],
"description": "Looks up which function or method a line of code belongs to",
"homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/",
"support": {
"issues": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/issues",
"source": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/tree/1.0.2"
},
"funding": [
{
"url": "https://github.com/sebastianbergmann",
"type": "github"
}
],
"time": "2020-11-30T08:15:22+00:00"
},
{
@ -2067,16 +1884,6 @@
"compare",
"equality"
],
"support": {
"issues": "https://github.com/sebastianbergmann/comparator/issues",
"source": "https://github.com/sebastianbergmann/comparator/tree/3.0.3"
},
"funding": [
{
"url": "https://github.com/sebastianbergmann",
"type": "github"
}
],
"time": "2020-11-30T08:04:30+00:00"
},
{
@ -2133,16 +1940,6 @@
"unidiff",
"unified diff"
],
"support": {
"issues": "https://github.com/sebastianbergmann/diff/issues",
"source": "https://github.com/sebastianbergmann/diff/tree/3.0.3"
},
"funding": [
{
"url": "https://github.com/sebastianbergmann",
"type": "github"
}
],
"time": "2020-11-30T07:59:04+00:00"
},
{
@ -2196,16 +1993,6 @@
"environment",
"hhvm"
],
"support": {
"issues": "https://github.com/sebastianbergmann/environment/issues",
"source": "https://github.com/sebastianbergmann/environment/tree/4.2.4"
},
"funding": [
{
"url": "https://github.com/sebastianbergmann",
"type": "github"
}
],
"time": "2020-11-30T07:53:42+00:00"
},
{
@ -2273,16 +2060,6 @@
"export",
"exporter"
],
"support": {
"issues": "https://github.com/sebastianbergmann/exporter/issues",
"source": "https://github.com/sebastianbergmann/exporter/tree/3.1.3"
},
"funding": [
{
"url": "https://github.com/sebastianbergmann",
"type": "github"
}
],
"time": "2020-11-30T07:47:53+00:00"
},
{
@ -2334,10 +2111,6 @@
"keywords": [
"global state"
],
"support": {
"issues": "https://github.com/sebastianbergmann/global-state/issues",
"source": "https://github.com/sebastianbergmann/global-state/tree/2.0.0"
},
"time": "2017-04-27T15:39:26+00:00"
},
{
@ -2385,16 +2158,6 @@
],
"description": "Traverses array structures and object graphs to enumerate all referenced objects",
"homepage": "https://github.com/sebastianbergmann/object-enumerator/",
"support": {
"issues": "https://github.com/sebastianbergmann/object-enumerator/issues",
"source": "https://github.com/sebastianbergmann/object-enumerator/tree/3.0.4"
},
"funding": [
{
"url": "https://github.com/sebastianbergmann",
"type": "github"
}
],
"time": "2020-11-30T07:40:27+00:00"
},
{
@ -2440,16 +2203,6 @@
],
"description": "Allows reflection of object attributes, including inherited and non-public ones",
"homepage": "https://github.com/sebastianbergmann/object-reflector/",
"support": {
"issues": "https://github.com/sebastianbergmann/object-reflector/issues",
"source": "https://github.com/sebastianbergmann/object-reflector/tree/1.1.2"
},
"funding": [
{
"url": "https://github.com/sebastianbergmann",
"type": "github"
}
],
"time": "2020-11-30T07:37:18+00:00"
},
{
@ -2503,16 +2256,6 @@
],
"description": "Provides functionality to recursively process PHP variables",
"homepage": "http://www.github.com/sebastianbergmann/recursion-context",
"support": {
"issues": "https://github.com/sebastianbergmann/recursion-context/issues",
"source": "https://github.com/sebastianbergmann/recursion-context/tree/3.0.1"
},
"funding": [
{
"url": "https://github.com/sebastianbergmann",
"type": "github"
}
],
"time": "2020-11-30T07:34:24+00:00"
},
{
@ -2555,16 +2298,6 @@
],
"description": "Provides a list of PHP built-in functions that operate on resources",
"homepage": "https://www.github.com/sebastianbergmann/resource-operations",
"support": {
"issues": "https://github.com/sebastianbergmann/resource-operations/issues",
"source": "https://github.com/sebastianbergmann/resource-operations/tree/2.0.2"
},
"funding": [
{
"url": "https://github.com/sebastianbergmann",
"type": "github"
}
],
"time": "2020-11-30T07:30:19+00:00"
},
{
@ -2608,10 +2341,6 @@
],
"description": "Library that helps with managing the version number of Git-hosted PHP projects",
"homepage": "https://github.com/sebastianbergmann/version",
"support": {
"issues": "https://github.com/sebastianbergmann/version/issues",
"source": "https://github.com/sebastianbergmann/version/tree/master"
},
"time": "2016-10-03T07:35:21+00:00"
},
{
@ -2663,11 +2392,6 @@
"phpcs",
"standards"
],
"support": {
"issues": "https://github.com/squizlabs/PHP_CodeSniffer/issues",
"source": "https://github.com/squizlabs/PHP_CodeSniffer",
"wiki": "https://github.com/squizlabs/PHP_CodeSniffer/wiki"
},
"time": "2021-04-09T00:54:41+00:00"
},
{
@ -2730,23 +2454,6 @@
"polyfill",
"portable"
],
"support": {
"source": "https://github.com/symfony/polyfill-ctype/tree/v1.23.0"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2021-02-19T12:13:01+00:00"
},
{
@ -2787,10 +2494,6 @@
}
],
"description": "A small library for converting tokenized PHP source code into XML and potentially other formats",
"support": {
"issues": "https://github.com/theseer/tokenizer/issues",
"source": "https://github.com/theseer/tokenizer/tree/master"
},
"time": "2019-06-13T22:48:21+00:00"
},
{
@ -2840,10 +2543,6 @@
"check",
"validate"
],
"support": {
"issues": "https://github.com/webmozarts/assert/issues",
"source": "https://github.com/webmozarts/assert/tree/1.9.1"
},
"time": "2020-07-08T17:02:28+00:00"
},
{
@ -2884,10 +2583,6 @@
"woocommerce",
"wordpress"
],
"support": {
"issues": "https://github.com/woocommerce/woocommerce-sniffs/issues",
"source": "https://github.com/woocommerce/woocommerce-sniffs/tree/0.1.1"
},
"time": "2021-07-29T17:25:16+00:00"
},
{
@ -2934,11 +2629,6 @@
"standards",
"wordpress"
],
"support": {
"issues": "https://github.com/WordPress/WordPress-Coding-Standards/issues",
"source": "https://github.com/WordPress/WordPress-Coding-Standards",
"wiki": "https://github.com/WordPress/WordPress-Coding-Standards/wiki"
},
"time": "2020-05-13T23:57:56+00:00"
}
],
@ -2951,5 +2641,5 @@
"ext-json": "*"
},
"platform-dev": [],
"plugin-api-version": "2.1.0"
"plugin-api-version": "1.1.0"
}

View file

@ -173,6 +173,7 @@ return array(
$intent = $settings->has( 'intent' ) && strtoupper( (string) $settings->get( 'intent' ) ) === 'AUTHORIZE' ? 'AUTHORIZE' : 'CAPTURE';
$application_context_repository = $container->get( 'api.repository.application-context' );
$paypal_request_id = $container->get( 'api.repository.paypal-request-id' );
$subscription_helper = $container->get( 'subscription.helper' );
return new OrderEndpoint(
$container->get( 'api.host' ),
$container->get( 'api.bearer' ),
@ -181,7 +182,8 @@ return array(
$intent,
$logger,
$application_context_repository,
$paypal_request_id
$paypal_request_id,
$subscription_helper
);
},
'api.repository.paypal-request-id' => static function( $container ) : PayPalRequestIdRepository {

View file

@ -25,6 +25,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Helper\ErrorResponse;
use WooCommerce\PayPalCommerce\ApiClient\Repository\ApplicationContextRepository;
use WooCommerce\PayPalCommerce\ApiClient\Repository\PayPalRequestIdRepository;
use Psr\Log\LoggerInterface;
use WooCommerce\PayPalCommerce\Subscription\Helper\SubscriptionHelper;
/**
* Class OrderEndpoint
@ -33,6 +34,13 @@ class OrderEndpoint {
use RequestTrait;
/**
* The subscription helper
*
* @var SubscriptionHelper
*/
protected $subscription_helper;
/**
* The host.
*
@ -107,6 +115,7 @@ class OrderEndpoint {
* @param LoggerInterface $logger The logger.
* @param ApplicationContextRepository $application_context_repository The application context repository.
* @param PayPalRequestIdRepository $paypal_request_id_repository The paypal request id repository.
* @param SubscriptionHelper $subscription_helper The subscription helper.
* @param string $bn_code The BN Code.
*/
public function __construct(
@ -118,6 +127,7 @@ class OrderEndpoint {
LoggerInterface $logger,
ApplicationContextRepository $application_context_repository,
PayPalRequestIdRepository $paypal_request_id_repository,
SubscriptionHelper $subscription_helper,
string $bn_code = ''
) {
@ -130,6 +140,7 @@ class OrderEndpoint {
$this->application_context_repository = $application_context_repository;
$this->bn_code = $bn_code;
$this->paypal_request_id_repository = $paypal_request_id_repository;
$this->subscription_helper = $subscription_helper;
}
/**
@ -193,7 +204,7 @@ class OrderEndpoint {
$bearer = $this->bearer->bearer();
$data = array(
'intent' => $this->intent,
'intent' => ( $this->subscription_helper->cart_contains_subscription() || $this->subscription_helper->current_product_is_subscription() ) ? 'AUTHORIZE' : $this->intent,
'purchase_units' => array_map(
static function ( PurchaseUnit $item ): array {
return $item->to_array();

View file

@ -738,6 +738,8 @@ class SmartButton implements SmartButtonInterface {
* @throws \WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException If a setting was not found.
*/
private function url(): string {
$intent = ( $this->settings->has( 'intent' ) ) ? $this->settings->get( 'intent' ) : 'capture';
$params = array(
'client-id' => $this->client_id,
'currency' => get_woocommerce_currency(),
@ -745,8 +747,9 @@ class SmartButton implements SmartButtonInterface {
'components' => implode( ',', $this->components() ),
'vault' => $this->can_save_vault_token() ? 'true' : 'false',
'commit' => is_checkout() ? 'true' : 'false',
'intent' => ( $this->settings->has( 'intent' ) ) ?
$this->settings->get( 'intent' ) : 'capture',
'intent' => ( $this->subscription_helper->cart_contains_subscription() || $this->subscription_helper->current_product_is_subscription() )
? 'authorize'
: $intent,
);
if (
$this->environment->current_environment_is( Environment::SANDBOX )

View file

@ -73,6 +73,7 @@ return array(
$intent = $settings->has( 'intent' ) && strtoupper( (string) $settings->get( 'intent' ) ) === 'AUTHORIZE' ? 'AUTHORIZE' : 'CAPTURE';
$application_context_repository = $container->get( 'api.repository.application-context' );
$pay_pal_request_id_repository = $container->get( 'api.repository.paypal-request-id' );
$subscription_helper = $container->get( 'subscription.helper' );
return new OrderEndpoint(
$container->get( 'api.host' ),
$container->get( 'api.bearer' ),
@ -82,6 +83,7 @@ return array(
$logger,
$application_context_repository,
$pay_pal_request_id_repository,
$subscription_helper,
$bn_code
);
},

View file

@ -24,6 +24,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Repository\PayPalRequestIdRepository;
use WooCommerce\PayPalCommerce\ApiClient\TestCase;
use Mockery;
use Psr\Log\LoggerInterface;
use WooCommerce\PayPalCommerce\Subscription\Helper\SubscriptionHelper;
use function Brain\Monkey\Functions\expect;
use function Brain\Monkey\Functions\when;
@ -65,6 +66,7 @@ class OrderEndpointTest extends TestCase
->expects('get_for_order_id')->with($orderId)->andReturn('uniqueRequestId');
$headers = Mockery::mock(Requests_Utility_CaseInsensitiveDictionary::class);
$headers->shouldReceive('getAll');
$subscription_helper = Mockery::mock(SubscriptionHelper::class);
$testee = new OrderEndpoint(
$host,
@ -74,7 +76,8 @@ class OrderEndpointTest extends TestCase
$intent,
$logger,
$applicationContextRepository,
$paypalRequestIdRepository
$paypalRequestIdRepository,
$subscription_helper
);
$rawResponse = [
@ -124,6 +127,7 @@ class OrderEndpointTest extends TestCase
->expects('get_for_order_id')->with($orderId)->andReturn('uniqueRequestId');
$headers = Mockery::mock(Requests_Utility_CaseInsensitiveDictionary::class);
$headers->shouldReceive('getAll');
$subscription_helper = Mockery::mock(SubscriptionHelper::class);
$testee = new OrderEndpoint(
$host,
@ -133,7 +137,8 @@ class OrderEndpointTest extends TestCase
$intent,
$logger,
$applicationContextRepository,
$paypalRequestIdRepository
$paypalRequestIdRepository,
$subscription_helper
);
$rawResponse = [
@ -174,6 +179,7 @@ class OrderEndpointTest extends TestCase
$paypalRequestIdRepository = Mockery::mock(PayPalRequestIdRepository::class);
$paypalRequestIdRepository
->expects('get_for_order_id')->with($orderId)->andReturn('uniqueRequestId');
$subscription_helper = Mockery::mock(SubscriptionHelper::class);
$testee = new OrderEndpoint(
$host,
@ -183,7 +189,8 @@ class OrderEndpointTest extends TestCase
$intent,
$logger,
$applicationContextRepository,
$paypalRequestIdRepository
$paypalRequestIdRepository,
$subscription_helper
);
expect('wp_remote_get')->andReturn($rawResponse);
@ -238,6 +245,8 @@ class OrderEndpointTest extends TestCase
$paypalRequestIdRepository = Mockery::mock(PayPalRequestIdRepository::class);
$paypalRequestIdRepository
->expects('get_for_order')->with($orderToCapture)->andReturn('uniqueRequestId');
$subscription_helper = Mockery::mock(SubscriptionHelper::class);
$testee = new OrderEndpoint(
$host,
$bearer,
@ -246,7 +255,8 @@ class OrderEndpointTest extends TestCase
$intent,
$logger,
$applicationContextRepository,
$paypalRequestIdRepository
$paypalRequestIdRepository,
$subscription_helper
);
expect('wp_remote_get')
@ -302,6 +312,8 @@ class OrderEndpointTest extends TestCase
$logger->shouldNotReceive('log');
$applicationContextRepository = Mockery::mock(ApplicationContextRepository::class);
$paypalRequestIdRepository = Mockery::mock(PayPalRequestIdRepository::class);
$subscription_helper = Mockery::mock(SubscriptionHelper::class);
$testee = new OrderEndpoint(
$host,
$bearer,
@ -310,7 +322,8 @@ class OrderEndpointTest extends TestCase
$intent,
$logger,
$applicationContextRepository,
$paypalRequestIdRepository
$paypalRequestIdRepository,
$subscription_helper
);
$result = $testee->capture($orderToCapture);
@ -344,6 +357,8 @@ class OrderEndpointTest extends TestCase
$paypalRequestIdRepository = Mockery::mock(PayPalRequestIdRepository::class);
$paypalRequestIdRepository
->expects('get_for_order')->with($orderToCapture)->andReturn('uniqueRequestId');
$subscription_helper = Mockery::mock(SubscriptionHelper::class);
$testee = new OrderEndpoint(
$host,
$bearer,
@ -352,7 +367,8 @@ class OrderEndpointTest extends TestCase
$intent,
$logger,
$applicationContextRepository,
$paypalRequestIdRepository
$paypalRequestIdRepository,
$subscription_helper
);
$headers = Mockery::mock(Requests_Utility_CaseInsensitiveDictionary::class);
$headers->shouldReceive('getAll');
@ -393,6 +409,8 @@ class OrderEndpointTest extends TestCase
$paypalRequestIdRepository = Mockery::mock(PayPalRequestIdRepository::class);
$paypalRequestIdRepository
->expects('get_for_order')->with($orderToCapture)->andReturn('uniqueRequestId');
$subscription_helper = Mockery::mock(SubscriptionHelper::class);
$testee = new OrderEndpoint(
$host,
$bearer,
@ -401,7 +419,8 @@ class OrderEndpointTest extends TestCase
$intent,
$logger,
$applicationContextRepository,
$paypalRequestIdRepository
$paypalRequestIdRepository,
$subscription_helper
);
$headers = Mockery::mock(Requests_Utility_CaseInsensitiveDictionary::class);
@ -444,6 +463,8 @@ class OrderEndpointTest extends TestCase
$paypalRequestIdRepository = Mockery::mock(PayPalRequestIdRepository::class);
$paypalRequestIdRepository
->expects('get_for_order')->with($orderToCapture)->andReturn('uniqueRequestId');
$subscription_helper = Mockery::mock(SubscriptionHelper::class);
$testee = Mockery::mock(
OrderEndpoint::class,
[
@ -455,6 +476,7 @@ class OrderEndpointTest extends TestCase
$logger,
$applicationContextRepository,
$paypalRequestIdRepository,
$subscription_helper,
]
)->makePartial();
$orderToExpect = Mockery::mock(Order::class);
@ -521,6 +543,8 @@ class OrderEndpointTest extends TestCase
$paypalRequestIdRepository = Mockery::mock(PayPalRequestIdRepository::class);
$paypalRequestIdRepository
->expects('get_for_order')->with($orderToUpdate)->andReturn('uniqueRequestId');
$subscription_helper = Mockery::mock(SubscriptionHelper::class);
$testee = Mockery::mock(
OrderEndpoint::class,
[
@ -532,6 +556,7 @@ class OrderEndpointTest extends TestCase
$logger,
$applicationContextRepository,
$paypalRequestIdRepository,
$subscription_helper,
]
)->makePartial();
$testee
@ -623,6 +648,7 @@ class OrderEndpointTest extends TestCase
$paypalRequestIdRepository = Mockery::mock(PayPalRequestIdRepository::class);
$paypalRequestIdRepository
->expects('get_for_order')->with($orderToUpdate)->andReturn('uniqueRequestId');
$subscription_helper = Mockery::mock(SubscriptionHelper::class);
$testee = new OrderEndpoint(
$host,
@ -632,7 +658,8 @@ class OrderEndpointTest extends TestCase
$intent,
$logger,
$applicationContextRepository,
$paypalRequestIdRepository
$paypalRequestIdRepository,
$subscription_helper
);
expect('wp_remote_get')
@ -720,6 +747,8 @@ class OrderEndpointTest extends TestCase
$paypalRequestIdRepository = Mockery::mock(PayPalRequestIdRepository::class);
$paypalRequestIdRepository
->expects('get_for_order')->with($orderToUpdate)->andReturn('uniqueRequestId');
$subscription_helper = Mockery::mock(SubscriptionHelper::class);
$testee = Mockery::mock(
OrderEndpoint::class,
[
@ -730,7 +759,8 @@ class OrderEndpointTest extends TestCase
$intent,
$logger,
$applicationContextRepository,
$paypalRequestIdRepository
$paypalRequestIdRepository,
$subscription_helper
]
)->makePartial();
@ -793,6 +823,8 @@ class OrderEndpointTest extends TestCase
$logger->shouldNotReceive('log');
$applicationContextRepository = Mockery::mock(ApplicationContextRepository::class);
$paypalRequestIdRepository = Mockery::mock(PayPalRequestIdRepository::class);
$subscription_helper = Mockery::mock(SubscriptionHelper::class);
$testee = new OrderEndpoint(
$host,
$bearer,
@ -801,7 +833,8 @@ class OrderEndpointTest extends TestCase
$intent,
$logger,
$applicationContextRepository,
$paypalRequestIdRepository
$paypalRequestIdRepository,
$subscription_helper
);
$result = $testee->patch_order_with($orderToUpdate, $orderToCompare);
@ -859,6 +892,8 @@ class OrderEndpointTest extends TestCase
return strpos($id, 'ppcp') !== false;
});
$subscription_helper = Mockery::mock(SubscriptionHelper::class);
$subscription_helper->shouldReceive('cart_contains_subscription')->andReturn(true);
$testee = new OrderEndpoint(
$host,
@ -868,7 +903,8 @@ class OrderEndpointTest extends TestCase
$intent,
$logger,
$applicationContextRepository,
$paypalRequestIdRepository
$paypalRequestIdRepository,
$subscription_helper
);
$purchaseUnit = Mockery::mock(PurchaseUnit::class, ['contains_physical_goods' => false]);
@ -895,9 +931,6 @@ class OrderEndpointTest extends TestCase
return false;
}
$body = json_decode($args['body'], true);
if ($body['intent'] !== 'CAPTURE') {
return false;
}
if ($body['purchase_units'][0][0] !== 'singlePurchaseUnit') {
return false;
}
@ -961,6 +994,8 @@ class OrderEndpointTest extends TestCase
return strpos($id, 'ppcp') !== false;
});
$subscription_helper = Mockery::mock(SubscriptionHelper::class);
$subscription_helper->shouldReceive('cart_contains_subscription')->andReturn(true);
$testee = new OrderEndpoint(
$host,
@ -970,7 +1005,8 @@ class OrderEndpointTest extends TestCase
$intent,
$logger,
$applicationContextRepository,
$paypalRequestIdRepository
$paypalRequestIdRepository,
$subscription_helper
);
$purchaseUnit = Mockery::mock(PurchaseUnit::class, ['contains_physical_goods' => true]);
@ -1034,6 +1070,8 @@ class OrderEndpointTest extends TestCase
->with(Matchers::identicalTo(ApplicationContext::SHIPPING_PREFERENCE_NO_SHIPPING))
->andReturn($applicationContext);
$paypalRequestIdRepository = Mockery::mock(PayPalRequestIdRepository::class);
$subscription_helper = Mockery::mock(SubscriptionHelper::class);
$subscription_helper->shouldReceive('cart_contains_subscription')->andReturn(true);
$testee = new OrderEndpoint(
$host,
@ -1043,7 +1081,8 @@ class OrderEndpointTest extends TestCase
$intent,
$logger,
$applicationContextRepository,
$paypalRequestIdRepository
$paypalRequestIdRepository,
$subscription_helper
);
$purchaseUnit = Mockery::mock(PurchaseUnit::class, ['contains_physical_goods' => false]);
@ -1070,9 +1109,6 @@ class OrderEndpointTest extends TestCase
return false;
}
$body = json_decode($args['body'], true);
if ($body['intent'] !== 'CAPTURE') {
return false;
}
if ($body['purchase_units'][0][0] !== 'singlePurchaseUnit') {
return false;
}
@ -1118,6 +1154,9 @@ class OrderEndpointTest extends TestCase
->with(Matchers::identicalTo(ApplicationContext::SHIPPING_PREFERENCE_GET_FROM_FILE))
->andReturn($applicationContext);
$paypalRequestIdRepository = Mockery::mock(PayPalRequestIdRepository::class);
$subscription_helper = Mockery::mock(SubscriptionHelper::class);
$subscription_helper->shouldReceive('cart_contains_subscription')->andReturn(true);
$testee = new OrderEndpoint(
$host,
$bearer,
@ -1126,7 +1165,8 @@ class OrderEndpointTest extends TestCase
$intent,
$logger,
$applicationContextRepository,
$paypalRequestIdRepository
$paypalRequestIdRepository,
$subscription_helper
);
$purchaseUnit = Mockery::mock(PurchaseUnit::class, ['contains_physical_goods' => true]);
@ -1153,9 +1193,6 @@ class OrderEndpointTest extends TestCase
return false;
}
$body = json_decode($args['body'], true);
if ($body['intent'] !== 'CAPTURE') {
return false;
}
if ($body['purchase_units'][0][0] !== 'singlePurchaseUnit') {
return false;
}