diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php index 8048365ad..785aa4f6f 100644 --- a/modules/ppcp-wc-gateway/services.php +++ b/modules/ppcp-wc-gateway/services.php @@ -231,8 +231,8 @@ return array( return new AuthorizedPaymentsProcessor( $order_endpoint, $payments_endpoint, $logger ); }, 'wcgateway.admin.render-authorize-action' => static function ( ContainerInterface $container ): RenderAuthorizeAction { - - return new RenderAuthorizeAction(); + $column = $container->get( 'wcgateway.admin.orders-payment-status-column' ); + return new RenderAuthorizeAction( $column ); }, 'wcgateway.admin.order-payment-status' => static function ( ContainerInterface $container ): PaymentStatusOrderDetail { $column = $container->get( 'wcgateway.admin.orders-payment-status-column' ); diff --git a/modules/ppcp-wc-gateway/src/Admin/RenderAuthorizeAction.php b/modules/ppcp-wc-gateway/src/Admin/RenderAuthorizeAction.php index ad6640efe..a65e0989a 100644 --- a/modules/ppcp-wc-gateway/src/Admin/RenderAuthorizeAction.php +++ b/modules/ppcp-wc-gateway/src/Admin/RenderAuthorizeAction.php @@ -15,6 +15,21 @@ use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway; * Class RenderAuthorizeAction */ class RenderAuthorizeAction { + /** + * The capture info column. + * + * @var OrderTablePaymentStatusColumn + */ + private $column; + + /** + * PaymentStatusOrderDetail constructor. + * + * @param OrderTablePaymentStatusColumn $column The capture info column. + */ + public function __construct( OrderTablePaymentStatusColumn $column ) { + $this->column = $column; + } /** * Renders the action into the $order_actions array based on the WooCommerce order. @@ -45,7 +60,10 @@ class RenderAuthorizeAction { * @return bool */ private function should_render_for_order( \WC_Order $order ) : bool { - $data = $order->get_meta( PayPalGateway::CAPTURED_META_KEY ); - return in_array( $data, array( 'true', 'false' ), true ); + $status = $order->get_status(); + $not_allowed_statuses = array( 'refunded', 'cancelled', 'failed' ); + return $this->column->should_render_for_order( $order ) && + ! $this->column->is_captured( $order ) && + ! in_array( $status, $not_allowed_statuses, true ); } }