mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
Mm 52577 Tie use of Stripe (or its mock) to use of CWS (or its mock) (#23277)
* set config CWSMock value according to model.MockCWS
This commit is contained in:
parent
9f1796f98b
commit
9ee3526ca1
@ -93,6 +93,7 @@ func GenerateClientConfig(c *model.Config, telemetryID string, license *model.Li
|
||||
props["EnableEmailInvitations"] = strconv.FormatBool(*c.ServiceSettings.EnableEmailInvitations)
|
||||
|
||||
props["CWSURL"] = *c.CloudSettings.CWSURL
|
||||
props["CWSMock"] = model.MockCWS
|
||||
|
||||
props["DisableRefetchingOnBrowserFocus"] = strconv.FormatBool(*c.ExperimentalSettings.DisableRefetchingOnBrowserFocus)
|
||||
|
||||
|
@ -2780,6 +2780,7 @@ func (s *JobSettings) SetDefaults() {
|
||||
type CloudSettings struct {
|
||||
CWSURL *string `access:"write_restrictable"`
|
||||
CWSAPIURL *string `access:"write_restrictable"`
|
||||
CWSMock *bool `access:"write_restrictable"`
|
||||
}
|
||||
|
||||
func (s *CloudSettings) SetDefaults() {
|
||||
@ -2795,6 +2796,10 @@ func (s *CloudSettings) SetDefaults() {
|
||||
s.CWSAPIURL = NewString(CloudSettingsDefaultCwsAPIURLTest)
|
||||
}
|
||||
}
|
||||
if s.CWSMock == nil {
|
||||
isMockCws := MockCWS == "true"
|
||||
s.CWSMock = &isMockCws
|
||||
}
|
||||
}
|
||||
|
||||
type ProductSettings struct {
|
||||
|
@ -22,7 +22,7 @@ import {Address, Feedback, WorkspaceDeletionRequest} from '@mattermost/types/clo
|
||||
export function completeStripeAddPaymentMethod(
|
||||
stripe: Stripe,
|
||||
billingDetails: BillingDetails,
|
||||
isDevMode: boolean,
|
||||
cwsMockMode: boolean,
|
||||
) {
|
||||
return async () => {
|
||||
let paymentSetupIntent: StripeSetupIntent;
|
||||
@ -31,7 +31,7 @@ export function completeStripeAddPaymentMethod(
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
const cardSetupFunction = getConfirmCardSetup(isDevMode);
|
||||
const cardSetupFunction = getConfirmCardSetup(cwsMockMode);
|
||||
const confirmCardSetup = cardSetupFunction(stripe.confirmCardSetup);
|
||||
|
||||
const result = await confirmCardSetup(
|
||||
|
@ -35,13 +35,13 @@ const STRIPE_ALREADY_SUCCEEDED = 'You cannot update this SetupIntent because it
|
||||
export function confirmSelfHostedSignup(
|
||||
stripe: Stripe,
|
||||
stripeSetupIntent: StripeSetupIntent,
|
||||
isDevMode: boolean,
|
||||
cwsMockMode: boolean,
|
||||
billingDetails: BillingDetails,
|
||||
initialProgress: ValueOf<typeof SelfHostedSignupProgress>,
|
||||
subscriptionRequest: CreateSubscriptionRequest,
|
||||
): ActionFunc {
|
||||
return async (dispatch: DispatchFunc) => {
|
||||
const cardSetupFunction = getConfirmCardSetup(isDevMode);
|
||||
const cardSetupFunction = getConfirmCardSetup(cwsMockMode);
|
||||
const confirmCardSetup = cardSetupFunction(stripe.confirmCardSetup);
|
||||
|
||||
const shouldConfirmCard = selfHostedNeedsConfirmation(initialProgress);
|
||||
@ -202,13 +202,13 @@ export function getTrueUpReviewStatus(): ActionFunc {
|
||||
export function confirmSelfHostedExpansion(
|
||||
stripe: Stripe,
|
||||
stripeSetupIntent: StripeSetupIntent,
|
||||
isDevMode: boolean,
|
||||
cwsMockMode: boolean,
|
||||
billingDetails: BillingDetails,
|
||||
initialProgress: ValueOf<typeof SelfHostedSignupProgress>,
|
||||
expansionRequest: SelfHostedExpansionRequest,
|
||||
): ActionFunc {
|
||||
return async (dispatch: DispatchFunc) => {
|
||||
const cardSetupFunction = getConfirmCardSetup(isDevMode);
|
||||
const cardSetupFunction = getConfirmCardSetup(cwsMockMode);
|
||||
const confirmCardSetup = cardSetupFunction(stripe.confirmCardSetup);
|
||||
|
||||
const shouldConfirmCard = selfHostedNeedsConfirmation(initialProgress);
|
||||
|
@ -15,7 +15,7 @@ import {getTheme} from 'mattermost-redux/selectors/entities/preferences';
|
||||
|
||||
import {completeStripeAddPaymentMethod} from 'actions/cloud';
|
||||
|
||||
import {isDevModeEnabled} from 'selectors/general';
|
||||
import {isCwsMockMode} from 'selectors/cloud';
|
||||
|
||||
import {areBillingDetailsValid, BillingDetails} from 'types/cloud/sku';
|
||||
import {GlobalState} from 'types/store';
|
||||
@ -37,7 +37,7 @@ const PaymentInfoEdit: React.FC = () => {
|
||||
const dispatch = useDispatch();
|
||||
const history = useHistory();
|
||||
|
||||
const isDevMode = useSelector(isDevModeEnabled);
|
||||
const cwsMockMode = useSelector(isCwsMockMode);
|
||||
const paymentInfo = useSelector((state: GlobalState) => state.entities.cloud.customer);
|
||||
const theme = useSelector(getTheme);
|
||||
|
||||
@ -68,7 +68,7 @@ const PaymentInfoEdit: React.FC = () => {
|
||||
|
||||
const handleSubmit = async () => {
|
||||
setIsSaving(true);
|
||||
const setPaymentMethod = completeStripeAddPaymentMethod((await stripePromise)!, billingDetails!, isDevMode);
|
||||
const setPaymentMethod = completeStripeAddPaymentMethod((await stripePromise)!, billingDetails!, cwsMockMode);
|
||||
const success = await setPaymentMethod();
|
||||
|
||||
if (success) {
|
||||
|
@ -22,7 +22,7 @@ function devConfirmCardSetup(confirmCardSetup: ConfirmCardSetupType): ConfirmCar
|
||||
};
|
||||
}
|
||||
|
||||
export const getConfirmCardSetup = (isDevMode?: boolean) => (isDevMode ? devConfirmCardSetup : prodConfirmCardSetup);
|
||||
export const getConfirmCardSetup = (isCwsMockMode?: boolean) => (isCwsMockMode ? devConfirmCardSetup : prodConfirmCardSetup);
|
||||
|
||||
export const STRIPE_CSS_SRC = 'https://fonts.googleapis.com/css?family=Open+Sans:400,400i,600,600i&display=swap';
|
||||
//eslint-disable-next-line no-process-env
|
||||
|
@ -19,8 +19,7 @@ import {GlobalState} from 'types/store';
|
||||
import {BillingDetails} from 'types/cloud/sku';
|
||||
|
||||
import {isModalOpen} from 'selectors/views/modals';
|
||||
import {getCloudDelinquentInvoices, isCloudDelinquencyGreaterThan90Days} from 'selectors/cloud';
|
||||
import {isDevModeEnabled} from 'selectors/general';
|
||||
import {getCloudDelinquentInvoices, isCloudDelinquencyGreaterThan90Days, isCwsMockMode} from 'selectors/cloud';
|
||||
|
||||
import {ModalIdentifiers} from 'utils/constants';
|
||||
|
||||
@ -52,7 +51,7 @@ function mapStateToProps(state: GlobalState) {
|
||||
show: isModalOpen(state, ModalIdentifiers.CLOUD_PURCHASE),
|
||||
products,
|
||||
yearlyProducts,
|
||||
isDevMode: isDevModeEnabled(state),
|
||||
cwsMockMode: isCwsMockMode(state),
|
||||
contactSupportLink,
|
||||
invoices: getCloudDelinquentInvoices(state),
|
||||
isCloudDelinquencyGreaterThan90Days: isCloudDelinquencyGreaterThan90Days(state),
|
||||
@ -71,7 +70,7 @@ type Actions = {
|
||||
closeModal: () => void;
|
||||
openModal: <P>(modalData: ModalData<P>) => void;
|
||||
getCloudProducts: () => void;
|
||||
completeStripeAddPaymentMethod: (stripe: Stripe, billingDetails: BillingDetails, isDevMode: boolean) => Promise<boolean | null>;
|
||||
completeStripeAddPaymentMethod: (stripe: Stripe, billingDetails: BillingDetails, cwsMockMode: boolean) => Promise<boolean | null>;
|
||||
subscribeCloudSubscription: typeof subscribeCloudSubscription;
|
||||
getClientConfig: () => void;
|
||||
getCloudSubscription: () => void;
|
||||
|
@ -36,13 +36,13 @@ type Props = RouteComponentProps & {
|
||||
billingDetails: BillingDetails | null;
|
||||
shippingAddress: Address | null;
|
||||
stripe: Promise<Stripe | null>;
|
||||
isDevMode: boolean;
|
||||
cwsMockMode: boolean;
|
||||
contactSupportLink: string;
|
||||
currentTeam: Team;
|
||||
addPaymentMethod: (
|
||||
stripe: Stripe,
|
||||
billingDetails: BillingDetails,
|
||||
isDevMode: boolean
|
||||
cwsMockMode: boolean
|
||||
) => Promise<boolean | null>;
|
||||
subscribeCloudSubscription:
|
||||
| ((productId: string, shippingAddress: Address, seats?: number, downgradeFeedback?: Feedback) => Promise<ActionResult<Subscription, ComplianceError>>)
|
||||
@ -120,10 +120,10 @@ class ProcessPaymentSetup extends React.PureComponent<Props, State> {
|
||||
stripe,
|
||||
addPaymentMethod,
|
||||
billingDetails,
|
||||
isDevMode,
|
||||
cwsMockMode,
|
||||
subscribeCloudSubscription,
|
||||
} = this.props;
|
||||
const success = await addPaymentMethod((await stripe)!, billingDetails!, isDevMode);
|
||||
const success = await addPaymentMethod((await stripe)!, billingDetails!, cwsMockMode);
|
||||
|
||||
if (typeof success !== 'boolean' || !success) {
|
||||
trackEvent('cloud_admin', 'complete_payment_failed', {
|
||||
|
@ -111,7 +111,7 @@ type CardProps = {
|
||||
type Props = {
|
||||
customer: CloudCustomer | undefined;
|
||||
show: boolean;
|
||||
isDevMode: boolean;
|
||||
cwsMockMode: boolean;
|
||||
products: Record<string, Product> | undefined;
|
||||
yearlyProducts: Record<string, Product>;
|
||||
contactSalesLink: string;
|
||||
@ -137,7 +137,7 @@ type Props = {
|
||||
completeStripeAddPaymentMethod: (
|
||||
stripe: Stripe,
|
||||
billingDetails: BillingDetails,
|
||||
isDevMode: boolean
|
||||
cwsMockMode: boolean
|
||||
) => Promise<boolean | null>;
|
||||
subscribeCloudSubscription: (
|
||||
productId: string,
|
||||
@ -1006,7 +1006,7 @@ class PurchaseModal extends React.PureComponent<Props, State> {
|
||||
this.props.actions.
|
||||
subscribeCloudSubscription
|
||||
}
|
||||
isDevMode={this.props.isDevMode}
|
||||
cwsMockMode={this.props.cwsMockMode}
|
||||
onClose={() => {
|
||||
this.props.actions.getCloudSubscription();
|
||||
this.props.actions.closeModal();
|
||||
|
@ -16,7 +16,7 @@ import {getSelfHostedSignupProgress} from 'mattermost-redux/selectors/entities/h
|
||||
import {DispatchFunc} from 'mattermost-redux/types/actions';
|
||||
import {HostedCustomerTypes} from 'mattermost-redux/action_types';
|
||||
import {Client4} from 'mattermost-redux/client';
|
||||
import {isDevModeEnabled} from 'selectors/general';
|
||||
import {isCwsMockMode} from 'selectors/cloud';
|
||||
|
||||
import {closeModal} from 'actions/views/modals';
|
||||
import {pageVisited} from 'actions/telemetry_actions';
|
||||
@ -169,7 +169,7 @@ export default function SelfHostedExpansionModal() {
|
||||
const theme = useSelector(getTheme);
|
||||
const progress = useSelector(getSelfHostedSignupProgress);
|
||||
const user = useSelector(getCurrentUser);
|
||||
const isDevMode = useSelector(isDevModeEnabled);
|
||||
const cwsMockMode = useSelector(isCwsMockMode);
|
||||
|
||||
const license = useSelector(getLicense);
|
||||
const licensedSeats = parseInt(license.Users, 10);
|
||||
@ -259,7 +259,7 @@ export default function SelfHostedExpansionModal() {
|
||||
id: signupCustomerResult.setup_intent_id,
|
||||
client_secret: signupCustomerResult.setup_intent_secret,
|
||||
},
|
||||
isDevMode,
|
||||
cwsMockMode,
|
||||
{
|
||||
address: formState.address,
|
||||
address2: formState.address2,
|
||||
|
@ -24,7 +24,7 @@ import {confirmSelfHostedSignup} from 'actions/hosted_customer';
|
||||
import {GlobalState} from 'types/store';
|
||||
|
||||
import {isModalOpen} from 'selectors/views/modals';
|
||||
import {isDevModeEnabled} from 'selectors/general';
|
||||
import {isCwsMockMode} from 'selectors/cloud';
|
||||
|
||||
import {inferNames} from 'utils/hosted_customer';
|
||||
|
||||
@ -323,7 +323,7 @@ export default function SelfHostedPurchaseModal(props: Props) {
|
||||
const desiredProductName = desiredProduct?.name || '';
|
||||
const desiredPlanName = getPlanNameFromProductName(desiredProductName);
|
||||
const currentUsers = analytics[StatTypes.TOTAL_USERS] as number;
|
||||
const isDevMode = useSelector(isDevModeEnabled);
|
||||
const cwsMockMode = useSelector(isCwsMockMode);
|
||||
const hasLicense = Object.keys(useSelector(getLicense) || {}).length > 0;
|
||||
|
||||
const intl = useIntl();
|
||||
@ -453,7 +453,7 @@ export default function SelfHostedPurchaseModal(props: Props) {
|
||||
id: signupCustomerResult.setup_intent_id,
|
||||
client_secret: signupCustomerResult.setup_intent_secret,
|
||||
},
|
||||
isDevMode,
|
||||
cwsMockMode,
|
||||
{
|
||||
address: state.address,
|
||||
address2: state.address2,
|
||||
|
@ -43,3 +43,5 @@ export const isCloudDelinquencyGreaterThan90Days = createSelector(
|
||||
return (Math.floor((now.getTime() - delinquentDate.getTime()) / (1000 * 60 * 60 * 24)) >= 90);
|
||||
},
|
||||
);
|
||||
|
||||
export const isCwsMockMode = (state: GlobalState) => getConfig(state)?.CWSMock === 'true';
|
||||
|
@ -30,6 +30,7 @@ export type ClientConfig = {
|
||||
CustomTermsOfServiceReAcceptancePeriod: string;
|
||||
CustomUrlSchemes: string;
|
||||
CWSURL: string;
|
||||
CWSMock: string;
|
||||
DataRetentionEnableFileDeletion: string;
|
||||
DataRetentionEnableMessageDeletion: string;
|
||||
DataRetentionFileRetentionDays: string;
|
||||
|
Loading…
Reference in New Issue
Block a user