Skip to content

Commit b4620f9

Browse files
committed
refactor: 🚚 Register ppc-update-shipping unconditionally in ppcp-order-endpoints
1 parent 2477801 commit b4620f9

11 files changed

Lines changed: 36 additions & 35 deletions

File tree

‎modules/ppcp-blocks/services.php‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
use WooCommerce\PayPalCommerce\Assets\AssetGetter;
1313
use WooCommerce\PayPalCommerce\Assets\AssetGetterFactory;
14-
use WooCommerce\PayPalCommerce\Blocks\Endpoint\UpdateShippingEndpoint;
14+
use WooCommerce\PayPalCommerce\OrderEndpoints\Endpoint\UpdateShippingEndpoint;
1515
use WooCommerce\PayPalCommerce\Settings\Data\SettingsProvider;
1616
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
1717
use WooCommerce\PayPalCommerce\Button\Assets\SmartButtonInterface;
@@ -67,13 +67,7 @@ function () use ( $container ): SmartButtonInterface {
6767
},
6868

6969
'blocks.endpoint.update-shipping' => static function ( ContainerInterface $container ): UpdateShippingEndpoint {
70-
return new UpdateShippingEndpoint(
71-
$container->get( 'button.request-data' ),
72-
$container->get( 'api.endpoint.order' ),
73-
$container->get( 'api.factory.purchase-unit' ),
74-
$container->get( 'session.handler' ),
75-
$container->get( 'woocommerce.logger.woocommerce' )
76-
);
70+
return $container->get( 'order-endpoints.endpoint.update-shipping' );
7771
},
7872

7973
'blocks.add-place-order-method' => function ( ContainerInterface $container ): bool {

‎modules/ppcp-blocks/src/BlocksModule.php‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
use Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry;
1313
use WooCommerce\PayPalCommerce\Assets\AssetGetter;
14-
use WooCommerce\PayPalCommerce\Blocks\Endpoint\UpdateShippingEndpoint;
1514
use WooCommerce\PayPalCommerce\Button\Assets\SmartButtonInterface;
1615
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ExecutableModule;
1716
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ExtendingModule;
@@ -88,16 +87,6 @@ function ( PaymentMethodRegistry $payment_method_registry ) use ( $c ): void {
8887
)
8988
);
9089

91-
add_action(
92-
'wc_ajax_' . UpdateShippingEndpoint::ENDPOINT,
93-
static function () use ( $c ) {
94-
$endpoint = $c->get( 'blocks.endpoint.update-shipping' );
95-
assert( $endpoint instanceof UpdateShippingEndpoint );
96-
97-
$endpoint->handle_request();
98-
}
99-
);
100-
10190
// Enqueue frontend scripts.
10291
add_action(
10392
'wp_enqueue_scripts',

‎modules/ppcp-blocks/src/PayPalPaymentMethod.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType;
1313
use WC_AJAX;
1414
use WooCommerce\PayPalCommerce\Assets\AssetGetter;
15-
use WooCommerce\PayPalCommerce\Blocks\Endpoint\UpdateShippingEndpoint;
15+
use WooCommerce\PayPalCommerce\OrderEndpoints\Endpoint\UpdateShippingEndpoint;
1616
use WooCommerce\PayPalCommerce\Button\Assets\SmartButtonInterface;
1717
use WooCommerce\PayPalCommerce\Session\Cancellation\CancelController;
1818
use WooCommerce\PayPalCommerce\Session\Cancellation\CancelView;

‎modules/ppcp-button/src/Assets/SmartButton.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
use WooCommerce\PayPalCommerce\ApiClient\Helper\DccApplies;
2424
use WooCommerce\PayPalCommerce\ApiClient\Helper\PartnerAttribution;
2525
use WooCommerce\PayPalCommerce\Assets\AssetGetter;
26-
use WooCommerce\PayPalCommerce\Blocks\Endpoint\UpdateShippingEndpoint;
26+
use WooCommerce\PayPalCommerce\OrderEndpoints\Endpoint\UpdateShippingEndpoint;
2727
use WooCommerce\PayPalCommerce\OrderEndpoints\Endpoint\ApproveOrderEndpoint;
2828
use WooCommerce\PayPalCommerce\Button\Endpoint\ApproveSubscriptionEndpoint;
2929
use WooCommerce\PayPalCommerce\Button\Endpoint\CartScriptParamsEndpoint;

‎modules/ppcp-order-endpoints/services.php‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use WooCommerce\PayPalCommerce\OrderEndpoints\Endpoint\ChangeCartEndpoint;
1515
use WooCommerce\PayPalCommerce\OrderEndpoints\Endpoint\CreateOrderEndpoint;
1616
use WooCommerce\PayPalCommerce\OrderEndpoints\Endpoint\RequestData;
17+
use WooCommerce\PayPalCommerce\OrderEndpoints\Endpoint\UpdateShippingEndpoint;
1718
use WooCommerce\PayPalCommerce\OrderEndpoints\Helper\CartProductsHelper;
1819
use WooCommerce\PayPalCommerce\OrderEndpoints\Helper\EarlyOrderHandler;
1920
use WooCommerce\PayPalCommerce\OrderEndpoints\Helper\WooCommerceOrderCreator;
@@ -100,6 +101,15 @@
100101
$context
101102
);
102103
},
104+
'order-endpoints.endpoint.update-shipping' => static function ( ContainerInterface $container ): UpdateShippingEndpoint {
105+
return new UpdateShippingEndpoint(
106+
$container->get( 'order-endpoints.request-data' ),
107+
$container->get( 'api.endpoint.order' ),
108+
$container->get( 'api.factory.purchase-unit' ),
109+
$container->get( 'session.handler' ),
110+
$container->get( 'woocommerce.logger.woocommerce' )
111+
);
112+
},
103113
'order-endpoints.is-logged-in' => static function ( ContainerInterface $container ): bool {
104114
return is_user_logged_in();
105115
},

