Allow credit card gateway to use saved credit cards

This commit is contained in:
dinamiko 2021-03-25 16:11:45 +01:00
parent 38d1b1ad9d
commit fd7dfaf13b
10 changed files with 229 additions and 16 deletions

View file

@ -72,6 +72,26 @@ class PaymentTokenRepository {
}
}
/**
* @param int $id
* @return array
*/
public function all_for_user_id( int $id ) {
$tokens = get_user_meta( $id, self::USER_META, true );
if($tokens) {
return (array) $tokens;
}
$tokens_array = [];
try {
$tokens = $this->endpoint->for_user( $id );
update_user_meta( $id, self::USER_META, $tokens );
return $tokens;
} catch (RuntimeException $exception) {
return [];
}
}
/**
* Delete a token for a user.
*

View file

@ -58,6 +58,24 @@ class SubscriptionModule implements ModuleInterface {
10,
2
);
/*
add_action('woocommerce_init', function () use($container) {
$api = $container->get('api.endpoint.payment-token' );
try {
$tokens = $api->for_user(1);
for($i = 0; $i < count($tokens); $i++) {
$api->delete_token($tokens[$i]);
}
$a = 1;
} catch (RuntimeException $exception) {
$a = 1;
}
});
*/
}
/**