Fail WC order only if PayPal order status is not completed

This commit is contained in:
dinamiko 2022-06-23 11:13:41 +02:00
parent 5fbe7580d0
commit 035ff32d59

View file

@ -14,6 +14,7 @@ use Dhii\Modular\Module\ModuleInterface;
use WC_Order;
use WooCommerce\PayPalCommerce\AdminNotices\Repository\Repository;
use WooCommerce\PayPalCommerce\ApiClient\Entity\Capture;
use WooCommerce\PayPalCommerce\ApiClient\Entity\OrderStatus;
use WooCommerce\PayPalCommerce\ApiClient\Helper\DccApplies;
use WooCommerce\PayPalCommerce\ApiClient\Repository\PayPalRequestIdRepository;
use WooCommerce\PayPalCommerce\WcGateway\Admin\FeesRenderer;
@ -239,20 +240,26 @@ class WCGatewayModule implements ModuleInterface {
$order_endpoint = $c->get( 'api.endpoint.order' );
$logger = $c->get( 'woocommerce.logger.woocommerce' );
$order = $order_endpoint->order( $order_id );
$order_status = $order->status();
$logger->info( 'Checking payment captured webhook, order status: ' . $order_status->name());
$order_status = $order->status();
$logger->info( "Checking payment captured webhook for WC order #{$wc_order_id}, PayPal order status: " . $order_status->name() );
$wc_order = wc_get_order( $wc_order_id );
if ( ! is_a( $wc_order, WC_Order::class ) || $wc_order->get_status() !== 'on-hold' ) {
return;
}
$message = __(
'Could not process order because PAYMENT.CAPTURE.COMPLETED webhook not received.',
'woocommerce-paypal-payments'
);
$wc_order->update_status( 'failed', $message );
}, 10, 2
if ( $order_status->name() !== OrderStatus::COMPLETED ) {
$message = __(
'Could not process WC order because PAYMENT.CAPTURE.COMPLETED webhook not received.',
'woocommerce-paypal-payments'
);
$logger->error( $message );
$wc_order->update_status( 'failed', $message );
}
},
10,
2
);
}