Skip to content

Commit 8e411ff

Browse files
mgascamCopilothtdat
authored
Fee Taxes - provide a way for the merchant to enter Tax ID ahead of release (#10859)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Dat Hoang <htdat@users.noreply.github.com>
1 parent c0cace9 commit 8e411ff

4 files changed

Lines changed: 102 additions & 2 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: minor
2+
Type: add
3+
4+
Added a URL parameter to allow merchants to access the VAT details modal.

client/settings/settings-manager/index.js

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
/**
33
* External dependencies
44
*/
5-
import React, { useState, useLayoutEffect, useEffect } from 'react';
5+
import React, { useState, useEffect, useLayoutEffect } from 'react';
66
import { ExternalLink } from '@wordpress/components';
77
import { __, sprintf } from '@wordpress/i18n';
8-
import { getQuery } from '@woocommerce/navigation';
8+
import { getQuery, updateQueryString } from '@woocommerce/navigation';
9+
import { dispatch } from '@wordpress/data';
910

1011
/**
1112
* Internal dependencies
@@ -29,6 +30,7 @@ import {
2930
} from '../../data';
3031
import FraudProtection from '../fraud-protection';
3132
import DuplicatedPaymentMethodsContext from './duplicated-payment-methods-context';
33+
import VatFormModal from '../../vat/form-modal';
3234
import './style.scss';
3335

3436
const ExpressCheckoutDescription = () => (
@@ -185,6 +187,36 @@ const SettingsManager = () => {
185187
dismissedDuplicateNotices,
186188
setDismissedDuplicateNotices,
187189
] = useState( wcpaySettings.dismissedDuplicateNotices || {} );
190+
const [ isVatFormModalOpen, setVatFormModalOpen ] = useState( false );
191+
192+
useEffect( () => {
193+
const urlParams = new URLSearchParams( window.location.search );
194+
if ( urlParams.get( 'woopayments-vat-details-modal' ) === 'true' ) {
195+
if ( ! wcpaySettings.accountStatus.hasSubmittedVatData ) {
196+
setVatFormModalOpen( true );
197+
} else {
198+
dispatch( 'core/notices' ).createInfoNotice(
199+
__(
200+
'Tax details are already submitted.',
201+
'woocommerce-payments'
202+
)
203+
);
204+
}
205+
}
206+
}, [] );
207+
208+
const handleVatFormModalClose = () => {
209+
setVatFormModalOpen( false );
210+
// Remove the URL parameter when the modal is closed.
211+
updateQueryString( { 'woopayments-vat-details-modal': undefined } );
212+
};
213+
214+
const handleVatFormModalCompleted = () => {
215+
dispatch( 'core/notices' ).createInfoNotice(
216+
__( 'Tax details updated', 'woocommerce-payments' )
217+
);
218+
handleVatFormModalClose();
219+
};
188220

189221
return (
190222
<SettingsLayout>
@@ -262,6 +294,11 @@ const SettingsManager = () => {
262294
</LoadableSettingsSection>
263295
</SettingsSection>
264296
<SaveSettingsSection disabled={ ! isTransactionInputsValid } />
297+
<VatFormModal
298+
isModalOpen={ isVatFormModalOpen }
299+
setModalOpen={ handleVatFormModalClose }
300+
onCompleted={ handleVatFormModalCompleted }
301+
/>
265302
</SettingsLayout>
266303
);
267304
};
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
/**
3+
* WooCommerce Payments VAT Redirect Service.
4+
*
5+
* @package WooCommerce\Payments
6+
*/
7+
8+
namespace WCPay;
9+
10+
defined( 'ABSPATH' ) || exit; // block direct access.
11+
12+
/**
13+
* Service class for handling VAT details redirect functionality.
14+
*
15+
* @todo This is a temporary solution that will be replaced by a dedicated VAT settings section.
16+
* Remove this class when the permanent solution is implemented.
17+
*/
18+
class WC_Payments_VAT_Redirect_Service {
19+
20+
/**
21+
* Initialize hooks.
22+
*
23+
* @return void
24+
*/
25+
public function init_hooks(): void {
26+
add_action( 'template_redirect', [ $this, 'maybe_redirect' ], 1 );
27+
}
28+
29+
/**
30+
* Handles redirection to VAT details modal if needed.
31+
*
32+
* @return void
33+
*/
34+
public function maybe_redirect(): void {
35+
// phpcs:disable WordPress.Security.NonceVerification.Recommended
36+
if ( ! isset( $_GET['woopayments-vat-details-redirect'] ) ) {
37+
return;
38+
}
39+
// phpcs:enable WordPress.Security.NonceVerification.Recommended
40+
41+
// skip REST API calls.
42+
if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
43+
return;
44+
}
45+
46+
// skip AJAX requests.
47+
if ( function_exists( 'wp_doing_ajax' ) && wp_doing_ajax() ) {
48+
return;
49+
}
50+
51+
wp_safe_redirect( admin_url( 'admin.php?page=wc-settings&tab=checkout&section=woocommerce_payments&woopayments-vat-details-modal=true' ) );
52+
exit;
53+
}
54+
}

woocommerce-payments.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,11 @@ function wcpay_init() {
169169
*/
170170
\WCPay\WooPay\WooPay_Session::init();
171171
( new WC_Payments_Payment_Request_Session() )->init();
172+
173+
// @todo This is a temporary solution that will be replaced by a dedicated VAT settings section.
174+
// Remove this initialization when the permanent solution is implemented.
175+
require_once WCPAY_ABSPATH . '/includes/class-wc-payments-vat-redirect-service.php';
176+
( new \WCPay\WC_Payments_VAT_Redirect_Service() )->init_hooks();
172177
}
173178

174179
// Make sure this is run *after* WooCommerce has a chance to initialize its packages (wc-admin, etc). That is run with priority 10.

0 commit comments

Comments
 (0)