diff --git a/modules/ppcp-api-client/services.php b/modules/ppcp-api-client/services.php index 0a4a85728..393d868bc 100644 --- a/modules/ppcp-api-client/services.php +++ b/modules/ppcp-api-client/services.php @@ -54,7 +54,6 @@ use WooCommerce\PayPalCommerce\ApiClient\Repository\CustomerRepository; use WooCommerce\PayPalCommerce\ApiClient\Repository\OrderRepository; use WooCommerce\PayPalCommerce\ApiClient\Repository\PartnerReferralsData; use WooCommerce\PayPalCommerce\ApiClient\Repository\PayeeRepository; -use WooCommerce\PayPalCommerce\ApiClient\Repository\PayPalRequestIdRepository; use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings; return array( @@ -118,8 +117,7 @@ return array( $container->get( 'api.factory.payment-token' ), $container->get( 'api.factory.payment-token-action-links' ), $container->get( 'woocommerce.logger.woocommerce' ), - $container->get( 'api.repository.customer' ), - $container->get( 'api.repository.paypal-request-id' ) + $container->get( 'api.repository.customer' ) ); }, 'api.endpoint.webhook' => static function ( ContainerInterface $container ) : WebhookEndpoint { @@ -187,7 +185,6 @@ return array( $settings = $container->get( 'wcgateway.settings' ); $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' ), @@ -197,7 +194,6 @@ return array( $intent, $logger, $application_context_repository, - $paypal_request_id, $subscription_helper ); }, @@ -208,9 +204,6 @@ return array( $container->get( 'woocommerce.logger.woocommerce' ) ); }, - 'api.repository.paypal-request-id' => static function( ContainerInterface $container ) : PayPalRequestIdRepository { - return new PayPalRequestIdRepository(); - }, 'api.repository.application-context' => static function( ContainerInterface $container ) : ApplicationContextRepository { $settings = $container->get( 'wcgateway.settings' ); diff --git a/modules/ppcp-api-client/src/Endpoint/OrderEndpoint.php b/modules/ppcp-api-client/src/Endpoint/OrderEndpoint.php index 57b8b73d6..997b43413 100644 --- a/modules/ppcp-api-client/src/Endpoint/OrderEndpoint.php +++ b/modules/ppcp-api-client/src/Endpoint/OrderEndpoint.php @@ -101,13 +101,6 @@ class OrderEndpoint { */ private $bn_code; - /** - * The paypal request id repository. - * - * @var PayPalRequestIdRepository - */ - private $paypal_request_id_repository; - /** * OrderEndpoint constructor. * @@ -118,7 +111,6 @@ class OrderEndpoint { * @param string $intent The intent. * @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. */ @@ -130,7 +122,6 @@ class OrderEndpoint { string $intent, LoggerInterface $logger, ApplicationContextRepository $application_context_repository, - PayPalRequestIdRepository $paypal_request_id_repository, SubscriptionHelper $subscription_helper, string $bn_code = '' ) { @@ -143,7 +134,6 @@ class OrderEndpoint { $this->logger = $logger; $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; } @@ -169,7 +159,6 @@ class OrderEndpoint { * @param Payer|null $payer The payer off the order. * @param PaymentToken|null $payment_token The payment token. * @param PaymentMethod|null $payment_method The payment method. - * @param string $paypal_request_id The paypal request id. * * @return Order * @throws RuntimeException If the request fails. @@ -179,8 +168,7 @@ class OrderEndpoint { string $shipping_preference, Payer $payer = null, PaymentToken $payment_token = null, - PaymentMethod $payment_method = null, - string $paypal_request_id = '' + PaymentMethod $payment_method = null ): Order { $bearer = $this->bearer->bearer(); $data = array( @@ -219,8 +207,6 @@ class OrderEndpoint { 'body' => wp_json_encode( $data ), ); - $paypal_request_id = $paypal_request_id ? $paypal_request_id : uniqid( 'ppcp-', true ); - $args['headers']['PayPal-Request-Id'] = $paypal_request_id; if ( $this->bn_code ) { $args['headers']['PayPal-Partner-Attribution-Id'] = $this->bn_code; } @@ -260,7 +246,6 @@ class OrderEndpoint { throw $error; } $order = $this->order_factory->from_paypal_response( $json ); - $this->paypal_request_id_repository->set_for_order( $order, $paypal_request_id ); return $order; } @@ -281,10 +266,9 @@ class OrderEndpoint { $args = array( 'method' => 'POST', 'headers' => array( - 'Authorization' => 'Bearer ' . $bearer->token(), - 'Content-Type' => 'application/json', - 'Prefer' => 'return=representation', - 'PayPal-Request-Id' => $this->paypal_request_id_repository->get_for_order( $order ), + 'Authorization' => 'Bearer ' . $bearer->token(), + 'Content-Type' => 'application/json', + 'Prefer' => 'return=representation', ), ); if ( $this->bn_code ) { @@ -356,10 +340,9 @@ class OrderEndpoint { $args = array( 'method' => 'POST', 'headers' => array( - 'Authorization' => 'Bearer ' . $bearer->token(), - 'Content-Type' => 'application/json', - 'Prefer' => 'return=representation', - 'PayPal-Request-Id' => $this->paypal_request_id_repository->get_for_order( $order ), + 'Authorization' => 'Bearer ' . $bearer->token(), + 'Content-Type' => 'application/json', + 'Prefer' => 'return=representation', ), ); if ( $this->bn_code ) { @@ -430,9 +413,8 @@ class OrderEndpoint { $url = trailingslashit( $this->host ) . 'v2/checkout/orders/' . $id; $args = array( 'headers' => array( - 'Authorization' => 'Bearer ' . $bearer->token(), - 'Content-Type' => 'application/json', - 'PayPal-Request-Id' => $this->paypal_request_id_repository->get_for_order_id( $id ), + 'Authorization' => 'Bearer ' . $bearer->token(), + 'Content-Type' => 'application/json', ), ); if ( $this->bn_code ) { @@ -517,12 +499,9 @@ class OrderEndpoint { $args = array( 'method' => 'PATCH', 'headers' => array( - 'Authorization' => 'Bearer ' . $bearer->token(), - 'Content-Type' => 'application/json', - 'Prefer' => 'return=representation', - 'PayPal-Request-Id' => $this->paypal_request_id_repository->get_for_order( - $order_to_update - ), + 'Authorization' => 'Bearer ' . $bearer->token(), + 'Content-Type' => 'application/json', + 'Prefer' => 'return=representation', ), 'body' => wp_json_encode( $patches_array ), ); diff --git a/modules/ppcp-api-client/src/Endpoint/PayUponInvoiceOrderEndpoint.php b/modules/ppcp-api-client/src/Endpoint/PayUponInvoiceOrderEndpoint.php index 29a16302b..2c1d85812 100644 --- a/modules/ppcp-api-client/src/Endpoint/PayUponInvoiceOrderEndpoint.php +++ b/modules/ppcp-api-client/src/Endpoint/PayUponInvoiceOrderEndpoint.php @@ -133,7 +133,7 @@ class PayUponInvoiceOrderEndpoint { 'Content-Type' => 'application/json', 'Prefer' => 'return=representation', 'PayPal-Client-Metadata-Id' => $this->fraudnet->session_id(), - 'PayPal-Request-Id' => uniqid( 'ppcp-', true ), + 'PayPal-Request-Id' => uniqid( 'ppcp-', true ), // Request-Id header is required. ), 'body' => wp_json_encode( $data ), ); diff --git a/modules/ppcp-api-client/src/Endpoint/PaymentTokenEndpoint.php b/modules/ppcp-api-client/src/Endpoint/PaymentTokenEndpoint.php index 9e1b3a74b..a781dd8a8 100644 --- a/modules/ppcp-api-client/src/Endpoint/PaymentTokenEndpoint.php +++ b/modules/ppcp-api-client/src/Endpoint/PaymentTokenEndpoint.php @@ -19,7 +19,6 @@ use WooCommerce\PayPalCommerce\ApiClient\Factory\PaymentTokenActionLinksFactory; use WooCommerce\PayPalCommerce\ApiClient\Factory\PaymentTokenFactory; use Psr\Log\LoggerInterface; use WooCommerce\PayPalCommerce\ApiClient\Repository\CustomerRepository; -use WooCommerce\PayPalCommerce\ApiClient\Repository\PayPalRequestIdRepository; /** * Class PaymentTokenEndpoint @@ -70,13 +69,6 @@ class PaymentTokenEndpoint { */ protected $customer_repository; - /** - * The request id repository. - * - * @var PayPalRequestIdRepository - */ - private $request_id_repository; - /** * PaymentTokenEndpoint constructor. * @@ -86,7 +78,6 @@ class PaymentTokenEndpoint { * @param PaymentTokenActionLinksFactory $payment_token_action_links_factory The PaymentTokenActionLinks factory. * @param LoggerInterface $logger The logger. * @param CustomerRepository $customer_repository The customer repository. - * @param PayPalRequestIdRepository $request_id_repository The request id repository. */ public function __construct( string $host, @@ -94,8 +85,7 @@ class PaymentTokenEndpoint { PaymentTokenFactory $factory, PaymentTokenActionLinksFactory $payment_token_action_links_factory, LoggerInterface $logger, - CustomerRepository $customer_repository, - PayPalRequestIdRepository $request_id_repository + CustomerRepository $customer_repository ) { $this->host = $host; @@ -104,7 +94,6 @@ class PaymentTokenEndpoint { $this->payment_token_action_links_factory = $payment_token_action_links_factory; $this->logger = $logger; $this->customer_repository = $customer_repository; - $this->request_id_repository = $request_id_repository; } /** @@ -243,14 +232,11 @@ class PaymentTokenEndpoint { ), ); - $request_id = uniqid( 'ppcp-vault', true ); - $args = array( 'method' => 'POST', 'headers' => array( 'Authorization' => 'Bearer ' . $bearer->token(), 'Content-Type' => 'application/json', - 'Request-Id' => $request_id, ), 'body' => wp_json_encode( $data ), ); @@ -277,8 +263,6 @@ class PaymentTokenEndpoint { $links = $this->payment_token_action_links_factory->from_paypal_response( $json ); - $this->request_id_repository->set( "ppcp-vault-{$user_id}", $request_id ); - return $links; } @@ -302,7 +286,6 @@ class PaymentTokenEndpoint { 'method' => 'POST', 'headers' => array( 'Authorization' => 'Bearer ' . $bearer->token(), - 'Request-Id' => $this->request_id_repository->get( "ppcp-vault-{$user_id}" ), 'Content-Type' => 'application/json', ), ); diff --git a/modules/ppcp-api-client/src/Repository/PayPalRequestIdRepository.php b/modules/ppcp-api-client/src/Repository/PayPalRequestIdRepository.php deleted file mode 100644 index de0f7e650..000000000 --- a/modules/ppcp-api-client/src/Repository/PayPalRequestIdRepository.php +++ /dev/null @@ -1,112 +0,0 @@ -get( $order_id ); - } - - /** - * Returns the request ID for an order. - * - * @param Order $order The order. - * - * @return string - */ - public function get_for_order( Order $order ): string { - return $this->get_for_order_id( $order->id() ); - } - - /** - * Sets a request ID for a specific order. - * - * @param Order $order The order. - * @param string $request_id The ID. - * - * @return bool - */ - public function set_for_order( Order $order, string $request_id ): bool { - $this->set( $order->id(), $request_id ); - return true; - } - - /** - * Sets a request ID for the given key. - * - * @param string $key The key in the request ID storage. - * @param string $request_id The ID. - */ - public function set( string $key, string $request_id ): void { - $all = $this->all(); - $day_in_seconds = 86400; - $all[ $key ] = array( - 'id' => $request_id, - 'expiration' => time() + 10 * $day_in_seconds, - ); - $all = $this->cleanup( $all ); - update_option( self::KEY, $all ); - } - - /** - * Returns a request ID. - * - * @param string $key The key in the request ID storage. - * - * @return string - */ - public function get( string $key ): string { - $all = $this->all(); - return isset( $all[ $key ] ) ? (string) $all[ $key ]['id'] : ''; - } - - /** - * Return all IDs. - * - * @return array - */ - private function all(): array { - - return (array) get_option( 'ppcp-request-ids', array() ); - } - - /** - * Clean up outdated request IDs. - * - * @param array $all All request IDs. - * - * @return array - */ - private function cleanup( array $all ): array { - - foreach ( $all as $order_id => $value ) { - if ( time() < $value['expiration'] ) { - continue; - } - unset( $all[ $order_id ] ); - } - return $all; - } -} diff --git a/modules/ppcp-wc-gateway/extensions.php b/modules/ppcp-wc-gateway/extensions.php index 68bcf2590..705c043e3 100644 --- a/modules/ppcp-wc-gateway/extensions.php +++ b/modules/ppcp-wc-gateway/extensions.php @@ -72,7 +72,6 @@ return array( $settings = $container->get( 'wcgateway.settings' ); $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' ), @@ -82,7 +81,6 @@ return array( $intent, $logger, $application_context_repository, - $pay_pal_request_id_repository, $subscription_helper, $bn_code ); diff --git a/modules/ppcp-wc-gateway/src/WCGatewayModule.php b/modules/ppcp-wc-gateway/src/WCGatewayModule.php index 07645ccd5..7f4a62939 100644 --- a/modules/ppcp-wc-gateway/src/WCGatewayModule.php +++ b/modules/ppcp-wc-gateway/src/WCGatewayModule.php @@ -16,7 +16,6 @@ use WooCommerce\PayPalCommerce\AdminNotices\Repository\Repository; use WooCommerce\PayPalCommerce\ApiClient\Entity\Capture; use WooCommerce\PayPalCommerce\ApiClient\Entity\OrderStatus; use WooCommerce\PayPalCommerce\ApiClient\Helper\DccApplies; -use WooCommerce\PayPalCommerce\ApiClient\Repository\PayPalRequestIdRepository; use WooCommerce\PayPalCommerce\Onboarding\State; use WooCommerce\PayPalCommerce\WcGateway\Admin\FeesRenderer; use WooCommerce\PayPalCommerce\WcGateway\Admin\OrderTablePaymentStatusColumn; @@ -214,7 +213,6 @@ class WCGatewayModule implements ModuleInterface { 'woocommerce_paypal_commerce_gateway_deactivate', static function () use ( $c ) { delete_option( Settings::KEY ); - delete_option( PayPalRequestIdRepository::KEY ); delete_option( 'woocommerce_' . PayPalGateway::ID . '_settings' ); delete_option( 'woocommerce_' . CreditCardGateway::ID . '_settings' ); } @@ -236,6 +234,8 @@ class WCGatewayModule implements ModuleInterface { add_action( 'woocommerce_paypal_payments_gateway_migrate', static function () use ( $c ) { + delete_option( 'ppcp-request-ids' ); + $settings = $c->get( 'wcgateway.settings' ); assert( $settings instanceof Settings ); diff --git a/tests/PHPUnit/ApiClient/Endpoint/OrderEndpointTest.php b/tests/PHPUnit/ApiClient/Endpoint/OrderEndpointTest.php index 4052febd2..ea7938d4f 100644 --- a/tests/PHPUnit/ApiClient/Endpoint/OrderEndpointTest.php +++ b/tests/PHPUnit/ApiClient/Endpoint/OrderEndpointTest.php @@ -24,7 +24,6 @@ use WooCommerce\PayPalCommerce\ApiClient\Factory\OrderFactory; use WooCommerce\PayPalCommerce\ApiClient\Factory\PatchCollectionFactory; use WooCommerce\PayPalCommerce\ApiClient\Helper\ErrorResponse; use WooCommerce\PayPalCommerce\ApiClient\Repository\ApplicationContextRepository; -use WooCommerce\PayPalCommerce\ApiClient\Repository\PayPalRequestIdRepository; use Mockery; use Psr\Log\LoggerInterface; use WooCommerce\PayPalCommerce\Subscription\Helper\SubscriptionHelper; @@ -67,9 +66,6 @@ class OrderEndpointTest extends TestCase $logger->shouldNotReceive('log'); $logger->shouldReceive('debug'); $applicationContextRepository = Mockery::mock(ApplicationContextRepository::class); - $paypalRequestIdRepository = Mockery::mock(PayPalRequestIdRepository::class); - $paypalRequestIdRepository - ->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); @@ -82,7 +78,6 @@ class OrderEndpointTest extends TestCase $intent, $logger, $applicationContextRepository, - $paypalRequestIdRepository, $subscription_helper ); @@ -128,9 +123,6 @@ class OrderEndpointTest extends TestCase $logger->shouldReceive('log'); $logger->shouldReceive('debug'); $applicationContextRepository = Mockery::mock(ApplicationContextRepository::class); - $paypalRequestIdRepository = Mockery::mock(PayPalRequestIdRepository::class); - $paypalRequestIdRepository - ->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); @@ -143,7 +135,6 @@ class OrderEndpointTest extends TestCase $intent, $logger, $applicationContextRepository, - $paypalRequestIdRepository, $subscription_helper ); @@ -182,9 +173,6 @@ class OrderEndpointTest extends TestCase $logger->shouldReceive('log'); $logger->shouldReceive('debug'); $applicationContextRepository = Mockery::mock(ApplicationContextRepository::class); - $paypalRequestIdRepository = Mockery::mock(PayPalRequestIdRepository::class); - $paypalRequestIdRepository - ->expects('get_for_order_id')->with($orderId)->andReturn('uniqueRequestId'); $subscription_helper = Mockery::mock(SubscriptionHelper::class); $testee = new OrderEndpoint( @@ -195,7 +183,6 @@ class OrderEndpointTest extends TestCase $intent, $logger, $applicationContextRepository, - $paypalRequestIdRepository, $subscription_helper ); @@ -248,9 +235,6 @@ class OrderEndpointTest extends TestCase $logger->shouldNotReceive('log'); $logger->shouldReceive('debug'); $applicationContextRepository = Mockery::mock(ApplicationContextRepository::class); - $paypalRequestIdRepository = Mockery::mock(PayPalRequestIdRepository::class); - $paypalRequestIdRepository - ->expects('get_for_order')->with($orderToCapture)->andReturn('uniqueRequestId'); $subscription_helper = Mockery::mock(SubscriptionHelper::class); $testee = new OrderEndpoint( @@ -261,7 +245,6 @@ class OrderEndpointTest extends TestCase $intent, $logger, $applicationContextRepository, - $paypalRequestIdRepository, $subscription_helper ); @@ -317,7 +300,6 @@ class OrderEndpointTest extends TestCase $logger = Mockery::mock(LoggerInterface::class); $logger->shouldNotReceive('log'); $applicationContextRepository = Mockery::mock(ApplicationContextRepository::class); - $paypalRequestIdRepository = Mockery::mock(PayPalRequestIdRepository::class); $subscription_helper = Mockery::mock(SubscriptionHelper::class); $testee = new OrderEndpoint( @@ -328,7 +310,6 @@ class OrderEndpointTest extends TestCase $intent, $logger, $applicationContextRepository, - $paypalRequestIdRepository, $subscription_helper ); @@ -360,9 +341,6 @@ class OrderEndpointTest extends TestCase $logger->shouldReceive('log'); $logger->shouldReceive('debug'); $applicationContextRepository = Mockery::mock(ApplicationContextRepository::class); - $paypalRequestIdRepository = Mockery::mock(PayPalRequestIdRepository::class); - $paypalRequestIdRepository - ->expects('get_for_order')->with($orderToCapture)->andReturn('uniqueRequestId'); $subscription_helper = Mockery::mock(SubscriptionHelper::class); $testee = new OrderEndpoint( @@ -373,7 +351,6 @@ class OrderEndpointTest extends TestCase $intent, $logger, $applicationContextRepository, - $paypalRequestIdRepository, $subscription_helper ); $headers = Mockery::mock(Requests_Utility_CaseInsensitiveDictionary::class); @@ -412,9 +389,6 @@ class OrderEndpointTest extends TestCase $logger->shouldReceive('log'); $logger->shouldReceive('debug'); $applicationContextRepository = Mockery::mock(ApplicationContextRepository::class); - $paypalRequestIdRepository = Mockery::mock(PayPalRequestIdRepository::class); - $paypalRequestIdRepository - ->expects('get_for_order')->with($orderToCapture)->andReturn('uniqueRequestId'); $subscription_helper = Mockery::mock(SubscriptionHelper::class); $testee = new OrderEndpoint( @@ -425,7 +399,6 @@ class OrderEndpointTest extends TestCase $intent, $logger, $applicationContextRepository, - $paypalRequestIdRepository, $subscription_helper ); @@ -466,9 +439,6 @@ class OrderEndpointTest extends TestCase $logger->shouldNotReceive('log'); $logger->shouldReceive('debug'); $applicationContextRepository = Mockery::mock(ApplicationContextRepository::class); - $paypalRequestIdRepository = Mockery::mock(PayPalRequestIdRepository::class); - $paypalRequestIdRepository - ->expects('get_for_order')->with($orderToCapture)->andReturn('uniqueRequestId'); $subscription_helper = Mockery::mock(SubscriptionHelper::class); $testee = Mockery::mock( @@ -481,7 +451,6 @@ class OrderEndpointTest extends TestCase $intent, $logger, $applicationContextRepository, - $paypalRequestIdRepository, $subscription_helper, ] )->makePartial(); @@ -546,9 +515,6 @@ class OrderEndpointTest extends TestCase $logger->shouldNotReceive('log'); $logger->shouldReceive('debug'); $applicationContextRepository = Mockery::mock(ApplicationContextRepository::class); - $paypalRequestIdRepository = Mockery::mock(PayPalRequestIdRepository::class); - $paypalRequestIdRepository - ->expects('get_for_order')->with($orderToUpdate)->andReturn('uniqueRequestId'); $subscription_helper = Mockery::mock(SubscriptionHelper::class); $testee = Mockery::mock( @@ -561,7 +527,6 @@ class OrderEndpointTest extends TestCase $intent, $logger, $applicationContextRepository, - $paypalRequestIdRepository, $subscription_helper, ] )->makePartial(); @@ -588,9 +553,6 @@ class OrderEndpointTest extends TestCase if ($args['headers']['Prefer'] !== 'return=representation') { return false; } - if ($args['headers']['PayPal-Request-Id'] !== 'uniqueRequestId') { - return false; - } $body = json_decode($args['body']); if (! is_array($body) || $body[0] !== 'patch-1' || $body[1] !== 'patch-2') { return false; @@ -651,9 +613,6 @@ class OrderEndpointTest extends TestCase $logger->shouldReceive('log'); $logger->shouldReceive('debug'); $applicationContextRepository = Mockery::mock(ApplicationContextRepository::class); - $paypalRequestIdRepository = Mockery::mock(PayPalRequestIdRepository::class); - $paypalRequestIdRepository - ->expects('get_for_order')->with($orderToUpdate)->andReturn('uniqueRequestId'); $subscription_helper = Mockery::mock(SubscriptionHelper::class); $testee = new OrderEndpoint( @@ -664,7 +623,6 @@ class OrderEndpointTest extends TestCase $intent, $logger, $applicationContextRepository, - $paypalRequestIdRepository, $subscription_helper ); @@ -686,9 +644,6 @@ class OrderEndpointTest extends TestCase if ($args['headers']['Prefer'] !== 'return=representation') { return false; } - if ($args['headers']['PayPal-Request-Id'] !== 'uniqueRequestId') { - return false; - } $body = json_decode($args['body']); if (! is_array($body) || $body[0] !== 'patch-1' || $body[1] !== 'patch-2') { return false; @@ -750,9 +705,6 @@ class OrderEndpointTest extends TestCase $logger->shouldReceive('debug'); $applicationContextRepository = Mockery::mock(ApplicationContextRepository::class); - $paypalRequestIdRepository = Mockery::mock(PayPalRequestIdRepository::class); - $paypalRequestIdRepository - ->expects('get_for_order')->with($orderToUpdate)->andReturn('uniqueRequestId'); $subscription_helper = Mockery::mock(SubscriptionHelper::class); $testee = Mockery::mock( @@ -765,7 +717,6 @@ class OrderEndpointTest extends TestCase $intent, $logger, $applicationContextRepository, - $paypalRequestIdRepository, $subscription_helper ] )->makePartial(); @@ -788,9 +739,6 @@ class OrderEndpointTest extends TestCase if ($args['headers']['Prefer'] !== 'return=representation') { return false; } - if ($args['headers']['PayPal-Request-Id'] !== 'uniqueRequestId') { - return false; - } $body = json_decode($args['body']); if (! is_array($body) || $body[0] !== 'patch-1' || $body[1] !== 'patch-2') { return false; @@ -828,7 +776,6 @@ class OrderEndpointTest extends TestCase $logger = Mockery::mock(LoggerInterface::class); $logger->shouldNotReceive('log'); $applicationContextRepository = Mockery::mock(ApplicationContextRepository::class); - $paypalRequestIdRepository = Mockery::mock(PayPalRequestIdRepository::class); $subscription_helper = Mockery::mock(SubscriptionHelper::class); $testee = new OrderEndpoint( @@ -839,7 +786,6 @@ class OrderEndpointTest extends TestCase $intent, $logger, $applicationContextRepository, - $paypalRequestIdRepository, $subscription_helper ); @@ -889,15 +835,6 @@ class OrderEndpointTest extends TestCase ->expects('current_context') ->with(Matchers::identicalTo(ApplicationContext::SHIPPING_PREFERENCE_NO_SHIPPING)) ->andReturn($applicationContext); - $paypalRequestIdRepository = Mockery::mock(PayPalRequestIdRepository::class); - $paypalRequestIdRepository - ->expects('set_for_order')->andReturnUsing(function ($order, $id) use ($expectedOrder) : bool { - if ($order !== $expectedOrder) { - return false; - } - - return strpos($id, 'ppcp') !== false; - }); $subscription_helper = Mockery::mock(SubscriptionHelper::class); $subscription_helper->shouldReceive('cart_contains_subscription')->andReturn(true); @@ -909,7 +846,6 @@ class OrderEndpointTest extends TestCase $intent, $logger, $applicationContextRepository, - $paypalRequestIdRepository, $subscription_helper ); @@ -998,15 +934,6 @@ class OrderEndpointTest extends TestCase ->expects('current_context') ->with(Matchers::identicalTo(ApplicationContext::SHIPPING_PREFERENCE_GET_FROM_FILE)) ->andReturn($applicationContext); - $paypalRequestIdRepository = Mockery::mock(PayPalRequestIdRepository::class); - $paypalRequestIdRepository - ->expects('set_for_order')->andReturnUsing(function ($order, $id) use ($expectedOrder) : bool { - if ($order !== $expectedOrder) { - return false; - } - - return strpos($id, 'ppcp') !== false; - }); $subscription_helper = Mockery::mock(SubscriptionHelper::class); $subscription_helper->shouldReceive('cart_contains_subscription')->andReturn(true); @@ -1018,7 +945,6 @@ class OrderEndpointTest extends TestCase $intent, $logger, $applicationContextRepository, - $paypalRequestIdRepository, $subscription_helper ); @@ -1084,7 +1010,6 @@ class OrderEndpointTest extends TestCase ->expects('current_context') ->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); @@ -1096,7 +1021,6 @@ class OrderEndpointTest extends TestCase $intent, $logger, $applicationContextRepository, - $paypalRequestIdRepository, $subscription_helper ); @@ -1173,7 +1097,6 @@ class OrderEndpointTest extends TestCase ->expects('current_context') ->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); @@ -1185,7 +1108,6 @@ class OrderEndpointTest extends TestCase $intent, $logger, $applicationContextRepository, - $paypalRequestIdRepository, $subscription_helper ); @@ -1229,3 +1151,4 @@ class OrderEndpointTest extends TestCase $testee->create([$purchaseUnit], ApplicationContext::SHIPPING_PREFERENCE_GET_FROM_FILE, $payer); } } + diff --git a/tests/PHPUnit/ApiClient/Repository/PayPalRequestIdRepositoryTest.php b/tests/PHPUnit/ApiClient/Repository/PayPalRequestIdRepositoryTest.php deleted file mode 100644 index f27b0ed3e..000000000 --- a/tests/PHPUnit/ApiClient/Repository/PayPalRequestIdRepositoryTest.php +++ /dev/null @@ -1,58 +0,0 @@ -testee = new PayPalRequestIdRepository(); - - when('get_option')->alias(function () { - return $this->data; - }); - when('update_option')->alias(function (string $key, array $data) { - $this->data = $data; - }); - } - - public function testForOrder() - { - $this->testee->set_for_order($this->createPaypalOrder('42'), 'request1'); - $this->testee->set_for_order($this->createPaypalOrder('43'), 'request2'); - - self::assertEquals('request1', $this->testee->get_for_order($this->createPaypalOrder('42'))); - self::assertEquals('request2', $this->testee->get_for_order($this->createPaypalOrder('43'))); - self::assertEquals('', $this->testee->get_for_order($this->createPaypalOrder('41'))); - } - - public function testExpiration() - { - $this->testee->set_for_order($this->createPaypalOrder('42'), 'request1'); - $this->data['42']['expiration'] = time() - 1; - $this->testee->set_for_order($this->createPaypalOrder('43'), 'request2'); - - self::assertEquals('', $this->testee->get_for_order($this->createPaypalOrder('42'))); - self::assertEquals('request2', $this->testee->get_for_order($this->createPaypalOrder('43'))); - } - - private function createPaypalOrder(string $id): Order { - $order = Mockery::mock(Order::class); - $order - ->shouldReceive('id') - ->andReturn($id); - return $order; - } -}