diff --git a/modules/ppcp-vaulting/services.php b/modules/ppcp-vaulting/services.php index e9b702e6b..2c584b531 100644 --- a/modules/ppcp-vaulting/services.php +++ b/modules/ppcp-vaulting/services.php @@ -9,4 +9,8 @@ declare(strict_types=1); namespace WooCommerce\PayPalCommerce\Vaulting; -return array(); +return array( + 'vaulting.payment-tokens-renderer' => static function (): PaymentTokensRendered { + return new PaymentTokensRendered(); + }, +); diff --git a/modules/ppcp-vaulting/src/class-payment-tokens-renderer.php b/modules/ppcp-vaulting/src/class-payment-tokens-renderer.php new file mode 100644 index 000000000..27e2fa679 --- /dev/null +++ b/modules/ppcp-vaulting/src/class-payment-tokens-renderer.php @@ -0,0 +1,53 @@ + + + + + + + + + + source() ?? null; + if ( $source && isset( $source->card ) ) { + ?> + + + + + paypal ) ) { + ?> + + + + + + + +
Payment sources
card->brand . ' ...' . $source->card->last_digits;?> + Delete +
paypal->payer->email_address;?> + Delete +
+ 'PayPal payments' ) - + array_slice( $menu_links, 5, NULL, true ); + + array_slice( $menu_links, 5, null, true ); - return $menu_links; - }, 40 ); + return $menu_links; + }, + 40 + ); - add_action( 'init', function() { - add_rewrite_endpoint( 'ppcp-paypal-payment-tokens', EP_PAGES ); - } ); + add_action( + 'init', + function () { + add_rewrite_endpoint( 'ppcp-paypal-payment-tokens', EP_PAGES ); + // TODO flush rewrite + } + ); - add_action( 'woocommerce_account_ppcp-paypal-payment-tokens_endpoint', function() use ($container){ + add_action( + 'woocommerce_account_ppcp-paypal-payment-tokens_endpoint', + function () use ( $container ) { - $repo = $container->get('subscription.repository.payment-token'); - $tokens = $repo->all_for_user_id( get_current_user_id() ); - $a = 1; - }); + /** @var PaymentTokenRepository $payment_token_repository */ + $payment_token_repository = $container->get( 'subscription.repository.payment-token' ); + $tokens = $payment_token_repository->all_for_user_id( get_current_user_id() ); + if ( $tokens ) { + $renderer = $container->get( 'vaulting.payment-tokens-renderer' ); + echo wp_kses_post( $renderer->render( $tokens ) ); + } + } + ); } /**