Skip to content

Commit

Permalink
Show error message in paylater block when vaulting enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexP11223 committed Dec 20, 2023
1 parent f4ac440 commit fc1b5e9
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
6 changes: 6 additions & 0 deletions modules/ppcp-paylater-block/resources/css/edit.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@
.ppcp-unclicable-overlay {
z-index: 10;
}

.ppcp-paylater-unavailable {
p.block-editor-warning__message {
margin-bottom: 10px;
}
}
27 changes: 26 additions & 1 deletion modules/ppcp-paylater-block/resources/js/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ export default function Edit( { attributes, clientId, setAttributes } ) {
},
};

const props = useBlockProps({className: ['ppcp-paylater-block-preview', 'ppcp-overlay-parent']});
let classes = ['ppcp-paylater-block-preview', 'ppcp-overlay-parent'];
if (PcpPayLaterBlock.vaultingEnabled) {
classes = ['ppcp-paylater-block-preview', 'ppcp-paylater-unavailable', 'block-editor-warning'];
}
const props = useBlockProps({className: classes});

const loadingElement = <div {...props}><Spinner/></div>;

Expand All @@ -43,6 +47,27 @@ export default function Edit( { attributes, clientId, setAttributes } ) {
}
}, []);

if (PcpPayLaterBlock.vaultingEnabled) {
return <div {...props}>
<div className={'block-editor-warning__contents'}>
<h3>{__('PayPal Pay Later Messaging', 'woocommerce-paypal-payments')}</h3>
<p className={'block-editor-warning__message'}>{__('Pay Later Messaging cannot be used while PayPal Vaulting is active. Disable PayPal Vaulting in the PayPal Payment settings to reactivate this block', 'woocommerce-paypal-payments')}</p>
<div className={'class="block-editor-warning__actions"'}>
<span className={'block-editor-warning__action'}>
<a href={PcpPayLaterBlock.settingsUrl} className={'components-button is-primary'}>
{__('PayPal Payments Settings', 'woocommerce-paypal-payments')}
</a>
</span>
<span className={'block-editor-warning__action'}>
<button onClick={() => wp.data.dispatch( 'core/block-editor' ).removeBlock(clientId)} type={'button'} className={'components-button is-secondary'}>
{__('Remove Block', 'woocommerce-paypal-payments')}
</button>
</span>
</div>
</div>
</div>
}

let scriptParams = useScriptParams(PcpPayLaterBlock.ajax.cart_script_params);
if (scriptParams === null) {
return loadingElement;
Expand Down
10 changes: 8 additions & 2 deletions modules/ppcp-paylater-block/src/PayLaterBlockModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use WooCommerce\PayPalCommerce\Vendor\Dhii\Modular\Module\ModuleInterface;
use WooCommerce\PayPalCommerce\Vendor\Interop\Container\ServiceProviderInterface;
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;

/**
* Class PayLaterBlockModule
Expand Down Expand Up @@ -52,9 +53,12 @@ public function run( ContainerInterface $c ): void {
return;
}

$settings = $c->get( 'wcgateway.settings' );
assert( $settings instanceof Settings );

add_action(
'init',
function () use ( $c ): void {
function () use ( $c, $settings ): void {
$script_handle = 'ppcp-paylater-block';
wp_register_script(
$script_handle,
Expand All @@ -67,11 +71,13 @@ function () use ( $c ): void {
$script_handle,
'PcpPayLaterBlock',
array(
'ajax' => array(
'ajax' => array(
'cart_script_params' => array(
'endpoint' => \WC_AJAX::get_endpoint( CartScriptParamsEndpoint::ENDPOINT ),
),
),
'settingsUrl' => admin_url( 'admin.php?page=wc-settings&tab=checkout&section=ppcp-gateway' ),
'vaultingEnabled' => $settings->has( 'vault_enabled' ) && $settings->get( 'vault_enabled' ),
)
);

Expand Down

0 comments on commit fc1b5e9

Please sign in to comment.