Move real time account updater to wc subscriptions module to have it available when vault v3 is disabled

This commit is contained in:
Emili Castells Guasch 2024-02-16 16:28:13 +01:00
parent 821e425944
commit 0482f011f7
5 changed files with 11 additions and 10 deletions

View file

@ -12,13 +12,17 @@ namespace WooCommerce\PayPalCommerce\WcSubscriptions;
use WooCommerce\PayPalCommerce\Vaulting\PaymentTokenRepository;
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
use WooCommerce\PayPalCommerce\WcSubscriptions\Endpoint\SubscriptionChangePaymentMethod;
use WooCommerce\PayPalCommerce\WcSubscriptions\Helper\RealTimeAccountUpdaterHelper;
use WooCommerce\PayPalCommerce\WcSubscriptions\Helper\SubscriptionHelper;
return array(
'wc-subscriptions.helper' => static function ( ContainerInterface $container ): SubscriptionHelper {
'wc-subscriptions.helper' => static function ( ContainerInterface $container ): SubscriptionHelper {
return new SubscriptionHelper();
},
'wc-subscriptions.renewal-handler' => static function ( ContainerInterface $container ): RenewalHandler {
'wc-subscriptions.helpers.real-time-account-updater' => static function ( ContainerInterface $container ) : RealTimeAccountUpdaterHelper {
return new RealTimeAccountUpdaterHelper();
},
'wc-subscriptions.renewal-handler' => static function ( ContainerInterface $container ): RenewalHandler {
$logger = $container->get( 'woocommerce.logger.woocommerce' );
$repository = $container->get( 'vaulting.repository.payment-token' );
$endpoint = $container->get( 'api.endpoint.order' );
@ -39,11 +43,11 @@ return array(
$settings,
$authorized_payments_processor,
$funding_source_renderer,
$container->get( 'save-payment-methods.helpers.real-time-account-updater' ),
$container->get( 'wc-subscriptions.helpers.real-time-account-updater' ),
$container->get( 'wc-subscriptions.helper' )
);
},
'wc-subscriptions.repository.payment-token' => static function ( ContainerInterface $container ): PaymentTokenRepository {
'wc-subscriptions.repository.payment-token' => static function ( ContainerInterface $container ): PaymentTokenRepository {
$factory = $container->get( 'api.factory.payment-token' );
$endpoint = $container->get( 'api.endpoint.payment-token' );
return new PaymentTokenRepository( $factory, $endpoint );

View file

@ -0,0 +1,51 @@
<?php
/**
* Real Time Account Updater helper class.
*
* @package WooCommerce\PayPalCommerce\SavePaymentMethods\Helper
*/
declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\WcSubscriptions\Helper;
use WC_Payment_Token;
use WC_Payment_Token_CC;
/**
* Class RealTimeAccountUpdaterHelper
*/
class RealTimeAccountUpdaterHelper {
/**
* Updates WC card token with the given data.
*
* @param string $expiry Card expiry.
* @param string $last_digits Card last 4 digits.
* @param WC_Payment_Token $token WC Payment Token.
* @return void
*/
public function update_wc_card_token( string $expiry, string $last_digits, WC_Payment_Token $token ): void {
if (
! is_a( $token, WC_Payment_Token_CC::class )
|| $token->get_type() !== 'CC'
|| ! in_array( $token->get_card_type(), array( 'VISA', 'MASTERCARD' ), true )
) {
return;
}
$wc_expiry = $token->get_expiry_month() . '-' . $token->get_expiry_year();
if ( $expiry !== $wc_expiry ) {
$expiry_split = explode( '-', $expiry );
$token->set_expiry_year( $expiry_split[0] );
$token->set_expiry_month( $expiry_split[1] );
$token->save();
}
$wc_last_digits = $token->get_last4();
if ( $last_digits !== $wc_last_digits ) {
$token->set_last4( $last_digits );
$token->save();
}
}
}

View file

@ -22,7 +22,6 @@ use WooCommerce\PayPalCommerce\ApiClient\Factory\PayerFactory;
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
use WooCommerce\PayPalCommerce\ApiClient\Factory\ShippingPreferenceFactory;
use WooCommerce\PayPalCommerce\Onboarding\Environment;
use WooCommerce\PayPalCommerce\SavePaymentMethods\Helper\RealTimeAccountUpdaterHelper;
use WooCommerce\PayPalCommerce\Vaulting\PaymentTokenApplePay;
use WooCommerce\PayPalCommerce\Vaulting\PaymentTokenPayPal;
use WooCommerce\PayPalCommerce\Vaulting\PaymentTokenRepository;
@ -37,6 +36,7 @@ use WooCommerce\PayPalCommerce\WcGateway\Processor\OrderMetaTrait;
use WooCommerce\PayPalCommerce\WcGateway\Processor\PaymentsStatusHandlingTrait;
use WooCommerce\PayPalCommerce\WcGateway\Processor\TransactionIdHandlingTrait;
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
use WooCommerce\PayPalCommerce\WcSubscriptions\Helper\RealTimeAccountUpdaterHelper;
use WooCommerce\PayPalCommerce\WcSubscriptions\Helper\SubscriptionHelper;
/**