mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-08-31 06:52:50 +08:00
♻️ Refactor EarlyOrderHandler
This commit is contained in:
parent
7d2b0694d9
commit
a3fbe6f19f
2 changed files with 12 additions and 12 deletions
|
@ -241,11 +241,11 @@ return array(
|
|||
);
|
||||
},
|
||||
'button.helper.early-order-handler' => static function ( ContainerInterface $container ) : EarlyOrderHandler {
|
||||
|
||||
$state = $container->get( 'onboarding.state' );
|
||||
$order_processor = $container->get( 'wcgateway.order-processor' );
|
||||
$session_handler = $container->get( 'session.handler' );
|
||||
return new EarlyOrderHandler( $state, $order_processor, $session_handler );
|
||||
return new EarlyOrderHandler(
|
||||
$container->get( 'settings.flag.is-connected' ),
|
||||
$container->get( 'wcgateway.order-processor' ),
|
||||
$container->get( 'session.handler' )
|
||||
);
|
||||
},
|
||||
'button.endpoint.approve-order' => static function ( ContainerInterface $container ): ApproveOrderEndpoint {
|
||||
$request_data = $container->get( 'button.request-data' );
|
||||
|
|
|
@ -23,11 +23,11 @@ use WooCommerce\PayPalCommerce\WcGateway\Processor\OrderProcessor;
|
|||
class EarlyOrderHandler {
|
||||
|
||||
/**
|
||||
* The State.
|
||||
* Whether the merchant is connected to PayPal (onboarding completed).
|
||||
*
|
||||
* @var State
|
||||
* @var bool
|
||||
*/
|
||||
private $state;
|
||||
private bool $is_connected;
|
||||
|
||||
/**
|
||||
* The Order Processor.
|
||||
|
@ -46,17 +46,17 @@ class EarlyOrderHandler {
|
|||
/**
|
||||
* EarlyOrderHandler constructor.
|
||||
*
|
||||
* @param State $state The State.
|
||||
* @param bool $is_connected Whether onboarding was completed.
|
||||
* @param OrderProcessor $order_processor The Order Processor.
|
||||
* @param SessionHandler $session_handler The Session Handler.
|
||||
*/
|
||||
public function __construct(
|
||||
State $state,
|
||||
bool $is_connected,
|
||||
OrderProcessor $order_processor,
|
||||
SessionHandler $session_handler
|
||||
) {
|
||||
|
||||
$this->state = $state;
|
||||
$this->is_connected = $is_connected;
|
||||
$this->order_processor = $order_processor;
|
||||
$this->session_handler = $session_handler;
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ class EarlyOrderHandler {
|
|||
* @return bool
|
||||
*/
|
||||
public function should_create_early_order(): bool {
|
||||
return $this->state->current_state() === State::STATE_ONBOARDED;
|
||||
return $this->is_connected;
|
||||
}
|
||||
|
||||
//phpcs:disable WordPress.Security.NonceVerification.Recommended
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue