Do not return stored tokens in meta but call the endpoint each time

This commit is contained in:
dinamiko 2021-03-29 11:57:03 +02:00
parent 179b1b2b81
commit 5afbfb0e3b
4 changed files with 3911 additions and 8 deletions

1
.gitignore vendored
View file

@ -5,5 +5,6 @@ node_modules
composer.lock composer.lock
yarn-error.log yarn-error.log
modules/ppcp-button/assets/* modules/ppcp-button/assets/*
modules/ppcp-wc-gateway/assets/*
.idea/ .idea/
*.zip *.zip

View file

@ -223,9 +223,8 @@ class SmartButton implements SmartButtonInterface {
$tokens = $payment_token_repository->all_for_user_id( 1 ); $tokens = $payment_token_repository->all_for_user_id( 1 );
if ( $tokens && $this->tokens_contains_card( $tokens ) ) { if ( $tokens && $this->tokens_contains_card( $tokens ) ) {
$output = sprintf( $output = sprintf(
'<select id="saved-credit-card" name="saved_credit_card"><option value="">%s</option>', '<p class="form-row form-row-wide"><label>Or select a saved Credit Card payment</label><select id="saved-credit-card" name="saved_credit_card"><option value="">%s</option>',
esc_html__( 'Choose a saved payment', 'woocommerce-paypal-payments' ) esc_html__( 'Choose a saved payment', 'woocommerce-paypal-payments' )
); );
foreach ( $tokens as $token ) { foreach ( $tokens as $token ) {
@ -238,7 +237,7 @@ class SmartButton implements SmartButtonInterface {
); );
} }
} }
$output .= '</select>'; $output .= '</select></p>';
$default_fields['saved-credit-card'] = $output; $default_fields['saved-credit-card'] = $output;
} }

View file

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

File diff suppressed because it is too large Load diff