Open payer action in modal window

This commit is contained in:
dinamiko 2022-07-12 14:44:08 +02:00
parent e1ff5c240b
commit 52c3cc72a8
5 changed files with 79 additions and 7 deletions

View file

@ -0,0 +1,15 @@
window.addEventListener('load', function() {
const oxxoButton = document.getElementById('ppcp-oxxo-payer-action');
if(oxxoButton) {
oxxoButton.addEventListener('click', (event) => {
event.preventDefault();
window.open(
oxxoButton.href,
'_blank',
'popup'
);
});
window.open(oxxoButton.href);
}
});

View file

@ -2226,12 +2226,15 @@ return array(
$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( 'wcgateway.checkout-helper' ),
$container->get( 'api.factory.capture' )
);
},
'wcgateway.oxxo' => static function( ContainerInterface $container ): OXXO {
return new OXXO(
$container->get( 'wcgateway.checkout-helper' )
$container->get( 'wcgateway.checkout-helper' ),
$container->get( 'wcgateway.url' ),
$container->get( 'ppcp.asset-version' )
);
},
'wcgateway.oxxo-gateway' => static function( ContainerInterface $container ): OXXOGateway {

View file

@ -24,14 +24,36 @@ class OXXO {
*/
protected $checkout_helper;
/**
* The module URL.
*
* @var string
*/
protected $module_url;
/**
* The asset version.
*
* @var string
*/
protected $asset_version;
/**
* OXXO constructor.
*
* @param CheckoutHelper $checkout_helper The checkout helper.
* @param string $module_url The module URL.
* @param string $asset_version The asset version.
*/
public function __construct( CheckoutHelper $checkout_helper ) {
public function __construct(
CheckoutHelper $checkout_helper,
string $module_url,
string $asset_version
) {
$this->checkout_helper = $checkout_helper;
$this->module_url = $module_url;
$this->asset_version = $asset_version;
}
/**
@ -58,7 +80,7 @@ class OXXO {
$button = '';
if ( $payer_action ) {
$button = '<p><a class="button" href="' . $payer_action . '" target="_blank">See OXXO Voucher/Ticket</a></p>';
$button = '<p><a id="ppcp-oxxo-payer-action" class="button" href="' . $payer_action . '" target="_blank">See OXXO Voucher/Ticket</a></p>';
}
return $message . ' ' . $button;
@ -66,6 +88,11 @@ class OXXO {
10,
2
);
add_action(
'wp_enqueue_scripts',
array( $this, 'register_assets' )
);
}
/**
@ -89,4 +116,18 @@ class OXXO {
return true;
}
public function register_assets(): void {
$gateway_settings = get_option( 'woocommerce_ppcp-oxxo-gateway_settings' );
$gateway_enabled = $gateway_settings['enabled'] ?? '';
if ( $gateway_enabled === 'yes' && is_checkout() && !empty( is_wc_endpoint_url('order-received') ) ) {
wp_enqueue_script(
'ppcp-pay-upon-invoice',
trailingslashit($this->module_url) . 'assets/js/oxxo.js',
array(),
$this->asset_version,
true
);
}
}
}

View file

@ -117,10 +117,19 @@ class PayUponInvoice {
protected $pui_product_status;
/**
* The checkout helper.
*
* @var CheckoutHelper
*/
protected $checkout_helper;
/**
* The capture factory.
*
* @var CaptureFactory
*/
protected $capture_factory;
/**
* PayUponInvoice constructor.
*
@ -136,7 +145,8 @@ class PayUponInvoice {
* @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 CheckoutHelper $checkout_helper The checkout helper.
* @param CaptureFactory $capture_factory The capture factory.
*/
public function __construct(
string $module_url,
@ -151,7 +161,8 @@ class PayUponInvoice {
string $current_ppcp_settings_page_id,
PayUponInvoiceProductStatus $pui_product_status,
PayUponInvoiceHelper $pui_helper,
CheckoutHelper $checkout_helper
CheckoutHelper $checkout_helper,
CaptureFactory $capture_factory
) {
$this->module_url = $module_url;
$this->fraud_net = $fraud_net;
@ -165,7 +176,8 @@ class PayUponInvoice {
$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->checkout_helper = $checkout_helper;
$this->capture_factory = $capture_factory;
}
/**

View file

@ -8,6 +8,7 @@ module.exports = {
entry: {
'gateway-settings': path.resolve('./resources/js/gateway-settings.js'),
'pay-upon-invoice': path.resolve('./resources/js/pay-upon-invoice.js'),
'oxxo': path.resolve('./resources/js/oxxo.js'),
},
output: {
path: path.resolve(__dirname, 'assets/'),