mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 10:55:00 +08:00
Refactor pui is active calls
This commit is contained in:
parent
8a1d38ec0e
commit
99c5351689
1 changed files with 20 additions and 28 deletions
|
@ -423,15 +423,19 @@ class PayUponInvoice {
|
|||
* @psalm-suppress MissingClosureParamType
|
||||
*/
|
||||
function ( $methods ) {
|
||||
if ( ! is_array( $methods ) || State::STATE_ONBOARDED !== $this->state->current_state() ) {
|
||||
if (
|
||||
! is_array( $methods )
|
||||
|| State::STATE_ONBOARDED !== $this->state->current_state()
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
|| ! ( is_checkout() || isset( $_GET['pay_for_order'] ) && $_GET['pay_for_order'] === 'true' )
|
||||
) {
|
||||
return $methods;
|
||||
}
|
||||
|
||||
if (
|
||||
! $this->pui_product_status->pui_is_active()
|
||||
|| ! $this->pui_helper->is_checkout_ready_for_pui()
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
|| ( isset( $_GET['pay_for_order'] ) && $_GET['pay_for_order'] === 'true' && ! $this->pui_helper->is_pay_for_order_ready_for_pui() )
|
||||
|| ! $this->pui_helper->is_pay_for_order_ready_for_pui()
|
||||
) {
|
||||
unset( $methods[ PayUponInvoiceGateway::ID ] );
|
||||
}
|
||||
|
@ -440,31 +444,6 @@ class PayUponInvoice {
|
|||
}
|
||||
);
|
||||
|
||||
add_action(
|
||||
'woocommerce_settings_checkout',
|
||||
function () {
|
||||
if (
|
||||
PayUponInvoiceGateway::ID === $this->current_ppcp_settings_page_id
|
||||
&& ! $this->pui_product_status->pui_is_active()
|
||||
) {
|
||||
$gateway_settings = get_option( 'woocommerce_ppcp-pay-upon-invoice-gateway_settings' );
|
||||
$gateway_enabled = $gateway_settings['enabled'] ?? '';
|
||||
if ( 'yes' === $gateway_enabled ) {
|
||||
$gateway_settings['enabled'] = 'no';
|
||||
update_option( 'woocommerce_ppcp-pay-upon-invoice-gateway_settings', $gateway_settings );
|
||||
$redirect_url = admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=ppcp-pay-upon-invoice-gateway' );
|
||||
wp_safe_redirect( $redirect_url );
|
||||
exit;
|
||||
}
|
||||
|
||||
printf(
|
||||
'<div class="notice notice-error"><p>%1$s</p></div>',
|
||||
esc_html__( 'Could not enable gateway because the connected PayPal account is not activated for Pay upon Invoice. Reconnect your account while Onboard with Pay upon Invoice is selected to try again.', 'woocommerce-paypal-payments' )
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
add_action(
|
||||
'woocommerce_update_options_checkout_ppcp-pay-upon-invoice-gateway',
|
||||
function () {
|
||||
|
@ -509,6 +488,19 @@ class PayUponInvoice {
|
|||
</div>
|
||||
<?php
|
||||
}
|
||||
} elseif ( PayUponInvoiceGateway::ID === $this->current_ppcp_settings_page_id ) {
|
||||
$pui_gateway = WC()->payment_gateways->payment_gateways()[ PayUponInvoiceGateway::ID ];
|
||||
if ( 'yes' === $pui_gateway->get_option( 'enabled' ) ) {
|
||||
$pui_gateway->update_option( 'enabled', 'no' );
|
||||
$redirect_url = admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=ppcp-pay-upon-invoice-gateway' );
|
||||
wp_safe_redirect( $redirect_url );
|
||||
exit;
|
||||
}
|
||||
|
||||
printf(
|
||||
'<div class="notice notice-error"><p>%1$s</p></div>',
|
||||
esc_html__( 'Could not enable gateway because the connected PayPal account is not activated for Pay upon Invoice. Reconnect your account while Onboard with Pay upon Invoice is selected to try again.', 'woocommerce-paypal-payments' )
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue