Display saved payment tokens

This commit is contained in:
dinamiko 2021-09-17 16:54:31 +02:00
parent 6c3a11fcd8
commit 60dc34e510
3 changed files with 89 additions and 14 deletions

View file

@ -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();
},
);

View file

@ -0,0 +1,53 @@
<?php
declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\Vaulting;
class PaymentTokensRendered {
public function render( array $tokens ) {
ob_start();
?>
<table class="shop_table shop_table_responsive">
<thead>
<tr>
<th>Payment sources</th>
<th></th>
</tr>
</thead>
<tbody>
<?php
foreach ( $tokens as $token ) {
$source = $token->source() ?? null;
if ( $source && isset( $source->card ) ) {
?>
<tr>
<td><?= $source->card->brand . ' ...' . $source->card->last_digits;?></td>
<td>
<a href="">Delete</a>
</td>
</tr>
<?php
}
if ( $source && isset( $source->paypal ) ) {
?>
<tr>
<td><?= $source->paypal->payer->email_address;?></td>
<td>
<a href="">Delete</a>
</td>
</tr>
<?php
}
?>
<?php
}
?>
</tbody>
</table>
<?php
return ob_get_clean();
}
}

View file

@ -13,12 +13,15 @@ use Dhii\Container\ServiceProvider;
use Dhii\Modular\Module\ModuleInterface;
use Interop\Container\ServiceProviderInterface;
use Psr\Container\ContainerInterface;
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
use WooCommerce\PayPalCommerce\Subscription\Repository\PaymentTokenRepository;
/**
* Class StatusReportModule
*/
class VaultingModule implements ModuleInterface {
/**
* {@inheritDoc}
*/
@ -36,25 +39,40 @@ class VaultingModule implements ModuleInterface {
*/
public function run( ContainerInterface $container ): void {
add_filter ( 'woocommerce_account_menu_items', function($menu_links) {
$menu_links = array_slice( $menu_links, 0, 5, true )
add_filter(
'woocommerce_account_menu_items',
function( $menu_links ) {
$menu_links = array_slice( $menu_links, 0, 5, true )
+ array( 'ppcp-paypal-payment-tokens' => '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 ) );
}
}
);
}
/**