Skip to content

Commit a311aa4

Browse files
subirjollySubir Jolly
andauthored
feat: add checkout query param (#3207)
* feat: add checkout query param * chore: remove unused import * chore: updated to use inbuilt lib function/obj * chore: remove credit if upgrading * chore: switched to google experiment * chore: added key for variant * style: fix formatting issue * chore: use PAYG_CREDIT_EXPERIMENT_ID from env * style: fix formatting error * chore: add Google Experiment Var * chore: remove and add in another pr Co-authored-by: Subir Jolly <subirjolly@Subirs-MacBook-Pro.local>
1 parent 3240c17 commit a311aa4

File tree

3 files changed

+37
-9
lines changed

3 files changed

+37
-9
lines changed

src/checkout/CheckoutForm.tsx

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
JustifyContent,
1818
Panel,
1919
} from '@influxdata/clockface'
20+
import {GoogleOptimizeExperiment} from 'src/cloud/components/experiments/GoogleOptimizeExperiment'
2021

2122
// Components
2223
import ContactForm from 'src/checkout/utils/ContactForm'
@@ -31,16 +32,20 @@ import {CheckoutContext} from 'src/checkout/context/checkout'
3132

3233
// Events
3334
import {event} from 'src/cloud/utils/reporting'
35+
import {isFlagEnabled} from 'src/shared/utils/featureFlag'
36+
37+
// Constants
38+
import {PAYG_CREDIT_EXPERIMENT_ID} from 'src/shared/constants'
3439

3540
// Utils
36-
import {isFlagEnabled} from 'src/shared/utils/featureFlag'
3741

3842
const CheckoutForm: FC = () => {
3943
const {
4044
handleFormValidation,
4145
zuoraParams,
4246
handleSubmit,
4347
setIsDirty,
48+
isSubmitting,
4449
} = useContext(CheckoutContext)
4550

4651
const onSubmit = () => {
@@ -58,8 +63,6 @@ const CheckoutForm: FC = () => {
5863
}
5964
}
6065

61-
const {isSubmitting} = useContext(CheckoutContext)
62-
6366
return (
6467
<Form noValidate onSubmit={onSubmit}>
6568
<AppWrapper type="funnel">
@@ -88,11 +91,20 @@ const CheckoutForm: FC = () => {
8891
</a>
8992
.
9093
</p>
94+
9195
{isFlagEnabled('paygCheckoutCredit') && (
92-
<div className="checkout-form--banner">
93-
<strong className="checkout-banner--credit">$250</strong>
94-
<p>credit applied</p>
95-
</div>
96+
<GoogleOptimizeExperiment
97+
experimentID={PAYG_CREDIT_EXPERIMENT_ID}
98+
variants={[
99+
<div
100+
className="checkout-form--banner"
101+
key="checkout-form-banner"
102+
>
103+
<strong className="checkout-banner--credit">$250</strong>
104+
<p>credit applied</p>
105+
</div>,
106+
]}
107+
/>
96108
)}
97109
</Panel.Body>
98110
</Panel>

src/checkout/context/checkout.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import React, {FC, useCallback, useEffect, useState} from 'react'
33
import {useDispatch, useSelector} from 'react-redux'
44
import {useHistory} from 'react-router-dom'
55

6+
// Components
7+
import {getExperimentVariantId} from 'src/cloud/utils/experiments'
8+
69
// Utils
710
import {notify} from 'src/shared/actions/notifications'
811
import {
@@ -23,10 +26,12 @@ import {
2326
BALANCE_THRESHOLD_DEFAULT,
2427
EMPTY_ZUORA_PARAMS,
2528
} from 'src/shared/constants'
29+
import {PAYG_CREDIT_EXPERIMENT_ID} from 'src/shared/constants'
2630

2731
// Types
2832
import {CreditCardParams, RemoteDataState} from 'src/types'
2933
import {getErrorMessage} from 'src/utils/api'
34+
import {isFlagEnabled} from 'src/shared/utils/featureFlag'
3035

3136
export type Props = {
3237
children: JSX.Element
@@ -59,6 +64,7 @@ export interface CheckoutContextType {
5964
isSubmitting: boolean
6065
setIsDirty: (_: boolean) => void
6166
zuoraParams: CreditCardParams
67+
isPaygCreditActive: boolean
6268
}
6369

6470
export const DEFAULT_CONTEXT: CheckoutContextType = {
@@ -74,6 +80,7 @@ export const DEFAULT_CONTEXT: CheckoutContextType = {
7480
isSubmitting: false,
7581
setIsDirty: (_: boolean) => {},
7682
zuoraParams: EMPTY_ZUORA_PARAMS,
83+
isPaygCreditActive: false,
7784
}
7885

7986
export const CheckoutContext = React.createContext<CheckoutContextType>(
@@ -249,6 +256,10 @@ export const CheckoutProvider: FC<Props> = React.memo(({children}) => {
249256
return errs.length
250257
}
251258

259+
const isPaygCreditActive =
260+
isFlagEnabled('paygCheckoutCredit') &&
261+
getExperimentVariantId(PAYG_CREDIT_EXPERIMENT_ID) === '1'
262+
252263
const handleSubmit = useCallback(
253264
async (paymentMethodId: string) => {
254265
if (isDirty === false) {
@@ -283,8 +294,11 @@ export const CheckoutProvider: FC<Props> = React.memo(({children}) => {
283294
delete formData.intlSubdivision
284295
delete formData.shouldNotify
285296

286-
const paymentInformation = {...formData, paymentMethodId}
287-
297+
const paymentInformation = {
298+
...formData,
299+
paymentMethodId,
300+
isPaygCreditActive,
301+
}
288302
const response = await postCheckout({data: paymentInformation})
289303

290304
if (response.status !== 201) {
@@ -328,6 +342,7 @@ export const CheckoutProvider: FC<Props> = React.memo(({children}) => {
328342
isSubmitting,
329343
setIsDirty,
330344
zuoraParams,
345+
isPaygCreditActive,
331346
}}
332347
>
333348
{children}

src/shared/constants/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,4 @@ export const GLOBALSEARCH_API_KEY = formatConstant(
164164

165165
export const PAYG_CREDIT_DAYS = 30
166166
export const PAYG_MAX_CREDIT = 250
167+
export const PAYG_CREDIT_EXPERIMENT_ID = process.env.PAYG_CREDIT_EXPERIMENT_ID

0 commit comments

Comments
 (0)