mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Display saved payment tokens
This commit is contained in:
parent
6c3a11fcd8
commit
60dc34e510
3 changed files with 89 additions and 14 deletions
|
@ -9,4 +9,8 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace WooCommerce\PayPalCommerce\Vaulting;
|
namespace WooCommerce\PayPalCommerce\Vaulting;
|
||||||
|
|
||||||
return array();
|
return array(
|
||||||
|
'vaulting.payment-tokens-renderer' => static function (): PaymentTokensRendered {
|
||||||
|
return new PaymentTokensRendered();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
53
modules/ppcp-vaulting/src/class-payment-tokens-renderer.php
Normal file
53
modules/ppcp-vaulting/src/class-payment-tokens-renderer.php
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -13,12 +13,15 @@ use Dhii\Container\ServiceProvider;
|
||||||
use Dhii\Modular\Module\ModuleInterface;
|
use Dhii\Modular\Module\ModuleInterface;
|
||||||
use Interop\Container\ServiceProviderInterface;
|
use Interop\Container\ServiceProviderInterface;
|
||||||
use Psr\Container\ContainerInterface;
|
use Psr\Container\ContainerInterface;
|
||||||
|
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
|
||||||
|
use WooCommerce\PayPalCommerce\Subscription\Repository\PaymentTokenRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class StatusReportModule
|
* Class StatusReportModule
|
||||||
*/
|
*/
|
||||||
class VaultingModule implements ModuleInterface {
|
class VaultingModule implements ModuleInterface {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
|
@ -36,25 +39,40 @@ class VaultingModule implements ModuleInterface {
|
||||||
*/
|
*/
|
||||||
public function run( ContainerInterface $container ): void {
|
public function run( ContainerInterface $container ): void {
|
||||||
|
|
||||||
add_filter ( 'woocommerce_account_menu_items', function($menu_links) {
|
add_filter(
|
||||||
|
'woocommerce_account_menu_items',
|
||||||
|
function( $menu_links ) {
|
||||||
$menu_links = array_slice( $menu_links, 0, 5, true )
|
$menu_links = array_slice( $menu_links, 0, 5, true )
|
||||||
+ array( 'ppcp-paypal-payment-tokens' => 'PayPal payments' )
|
+ array( 'ppcp-paypal-payment-tokens' => 'PayPal payments' )
|
||||||
+ array_slice( $menu_links, 5, NULL, true );
|
+ array_slice( $menu_links, 5, null, true );
|
||||||
|
|
||||||
return $menu_links;
|
return $menu_links;
|
||||||
}, 40 );
|
},
|
||||||
|
40
|
||||||
|
);
|
||||||
|
|
||||||
add_action( 'init', function() {
|
add_action(
|
||||||
|
'init',
|
||||||
|
function () {
|
||||||
add_rewrite_endpoint( 'ppcp-paypal-payment-tokens', EP_PAGES );
|
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');
|
/** @var PaymentTokenRepository $payment_token_repository */
|
||||||
$tokens = $repo->all_for_user_id( get_current_user_id() );
|
$payment_token_repository = $container->get( 'subscription.repository.payment-token' );
|
||||||
$a = 1;
|
|
||||||
});
|
|
||||||
|
|
||||||
|
$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 ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue