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

@ -820,9 +820,6 @@ return array(
$container->get( 'save-payment-methods.wc-payment-tokens' )
);
},
'save-payment-methods.helpers.real-time-account-updater' => static function ( ContainerInterface $container ) : RealTimeAccountUpdaterHelper {
return new RealTimeAccountUpdaterHelper();
},
'save-payment-methods.endpoint.capture-card-payment' => static function( ContainerInterface $container ): CaptureCardPayment {
return new CaptureCardPayment(
$container->get( 'button.request-data' ),

View file

@ -21,8 +21,8 @@ use WooCommerce\PayPalCommerce\ApiClient\Factory\OrderFactory;
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
use WooCommerce\PayPalCommerce\Button\Endpoint\EndpointInterface;
use WooCommerce\PayPalCommerce\Button\Endpoint\RequestData;
use WooCommerce\PayPalCommerce\SavePaymentMethods\Helper\RealTimeAccountUpdaterHelper;
use WooCommerce\PayPalCommerce\Session\SessionHandler;
use WooCommerce\PayPalCommerce\WcSubscriptions\Helper\RealTimeAccountUpdaterHelper;
use WP_Error;
/**

View file

@ -1,51 +0,0 @@
<?php
/**
* Real Time Account Updater helper class.
*
* @package WooCommerce\PayPalCommerce\SavePaymentMethods\Helper
*/
declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\SavePaymentMethods\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();
}
}
}