Log 3DS authentication result

This commit is contained in:
dinamiko 2021-09-21 11:34:16 +02:00
parent 66c4c2f0a8
commit ead6858a51
4 changed files with 25 additions and 5 deletions

View file

@ -112,7 +112,7 @@ class CardAuthenticationResult {
$data['liability_shift'] = $this->liability_shift(); $data['liability_shift'] = $this->liability_shift();
$data['three_d_secure'] = array( $data['three_d_secure'] = array(
'enrollment_status' => $this->enrollment_status(), 'enrollment_status' => $this->enrollment_status(),
'authentication_result' => $this->authentication_result(), 'authentication_status' => $this->authentication_result(),
); );
return $data; return $data;
} }

View file

@ -37,8 +37,8 @@ class PaymentSourceFactory {
(string) $data->card->authentication_result->liability_shift : '', (string) $data->card->authentication_result->liability_shift : '',
isset( $data->card->authentication_result->three_d_secure->enrollment_status ) ? isset( $data->card->authentication_result->three_d_secure->enrollment_status ) ?
(string) $data->card->authentication_result->three_d_secure->enrollment_status : '', (string) $data->card->authentication_result->three_d_secure->enrollment_status : '',
isset( $data->card->authentication_result->three_d_secure->authentication_result ) ? isset( $data->card->authentication_result->three_d_secure->authentication_status ) ?
(string) $data->card->authentication_result->three_d_secure->authentication_result : '' (string) $data->card->authentication_result->three_d_secure->authentication_status : ''
); );
} }
$card = new PaymentSourceCard( $card = new PaymentSourceCard(

View file

@ -159,7 +159,8 @@ return array(
); );
}, },
'button.helper.three-d-secure' => static function ( $container ): ThreeDSecure { 'button.helper.three-d-secure' => static function ( $container ): ThreeDSecure {
return new ThreeDSecure(); $logger = $container->get( 'woocommerce.logger.woocommerce' );
return new ThreeDSecure( $logger );
}, },
'button.helper.messages-apply' => static function ( $container ): MessagesApply { 'button.helper.messages-apply' => static function ( $container ): MessagesApply {
return new MessagesApply(); return new MessagesApply();

View file

@ -9,6 +9,7 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\Button\Helper; namespace WooCommerce\PayPalCommerce\Button\Helper;
use Psr\Log\LoggerInterface;
use WooCommerce\PayPalCommerce\ApiClient\Entity\CardAuthenticationResult as AuthResult; use WooCommerce\PayPalCommerce\ApiClient\Entity\CardAuthenticationResult as AuthResult;
use WooCommerce\PayPalCommerce\ApiClient\Entity\Order; use WooCommerce\PayPalCommerce\ApiClient\Entity\Order;
@ -17,12 +18,27 @@ use WooCommerce\PayPalCommerce\ApiClient\Entity\Order;
*/ */
class ThreeDSecure { class ThreeDSecure {
const NO_DECISION = 0; const NO_DECISION = 0;
const PROCCEED = 1; const PROCCEED = 1;
const REJECT = 2; const REJECT = 2;
const RETRY = 3; const RETRY = 3;
/**
* The logger.
*
* @var LoggerInterface
*/
protected $logger;
/**
* ThreeDSecure constructor.
*
* @param LoggerInterface $logger The logger.
*/
public function __construct( LoggerInterface $logger ) {
$this->logger = $logger;
}
/** /**
* Determine, how we proceed with a given order. * Determine, how we proceed with a given order.
* *
@ -42,7 +58,10 @@ class ThreeDSecure {
if ( ! $order->payment_source()->card()->authentication_result() ) { if ( ! $order->payment_source()->card()->authentication_result() ) {
return self::NO_DECISION; return self::NO_DECISION;
} }
$result = $order->payment_source()->card()->authentication_result(); $result = $order->payment_source()->card()->authentication_result();
$this->logger->info( '3DS authentication result: ' . wc_print_r( $result->to_array(), true ) );
if ( $result->liability_shift() === AuthResult::LIABILITY_SHIFT_POSSIBLE ) { if ( $result->liability_shift() === AuthResult::LIABILITY_SHIFT_POSSIBLE ) {
return self::PROCCEED; return self::PROCCEED;
} }