Get latest payment token for subscription renewal

This commit is contained in:
dinamiko 2021-04-23 12:22:29 +02:00
parent ea23200de6
commit bb5a04c4b3
2 changed files with 5 additions and 5 deletions

View file

@ -79,7 +79,6 @@ class PaymentTokenRepository {
* @return PaymentToken[]
*/
public function all_for_user_id( int $id ) {
$tokens_array = array();
try {
$tokens = $this->endpoint->for_user( $id );
update_user_meta( $id, self::USER_META, $tokens );

View file

@ -176,14 +176,14 @@ class RenewalHandler {
*/
private function get_token_for_customer( \WC_Customer $customer, \WC_Order $wc_order ) {
$token = $this->repository->for_user_id( (int) $customer->get_id() );
if ( ! $token ) {
$tokens = $this->repository->all_for_user_id( (int) $customer->get_id() );
if ( ! $tokens ) {
$this->logger->log(
'error',
sprintf(
// translators: %d is the customer id.
__(
'No payment token found for customer %d',
'No payment tokens found for customer %d',
'woocommerce-paypal-payments'
),
(int) $customer->get_id()
@ -194,7 +194,8 @@ class RenewalHandler {
)
);
}
return $token;
return current( $tokens );
}
/**