mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-08-30 05:00:51 +08:00
Add FraudNet header when creating order.
This commit is contained in:
parent
8d74fcdf17
commit
50e18c1518
5 changed files with 109 additions and 24 deletions
|
@ -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 {
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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
|
||||
);
|
||||
},
|
||||
|
|
|
@ -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' ),
|
||||
|
|
|
@ -29,6 +29,7 @@ use Mockery;
|
|||
use Psr\Log\LoggerInterface;
|
||||
use WooCommerce\PayPalCommerce\Subscription\Helper\SubscriptionHelper;
|
||||
use WooCommerce\PayPalCommerce\TestCase;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\FraudNet\FraudNet;
|
||||
use function Brain\Monkey\Functions\expect;
|
||||
use function Brain\Monkey\Functions\when;
|
||||
|
||||
|
@ -74,6 +75,8 @@ class OrderEndpointTest extends TestCase
|
|||
$headers->shouldReceive('getAll');
|
||||
$subscription_helper = Mockery::mock(SubscriptionHelper::class);
|
||||
|
||||
$fraudnet = Mockery::mock(FraudNet::class);
|
||||
|
||||
$testee = new OrderEndpoint(
|
||||
$host,
|
||||
$bearer,
|
||||
|
@ -83,7 +86,9 @@ class OrderEndpointTest extends TestCase
|
|||
$logger,
|
||||
$applicationContextRepository,
|
||||
$paypalRequestIdRepository,
|
||||
$subscription_helper
|
||||
$subscription_helper,
|
||||
false,
|
||||
$fraudnet
|
||||
);
|
||||
|
||||
$rawResponse = [
|
||||
|
@ -135,6 +140,8 @@ class OrderEndpointTest extends TestCase
|
|||
$headers->shouldReceive('getAll');
|
||||
$subscription_helper = Mockery::mock(SubscriptionHelper::class);
|
||||
|
||||
$fraudnet = Mockery::mock(FraudNet::class);
|
||||
|
||||
$testee = new OrderEndpoint(
|
||||
$host,
|
||||
$bearer,
|
||||
|
@ -144,7 +151,9 @@ class OrderEndpointTest extends TestCase
|
|||
$logger,
|
||||
$applicationContextRepository,
|
||||
$paypalRequestIdRepository,
|
||||
$subscription_helper
|
||||
$subscription_helper,
|
||||
false,
|
||||
$fraudnet
|
||||
);
|
||||
|
||||
$rawResponse = [
|
||||
|
@ -187,6 +196,8 @@ class OrderEndpointTest extends TestCase
|
|||
->expects('get_for_order_id')->with($orderId)->andReturn('uniqueRequestId');
|
||||
$subscription_helper = Mockery::mock(SubscriptionHelper::class);
|
||||
|
||||
$fraudnet = Mockery::mock(FraudNet::class);
|
||||
|
||||
$testee = new OrderEndpoint(
|
||||
$host,
|
||||
$bearer,
|
||||
|
@ -196,7 +207,9 @@ class OrderEndpointTest extends TestCase
|
|||
$logger,
|
||||
$applicationContextRepository,
|
||||
$paypalRequestIdRepository,
|
||||
$subscription_helper
|
||||
$subscription_helper,
|
||||
false,
|
||||
$fraudnet
|
||||
);
|
||||
|
||||
expect('wp_remote_get')->andReturn($rawResponse);
|
||||
|
@ -253,6 +266,8 @@ class OrderEndpointTest extends TestCase
|
|||
->expects('get_for_order')->with($orderToCapture)->andReturn('uniqueRequestId');
|
||||
$subscription_helper = Mockery::mock(SubscriptionHelper::class);
|
||||
|
||||
$fraudnet = Mockery::mock(FraudNet::class);
|
||||
|
||||
$testee = new OrderEndpoint(
|
||||
$host,
|
||||
$bearer,
|
||||
|
@ -262,7 +277,9 @@ class OrderEndpointTest extends TestCase
|
|||
$logger,
|
||||
$applicationContextRepository,
|
||||
$paypalRequestIdRepository,
|
||||
$subscription_helper
|
||||
$subscription_helper,
|
||||
false,
|
||||
$fraudnet
|
||||
);
|
||||
|
||||
expect('wp_remote_get')
|
||||
|
@ -320,6 +337,8 @@ class OrderEndpointTest extends TestCase
|
|||
$paypalRequestIdRepository = Mockery::mock(PayPalRequestIdRepository::class);
|
||||
$subscription_helper = Mockery::mock(SubscriptionHelper::class);
|
||||
|
||||
$fraudnet = Mockery::mock(FraudNet::class);
|
||||
|
||||
$testee = new OrderEndpoint(
|
||||
$host,
|
||||
$bearer,
|
||||
|
@ -329,7 +348,9 @@ class OrderEndpointTest extends TestCase
|
|||
$logger,
|
||||
$applicationContextRepository,
|
||||
$paypalRequestIdRepository,
|
||||
$subscription_helper
|
||||
$subscription_helper,
|
||||
false,
|
||||
$fraudnet
|
||||
);
|
||||
|
||||
$result = $testee->capture($orderToCapture);
|
||||
|
@ -365,6 +386,8 @@ class OrderEndpointTest extends TestCase
|
|||
->expects('get_for_order')->with($orderToCapture)->andReturn('uniqueRequestId');
|
||||
$subscription_helper = Mockery::mock(SubscriptionHelper::class);
|
||||
|
||||
$fraudnet = Mockery::mock(FraudNet::class);
|
||||
|
||||
$testee = new OrderEndpoint(
|
||||
$host,
|
||||
$bearer,
|
||||
|
@ -374,7 +397,9 @@ class OrderEndpointTest extends TestCase
|
|||
$logger,
|
||||
$applicationContextRepository,
|
||||
$paypalRequestIdRepository,
|
||||
$subscription_helper
|
||||
$subscription_helper,
|
||||
false,
|
||||
$fraudnet
|
||||
);
|
||||
$headers = Mockery::mock(Requests_Utility_CaseInsensitiveDictionary::class);
|
||||
$headers->shouldReceive('getAll');
|
||||
|
@ -417,6 +442,8 @@ class OrderEndpointTest extends TestCase
|
|||
->expects('get_for_order')->with($orderToCapture)->andReturn('uniqueRequestId');
|
||||
$subscription_helper = Mockery::mock(SubscriptionHelper::class);
|
||||
|
||||
$fraudnet = Mockery::mock(FraudNet::class);
|
||||
|
||||
$testee = new OrderEndpoint(
|
||||
$host,
|
||||
$bearer,
|
||||
|
@ -426,7 +453,9 @@ class OrderEndpointTest extends TestCase
|
|||
$logger,
|
||||
$applicationContextRepository,
|
||||
$paypalRequestIdRepository,
|
||||
$subscription_helper
|
||||
$subscription_helper,
|
||||
false,
|
||||
$fraudnet
|
||||
);
|
||||
|
||||
$headers = Mockery::mock(Requests_Utility_CaseInsensitiveDictionary::class);
|
||||
|
@ -471,6 +500,8 @@ class OrderEndpointTest extends TestCase
|
|||
->expects('get_for_order')->with($orderToCapture)->andReturn('uniqueRequestId');
|
||||
$subscription_helper = Mockery::mock(SubscriptionHelper::class);
|
||||
|
||||
$fraudnet = Mockery::mock(FraudNet::class);
|
||||
|
||||
$testee = Mockery::mock(
|
||||
OrderEndpoint::class,
|
||||
[
|
||||
|
@ -483,6 +514,8 @@ class OrderEndpointTest extends TestCase
|
|||
$applicationContextRepository,
|
||||
$paypalRequestIdRepository,
|
||||
$subscription_helper,
|
||||
false,
|
||||
$fraudnet
|
||||
]
|
||||
)->makePartial();
|
||||
$orderToExpect = Mockery::mock(Order::class);
|
||||
|
@ -551,6 +584,8 @@ class OrderEndpointTest extends TestCase
|
|||
->expects('get_for_order')->with($orderToUpdate)->andReturn('uniqueRequestId');
|
||||
$subscription_helper = Mockery::mock(SubscriptionHelper::class);
|
||||
|
||||
$fraudnet = Mockery::mock(FraudNet::class);
|
||||
|
||||
$testee = Mockery::mock(
|
||||
OrderEndpoint::class,
|
||||
[
|
||||
|
@ -563,6 +598,8 @@ class OrderEndpointTest extends TestCase
|
|||
$applicationContextRepository,
|
||||
$paypalRequestIdRepository,
|
||||
$subscription_helper,
|
||||
false,
|
||||
$fraudnet
|
||||
]
|
||||
)->makePartial();
|
||||
$testee
|
||||
|
@ -656,6 +693,8 @@ class OrderEndpointTest extends TestCase
|
|||
->expects('get_for_order')->with($orderToUpdate)->andReturn('uniqueRequestId');
|
||||
$subscription_helper = Mockery::mock(SubscriptionHelper::class);
|
||||
|
||||
$fraudnet = Mockery::mock(FraudNet::class);
|
||||
|
||||
$testee = new OrderEndpoint(
|
||||
$host,
|
||||
$bearer,
|
||||
|
@ -665,7 +704,9 @@ class OrderEndpointTest extends TestCase
|
|||
$logger,
|
||||
$applicationContextRepository,
|
||||
$paypalRequestIdRepository,
|
||||
$subscription_helper
|
||||
$subscription_helper,
|
||||
false,
|
||||
$fraudnet
|
||||
);
|
||||
|
||||
expect('wp_remote_get')
|
||||
|
@ -755,6 +796,8 @@ class OrderEndpointTest extends TestCase
|
|||
->expects('get_for_order')->with($orderToUpdate)->andReturn('uniqueRequestId');
|
||||
$subscription_helper = Mockery::mock(SubscriptionHelper::class);
|
||||
|
||||
$fraudnet = Mockery::mock(FraudNet::class);
|
||||
|
||||
$testee = Mockery::mock(
|
||||
OrderEndpoint::class,
|
||||
[
|
||||
|
@ -766,7 +809,9 @@ class OrderEndpointTest extends TestCase
|
|||
$logger,
|
||||
$applicationContextRepository,
|
||||
$paypalRequestIdRepository,
|
||||
$subscription_helper
|
||||
$subscription_helper,
|
||||
false,
|
||||
$fraudnet
|
||||
]
|
||||
)->makePartial();
|
||||
|
||||
|
@ -831,6 +876,8 @@ class OrderEndpointTest extends TestCase
|
|||
$paypalRequestIdRepository = Mockery::mock(PayPalRequestIdRepository::class);
|
||||
$subscription_helper = Mockery::mock(SubscriptionHelper::class);
|
||||
|
||||
$fraudnet = Mockery::mock(FraudNet::class);
|
||||
|
||||
$testee = new OrderEndpoint(
|
||||
$host,
|
||||
$bearer,
|
||||
|
@ -840,7 +887,9 @@ class OrderEndpointTest extends TestCase
|
|||
$logger,
|
||||
$applicationContextRepository,
|
||||
$paypalRequestIdRepository,
|
||||
$subscription_helper
|
||||
$subscription_helper,
|
||||
false,
|
||||
$fraudnet
|
||||
);
|
||||
|
||||
$result = $testee->patch_order_with($orderToUpdate, $orderToCompare);
|
||||
|
@ -901,6 +950,8 @@ class OrderEndpointTest extends TestCase
|
|||
$subscription_helper = Mockery::mock(SubscriptionHelper::class);
|
||||
$subscription_helper->shouldReceive('cart_contains_subscription')->andReturn(true);
|
||||
|
||||
$fraudnet = Mockery::mock(FraudNet::class);
|
||||
|
||||
$testee = new OrderEndpoint(
|
||||
$host,
|
||||
$bearer,
|
||||
|
@ -910,7 +961,9 @@ class OrderEndpointTest extends TestCase
|
|||
$logger,
|
||||
$applicationContextRepository,
|
||||
$paypalRequestIdRepository,
|
||||
$subscription_helper
|
||||
$subscription_helper,
|
||||
false,
|
||||
$fraudnet
|
||||
);
|
||||
|
||||
$purchaseUnit = Mockery::mock(PurchaseUnit::class, ['contains_physical_goods' => false]);
|
||||
|
@ -1010,6 +1063,8 @@ class OrderEndpointTest extends TestCase
|
|||
$subscription_helper = Mockery::mock(SubscriptionHelper::class);
|
||||
$subscription_helper->shouldReceive('cart_contains_subscription')->andReturn(true);
|
||||
|
||||
$fraudnet = Mockery::mock(FraudNet::class);
|
||||
|
||||
$testee = new OrderEndpoint(
|
||||
$host,
|
||||
$bearer,
|
||||
|
@ -1019,7 +1074,9 @@ class OrderEndpointTest extends TestCase
|
|||
$logger,
|
||||
$applicationContextRepository,
|
||||
$paypalRequestIdRepository,
|
||||
$subscription_helper
|
||||
$subscription_helper,
|
||||
false,
|
||||
$fraudnet
|
||||
);
|
||||
|
||||
$purchaseUnit = Mockery::mock(PurchaseUnit::class, ['contains_physical_goods' => true]);
|
||||
|
@ -1088,6 +1145,8 @@ class OrderEndpointTest extends TestCase
|
|||
$subscription_helper = Mockery::mock(SubscriptionHelper::class);
|
||||
$subscription_helper->shouldReceive('cart_contains_subscription')->andReturn(true);
|
||||
|
||||
$fraudnet = Mockery::mock(FraudNet::class);
|
||||
|
||||
$testee = new OrderEndpoint(
|
||||
$host,
|
||||
$bearer,
|
||||
|
@ -1097,7 +1156,9 @@ class OrderEndpointTest extends TestCase
|
|||
$logger,
|
||||
$applicationContextRepository,
|
||||
$paypalRequestIdRepository,
|
||||
$subscription_helper
|
||||
$subscription_helper,
|
||||
false,
|
||||
$fraudnet
|
||||
);
|
||||
|
||||
$purchaseUnit = Mockery::mock(PurchaseUnit::class, ['contains_physical_goods' => false]);
|
||||
|
@ -1177,6 +1238,8 @@ class OrderEndpointTest extends TestCase
|
|||
$subscription_helper = Mockery::mock(SubscriptionHelper::class);
|
||||
$subscription_helper->shouldReceive('cart_contains_subscription')->andReturn(true);
|
||||
|
||||
$fraudnet = Mockery::mock(FraudNet::class);
|
||||
|
||||
$testee = new OrderEndpoint(
|
||||
$host,
|
||||
$bearer,
|
||||
|
@ -1186,7 +1249,9 @@ class OrderEndpointTest extends TestCase
|
|||
$logger,
|
||||
$applicationContextRepository,
|
||||
$paypalRequestIdRepository,
|
||||
$subscription_helper
|
||||
$subscription_helper,
|
||||
false,
|
||||
$fraudnet
|
||||
);
|
||||
|
||||
$purchaseUnit = Mockery::mock(PurchaseUnit::class, ['contains_physical_goods' => true]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue