mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-04 08:47:23 +08:00
Ensure payment token exist for customer for card payment subscription renewal
This commit is contained in:
parent
8ea790fedd
commit
3de845a934
1 changed files with 18 additions and 0 deletions
|
@ -298,6 +298,24 @@ class RenewalHandler {
|
|||
}
|
||||
|
||||
if ( $wc_order->get_payment_method() === CreditCardGateway::ID ) {
|
||||
$customer_id = get_user_meta( $user_id, '_ppcp_target_customer_id', true );
|
||||
if ( ! $customer_id ) {
|
||||
$customer_id = get_user_meta( $user_id, 'ppcp_customer_id', true );
|
||||
}
|
||||
|
||||
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( $wc_order->get_customer_id(), CreditCardGateway::ID );
|
||||
foreach ( $wc_tokens as $token ) {
|
||||
if ( ! in_array( $token->get_token(), $customer_tokens, true ) ) {
|
||||
$token->delete();
|
||||
}
|
||||
}
|
||||
|
||||
$wc_tokens = WC_Payment_Tokens::get_customer_tokens( $wc_order->get_customer_id(), CreditCardGateway::ID );
|
||||
$last_token = end( $wc_tokens );
|
||||
if ( $last_token ) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue