mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-01 07:02:48 +08:00
Add sca indicators and card update to card subscription renewals
This commit is contained in:
parent
36e3d261f6
commit
9948b648e0
5 changed files with 62 additions and 56 deletions
|
@ -158,8 +158,14 @@ class CaptureCardPayment implements EndpointInterface {
|
|||
$id = $order->id ?? '';
|
||||
$status = $order->status ?? '';
|
||||
$payment_source = isset( $order->payment_source->card ) ? 'card' : '';
|
||||
if ( $id && $status && $payment_source ) {
|
||||
$this->real_time_account_updater_helper->update_wc_token_from_paypal_response( $order, $token );
|
||||
$expiry = $order->payment_source->card->expiry ?? '';
|
||||
$last_digits = $order->payment_source->card->last_digits ?? '';
|
||||
if ( $id && $status && $payment_source && $expiry && $last_digits ) {
|
||||
$this->real_time_account_updater_helper->update_wc_card_token(
|
||||
$expiry,
|
||||
$last_digits,
|
||||
$token
|
||||
);
|
||||
|
||||
WC()->session->set(
|
||||
'ppcp_saved_payment_card',
|
||||
|
|
|
@ -18,13 +18,12 @@ use WC_Payment_Token;
|
|||
class RealTimeAccountUpdaterHelper {
|
||||
|
||||
/**
|
||||
* Updates WC Payment Token from PayPal response.
|
||||
*
|
||||
* @param stdClass $order PayPal order response data.
|
||||
* @param string $expiry Card expìry.
|
||||
* @param string $last_digits Card last 4 digits.
|
||||
* @param WC_Payment_Token $token WC Payment Token.
|
||||
* @return void
|
||||
*/
|
||||
public function update_wc_token_from_paypal_response( stdClass $order, WC_Payment_Token $token ): void {
|
||||
public function update_wc_card_token( string $expiry, string $last_digits, WC_Payment_Token $token ): void {
|
||||
if (
|
||||
$token->get_type() !== 'CC'
|
||||
|| ! in_array( $token->get_card_type(), array( 'VISA', 'MASTERCARD' ), true )
|
||||
|
@ -32,9 +31,7 @@ class RealTimeAccountUpdaterHelper {
|
|||
return;
|
||||
}
|
||||
|
||||
$expiry = $order->payment_source->card->expiry ?? '';
|
||||
$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] );
|
||||
|
@ -42,7 +39,6 @@ class RealTimeAccountUpdaterHelper {
|
|||
$token->save();
|
||||
}
|
||||
|
||||
$last_digits = $order->payment_source->card->last_digits ?? '';
|
||||
$wc_last_digits = $token->get_last4();
|
||||
if ( $last_digits !== $wc_last_digits ) {
|
||||
$token->set_last4( $last_digits );
|
||||
|
|
|
@ -38,7 +38,8 @@ return array(
|
|||
$environment,
|
||||
$settings,
|
||||
$authorized_payments_processor,
|
||||
$funding_source_renderer
|
||||
$funding_source_renderer,
|
||||
$container->get( 'save-payment-methods.helpers.real-time-account-updater' )
|
||||
);
|
||||
},
|
||||
'wc-subscriptions.repository.payment-token' => static function ( ContainerInterface $container ): PaymentTokenRepository {
|
||||
|
|
|
@ -22,6 +22,7 @@ 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;
|
||||
|
@ -116,19 +117,27 @@ class RenewalHandler {
|
|||
*/
|
||||
protected $funding_source_renderer;
|
||||
|
||||
/**
|
||||
* Real Time Account Updater helper.
|
||||
*
|
||||
* @var RealTimeAccountUpdaterHelper
|
||||
*/
|
||||
private $real_time_account_updater_helper;
|
||||
|
||||
/**
|
||||
* RenewalHandler constructor.
|
||||
*
|
||||
* @param LoggerInterface $logger The logger.
|
||||
* @param PaymentTokenRepository $repository The payment token repository.
|
||||
* @param OrderEndpoint $order_endpoint The order endpoint.
|
||||
* @param PurchaseUnitFactory $purchase_unit_factory The purchase unit factory.
|
||||
* @param ShippingPreferenceFactory $shipping_preference_factory The shipping_preference factory.
|
||||
* @param PayerFactory $payer_factory The payer factory.
|
||||
* @param Environment $environment The environment.
|
||||
* @param Settings $settings The Settings.
|
||||
* @param AuthorizedPaymentsProcessor $authorized_payments_processor The Authorized Payments Processor.
|
||||
* @param FundingSourceRenderer $funding_source_renderer The funding source renderer.
|
||||
* @param LoggerInterface $logger The logger.
|
||||
* @param PaymentTokenRepository $repository The payment token repository.
|
||||
* @param OrderEndpoint $order_endpoint The order endpoint.
|
||||
* @param PurchaseUnitFactory $purchase_unit_factory The purchase unit factory.
|
||||
* @param ShippingPreferenceFactory $shipping_preference_factory The shipping_preference factory.
|
||||
* @param PayerFactory $payer_factory The payer factory.
|
||||
* @param Environment $environment The environment.
|
||||
* @param Settings $settings The Settings.
|
||||
* @param AuthorizedPaymentsProcessor $authorized_payments_processor The Authorized Payments Processor.
|
||||
* @param FundingSourceRenderer $funding_source_renderer The funding source renderer.
|
||||
* @param RealTimeAccountUpdaterHelper $real_time_account_updater_helper Real Time Account Updater helper.
|
||||
*/
|
||||
public function __construct(
|
||||
LoggerInterface $logger,
|
||||
|
@ -140,19 +149,21 @@ class RenewalHandler {
|
|||
Environment $environment,
|
||||
Settings $settings,
|
||||
AuthorizedPaymentsProcessor $authorized_payments_processor,
|
||||
FundingSourceRenderer $funding_source_renderer
|
||||
FundingSourceRenderer $funding_source_renderer,
|
||||
RealTimeAccountUpdaterHelper $real_time_account_updater_helper
|
||||
) {
|
||||
|
||||
$this->logger = $logger;
|
||||
$this->repository = $repository;
|
||||
$this->order_endpoint = $order_endpoint;
|
||||
$this->purchase_unit_factory = $purchase_unit_factory;
|
||||
$this->shipping_preference_factory = $shipping_preference_factory;
|
||||
$this->payer_factory = $payer_factory;
|
||||
$this->environment = $environment;
|
||||
$this->settings = $settings;
|
||||
$this->authorized_payments_processor = $authorized_payments_processor;
|
||||
$this->funding_source_renderer = $funding_source_renderer;
|
||||
$this->logger = $logger;
|
||||
$this->repository = $repository;
|
||||
$this->order_endpoint = $order_endpoint;
|
||||
$this->purchase_unit_factory = $purchase_unit_factory;
|
||||
$this->shipping_preference_factory = $shipping_preference_factory;
|
||||
$this->payer_factory = $payer_factory;
|
||||
$this->environment = $environment;
|
||||
$this->settings = $settings;
|
||||
$this->authorized_payments_processor = $authorized_payments_processor;
|
||||
$this->funding_source_renderer = $funding_source_renderer;
|
||||
$this->real_time_account_updater_helper = $real_time_account_updater_helper;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -248,9 +259,10 @@ class RenewalHandler {
|
|||
}
|
||||
|
||||
if ( $wc_order->get_payment_method() === CreditCardGateway::ID ) {
|
||||
$wc_tokens = WC_Payment_Tokens::get_customer_tokens( $wc_order->get_customer_id(), CreditCardGateway::ID );
|
||||
foreach ( $wc_tokens as $token ) {
|
||||
$payment_source = $this->card_payment_source( $token->get_token(), $wc_order );
|
||||
$wc_tokens = WC_Payment_Tokens::get_customer_tokens( $wc_order->get_customer_id(), CreditCardGateway::ID );
|
||||
$last_token = end( $wc_tokens );
|
||||
if ( $last_token ) {
|
||||
$payment_source = $this->card_payment_source( $last_token->get_token(), $wc_order );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -269,6 +281,17 @@ class RenewalHandler {
|
|||
|
||||
$this->handle_paypal_order( $wc_order, $order );
|
||||
|
||||
if ( $wc_order->get_payment_method() === CreditCardGateway::ID ) {
|
||||
$wc_tokens = WC_Payment_Tokens::get_customer_tokens( $wc_order->get_customer_id(), CreditCardGateway::ID );
|
||||
|
||||
$last_token = end( $wc_tokens );
|
||||
$expiry = $order->payment_source()->properties()->expiry ?? '';
|
||||
$last_digits = $order->payment_source()->properties()->last_digits ?? '';
|
||||
if ( $last_token && $expiry && $last_digits ) {
|
||||
$this->real_time_account_updater_helper->update_wc_card_token( $expiry, $last_digits, $last_token );
|
||||
}
|
||||
}
|
||||
|
||||
$this->logger->info(
|
||||
sprintf(
|
||||
'Renewal for order %d is completed.',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue