Delete WC payment token if it does not exist for user

This commit is contained in:
Emili Castells Guasch 2024-03-18 12:18:04 +01:00
parent 2c8aecde76
commit 4f9800079f
2 changed files with 3 additions and 0 deletions

View file

@ -256,6 +256,7 @@ class RenewalHandler {
$customer_tokens = $this->payment_tokens_endpoint->payment_tokens_for_customer( $customer_id ); $customer_tokens = $this->payment_tokens_endpoint->payment_tokens_for_customer( $customer_id );
foreach ( $wc_tokens as $token ) { foreach ( $wc_tokens as $token ) {
if ( ! in_array( $token->get_token(), $customer_tokens, true ) ) { if ( ! in_array( $token->get_token(), $customer_tokens, true ) ) {
$token->delete();
continue; continue;
} }

View file

@ -120,6 +120,8 @@ class VaultPaymentTokenCreated implements RequestHandler {
return $this->success_response(); return $this->success_response();
} }
$this->logger->info(wc_print_r($request['resource'], true));
$customer_id = null !== $request['resource'] && isset( $request['resource']['customer_id'] ) $customer_id = null !== $request['resource'] && isset( $request['resource']['customer_id'] )
? $request['resource']['customer_id'] ? $request['resource']['customer_id']
: ''; : '';