Merge pull request #319 from woocommerce/capture-order-action-availability

Do not show capture order action after capture, refund/cancel/fail
This commit is contained in:
Emili Castells 2021-10-19 09:54:36 +02:00 committed by GitHub
commit cf3b6e6ab1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 4 deletions

View file

@ -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' );

View file

@ -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 );
}
}