Add FraudNet header when creating order.

This commit is contained in:
Narek Zakarian 2022-11-29 19:31:58 +04:00
parent 8d74fcdf17
commit 50e18c1518
No known key found for this signature in database
GPG key ID: 07AFD7E7A9C164A7
5 changed files with 109 additions and 24 deletions

View file

@ -198,7 +198,9 @@ return array(
$logger,
$application_context_repository,
$paypal_request_id,
$subscription_helper
$subscription_helper,
$container->get( 'wcgateway.is-fraudnet-enabled' ),
$container->get( 'wcgateway.fraudnet' )
);
},
'api.endpoint.billing-agreements' => static function ( ContainerInterface $container ): BillingAgreementsEndpoint {

View file

@ -29,6 +29,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Repository\ApplicationContextRepository
use WooCommerce\PayPalCommerce\ApiClient\Repository\PayPalRequestIdRepository;
use Psr\Log\LoggerInterface;
use WooCommerce\PayPalCommerce\Subscription\Helper\SubscriptionHelper;
use WooCommerce\PayPalCommerce\WcGateway\FraudNet\FraudNet;
use WP_Error;
/**
@ -101,6 +102,13 @@ class OrderEndpoint {
*/
protected $is_fraudnet_enabled;
/**
* The FrauNet entity.
*
* @var FraudNet
*/
protected $fraudnet;
/**
* The BN Code.
*
@ -128,6 +136,7 @@ class OrderEndpoint {
* @param PayPalRequestIdRepository $paypal_request_id_repository The paypal request id repository.
* @param SubscriptionHelper $subscription_helper The subscription helper.
* @param bool $is_fraudnet_enabled true if FraudNet support is enabled in settings, otherwise false.
* @param FraudNet $fraudnet The FrauNet entity.
* @param string $bn_code The BN Code.
*/
public function __construct(
@ -141,6 +150,7 @@ class OrderEndpoint {
PayPalRequestIdRepository $paypal_request_id_repository,
SubscriptionHelper $subscription_helper,
bool $is_fraudnet_enabled,
FraudNet $fraudnet,
string $bn_code = ''
) {
@ -155,6 +165,7 @@ class OrderEndpoint {
$this->paypal_request_id_repository = $paypal_request_id_repository;
$this->is_fraudnet_enabled = $is_fraudnet_enabled;
$this->subscription_helper = $subscription_helper;
$this->fraudnet = $fraudnet;
}
/**
@ -234,6 +245,11 @@ class OrderEndpoint {
if ( $this->bn_code ) {
$args['headers']['PayPal-Partner-Attribution-Id'] = $this->bn_code;
}
if ( $this->is_fraudnet_enabled ) {
$args['headers']['PayPal-Client-Metadata-Id'] = $this->fraudnet->session_id();
}
$response = $this->request( $url, $args );
if ( is_wp_error( $response ) ) {
$error = new RuntimeException(

View file

@ -84,6 +84,8 @@ return array(
$application_context_repository,
$pay_pal_request_id_repository,
$subscription_helper,
$container->get( 'wcgateway.is-fraudnet-enabled' ),
$container->get( 'wcgateway.fraudnet' ),
$bn_code
);
},

View file

@ -1594,13 +1594,13 @@ return array(
$container->get( 'wcgateway.processor.refunds' )
);
},
'wcgateway.fraudnet-session-id' => static function ( ContainerInterface $container ): FraudNetSessionId {
'wcgateway.fraudnet-session-id' => static function ( ContainerInterface $container ): FraudNetSessionId {
return new FraudNetSessionId();
},
'wcgateway.fraudnet-source-website-id' => static function ( ContainerInterface $container ): FraudNetSourceWebsiteId {
'wcgateway.fraudnet-source-website-id' => static function ( ContainerInterface $container ): FraudNetSourceWebsiteId {
return new FraudNetSourceWebsiteId( $container->get( 'api.merchant_id' ) );
},
'wcgateway.fraudnet' => static function ( ContainerInterface $container ): FraudNet {
'wcgateway.fraudnet' => static function ( ContainerInterface $container ): FraudNet {
$session_id = $container->get( 'wcgateway.fraudnet-session-id' );
$source_website_id = $container->get( 'wcgateway.fraudnet-source-website-id' );
return new FraudNet(
@ -1980,17 +1980,17 @@ return array(
}
return $context;
},
'wcgateway.is-fraudnet-enabled' => static function ( ContainerInterface $container ): bool {
$settings = $container->get( 'wcgateway.settings' );
assert($settings instanceof Settings);
'wcgateway.is-fraudnet-enabled' => static function ( ContainerInterface $container ): bool {
$settings = $container->get( 'wcgateway.settings' );
assert( $settings instanceof Settings );
return $settings->has( 'fraudnet_enabled' ) && $settings->get( 'fraudnet_enabled' );
},
return $settings->has( 'fraudnet_enabled' ) && $settings->get( 'fraudnet_enabled' );
},
'wcgateway.fraudnet-assets' => function( ContainerInterface $container ) : FraudNetAssets {
return new FraudNetAssets(
$container->get( 'wcgateway.url' ),
$container->get( 'ppcp.asset-version' ),
$container->get( 'wcgateway.pay-upon-invoice-fraudnet' ),
$container->get( 'wcgateway.fraudnet' ),
$container->get( 'onboarding.environment' ),
$container->get( 'wcgateway.settings' ),
$container->get( 'wcgateway.enabled-ppcp-gateways' ),