Add sca indicators and card update to card subscription renewals

This commit is contained in:
Emili Castells Guasch 2024-02-13 14:26:58 +01:00
parent 36e3d261f6
commit 9948b648e0
5 changed files with 62 additions and 56 deletions

View file

@ -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',

View file

@ -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 );