Do not check order approved status if it does not contains physical goods

This commit is contained in:
dinamiko 2022-06-02 15:11:01 +02:00
parent 77230fefa8
commit 0a993f854d
7 changed files with 88 additions and 8 deletions

View file

@ -151,6 +151,7 @@ return array(
$three_d_secure = $container->get( 'button.helper.three-d-secure' );
$settings = $container->get( 'wcgateway.settings' );
$dcc_applies = $container->get( 'api.helpers.dccapplies' );
$order_helper = $container->get( 'api.order-helper' );
$logger = $container->get( 'woocommerce.logger.woocommerce' );
return new ApproveOrderEndpoint(
$request_data,
@ -159,6 +160,7 @@ return array(
$three_d_secure,
$settings,
$dcc_applies,
$order_helper,
$logger
);
},

View file

@ -16,6 +16,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Endpoint\OrderEndpoint;
use WooCommerce\PayPalCommerce\ApiClient\Entity\OrderStatus;
use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
use WooCommerce\PayPalCommerce\ApiClient\Helper\DccApplies;
use WooCommerce\PayPalCommerce\ApiClient\Helper\OrderHelper;
use WooCommerce\PayPalCommerce\Button\Exception\RuntimeException;
use WooCommerce\PayPalCommerce\Button\Helper\ThreeDSecure;
use WooCommerce\PayPalCommerce\Session\SessionHandler;
@ -26,7 +27,6 @@ use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
*/
class ApproveOrderEndpoint implements EndpointInterface {
const ENDPOINT = 'ppc-approve-order';
/**
@ -71,6 +71,13 @@ class ApproveOrderEndpoint implements EndpointInterface {
*/
private $dcc_applies;
/**
* The order helper.
*
* @var OrderHelper
*/
protected $order_helper;
/**
* The logger.
*
@ -87,6 +94,7 @@ class ApproveOrderEndpoint implements EndpointInterface {
* @param ThreeDSecure $three_d_secure The 3d secure helper object.
* @param Settings $settings The settings.
* @param DccApplies $dcc_applies The DCC applies object.
* @param OrderHelper $order_helper The order helper.
* @param LoggerInterface $logger The logger.
*/
public function __construct(
@ -96,6 +104,7 @@ class ApproveOrderEndpoint implements EndpointInterface {
ThreeDSecure $three_d_secure,
Settings $settings,
DccApplies $dcc_applies,
OrderHelper $order_helper,
LoggerInterface $logger
) {
@ -105,6 +114,7 @@ class ApproveOrderEndpoint implements EndpointInterface {
$this->threed_secure = $three_d_secure;
$this->settings = $settings;
$this->dcc_applies = $dcc_applies;
$this->order_helper = $order_helper;
$this->logger = $logger;
}
@ -173,7 +183,7 @@ class ApproveOrderEndpoint implements EndpointInterface {
wp_send_json_success( $order );
}
if ( ! $order->status()->is( OrderStatus::APPROVED ) ) {
if ( $this->order_helper->contains_physical_goods( $order ) && ! $order->status()->is( OrderStatus::APPROVED ) ) {
$message = sprintf(
// translators: %s is the id of the order.
__( 'Order %s is not approved yet.', 'woocommerce-paypal-payments' ),