mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-03 08:37:53 +08:00
Refactor FraudNet namespace, isn't related specially to PUI
This commit is contained in:
parent
fe6c61584b
commit
6045c3855b
8 changed files with 121 additions and 107 deletions
|
@ -38,9 +38,9 @@ use WooCommerce\PayPalCommerce\WcGateway\Gateway\OXXO\OXXO;
|
|||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\OXXO\OXXOEndpoint;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\OXXO\OXXOGateway;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\FraudNet;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\FraudNetSessionId;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\FraudNetSourceWebsiteId;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\FraudNet\FraudNet;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\FraudNet\FraudNetSessionId;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\FraudNet\FraudNetSourceWebsiteId;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\PaymentSourceFactory;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\PayUponInvoice;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\PayUponInvoiceGateway;
|
||||
|
@ -1621,21 +1621,15 @@ return array(
|
|||
},
|
||||
'wcgateway.pay-upon-invoice' => static function ( ContainerInterface $container ): PayUponInvoice {
|
||||
return new PayUponInvoice(
|
||||
$container->get( 'wcgateway.url' ),
|
||||
$container->get( 'wcgateway.pay-upon-invoice-fraudnet' ),
|
||||
$container->get( 'wcgateway.pay-upon-invoice-order-endpoint' ),
|
||||
$container->get( 'woocommerce.logger.woocommerce' ),
|
||||
$container->get( 'wcgateway.settings' ),
|
||||
$container->get( 'onboarding.environment' ),
|
||||
$container->get( 'ppcp.asset-version' ),
|
||||
$container->get( 'onboarding.state' ),
|
||||
$container->get( 'wcgateway.is-ppcp-settings-page' ),
|
||||
$container->get( 'wcgateway.current-ppcp-settings-page-id' ),
|
||||
$container->get( 'wcgateway.pay-upon-invoice-product-status' ),
|
||||
$container->get( 'wcgateway.pay-upon-invoice-helper' ),
|
||||
$container->get( 'wcgateway.checkout-helper' ),
|
||||
$container->get( 'api.factory.capture' ),
|
||||
$container->get( 'session.handler' )
|
||||
$container->get( 'api.factory.capture' )
|
||||
);
|
||||
},
|
||||
'wcgateway.oxxo' => static function( ContainerInterface $container ): OXXO {
|
||||
|
|
111
modules/ppcp-wc-gateway/src/Assets/FraudNetAssets.php
Normal file
111
modules/ppcp-wc-gateway/src/Assets/FraudNetAssets.php
Normal file
|
@ -0,0 +1,111 @@
|
|||
<?php
|
||||
/**
|
||||
* Register and configure assets provided by this module.
|
||||
*
|
||||
* @package WooCommerce\PayPalCommerce\WcGateway\Assets
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\WcGateway\Assets;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Onboarding\Environment;
|
||||
use WooCommerce\PayPalCommerce\Session\SessionHandler;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\FraudNet\FraudNet;
|
||||
|
||||
/**
|
||||
* Class SettingsPageAssets
|
||||
*/
|
||||
class FraudNetAssets {
|
||||
|
||||
/**
|
||||
* The URL of this module.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $module_url;
|
||||
|
||||
/**
|
||||
* The assets version.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $version;
|
||||
|
||||
/**
|
||||
* The session handler.
|
||||
*
|
||||
* @var SessionHandler
|
||||
*/
|
||||
protected $session_handler;
|
||||
|
||||
/**
|
||||
* The FraudNet entity.
|
||||
*
|
||||
* @var FraudNet
|
||||
*/
|
||||
protected $fraud_net;
|
||||
|
||||
/**
|
||||
* The environment.
|
||||
*
|
||||
* @var Environment
|
||||
*/
|
||||
protected $environment;
|
||||
|
||||
/**
|
||||
* Assets constructor.
|
||||
*
|
||||
* @param string $module_url The url of this module.
|
||||
* @param string $version The assets version.
|
||||
* @param SessionHandler $session_handler The session handler.
|
||||
* @param FraudNet $fraud_net The FraudNet entity.
|
||||
* @param Environment $environment The environment.
|
||||
*/
|
||||
public function __construct(
|
||||
string $module_url,
|
||||
string $version,
|
||||
SessionHandler $session_handler,
|
||||
FraudNet $fraud_net,
|
||||
Environment $environment
|
||||
) {
|
||||
$this->module_url = $module_url;
|
||||
$this->version = $version;
|
||||
$this->fraud_net = $fraud_net;
|
||||
$this->session_handler = $session_handler;
|
||||
$this->environment = $environment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register assets provided by this module.
|
||||
*/
|
||||
public function register_assets() {
|
||||
add_action(
|
||||
'wp_enqueue_scripts',
|
||||
function() {
|
||||
$gateway_settings = get_option( 'woocommerce_ppcp-pay-upon-invoice-gateway_settings' );
|
||||
$gateway_enabled = $gateway_settings['enabled'] ?? '';
|
||||
if ( $gateway_enabled === 'yes' && ! $this->session_handler->order() && ( is_checkout() || is_checkout_pay_page() ) ) {
|
||||
wp_enqueue_script(
|
||||
'ppcp-pay-upon-invoice',
|
||||
trailingslashit( $this->module_url ) . 'assets/js/pay-upon-invoice.js',
|
||||
array(),
|
||||
$this->version,
|
||||
true
|
||||
);
|
||||
|
||||
wp_localize_script(
|
||||
'ppcp-pay-upon-invoice',
|
||||
'FraudNetConfig',
|
||||
array(
|
||||
'f' => $this->fraud_net->session_id(),
|
||||
's' => $this->fraud_net->source_website_id(),
|
||||
'sandbox' => $this->environment->current_environment_is( Environment::SANDBOX ),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
}
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice;
|
||||
namespace WooCommerce\PayPalCommerce\WcGateway\FraudNet;
|
||||
|
||||
/**
|
||||
* Class FraudNet
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice;
|
||||
namespace WooCommerce\PayPalCommerce\WcGateway\FraudNet;
|
||||
|
||||
use Exception;
|
||||
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice;
|
||||
namespace WooCommerce\PayPalCommerce\WcGateway\FraudNet;
|
||||
|
||||
/**
|
||||
* Class FraudNetSourceWebsiteId.
|
|
@ -17,6 +17,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Factory\CaptureFactory;
|
|||
use WooCommerce\PayPalCommerce\Button\Exception\RuntimeException;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\Environment;
|
||||
use WooCommerce\PayPalCommerce\Session\SessionHandler;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\FraudNet\FraudNet;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Helper\CheckoutHelper;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Helper\PayUponInvoiceHelper;
|
||||
|
@ -34,20 +35,6 @@ class PayUponInvoice {
|
|||
|
||||
use TransactionIdHandlingTrait;
|
||||
|
||||
/**
|
||||
* The module URL.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $module_url;
|
||||
|
||||
/**
|
||||
* The FraudNet entity.
|
||||
*
|
||||
* @var FraudNet
|
||||
*/
|
||||
protected $fraud_net;
|
||||
|
||||
/**
|
||||
* The pui order endpoint.
|
||||
*
|
||||
|
@ -69,20 +56,6 @@ class PayUponInvoice {
|
|||
*/
|
||||
protected $settings;
|
||||
|
||||
/**
|
||||
* The environment.
|
||||
*
|
||||
* @var Environment
|
||||
*/
|
||||
protected $environment;
|
||||
|
||||
/**
|
||||
* The asset version.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $asset_version;
|
||||
|
||||
/**
|
||||
* The PUI helper.
|
||||
*
|
||||
|
@ -97,13 +70,6 @@ class PayUponInvoice {
|
|||
*/
|
||||
protected $state;
|
||||
|
||||
/**
|
||||
* Whether the current page is the PPCP settings page.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $is_ppcp_settings_page;
|
||||
|
||||
/**
|
||||
* Current PayPal settings page id.
|
||||
*
|
||||
|
@ -132,64 +98,39 @@ class PayUponInvoice {
|
|||
*/
|
||||
protected $capture_factory;
|
||||
|
||||
/**
|
||||
* The session handler
|
||||
*
|
||||
* @var SessionHandler
|
||||
*/
|
||||
protected $session_handler;
|
||||
|
||||
/**
|
||||
* PayUponInvoice constructor.
|
||||
*
|
||||
* @param string $module_url The module URL.
|
||||
* @param FraudNet $fraud_net The FraudNet entity.
|
||||
* @param PayUponInvoiceOrderEndpoint $pui_order_endpoint The PUI order endpoint.
|
||||
* @param LoggerInterface $logger The logger.
|
||||
* @param Settings $settings The settings.
|
||||
* @param Environment $environment The environment.
|
||||
* @param string $asset_version The asset version.
|
||||
* @param State $state The onboarding state.
|
||||
* @param bool $is_ppcp_settings_page Whether page is PayPal settings poge.
|
||||
* @param string $current_ppcp_settings_page_id Current PayPal settings page id.
|
||||
* @param PayUponInvoiceProductStatus $pui_product_status The PUI product status.
|
||||
* @param PayUponInvoiceHelper $pui_helper The PUI helper.
|
||||
* @param CheckoutHelper $checkout_helper The checkout helper.
|
||||
* @param CaptureFactory $capture_factory The capture factory.
|
||||
* @param SessionHandler $session_handler The session handler.
|
||||
*/
|
||||
public function __construct(
|
||||
string $module_url,
|
||||
FraudNet $fraud_net,
|
||||
PayUponInvoiceOrderEndpoint $pui_order_endpoint,
|
||||
LoggerInterface $logger,
|
||||
Settings $settings,
|
||||
Environment $environment,
|
||||
string $asset_version,
|
||||
State $state,
|
||||
bool $is_ppcp_settings_page,
|
||||
string $current_ppcp_settings_page_id,
|
||||
PayUponInvoiceProductStatus $pui_product_status,
|
||||
PayUponInvoiceHelper $pui_helper,
|
||||
CheckoutHelper $checkout_helper,
|
||||
CaptureFactory $capture_factory,
|
||||
SessionHandler $session_handler
|
||||
CaptureFactory $capture_factory
|
||||
) {
|
||||
$this->module_url = $module_url;
|
||||
$this->fraud_net = $fraud_net;
|
||||
$this->pui_order_endpoint = $pui_order_endpoint;
|
||||
$this->logger = $logger;
|
||||
$this->settings = $settings;
|
||||
$this->environment = $environment;
|
||||
$this->asset_version = $asset_version;
|
||||
$this->state = $state;
|
||||
$this->is_ppcp_settings_page = $is_ppcp_settings_page;
|
||||
$this->current_ppcp_settings_page_id = $current_ppcp_settings_page_id;
|
||||
$this->pui_product_status = $pui_product_status;
|
||||
$this->pui_helper = $pui_helper;
|
||||
$this->checkout_helper = $checkout_helper;
|
||||
$this->capture_factory = $capture_factory;
|
||||
$this->session_handler = $session_handler;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -236,11 +177,6 @@ class PayUponInvoice {
|
|||
}
|
||||
);
|
||||
|
||||
add_action(
|
||||
'wp_enqueue_scripts',
|
||||
array( $this, 'register_assets' )
|
||||
);
|
||||
|
||||
add_action(
|
||||
'ppcp_payment_capture_completed_webhook_handler',
|
||||
function ( WC_Order $wc_order, string $order_id ) {
|
||||
|
@ -587,31 +523,4 @@ class PayUponInvoice {
|
|||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers PUI assets.
|
||||
*/
|
||||
public function register_assets(): void {
|
||||
$gateway_settings = get_option( 'woocommerce_ppcp-pay-upon-invoice-gateway_settings' );
|
||||
$gateway_enabled = $gateway_settings['enabled'] ?? '';
|
||||
if ( $gateway_enabled === 'yes' && ! $this->session_handler->order() && ( is_checkout() || is_checkout_pay_page() ) ) {
|
||||
wp_enqueue_script(
|
||||
'ppcp-pay-upon-invoice',
|
||||
trailingslashit( $this->module_url ) . 'assets/js/pay-upon-invoice.js',
|
||||
array(),
|
||||
$this->asset_version,
|
||||
true
|
||||
);
|
||||
|
||||
wp_localize_script(
|
||||
'ppcp-pay-upon-invoice',
|
||||
'FraudNetConfig',
|
||||
array(
|
||||
'f' => $this->fraud_net->session_id(),
|
||||
's' => $this->fraud_net->source_website_id(),
|
||||
'sandbox' => $this->environment->current_environment_is( Environment::SANDBOX ),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue