Pass the fraud to Authorization

This commit is contained in:
Narek Zakarian 2024-01-30 17:39:21 +04:00
parent 1acf16a878
commit 843917f061
No known key found for this signature in database
GPG key ID: 07AFD7E7A9C164A7
2 changed files with 23 additions and 2 deletions

View file

@ -417,7 +417,7 @@ return array(
return new PaymentsFactory( $authorizations_factory, $capture_factory, $refund_factory ); return new PaymentsFactory( $authorizations_factory, $capture_factory, $refund_factory );
}, },
'api.factory.authorization' => static function ( ContainerInterface $container ): AuthorizationFactory { '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 { 'api.factory.exchange-rate' => static function ( ContainerInterface $container ): ExchangeRateFactory {
return new ExchangeRateFactory(); return new ExchangeRateFactory();

View file

@ -19,6 +19,22 @@ use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
*/ */
class AuthorizationFactory { 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. * Returns an Authorization based off a PayPal response.
* *
@ -42,12 +58,17 @@ class AuthorizationFactory {
$reason = $data->status_details->reason ?? null; $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( return new Authorization(
$data->id, $data->id,
new AuthorizationStatus( new AuthorizationStatus(
$data->status, $data->status,
$reason ? new AuthorizationStatusDetails( $reason ) : null $reason ? new AuthorizationStatusDetails( $reason ) : null
) ),
$fraud_processor_response
); );
} }
} }