mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 10:55:00 +08:00
Merge branch 'trunk' into PCP-3677-pay-pal-subscriptions-api-renewal-order-not-created-in-woo-commerce
This commit is contained in:
commit
7250738e18
3 changed files with 24 additions and 65 deletions
|
@ -1285,17 +1285,12 @@ return array(
|
|||
$container->get( 'wcgateway.processor.refunds' )
|
||||
);
|
||||
},
|
||||
'wcgateway.fraudnet-session-id' => static function ( ContainerInterface $container ): FraudNetSessionId {
|
||||
return new FraudNetSessionId();
|
||||
},
|
||||
'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 {
|
||||
$session_id = $container->get( 'wcgateway.fraudnet-session-id' );
|
||||
$source_website_id = $container->get( 'wcgateway.fraudnet-source-website-id' );
|
||||
return new FraudNet(
|
||||
(string) $session_id(),
|
||||
(string) $source_website_id()
|
||||
);
|
||||
},
|
||||
|
|
|
@ -14,13 +14,6 @@ namespace WooCommerce\PayPalCommerce\WcGateway\FraudNet;
|
|||
*/
|
||||
class FraudNet {
|
||||
|
||||
/**
|
||||
* The session ID.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $session_id;
|
||||
|
||||
/**
|
||||
* The source website ID.
|
||||
*
|
||||
|
@ -31,21 +24,40 @@ class FraudNet {
|
|||
/**
|
||||
* FraudNet constructor.
|
||||
*
|
||||
* @param string $session_id The session ID.
|
||||
* @param string $source_website_id The source website ID.
|
||||
*/
|
||||
public function __construct( string $session_id, string $source_website_id ) {
|
||||
$this->session_id = $session_id;
|
||||
public function __construct( string $source_website_id ) {
|
||||
$this->source_website_id = $source_website_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the session ID.
|
||||
* Returns the Fraudnet session ID.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function session_id(): string {
|
||||
return $this->session_id;
|
||||
if ( WC()->session === null ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$fraudnet_session_id = WC()->session->get( 'ppcp_fraudnet_session_id' );
|
||||
if ( is_string( $fraudnet_session_id ) && $fraudnet_session_id !== '' ) {
|
||||
return $fraudnet_session_id;
|
||||
}
|
||||
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
if ( isset( $_GET['pay_for_order'] ) && $_GET['pay_for_order'] === 'true' ) {
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Missing
|
||||
$pui_pay_for_order_session_id = wc_clean( wp_unslash( $_POST['pui_pay_for_order_session_id'] ?? '' ) );
|
||||
if ( is_string( $pui_pay_for_order_session_id ) && $pui_pay_for_order_session_id !== '' ) {
|
||||
return $pui_pay_for_order_session_id;
|
||||
}
|
||||
}
|
||||
|
||||
$session_id = bin2hex( random_bytes( 16 ) );
|
||||
WC()->session->set( 'ppcp_fraudnet_session_id', $session_id );
|
||||
|
||||
return $session_id;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,48 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Fraudnet session id.
|
||||
*
|
||||
* @package WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\WcGateway\FraudNet;
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* Class FraudNetSessionId.
|
||||
*/
|
||||
class FraudNetSessionId {
|
||||
|
||||
/**
|
||||
* Generates a session ID or use the existing one from WC session.
|
||||
*
|
||||
* @return array|string
|
||||
* @throws Exception When there is a problem with the session ID.
|
||||
*/
|
||||
public function __invoke() {
|
||||
if ( WC()->session === null ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if ( WC()->session->get( 'ppcp_fraudnet_session_id' ) ) {
|
||||
return WC()->session->get( 'ppcp_fraudnet_session_id' );
|
||||
}
|
||||
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
if ( isset( $_GET['pay_for_order'] ) && 'true' === $_GET['pay_for_order'] ) {
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Missing
|
||||
$pui_pay_for_order_session_id = wc_clean( wp_unslash( $_POST['pui_pay_for_order_session_id'] ?? '' ) );
|
||||
if ( $pui_pay_for_order_session_id && '' !== $pui_pay_for_order_session_id ) {
|
||||
return $pui_pay_for_order_session_id;
|
||||
}
|
||||
}
|
||||
|
||||
$session_id = bin2hex( random_bytes( 16 ) );
|
||||
WC()->session->set( 'ppcp_fraudnet_session_id', $session_id );
|
||||
|
||||
return $session_id;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue