Handle not found exception when customer id does not exist

This commit is contained in:
Emili Castells Guasch 2024-03-18 13:09:14 +01:00
parent 4f9800079f
commit 3cb0630380
3 changed files with 9 additions and 4 deletions

View file

@ -19,6 +19,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Entity\Order;
use WooCommerce\PayPalCommerce\ApiClient\Entity\PaymentSource;
use WooCommerce\PayPalCommerce\ApiClient\Entity\PaymentToken;
use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
use WooCommerce\PayPalCommerce\ApiClient\Factory\PayerFactory;
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
use WooCommerce\PayPalCommerce\ApiClient\Factory\ShippingPreferenceFactory;
@ -252,8 +253,13 @@ class RenewalHandler {
$customer_id = get_user_meta( $user_id, 'ppcp_customer_id', true );
}
$wc_tokens = WC_Payment_Tokens::get_customer_tokens( $user_id, PayPalGateway::ID );
$customer_tokens = $this->payment_tokens_endpoint->payment_tokens_for_customer( $customer_id );
try {
$customer_tokens = $this->payment_tokens_endpoint->payment_tokens_for_customer( $customer_id );
} catch ( RuntimeException $exception ) {
$customer_tokens = array();
}
$wc_tokens = WC_Payment_Tokens::get_customer_tokens( $user_id, PayPalGateway::ID );
foreach ( $wc_tokens as $token ) {
if ( ! in_array( $token->get_token(), $customer_tokens, true ) ) {
$token->delete();

View file

@ -13,6 +13,7 @@ use Psr\Log\LoggerInterface;
use WC_Order;
use WC_Payment_Token_CC;
use WC_Payment_Tokens;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PaymentTokensEndpoint;
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
use WooCommerce\PayPalCommerce\Vaulting\PaymentTokenRepository;
use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\ServiceProvider;