Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*** Changelog ***

= 10.1.0 - xxxx-xx-xx =
* Dev - Add track events when clicking the "Reconnect to Stripe" button (both in the settings page and the admin notice)
* Update - Removes unnecessary legacy checkout gateway instantiations and UPE disablement code
* Dev - Renames previous Order Helper class methods to use the `_id` suffix
* Dev - Expands the Stripe Order Helper class to handle customer ID, card ID, UPE payment type, and UPE redirect status metas
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
useAccountKeysTestWebhookSecret,
} from 'wcstripe/data/account-keys/hooks';
import { useAccount } from 'wcstripe/data/account';
import { recordEvent } from 'wcstripe/tracking';

jest.mock( 'wcstripe/data', () => ( {
useIsStripeEnabled: jest.fn(),
Expand All @@ -36,6 +37,10 @@ jest.mock( 'wcstripe/data/account', () => ( {
useAccount: jest.fn(),
} ) );

jest.mock( 'wcstripe/tracking', () => ( {
recordEvent: jest.fn(),
} ) );

jest.mock( '@stripe/stripe-js', () => ( {
loadStripe: jest.fn(),
} ) );
Expand Down Expand Up @@ -287,5 +292,41 @@ describe( 'AccountDetailsSection', () => {
} );
expect( configureConnectionButton ).toBeInTheDocument();
} );

it( 'should record event when the reconnect button is clicked', async () => {
useAccount.mockReturnValue( {
data: {
webhook_url: 'example.com',
account: {
id: 'acct_123',
email: '[email protected]',
testmode: false,
},
configured_webhook_urls: {
live: 'example.com',
test: 'example.com',
},
oauth_connections: {
live: { connected: false },
test: { connected: false },
},
},
} );

render(
<AccountDetailsSection setModalType={ setModalTypeMock } />
);

const editKeysButton = screen.getByRole( 'button', {
name: /Configure connection/i,
} );

await userEvent.click( editKeysButton );

expect( recordEvent ).toHaveBeenCalledWith(
'wcstripe_reconnect_button_click',
{ source: 'account_details_section', mode: 'live' }
);
} );
} );
} );
20 changes: 17 additions & 3 deletions client/settings/payment-settings/account-details-section.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { useDispatch } from '@wordpress/data';
import './style.scss';
import { useTestMode } from 'wcstripe/data';
import { useAccount } from 'wcstripe/data/account';
import { recordEvent } from 'wcstripe/tracking';

const HeaderDetails = styled.div`
display: flex;
Expand Down Expand Up @@ -97,6 +98,21 @@ const AccountDetailsSection = ( { setModalType, setKeepModalContent } ) => {
const headingRef = useRef( null );
const [ isTestMode ] = useTestMode();
const { data } = useAccount();
const oauthConnected = isTestMode
? data?.oauth_connections?.test?.connected
: data?.oauth_connections?.live?.connected;

const handleButtonClick = () => {
const mode = isTestMode ? 'test' : 'live';
if ( ! oauthConnected ) {
recordEvent( 'wcstripe_reconnect_button_click', {
source: 'account_details_section',
mode,
} );
}

setModalType( mode );
};

useEffect( () => {
if ( ! headingRef.current ) {
Expand Down Expand Up @@ -146,9 +162,7 @@ const AccountDetailsSection = ( { setModalType, setKeepModalContent } ) => {
<Button
variant="secondary"
id="btn-configure-connection"
onClick={ () =>
setModalType( isTestMode ? 'test' : 'live' )
}
onClick={ handleButtonClick }
>
{ __(
'Configure connection',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,19 @@ describe( 'Reconnect banner', () => {
const reconnectButton = getByText( 'Re-authenticate' );
await userEvent.click( reconnectButton );

expect( recordEvent ).toHaveBeenCalledWith(
expect( recordEvent ).toHaveBeenNthCalledWith(
1,
'wcstripe_create_or_connect_test_account_click',
{}
);
expect( recordEvent ).toHaveBeenNthCalledWith(
2,
'wcstripe_reconnect_button_click',
{
source: 're-connect-account-banner',
mode: 'test',
}
);

expect( window.location.assign ).toHaveBeenCalledWith( oauthUrl );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,17 @@ export const ReConnectAccountBanner = ( { testOauthUrl, oauthUrl } ) => {
const handleButtonClick = () => {
if ( isTestModeEnabled && testOauthUrl ) {
recordEvent( 'wcstripe_create_or_connect_test_account_click', {} );
recordEvent( 'wcstripe_reconnect_button_click', {
source: 're-connect-account-banner',
mode: 'test',
} );
window.location.assign( testOauthUrl );
} else if ( ! isTestModeEnabled && oauthUrl ) {
recordEvent( 'wcstripe_create_or_connect_account_click', {} );
recordEvent( 'wcstripe_reconnect_button_click', {
source: 're-connect-account-banner',
mode: 'live',
} );
window.location.assign( oauthUrl );
} else {
createErrorNotice(
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
== Changelog ==

= 10.1.0 - xxxx-xx-xx =
* Dev - Add track events when clicking the "Reconnect to Stripe" button (both in the settings page and the admin notice)
* Update - Removes unnecessary legacy checkout gateway instantiations and UPE disablement code
* Dev - Renames previous Order Helper class methods to use the `_id` suffix
* Dev - Expands the Stripe Order Helper class to handle customer ID, card ID, UPE payment type, and UPE redirect status metas
Expand Down
Loading