Add PayPal token deletion to WC payment method delete action

This commit is contained in:
emilicastells 2022-11-24 11:26:06 +01:00
parent 9a0e25520c
commit 34798848bc
No known key found for this signature in database
GPG key ID: 1520C07081754570
2 changed files with 57 additions and 2 deletions

View file

@ -208,6 +208,32 @@ class PaymentTokenEndpoint {
return wp_remote_retrieve_response_code( $response ) === 204;
}
public function delete_token_by_id(string $token_id): bool {
$bearer = $this->bearer->bearer();
$url = trailingslashit( $this->host ) . 'v2/vault/payment-tokens/' . $token_id;
$args = array(
'method' => 'DELETE',
'headers' => array(
'Authorization' => 'Bearer ' . $bearer->token(),
'Content-Type' => 'application/json',
),
);
$response = $this->request( $url, $args );
if ( is_wp_error( $response ) ) {
$error = new RuntimeException(
__( 'Could not delete payment token.', 'woocommerce-paypal-payments' )
);
$this->logger->warning($error->getMessage());
throw $error;
}
return wp_remote_retrieve_response_code( $response ) === 204;
}
/**
* Starts the process of PayPal account vaulting (without payment), returns the links for further actions.
*