From 936915e53c916bffb6fc372aa2252ae783ef0478 Mon Sep 17 00:00:00 2001 From: Alex P Date: Mon, 11 Oct 2021 17:36:59 +0300 Subject: [PATCH] Do not show capture order action after capture, refund/cancel/fail --- modules/ppcp-wc-gateway/services.php | 4 ++-- .../src/Admin/class-renderauthorizeaction.php | 22 +++++++++++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php index 35be6f9fc..6f58c5461 100644 --- a/modules/ppcp-wc-gateway/services.php +++ b/modules/ppcp-wc-gateway/services.php @@ -229,8 +229,8 @@ return array( return new AuthorizedPaymentsProcessor( $order_endpoint, $payments_endpoint, $logger ); }, 'wcgateway.admin.render-authorize-action' => static function ( $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 ( $container ): PaymentStatusOrderDetail { $column = $container->get( 'wcgateway.admin.orders-payment-status-column' ); diff --git a/modules/ppcp-wc-gateway/src/Admin/class-renderauthorizeaction.php b/modules/ppcp-wc-gateway/src/Admin/class-renderauthorizeaction.php index ad6640efe..a65e0989a 100644 --- a/modules/ppcp-wc-gateway/src/Admin/class-renderauthorizeaction.php +++ b/modules/ppcp-wc-gateway/src/Admin/class-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 ); } }