Merge pull request #2038 from woocommerce/PCP-2668-add-more-checks-to-prevent-pay-pal-order-id-not-found-errors

Add more checks to prevent "PayPal order ID not found" errors
This commit is contained in:
Emili Castells 2024-02-21 10:39:30 +01:00 committed by GitHub
commit 135e7f2fd2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 11 additions and 1 deletions

View file

@ -196,7 +196,7 @@ class PayPalSubscriptionsModule implements ModuleInterface {
*
* @psalm-suppress MissingClosureParamType
*/
function( $actions, $subscription ): array {
function( $actions, $subscription = null ): array {
if ( ! is_array( $actions ) || ! is_a( $subscription, WC_Subscription::class ) ) {
return $actions;
}

View file

@ -126,6 +126,10 @@ class PaymentTokenChecker {
return;
}
if ( ! in_array( $wc_order->get_payment_method(), array( PayPalGateway::ID, CreditCardGateway::ID, CardButtonGateway::ID ), true ) ) {
return;
}
if ( $wc_order->get_status() === 'processing' || 'capture' !== $intent ) {
return;
}

View file

@ -22,6 +22,8 @@ use WooCommerce\PayPalCommerce\ApiClient\Entity\Order;
use WooCommerce\PayPalCommerce\ApiClient\Entity\Payments;
use WooCommerce\PayPalCommerce\ApiClient\Entity\RefundCapture;
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\CardButtonGateway;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
use WooCommerce\PayPalCommerce\WcGateway\Helper\RefundFeesUpdater;
@ -107,6 +109,10 @@ class RefundProcessor {
*/
public function process( WC_Order $wc_order, float $amount = null, string $reason = '' ) : bool {
try {
if ( ! in_array( $wc_order->get_payment_method(), array( PayPalGateway::ID, CreditCardGateway::ID, CardButtonGateway::ID ), true ) ) {
return true;
}
$order_id = $wc_order->get_meta( PayPalGateway::ORDER_ID_META_KEY );
if ( ! $order_id ) {
throw new RuntimeException( 'PayPal order ID not found in meta.' );