modules/ppcp-blocks/src/Endpoint/UpdateShippingEndpoint.php renamed to modules/ppcp-order-endpoints/src/Endpoint/UpdateShippingEndpoint.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
/**
33
* Updates PayPal order with the current shipping methods.
44
*
5-
* @package WooCommerce\PayPalCommerce\Button\Endpoint
5+
* @package WooCommerce\PayPalCommerce\OrderEndpoints\Endpoint
66
*/
77

88
declare(strict_types=1);
99

10-
namespace WooCommerce\PayPalCommerce\Blocks\Endpoint;
10+
namespace WooCommerce\PayPalCommerce\OrderEndpoints\Endpoint;
1111

1212
use Exception;
1313
use Psr\Log\LoggerInterface;
@@ -17,7 +17,6 @@
1717
use WooCommerce\PayPalCommerce\ApiClient\Entity\PatchCollection;
1818
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
1919
use WooCommerce\PayPalCommerce\Button\Endpoint\EndpointInterface;
20-
use WooCommerce\PayPalCommerce\OrderEndpoints\Endpoint\RequestData;
2120
use WooCommerce\PayPalCommerce\Button\Exception\NonceValidationException;
2221
use WooCommerce\PayPalCommerce\Session\SessionHandler;
2322

‎modules/ppcp-order-endpoints/src/OrderEndpointsModule.php‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use WooCommerce\PayPalCommerce\OrderEndpoints\Endpoint\ApproveOrderEndpoint;
1616
use WooCommerce\PayPalCommerce\OrderEndpoints\Endpoint\ChangeCartEndpoint;
1717
use WooCommerce\PayPalCommerce\OrderEndpoints\Endpoint\CreateOrderEndpoint;
18+
use WooCommerce\PayPalCommerce\OrderEndpoints\Endpoint\UpdateShippingEndpoint;
1819
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ExecutableModule;
1920
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ModuleClassNameIdTrait;
2021
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ServiceModule;
@@ -76,6 +77,16 @@ static function () use ( $c ) {
7677
}
7778
);
7879

80+
add_action(
81+
'wc_ajax_' . UpdateShippingEndpoint::ENDPOINT,
82+
static function () use ( $c ) {
83+
$endpoint = $c->get( 'order-endpoints.endpoint.update-shipping' );
84+
assert( $endpoint instanceof UpdateShippingEndpoint );
85+
86+
$endpoint->handle_request();
87+
}
88+
);
89+
7990
return true;
8091
}
8192
}

‎modules/ppcp-sdk-v6/src/Assets/SdkV6Manager.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
namespace WooCommerce\PayPalCommerce\SdkV6\Assets;
1111

1212
use WooCommerce\PayPalCommerce\Assets\AssetGetter;
13-
use WooCommerce\PayPalCommerce\Blocks\Endpoint\UpdateShippingEndpoint;
13+
use WooCommerce\PayPalCommerce\OrderEndpoints\Endpoint\UpdateShippingEndpoint;
1414
use WooCommerce\PayPalCommerce\OrderEndpoints\Endpoint\ApproveOrderEndpoint;
1515
use WooCommerce\PayPalCommerce\OrderEndpoints\Endpoint\ChangeCartEndpoint;
1616
use WooCommerce\PayPalCommerce\OrderEndpoints\Endpoint\CreateOrderEndpoint;

tests/PHPUnit/Blocks/Endpoint/UpdateShippingEndpointTest.php renamed to tests/PHPUnit/OrderEndpoints/Endpoint/UpdateShippingEndpointTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace WooCommerce\PayPalCommerce\Blocks\Endpoint;
5+
namespace WooCommerce\PayPalCommerce\OrderEndpoints\Endpoint;
66

77
use Mockery;
88
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
@@ -17,7 +17,7 @@
1717
use function Brain\Monkey\Functions\expect;
1818

1919
/**
20-
* @covers \WooCommerce\PayPalCommerce\Blocks\Endpoint\UpdateShippingEndpoint
20+
* @covers \WooCommerce\PayPalCommerce\OrderEndpoints\Endpoint\UpdateShippingEndpoint
2121
*/
2222
class UpdateShippingEndpointTest extends TestCase
2323
{

‎tests/integration/PHPUnit/Button/Endpoint/UpdateShippingEndpointContractTest.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Contract tests for the ppc-update-shipping WC-AJAX endpoint, shared by the
1313
* v5 and v6 SDK frontends.
1414
*
15-
* @covers \WooCommerce\PayPalCommerce\Blocks\Endpoint\UpdateShippingEndpoint
15+
* @covers \WooCommerce\PayPalCommerce\OrderEndpoints\Endpoint\UpdateShippingEndpoint
1616
*/
1717
class UpdateShippingEndpointContractTest extends WcAjaxEndpointTestCase {
1818

0 commit comments

Comments
 (0)