Skip to content

Integrate Account Management component into the Settings Page #10471

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions changelog/add-9129-account-management-component
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: add

Add the Stripe embedded account management component into the Payments → Settings page.
44 changes: 44 additions & 0 deletions client/embedded-components/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
StripeConnectInstance,
} from '@stripe/connect-js';
import {
ConnectAccountManagement,
ConnectAccountOnboarding,
ConnectComponentsProvider,
ConnectNotificationBanner,
Expand Down Expand Up @@ -228,3 +229,46 @@ export const EmbeddedConnectNotificationBanner: React.FC< EmbeddedAccountNotific
</>
);
};

/**
* Embedded Stripe Account Management Component.
*
* @param onLoaderStart - Callback when Stripe component starts rendering.
* @param onLoadError - Callback when Stripe component load error occurs.
*
* @return Rendered Account Management component.
*/
export const EmbeddedAccountManagement: React.FC< EmbeddedComponentProps > = ( {
onLoaderStart,
onLoadError,
} ) => {
const { stripeConnectInstance, initializationError } = useInitializeStripe(
false,
null,
false
);

return (
<>
{ initializationError && (
<BannerNotice status="error">
{ initializationError }
</BannerNotice>
) }
{ stripeConnectInstance && (
<ConnectComponentsProvider
connectInstance={ stripeConnectInstance }
>
<ConnectAccountManagement
onLoaderStart={ onLoaderStart }
onLoadError={ onLoadError }
collectionOptions={ {
fields: 'eventually_due',
futureRequirements: 'include',
} }
/>
</ConnectComponentsProvider>
) }
</>
);
};
73 changes: 73 additions & 0 deletions client/settings/account-management/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/**
* External dependencies
*/
import React, { useState } from 'react';
import { Card, CardBody } from '@wordpress/components';
import { LoadError } from '@stripe/connect-js';
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import './style.scss';
import BannerNotice from 'wcpay/components/banner-notice';
import StripeSpinner from 'wcpay/components/stripe-spinner';
import { EmbeddedAccountManagement } from 'wcpay/embedded-components';

const AccountManagement = () => {
const [ loading, setLoading ] = useState( true );
const [ loadError, setLoadError ] = useState< LoadError | null >( null );

const handleLoadError = ( err: LoadError ) => {
setLoadError( err );
};

return (
<>
<Card>
<CardBody>
{ loading && (
<div className="account-management-loader-wrapper">
<StripeSpinner />
</div>
) }
{ loadError &&
( loadError.error.type === 'invalid_request_error' ? (
<BannerNotice
icon={ true }
status="warning"
isDismissible={ false }
actions={ [
{
label: 'Learn more',
variant: 'primary',
url:
'https://woocommerce.com/document/woopayments/startup-guide/#requirements',
urlTarget: '_blank',
},
] }
>
{ __(
'Account management through our financial partner requires HTTPS and cannot be completed.',
'woocommerce-payments'
) }
</BannerNotice>
) : (
<BannerNotice
status="error"
isDismissible={ false }
>
{ loadError.error.message }
</BannerNotice>
) ) }
<EmbeddedAccountManagement
onLoaderStart={ () => setLoading( false ) }
onLoadError={ handleLoadError }
></EmbeddedAccountManagement>
</CardBody>
</Card>
</>
);
};

export default AccountManagement;
6 changes: 6 additions & 0 deletions client/settings/account-management/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Wrap loader so it's centered and does not get cut.
.account-management-loader-wrapper {
text-align: center;
height: 35px;
padding: 20px 0;
}
25 changes: 25 additions & 0 deletions client/settings/settings-manager/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import SettingsLayout from '../settings-layout';
import SaveSettingsSection from '../save-settings-section';
import Transactions from '../transactions';
import Deposits from '../deposits';
import AccountManagement from '../account-management';
import LoadableSettingsSection from '../loadable-settings-section';
import PaymentMethodsSection from '../payment-methods-section';
import BuyNowPayLaterSection from '../buy-now-pay-later-section';
Expand Down Expand Up @@ -103,6 +104,20 @@ const DepositsDescription = () => {
);
};

const AccountDetailsDescription = () => {
return (
<>
<h2>{ __( 'Account details', 'woocommerce-payments' ) }</h2>
<p>
{ __(
'View and edit your WooPayments account details like personal or business information and public information.',
'woocommerce-payments'
) }
</p>
</>
);
};

const FraudProtectionDescription = () => {
return (
<>
Expand Down Expand Up @@ -218,6 +233,16 @@ const SettingsManager = () => {
</LoadableSettingsSection>
</SettingsSection>
</DuplicatedPaymentMethodsContext.Provider>
<SettingsSection
description={ AccountDetailsDescription }
id="account-details"
>
<LoadableSettingsSection numLines={ 20 }>
<ErrorBoundary>
<AccountManagement />
</ErrorBoundary>
</LoadableSettingsSection>
</SettingsSection>
<SettingsSection
description={ TransactionsDescription }
id="transactions"
Expand Down
Loading