mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Open payer action in modal window
This commit is contained in:
parent
e1ff5c240b
commit
52c3cc72a8
5 changed files with 79 additions and 7 deletions
15
modules/ppcp-wc-gateway/resources/js/oxxo.js
Normal file
15
modules/ppcp-wc-gateway/resources/js/oxxo.js
Normal 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);
|
||||
}
|
||||
});
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
@ -137,6 +146,7 @@ class PayUponInvoice {
|
|||
* @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.
|
||||
*/
|
||||
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;
|
||||
|
@ -166,6 +177,7 @@ class PayUponInvoice {
|
|||
$this->pui_product_status = $pui_product_status;
|
||||
$this->pui_helper = $pui_helper;
|
||||
$this->checkout_helper = $checkout_helper;
|
||||
$this->capture_factory = $capture_factory;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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/'),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue