tf-checkout-react 1.0.101 → 1.0.102
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/billing-info-container/index.d.ts +3 -1
- package/dist/components/common/SnackbarAlert.d.ts +13 -0
- package/dist/components/confirmationContainer/index.d.ts +2 -1
- package/dist/components/ticketsContainer/index.d.ts +2 -1
- package/dist/env.d.ts +1 -0
- package/dist/images/done.svg +3 -3
- package/dist/tf-checkout-react.cjs.development.js +242 -117
- package/dist/tf-checkout-react.cjs.development.js.map +1 -1
- package/dist/tf-checkout-react.cjs.production.min.js +1 -1
- package/dist/tf-checkout-react.cjs.production.min.js.map +1 -1
- package/dist/tf-checkout-react.esm.js +243 -118
- package/dist/tf-checkout-react.esm.js.map +1 -1
- package/dist/tf-checkout-styles.css +1 -1
- package/package.json +89 -89
- package/src/.DS_Store +0 -0
- package/src/.d.ts +2 -2
- package/src/api/index.ts +278 -278
- package/src/assets/images/done.svg +3 -3
- package/src/components/.DS_Store +0 -0
- package/src/components/billing-info-container/index.tsx +796 -777
- package/src/components/billing-info-container/style.css +105 -105
- package/src/components/billing-info-container/utils.ts +224 -224
- package/src/components/common/CheckboxField.tsx +41 -41
- package/src/components/common/CustomField.tsx +84 -84
- package/src/components/common/FormikPhoneNumberField.tsx +51 -51
- package/src/components/common/Loader.tsx +9 -9
- package/src/components/common/RadioField.tsx +35 -35
- package/src/components/common/SelectField.tsx +80 -80
- package/src/components/common/SnackbarAlert.tsx +54 -0
- package/src/components/common/index.tsx +4 -4
- package/src/components/confirmModal/index.tsx +51 -51
- package/src/components/confirmModal/style.css +21 -21
- package/src/components/confirmationContainer/config.ts +72 -72
- package/src/components/confirmationContainer/index.tsx +197 -194
- package/src/components/confirmationContainer/social-buttons.tsx +94 -94
- package/src/components/confirmationContainer/style.css +202 -202
- package/src/components/countdown/index.tsx +89 -89
- package/src/components/countdown/style.css +9 -9
- package/src/components/index.ts +7 -7
- package/src/components/loginModal/index.tsx +209 -209
- package/src/components/loginModal/style.css +71 -71
- package/src/components/myTicketsContainer/index.tsx +196 -137
- package/src/components/myTicketsContainer/row.tsx +41 -41
- package/src/components/myTicketsContainer/style.css +39 -39
- package/src/components/myTicketsContainer/tableConfig.tsx +34 -34
- package/src/components/orderDetailsContainer/index.tsx +249 -249
- package/src/components/orderDetailsContainer/style.css +72 -72
- package/src/components/orderDetailsContainer/ticketsTable.tsx +124 -124
- package/src/components/paymentContainer/index.tsx +284 -284
- package/src/components/registerModal/index.tsx +190 -190
- package/src/components/stripePayment/index.tsx +253 -253
- package/src/components/stripePayment/style.css +59 -59
- package/src/components/ticketResale/index.tsx +56 -56
- package/src/components/ticketResaleModal/index.tsx +210 -210
- package/src/components/ticketResaleModal/style.css +28 -28
- package/src/components/ticketsContainer/PromoCodeSection.tsx +99 -99
- package/src/components/ticketsContainer/ReferralLogic.tsx +33 -33
- package/src/components/ticketsContainer/TicketRow.tsx +83 -83
- package/src/components/ticketsContainer/TicketsSection.tsx +81 -81
- package/src/components/ticketsContainer/index.tsx +430 -422
- package/src/components/ticketsContainer/style.css +181 -181
- package/src/components/ticketsContainer/utils.ts +11 -11
- package/src/components/timerWidget/index.tsx +70 -70
- package/src/components/timerWidget/style.css +26 -26
- package/src/components/waitingList/index.tsx +178 -178
- package/src/components/waitingList/style.css +26 -26
- package/src/env.ts +20 -19
- package/src/index.ts +13 -13
- package/src/normalizers/index.ts +45 -45
- package/src/types/billing-info-data.ts +37 -37
- package/src/types/payment-field.ts +7 -7
- package/src/types/referral-promotion.ts +7 -7
- package/src/utils/createCheckoutDataBodyWithDefaultHolder.ts +59 -59
- package/src/utils/downloadPDF.tsx +30 -30
- package/src/utils/formikErrorFocus.ts +24 -24
- package/src/utils/getImage.ts +14 -14
- package/src/utils/getQueryVariable.ts +13 -13
- package/src/utils/index.ts +5 -5
- package/src/utils/setConfigs.ts +26 -26
- package/src/utils/showZero.tsx +10 -10
- package/src/validators/index.ts +20 -20
|
@@ -1,284 +1,284 @@
|
|
|
1
|
-
import React, { useEffect, useState } from 'react'
|
|
2
|
-
import { AxiosError } from 'axios'
|
|
3
|
-
import Container from '@mui/material/Container'
|
|
4
|
-
import CircularProgress from '@mui/material/CircularProgress'
|
|
5
|
-
import Alert from '@mui/material/Alert'
|
|
6
|
-
import { Elements } from '@stripe/react-stripe-js'
|
|
7
|
-
import {
|
|
8
|
-
loadStripe,
|
|
9
|
-
StripeConstructorOptions,
|
|
10
|
-
StripeElementsOptions,
|
|
11
|
-
} from '@stripe/stripe-js'
|
|
12
|
-
import _map from 'lodash/map'
|
|
13
|
-
import _get from 'lodash/get'
|
|
14
|
-
import _identity from 'lodash/identity'
|
|
15
|
-
import { CONFIGS } from '../../utils'
|
|
16
|
-
import { nanoid } from 'nanoid'
|
|
17
|
-
import { getQueryVariable } from '../../utils/getQueryVariable'
|
|
18
|
-
|
|
19
|
-
import './style.css'
|
|
20
|
-
import StripePayment from '../stripePayment'
|
|
21
|
-
import { IOrderData, IPaymentField } from '../../types'
|
|
22
|
-
|
|
23
|
-
import { getPaymentData, handlePaymentSuccess, getConditions, handleFreeSuccess } from '../../api'
|
|
24
|
-
import { StripeCardNumberElementOptions } from '@stripe/stripe-js'
|
|
25
|
-
import { ThemeProvider, createTheme } from '@mui/material/styles'
|
|
26
|
-
import { ThemeOptions } from '@mui/material'
|
|
27
|
-
import { CSSProperties } from '@mui/styles'
|
|
28
|
-
import TimerWidget from '../timerWidget'
|
|
29
|
-
import { Loader } from '../common/index'
|
|
30
|
-
|
|
31
|
-
const publishableKey = CONFIGS.STRIPE_PUBLISHABLE_KEY || ''
|
|
32
|
-
|
|
33
|
-
const getStripePromise = (reviewData: any) => {
|
|
34
|
-
const stripePublishableKey =
|
|
35
|
-
_get(reviewData, 'payment_method.stripe_publishable_key') || publishableKey
|
|
36
|
-
const stripeAccount = _get(
|
|
37
|
-
reviewData,
|
|
38
|
-
'payment_method.stripe_connected_account'
|
|
39
|
-
)
|
|
40
|
-
|
|
41
|
-
const options: StripeConstructorOptions = {}
|
|
42
|
-
if (stripeAccount) {
|
|
43
|
-
options.stripeAccount = stripeAccount
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return loadStripe(stripePublishableKey, options)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export interface IPaymentPage {
|
|
50
|
-
paymentFields: IPaymentField[];
|
|
51
|
-
handlePayment: any;
|
|
52
|
-
checkoutData: any;
|
|
53
|
-
formTitle?: string;
|
|
54
|
-
errorText?: string;
|
|
55
|
-
onErrorClose?: () => void;
|
|
56
|
-
onGetPaymentDataSuccess: (value: any) => void;
|
|
57
|
-
onGetPaymentDataError: (value: AxiosError) => void;
|
|
58
|
-
onPaymentError: (value: AxiosError) => void;
|
|
59
|
-
stripeCardOptions?: StripeCardNumberElementOptions;
|
|
60
|
-
disableZipSection: boolean;
|
|
61
|
-
themeOptions?: ThemeOptions & {
|
|
62
|
-
input?: CSSProperties;
|
|
63
|
-
checkbox?: CSSProperties;
|
|
64
|
-
};
|
|
65
|
-
elementsOptions?: StripeElementsOptions;
|
|
66
|
-
onCountdownFinish?: () => void;
|
|
67
|
-
enableTimer?: boolean;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const initialOrderValues: IOrderData = {
|
|
71
|
-
product_name: '',
|
|
72
|
-
ticketType: '',
|
|
73
|
-
quantity: '',
|
|
74
|
-
price: '',
|
|
75
|
-
total: '',
|
|
76
|
-
currency: '',
|
|
77
|
-
}
|
|
78
|
-
const initialReviewValues = {
|
|
79
|
-
order_details: {
|
|
80
|
-
order_hash: '',
|
|
81
|
-
},
|
|
82
|
-
payment_method: {
|
|
83
|
-
stripe_client_secret: '',
|
|
84
|
-
},
|
|
85
|
-
billing_info: {},
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export const PaymentContainer = ({
|
|
89
|
-
paymentFields = [],
|
|
90
|
-
handlePayment,
|
|
91
|
-
formTitle = 'Get Your Tickets',
|
|
92
|
-
errorText,
|
|
93
|
-
checkoutData,
|
|
94
|
-
onErrorClose = _identity,
|
|
95
|
-
onGetPaymentDataSuccess = () => {},
|
|
96
|
-
onGetPaymentDataError = () => {},
|
|
97
|
-
onPaymentError = () => {},
|
|
98
|
-
stripeCardOptions = {},
|
|
99
|
-
disableZipSection = false,
|
|
100
|
-
themeOptions,
|
|
101
|
-
elementsOptions,
|
|
102
|
-
onCountdownFinish = () => {},
|
|
103
|
-
enableTimer = false,
|
|
104
|
-
}: IPaymentPage) => {
|
|
105
|
-
const [reviewData, setReviewData] = useState(initialReviewValues)
|
|
106
|
-
const [orderData, setOrderData] = useState(initialOrderValues)
|
|
107
|
-
const [error, setError] = useState(null)
|
|
108
|
-
const [paymentIsLoading, setPaymentIsLoading] = useState(false)
|
|
109
|
-
const [paymentDataIsLoading, setPaymentDataIsLoading] = useState(true)
|
|
110
|
-
const [conditions, setConditions] = useState<{ id: string; text: string }[]>(
|
|
111
|
-
[]
|
|
112
|
-
)
|
|
113
|
-
|
|
114
|
-
const showFormTitle: boolean = Boolean(formTitle)
|
|
115
|
-
const showErrorText: boolean = Boolean(errorText)
|
|
116
|
-
|
|
117
|
-
const eventId = getQueryVariable('event_id')
|
|
118
|
-
const { hash, total } = checkoutData;
|
|
119
|
-
|
|
120
|
-
useEffect(() => {
|
|
121
|
-
(async () => {
|
|
122
|
-
try {
|
|
123
|
-
const response = await getPaymentData(hash)
|
|
124
|
-
if (response.data.success) {
|
|
125
|
-
const attributes = _get(response, 'data.data.attributes')
|
|
126
|
-
setReviewData(attributes)
|
|
127
|
-
const { cart, order_details } = attributes
|
|
128
|
-
const {
|
|
129
|
-
tickets: [ticket],
|
|
130
|
-
} = order_details
|
|
131
|
-
const orderData = {
|
|
132
|
-
product_name: cart[0]?.product_name,
|
|
133
|
-
ticketType: ticket?.name,
|
|
134
|
-
quantity: ticket?.quantity,
|
|
135
|
-
price: ticket?.price,
|
|
136
|
-
total: order_details?.total,
|
|
137
|
-
currency: order_details?.currency,
|
|
138
|
-
}
|
|
139
|
-
setOrderData(orderData)
|
|
140
|
-
onGetPaymentDataSuccess(response.data)
|
|
141
|
-
}
|
|
142
|
-
} catch (e) {
|
|
143
|
-
setError(_get(e, 'response.data.message'))
|
|
144
|
-
onGetPaymentDataError(e.response)
|
|
145
|
-
} finally {
|
|
146
|
-
setPaymentDataIsLoading(false)
|
|
147
|
-
}
|
|
148
|
-
})()
|
|
149
|
-
}, [checkoutData])
|
|
150
|
-
|
|
151
|
-
//just once
|
|
152
|
-
useEffect(() => {
|
|
153
|
-
// fetch conditions data
|
|
154
|
-
const fetchConditions = async () => {
|
|
155
|
-
if (eventId) {
|
|
156
|
-
const res = await getConditions(eventId)
|
|
157
|
-
const conditionsInfo = _get(res, 'data.data.attributes')
|
|
158
|
-
setConditions(
|
|
159
|
-
conditionsInfo
|
|
160
|
-
? conditionsInfo.map((item: string) => ({
|
|
161
|
-
id: nanoid(),
|
|
162
|
-
text: item,
|
|
163
|
-
checked: false,
|
|
164
|
-
}))
|
|
165
|
-
: []
|
|
166
|
-
)
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
fetchConditions()
|
|
170
|
-
}, [])
|
|
171
|
-
|
|
172
|
-
// 1. get payment data ---> v1/order/${hash}/review/ done
|
|
173
|
-
// 2. handle payment ---> v1/order/${orderHash}/pay/
|
|
174
|
-
// 3. redirect to confirmation page
|
|
175
|
-
const handlePaymentMiddleWare = async (error: any) => {
|
|
176
|
-
try {
|
|
177
|
-
if (error) {
|
|
178
|
-
setPaymentIsLoading(false)
|
|
179
|
-
throw error
|
|
180
|
-
}
|
|
181
|
-
const {
|
|
182
|
-
order_details: { order_hash },
|
|
183
|
-
} = reviewData
|
|
184
|
-
const paymentSuccessResponse = total === "0.00" ? (await handleFreeSuccess(order_hash)) : (await handlePaymentSuccess(order_hash))
|
|
185
|
-
if (paymentSuccessResponse.status === 200) {
|
|
186
|
-
handlePayment(paymentSuccessResponse)
|
|
187
|
-
setPaymentIsLoading(false)
|
|
188
|
-
}
|
|
189
|
-
} catch (e) {
|
|
190
|
-
setError(_get(e, 'response.data.message'))
|
|
191
|
-
onPaymentError(e.response)
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
const themeMui = createTheme(themeOptions)
|
|
196
|
-
|
|
197
|
-
return (
|
|
198
|
-
<ThemeProvider theme={themeMui}>
|
|
199
|
-
<div className="payment_page">
|
|
200
|
-
{!paymentIsLoading && !error && enableTimer && (
|
|
201
|
-
<TimerWidget
|
|
202
|
-
expires_at={_get(reviewData, 'expires_at', 0)}
|
|
203
|
-
buyLoading={paymentIsLoading}
|
|
204
|
-
onCountdownFinish={onCountdownFinish}
|
|
205
|
-
/>
|
|
206
|
-
)}
|
|
207
|
-
{error && (
|
|
208
|
-
<Alert severity="error" onClose={onErrorClose} variant="filled">
|
|
209
|
-
{error}
|
|
210
|
-
</Alert>
|
|
211
|
-
)}
|
|
212
|
-
{paymentDataIsLoading && <Loader />}
|
|
213
|
-
{!paymentDataIsLoading && (
|
|
214
|
-
<Container maxWidth="md">
|
|
215
|
-
{showFormTitle && <h1>{formTitle}</h1>}
|
|
216
|
-
<div className="order_info_text">Order Review</div>
|
|
217
|
-
<div className="order_info_section">
|
|
218
|
-
{_map(paymentFields, field => {
|
|
219
|
-
const {
|
|
220
|
-
id,
|
|
221
|
-
label,
|
|
222
|
-
className = '',
|
|
223
|
-
normalizer = _identity,
|
|
224
|
-
} = field
|
|
225
|
-
return (
|
|
226
|
-
<div key={id} className="order_info_block">
|
|
227
|
-
<div className="order_info_title">{label}</div>
|
|
228
|
-
<div className={`${className} order_info_text`}>
|
|
229
|
-
{normalizer(orderData[id], orderData.currency)}
|
|
230
|
-
</div>
|
|
231
|
-
</div>
|
|
232
|
-
)
|
|
233
|
-
})}
|
|
234
|
-
</div>
|
|
235
|
-
{total !== "0.00" ? <div className="payment_info">
|
|
236
|
-
<div className="payment_info_label">
|
|
237
|
-
Please provide your payment information
|
|
238
|
-
</div>
|
|
239
|
-
{showErrorText && (
|
|
240
|
-
<p className="payment_info__error">{errorText}</p>
|
|
241
|
-
)}
|
|
242
|
-
<div>
|
|
243
|
-
<Elements
|
|
244
|
-
stripe={getStripePromise(reviewData)}
|
|
245
|
-
options={elementsOptions}
|
|
246
|
-
>
|
|
247
|
-
<StripePayment
|
|
248
|
-
stripe_client_secret={_get(
|
|
249
|
-
reviewData,
|
|
250
|
-
'payment_method.stripe_client_secret'
|
|
251
|
-
)}
|
|
252
|
-
total={orderData.total}
|
|
253
|
-
onSubmit={handlePaymentMiddleWare}
|
|
254
|
-
error={error}
|
|
255
|
-
currency={orderData.currency}
|
|
256
|
-
billing_info={reviewData.billing_info}
|
|
257
|
-
isLoading={paymentIsLoading}
|
|
258
|
-
handleSetLoading={value => setPaymentIsLoading(value)}
|
|
259
|
-
conditions={conditions}
|
|
260
|
-
stripeCardOptions={stripeCardOptions}
|
|
261
|
-
disableZipSection={disableZipSection}
|
|
262
|
-
/>
|
|
263
|
-
</Elements>
|
|
264
|
-
</div>
|
|
265
|
-
</div> :
|
|
266
|
-
<div
|
|
267
|
-
className={`payment_button ${paymentIsLoading ? 'disabled-payment-button' : ''}`}
|
|
268
|
-
>
|
|
269
|
-
<button disabled={paymentIsLoading} type="button" onClick={() => {
|
|
270
|
-
handlePaymentMiddleWare(null)
|
|
271
|
-
}}>
|
|
272
|
-
{paymentIsLoading ? (
|
|
273
|
-
<CircularProgress size={26} />
|
|
274
|
-
) : (
|
|
275
|
-
"Complete Registration"
|
|
276
|
-
)}
|
|
277
|
-
</button>
|
|
278
|
-
</div>}
|
|
279
|
-
</Container>
|
|
280
|
-
)}
|
|
281
|
-
</div>
|
|
282
|
-
</ThemeProvider>
|
|
283
|
-
)
|
|
284
|
-
}
|
|
1
|
+
import React, { useEffect, useState } from 'react'
|
|
2
|
+
import { AxiosError } from 'axios'
|
|
3
|
+
import Container from '@mui/material/Container'
|
|
4
|
+
import CircularProgress from '@mui/material/CircularProgress'
|
|
5
|
+
import Alert from '@mui/material/Alert'
|
|
6
|
+
import { Elements } from '@stripe/react-stripe-js'
|
|
7
|
+
import {
|
|
8
|
+
loadStripe,
|
|
9
|
+
StripeConstructorOptions,
|
|
10
|
+
StripeElementsOptions,
|
|
11
|
+
} from '@stripe/stripe-js'
|
|
12
|
+
import _map from 'lodash/map'
|
|
13
|
+
import _get from 'lodash/get'
|
|
14
|
+
import _identity from 'lodash/identity'
|
|
15
|
+
import { CONFIGS } from '../../utils'
|
|
16
|
+
import { nanoid } from 'nanoid'
|
|
17
|
+
import { getQueryVariable } from '../../utils/getQueryVariable'
|
|
18
|
+
|
|
19
|
+
import './style.css'
|
|
20
|
+
import StripePayment from '../stripePayment'
|
|
21
|
+
import { IOrderData, IPaymentField } from '../../types'
|
|
22
|
+
|
|
23
|
+
import { getPaymentData, handlePaymentSuccess, getConditions, handleFreeSuccess } from '../../api'
|
|
24
|
+
import { StripeCardNumberElementOptions } from '@stripe/stripe-js'
|
|
25
|
+
import { ThemeProvider, createTheme } from '@mui/material/styles'
|
|
26
|
+
import { ThemeOptions } from '@mui/material'
|
|
27
|
+
import { CSSProperties } from '@mui/styles'
|
|
28
|
+
import TimerWidget from '../timerWidget'
|
|
29
|
+
import { Loader } from '../common/index'
|
|
30
|
+
|
|
31
|
+
const publishableKey = CONFIGS.STRIPE_PUBLISHABLE_KEY || ''
|
|
32
|
+
|
|
33
|
+
const getStripePromise = (reviewData: any) => {
|
|
34
|
+
const stripePublishableKey =
|
|
35
|
+
_get(reviewData, 'payment_method.stripe_publishable_key') || publishableKey
|
|
36
|
+
const stripeAccount = _get(
|
|
37
|
+
reviewData,
|
|
38
|
+
'payment_method.stripe_connected_account'
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
const options: StripeConstructorOptions = {}
|
|
42
|
+
if (stripeAccount) {
|
|
43
|
+
options.stripeAccount = stripeAccount
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return loadStripe(stripePublishableKey, options)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface IPaymentPage {
|
|
50
|
+
paymentFields: IPaymentField[];
|
|
51
|
+
handlePayment: any;
|
|
52
|
+
checkoutData: any;
|
|
53
|
+
formTitle?: string;
|
|
54
|
+
errorText?: string;
|
|
55
|
+
onErrorClose?: () => void;
|
|
56
|
+
onGetPaymentDataSuccess: (value: any) => void;
|
|
57
|
+
onGetPaymentDataError: (value: AxiosError) => void;
|
|
58
|
+
onPaymentError: (value: AxiosError) => void;
|
|
59
|
+
stripeCardOptions?: StripeCardNumberElementOptions;
|
|
60
|
+
disableZipSection: boolean;
|
|
61
|
+
themeOptions?: ThemeOptions & {
|
|
62
|
+
input?: CSSProperties;
|
|
63
|
+
checkbox?: CSSProperties;
|
|
64
|
+
};
|
|
65
|
+
elementsOptions?: StripeElementsOptions;
|
|
66
|
+
onCountdownFinish?: () => void;
|
|
67
|
+
enableTimer?: boolean;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const initialOrderValues: IOrderData = {
|
|
71
|
+
product_name: '',
|
|
72
|
+
ticketType: '',
|
|
73
|
+
quantity: '',
|
|
74
|
+
price: '',
|
|
75
|
+
total: '',
|
|
76
|
+
currency: '',
|
|
77
|
+
}
|
|
78
|
+
const initialReviewValues = {
|
|
79
|
+
order_details: {
|
|
80
|
+
order_hash: '',
|
|
81
|
+
},
|
|
82
|
+
payment_method: {
|
|
83
|
+
stripe_client_secret: '',
|
|
84
|
+
},
|
|
85
|
+
billing_info: {},
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export const PaymentContainer = ({
|
|
89
|
+
paymentFields = [],
|
|
90
|
+
handlePayment,
|
|
91
|
+
formTitle = 'Get Your Tickets',
|
|
92
|
+
errorText,
|
|
93
|
+
checkoutData,
|
|
94
|
+
onErrorClose = _identity,
|
|
95
|
+
onGetPaymentDataSuccess = () => {},
|
|
96
|
+
onGetPaymentDataError = () => {},
|
|
97
|
+
onPaymentError = () => {},
|
|
98
|
+
stripeCardOptions = {},
|
|
99
|
+
disableZipSection = false,
|
|
100
|
+
themeOptions,
|
|
101
|
+
elementsOptions,
|
|
102
|
+
onCountdownFinish = () => {},
|
|
103
|
+
enableTimer = false,
|
|
104
|
+
}: IPaymentPage) => {
|
|
105
|
+
const [reviewData, setReviewData] = useState(initialReviewValues)
|
|
106
|
+
const [orderData, setOrderData] = useState(initialOrderValues)
|
|
107
|
+
const [error, setError] = useState(null)
|
|
108
|
+
const [paymentIsLoading, setPaymentIsLoading] = useState(false)
|
|
109
|
+
const [paymentDataIsLoading, setPaymentDataIsLoading] = useState(true)
|
|
110
|
+
const [conditions, setConditions] = useState<{ id: string; text: string }[]>(
|
|
111
|
+
[]
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
const showFormTitle: boolean = Boolean(formTitle)
|
|
115
|
+
const showErrorText: boolean = Boolean(errorText)
|
|
116
|
+
|
|
117
|
+
const eventId = getQueryVariable('event_id')
|
|
118
|
+
const { hash, total } = checkoutData;
|
|
119
|
+
|
|
120
|
+
useEffect(() => {
|
|
121
|
+
(async () => {
|
|
122
|
+
try {
|
|
123
|
+
const response = await getPaymentData(hash)
|
|
124
|
+
if (response.data.success) {
|
|
125
|
+
const attributes = _get(response, 'data.data.attributes')
|
|
126
|
+
setReviewData(attributes)
|
|
127
|
+
const { cart, order_details } = attributes
|
|
128
|
+
const {
|
|
129
|
+
tickets: [ticket],
|
|
130
|
+
} = order_details
|
|
131
|
+
const orderData = {
|
|
132
|
+
product_name: cart[0]?.product_name,
|
|
133
|
+
ticketType: ticket?.name,
|
|
134
|
+
quantity: ticket?.quantity,
|
|
135
|
+
price: ticket?.price,
|
|
136
|
+
total: order_details?.total,
|
|
137
|
+
currency: order_details?.currency,
|
|
138
|
+
}
|
|
139
|
+
setOrderData(orderData)
|
|
140
|
+
onGetPaymentDataSuccess(response.data)
|
|
141
|
+
}
|
|
142
|
+
} catch (e) {
|
|
143
|
+
setError(_get(e, 'response.data.message'))
|
|
144
|
+
onGetPaymentDataError(e.response)
|
|
145
|
+
} finally {
|
|
146
|
+
setPaymentDataIsLoading(false)
|
|
147
|
+
}
|
|
148
|
+
})()
|
|
149
|
+
}, [checkoutData])
|
|
150
|
+
|
|
151
|
+
//just once
|
|
152
|
+
useEffect(() => {
|
|
153
|
+
// fetch conditions data
|
|
154
|
+
const fetchConditions = async () => {
|
|
155
|
+
if (eventId) {
|
|
156
|
+
const res = await getConditions(eventId)
|
|
157
|
+
const conditionsInfo = _get(res, 'data.data.attributes')
|
|
158
|
+
setConditions(
|
|
159
|
+
conditionsInfo
|
|
160
|
+
? conditionsInfo.map((item: string) => ({
|
|
161
|
+
id: nanoid(),
|
|
162
|
+
text: item,
|
|
163
|
+
checked: false,
|
|
164
|
+
}))
|
|
165
|
+
: []
|
|
166
|
+
)
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
fetchConditions()
|
|
170
|
+
}, [])
|
|
171
|
+
|
|
172
|
+
// 1. get payment data ---> v1/order/${hash}/review/ done
|
|
173
|
+
// 2. handle payment ---> v1/order/${orderHash}/pay/
|
|
174
|
+
// 3. redirect to confirmation page
|
|
175
|
+
const handlePaymentMiddleWare = async (error: any) => {
|
|
176
|
+
try {
|
|
177
|
+
if (error) {
|
|
178
|
+
setPaymentIsLoading(false)
|
|
179
|
+
throw error
|
|
180
|
+
}
|
|
181
|
+
const {
|
|
182
|
+
order_details: { order_hash },
|
|
183
|
+
} = reviewData
|
|
184
|
+
const paymentSuccessResponse = total === "0.00" ? (await handleFreeSuccess(order_hash)) : (await handlePaymentSuccess(order_hash))
|
|
185
|
+
if (paymentSuccessResponse.status === 200) {
|
|
186
|
+
handlePayment(paymentSuccessResponse)
|
|
187
|
+
setPaymentIsLoading(false)
|
|
188
|
+
}
|
|
189
|
+
} catch (e) {
|
|
190
|
+
setError(_get(e, 'response.data.message'))
|
|
191
|
+
onPaymentError(e.response)
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const themeMui = createTheme(themeOptions)
|
|
196
|
+
|
|
197
|
+
return (
|
|
198
|
+
<ThemeProvider theme={themeMui}>
|
|
199
|
+
<div className="payment_page">
|
|
200
|
+
{!paymentIsLoading && !error && enableTimer && (
|
|
201
|
+
<TimerWidget
|
|
202
|
+
expires_at={_get(reviewData, 'expires_at', 0)}
|
|
203
|
+
buyLoading={paymentIsLoading}
|
|
204
|
+
onCountdownFinish={onCountdownFinish}
|
|
205
|
+
/>
|
|
206
|
+
)}
|
|
207
|
+
{error && (
|
|
208
|
+
<Alert severity="error" onClose={onErrorClose} variant="filled">
|
|
209
|
+
{error}
|
|
210
|
+
</Alert>
|
|
211
|
+
)}
|
|
212
|
+
{paymentDataIsLoading && <Loader />}
|
|
213
|
+
{!paymentDataIsLoading && (
|
|
214
|
+
<Container maxWidth="md">
|
|
215
|
+
{showFormTitle && <h1>{formTitle}</h1>}
|
|
216
|
+
<div className="order_info_text">Order Review</div>
|
|
217
|
+
<div className="order_info_section">
|
|
218
|
+
{_map(paymentFields, field => {
|
|
219
|
+
const {
|
|
220
|
+
id,
|
|
221
|
+
label,
|
|
222
|
+
className = '',
|
|
223
|
+
normalizer = _identity,
|
|
224
|
+
} = field
|
|
225
|
+
return (
|
|
226
|
+
<div key={id} className="order_info_block">
|
|
227
|
+
<div className="order_info_title">{label}</div>
|
|
228
|
+
<div className={`${className} order_info_text`}>
|
|
229
|
+
{normalizer(orderData[id], orderData.currency)}
|
|
230
|
+
</div>
|
|
231
|
+
</div>
|
|
232
|
+
)
|
|
233
|
+
})}
|
|
234
|
+
</div>
|
|
235
|
+
{total !== "0.00" ? <div className="payment_info">
|
|
236
|
+
<div className="payment_info_label">
|
|
237
|
+
Please provide your payment information
|
|
238
|
+
</div>
|
|
239
|
+
{showErrorText && (
|
|
240
|
+
<p className="payment_info__error">{errorText}</p>
|
|
241
|
+
)}
|
|
242
|
+
<div>
|
|
243
|
+
<Elements
|
|
244
|
+
stripe={getStripePromise(reviewData)}
|
|
245
|
+
options={elementsOptions}
|
|
246
|
+
>
|
|
247
|
+
<StripePayment
|
|
248
|
+
stripe_client_secret={_get(
|
|
249
|
+
reviewData,
|
|
250
|
+
'payment_method.stripe_client_secret'
|
|
251
|
+
)}
|
|
252
|
+
total={orderData.total}
|
|
253
|
+
onSubmit={handlePaymentMiddleWare}
|
|
254
|
+
error={error}
|
|
255
|
+
currency={orderData.currency}
|
|
256
|
+
billing_info={reviewData.billing_info}
|
|
257
|
+
isLoading={paymentIsLoading}
|
|
258
|
+
handleSetLoading={value => setPaymentIsLoading(value)}
|
|
259
|
+
conditions={conditions}
|
|
260
|
+
stripeCardOptions={stripeCardOptions}
|
|
261
|
+
disableZipSection={disableZipSection}
|
|
262
|
+
/>
|
|
263
|
+
</Elements>
|
|
264
|
+
</div>
|
|
265
|
+
</div> :
|
|
266
|
+
<div
|
|
267
|
+
className={`payment_button ${paymentIsLoading ? 'disabled-payment-button' : ''}`}
|
|
268
|
+
>
|
|
269
|
+
<button disabled={paymentIsLoading} type="button" onClick={() => {
|
|
270
|
+
handlePaymentMiddleWare(null)
|
|
271
|
+
}}>
|
|
272
|
+
{paymentIsLoading ? (
|
|
273
|
+
<CircularProgress size={26} />
|
|
274
|
+
) : (
|
|
275
|
+
"Complete Registration"
|
|
276
|
+
)}
|
|
277
|
+
</button>
|
|
278
|
+
</div>}
|
|
279
|
+
</Container>
|
|
280
|
+
)}
|
|
281
|
+
</div>
|
|
282
|
+
</ThemeProvider>
|
|
283
|
+
)
|
|
284
|
+
}
|