From 843917f061ae3e7553e8c018bd38524fd18b9f2a Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Tue, 30 Jan 2024 17:39:21 +0400 Subject: [PATCH] Pass the fraud to Authorization --- modules/ppcp-api-client/services.php | 2 +- .../src/Factory/AuthorizationFactory.php | 23 ++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/modules/ppcp-api-client/services.php b/modules/ppcp-api-client/services.php index be2872c3d..12e218387 100644 --- a/modules/ppcp-api-client/services.php +++ b/modules/ppcp-api-client/services.php @@ -417,7 +417,7 @@ return array( return new PaymentsFactory( $authorizations_factory, $capture_factory, $refund_factory ); }, 'api.factory.authorization' => static function ( ContainerInterface $container ): AuthorizationFactory { - return new AuthorizationFactory(); + return new AuthorizationFactory( $container->get( 'api.factory.fraud-processor-response' ) ); }, 'api.factory.exchange-rate' => static function ( ContainerInterface $container ): ExchangeRateFactory { return new ExchangeRateFactory(); diff --git a/modules/ppcp-api-client/src/Factory/AuthorizationFactory.php b/modules/ppcp-api-client/src/Factory/AuthorizationFactory.php index c65e764af..d16aee2fb 100644 --- a/modules/ppcp-api-client/src/Factory/AuthorizationFactory.php +++ b/modules/ppcp-api-client/src/Factory/AuthorizationFactory.php @@ -19,6 +19,22 @@ use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException; */ class AuthorizationFactory { + /** + * The FraudProcessorResponseFactory factory. + * + * @var FraudProcessorResponseFactory + */ + protected $fraud_processor_response_factory; + + /** + * AuthorizationFactory constructor. + * + * @param FraudProcessorResponseFactory $fraud_processor_response_factory The FraudProcessorResponseFactory factory. + */ + public function __construct( FraudProcessorResponseFactory $fraud_processor_response_factory ) { + $this->fraud_processor_response_factory = $fraud_processor_response_factory; + } + /** * Returns an Authorization based off a PayPal response. * @@ -42,12 +58,17 @@ class AuthorizationFactory { $reason = $data->status_details->reason ?? null; + $fraud_processor_response = isset( $data->processor_response ) ? + $this->fraud_processor_response_factory->from_paypal_response( $data->processor_response ) + : null; + return new Authorization( $data->id, new AuthorizationStatus( $data->status, $reason ? new AuthorizationStatusDetails( $reason ) : null - ) + ), + $fraud_processor_response ); } }