mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
render the authorize action depending on the orders status
This commit is contained in:
parent
d28f763115
commit
e3055a69f0
3 changed files with 71 additions and 6 deletions
|
@ -15,6 +15,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Helper\Cache;
|
|||
use WooCommerce\PayPalCommerce\Onboarding\State;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Admin\OrderTablePaymentStatusColumn;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Admin\PaymentStatusOrderDetail;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Admin\RenderAuthorizeAction;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Checkout\CheckoutPayPalAddressPreset;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Checkout\DisableGateways;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Endpoint\ReturnUrlEndpoint;
|
||||
|
@ -137,6 +138,10 @@ return array(
|
|||
$payments_endpoint = $container->get( 'api.endpoint.payments' );
|
||||
return new AuthorizedPaymentsProcessor( $order_endpoint, $payments_endpoint );
|
||||
},
|
||||
'wcgateway.admin.render-authorize-action' => static function ( $container ): RenderAuthorizeAction {
|
||||
|
||||
return new RenderAuthorizeAction();
|
||||
},
|
||||
'wcgateway.admin.order-payment-status' => static function ( $container ): PaymentStatusOrderDetail {
|
||||
return new PaymentStatusOrderDetail();
|
||||
},
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
/**
|
||||
* Renders the order action "Capture authorized PayPal payment"
|
||||
*
|
||||
* @package WooCommerce\PayPalCommerce\WcGateway\Admin
|
||||
*/
|
||||
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\WcGateway\Admin;
|
||||
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
|
||||
|
||||
/**
|
||||
* Class RenderAuthorizeAction
|
||||
*/
|
||||
class RenderAuthorizeAction {
|
||||
|
||||
/**
|
||||
* Renders the action into the $order_actions array based on the WooCommerce order.
|
||||
*
|
||||
* @param array $order_actions The actions to render into.
|
||||
* @param \WC_Order $wc_order The order for which to render the action.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function render( array $order_actions, \WC_Order $wc_order ) : array {
|
||||
|
||||
if ( ! $this->should_render_for_order( $wc_order ) ) {
|
||||
return $order_actions;
|
||||
}
|
||||
|
||||
$order_actions['ppcp_authorize_order'] = __(
|
||||
'Capture authorized PayPal payment',
|
||||
'paypal-payments-for-woocommerce'
|
||||
);
|
||||
return $order_actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the action should be rendered for a certain WooCommerce order.
|
||||
*
|
||||
* @param \WC_Order $order The Woocommerce order.
|
||||
*
|
||||
* @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 );
|
||||
}
|
||||
}
|
|
@ -16,6 +16,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Helper\DccApplies;
|
|||
use WooCommerce\PayPalCommerce\ApiClient\Repository\PayPalRequestIdRepository;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Admin\OrderTablePaymentStatusColumn;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Admin\PaymentStatusOrderDetail;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Admin\RenderAuthorizeAction;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Checkout\CheckoutPayPalAddressPreset;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Checkout\DisableGateways;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Endpoint\ReturnUrlEndpoint;
|
||||
|
@ -257,12 +258,20 @@ class WcGatewayModule implements ModuleInterface {
|
|||
private function register_order_functionality( ContainerInterface $container ) {
|
||||
add_filter(
|
||||
'woocommerce_order_actions',
|
||||
static function ( $order_actions ): array {
|
||||
$order_actions['ppcp_authorize_order'] = __(
|
||||
'Capture authorized PayPal payment',
|
||||
'paypal-payments-for-woocommerce'
|
||||
);
|
||||
return $order_actions;
|
||||
static function ( $order_actions ) use ( $container ): array {
|
||||
global $theorder;
|
||||
|
||||
if ( ! is_a( $theorder, \WC_Order::class ) ) {
|
||||
return $order_actions;
|
||||
}
|
||||
|
||||
$render = $container->get( 'wcgateway.admin.render-authorize-action' );
|
||||
/**
|
||||
* Renders the authorize action in the select field.
|
||||
*
|
||||
* @var RenderAuthorizeAction $render
|
||||
*/
|
||||
return $render->render( $order_actions, $theorder );
|
||||
}
|
||||
);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue