@blocklet/payment-react 1.14.22 → 1.14.24
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/README.md +77 -0
- package/es/checkout/donate.d.ts +3 -2
- package/es/checkout/donate.js +31 -4
- package/es/checkout/form.d.ts +1 -1
- package/es/checkout/form.js +31 -7
- package/es/checkout/table.js +4 -1
- package/es/components/input.d.ts +3 -3
- package/es/libs/util.d.ts +6 -6
- package/es/payment/index.d.ts +3 -1
- package/es/payment/index.js +67 -51
- package/es/payment/product-donation.js +26 -15
- package/es/payment/summary.js +1 -1
- package/es/theme/index.d.ts +8 -3
- package/es/theme/index.js +222 -209
- package/es/types/index.d.ts +6 -1
- package/lib/checkout/donate.d.ts +3 -2
- package/lib/checkout/donate.js +29 -5
- package/lib/checkout/form.d.ts +1 -1
- package/lib/checkout/form.js +41 -17
- package/lib/checkout/table.js +9 -1
- package/lib/components/input.d.ts +3 -3
- package/lib/libs/util.d.ts +6 -6
- package/lib/payment/index.d.ts +3 -1
- package/lib/payment/index.js +31 -26
- package/lib/payment/product-donation.js +5 -7
- package/lib/payment/summary.js +1 -1
- package/lib/theme/index.d.ts +8 -3
- package/lib/theme/index.js +211 -197
- package/lib/types/index.d.ts +6 -1
- package/package.json +3 -3
- package/src/checkout/donate.tsx +36 -5
- package/src/checkout/form.tsx +43 -18
- package/src/checkout/table.tsx +8 -1
- package/src/payment/index.tsx +66 -51
- package/src/payment/product-donation.tsx +9 -3
- package/src/payment/summary.tsx +1 -1
- package/src/theme/index.tsx +224 -203
- package/src/types/index.ts +6 -1
package/src/checkout/form.tsx
CHANGED
|
@@ -40,7 +40,8 @@ export default function CheckoutForm({
|
|
|
40
40
|
goBack,
|
|
41
41
|
extraParams,
|
|
42
42
|
action,
|
|
43
|
-
|
|
43
|
+
theme = 'default',
|
|
44
|
+
...restProps
|
|
44
45
|
}: CheckoutProps) {
|
|
45
46
|
if (!id.startsWith('plink_') && !id.startsWith('cs_')) {
|
|
46
47
|
throw new Error('Either a checkoutSession or a paymentLink id is required.');
|
|
@@ -75,9 +76,29 @@ export default function CheckoutForm({
|
|
|
75
76
|
onError?.(err);
|
|
76
77
|
};
|
|
77
78
|
|
|
78
|
-
if (
|
|
79
|
+
if (theme === 'inherit') {
|
|
79
80
|
return (
|
|
80
|
-
<
|
|
81
|
+
<Payment
|
|
82
|
+
checkoutSession={data?.checkoutSession as TCheckoutSessionExpanded}
|
|
83
|
+
paymentMethods={data?.paymentMethods as TPaymentMethodExpanded[]}
|
|
84
|
+
paymentIntent={data?.paymentIntent}
|
|
85
|
+
paymentLink={data?.paymentLink}
|
|
86
|
+
customer={data?.customer}
|
|
87
|
+
completed={state.completed}
|
|
88
|
+
error={apiError || state.appError}
|
|
89
|
+
onPaid={handlePaid}
|
|
90
|
+
onError={handleError}
|
|
91
|
+
onChange={onChange}
|
|
92
|
+
goBack={goBack}
|
|
93
|
+
mode={mode as string}
|
|
94
|
+
action={action}
|
|
95
|
+
{...restProps}
|
|
96
|
+
/>
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
if (theme && typeof theme === 'object') {
|
|
100
|
+
return (
|
|
101
|
+
<PaymentThemeProvider theme={theme}>
|
|
81
102
|
<Payment
|
|
82
103
|
checkoutSession={data?.checkoutSession as TCheckoutSessionExpanded}
|
|
83
104
|
paymentMethods={data?.paymentMethods as TPaymentMethodExpanded[]}
|
|
@@ -92,26 +113,30 @@ export default function CheckoutForm({
|
|
|
92
113
|
goBack={goBack}
|
|
93
114
|
mode={mode as string}
|
|
94
115
|
action={action}
|
|
116
|
+
{...restProps}
|
|
95
117
|
/>
|
|
96
118
|
</PaymentThemeProvider>
|
|
97
119
|
);
|
|
98
120
|
}
|
|
99
121
|
return (
|
|
100
|
-
<
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
122
|
+
<PaymentThemeProvider>
|
|
123
|
+
<Payment
|
|
124
|
+
checkoutSession={data?.checkoutSession as TCheckoutSessionExpanded}
|
|
125
|
+
paymentMethods={data?.paymentMethods as TPaymentMethodExpanded[]}
|
|
126
|
+
paymentIntent={data?.paymentIntent}
|
|
127
|
+
paymentLink={data?.paymentLink}
|
|
128
|
+
customer={data?.customer}
|
|
129
|
+
completed={state.completed}
|
|
130
|
+
error={apiError || state.appError}
|
|
131
|
+
onPaid={handlePaid}
|
|
132
|
+
onError={handleError}
|
|
133
|
+
onChange={onChange}
|
|
134
|
+
goBack={goBack}
|
|
135
|
+
mode={mode as string}
|
|
136
|
+
action={action}
|
|
137
|
+
{...restProps}
|
|
138
|
+
/>
|
|
139
|
+
</PaymentThemeProvider>
|
|
115
140
|
);
|
|
116
141
|
}
|
|
117
142
|
|
package/src/checkout/table.tsx
CHANGED
|
@@ -126,9 +126,16 @@ function CheckoutTableInner({ id, mode, onPaid, onError, onChange, extraParams,
|
|
|
126
126
|
}
|
|
127
127
|
|
|
128
128
|
export default function CheckoutTable(props: CheckoutProps) {
|
|
129
|
-
if (props.
|
|
129
|
+
if (props.theme === 'inherit') {
|
|
130
130
|
return <CheckoutTableInner {...props} />;
|
|
131
131
|
}
|
|
132
|
+
if (props.theme && typeof props.theme === 'object') {
|
|
133
|
+
return (
|
|
134
|
+
<PaymentThemeProvider theme={props.theme}>
|
|
135
|
+
<CheckoutTableInner {...props} />
|
|
136
|
+
</PaymentThemeProvider>
|
|
137
|
+
);
|
|
138
|
+
}
|
|
132
139
|
return (
|
|
133
140
|
<PaymentThemeProvider>
|
|
134
141
|
<CheckoutTableInner {...props} />
|
package/src/payment/index.tsx
CHANGED
|
@@ -34,10 +34,11 @@ import PaymentSummary from './summary';
|
|
|
34
34
|
import { useMobile } from '../hooks/mobile';
|
|
35
35
|
|
|
36
36
|
// eslint-disable-next-line react/no-unused-prop-types
|
|
37
|
-
type Props = CheckoutContext & CheckoutCallbacks & { completed?: boolean; error?: any };
|
|
37
|
+
type Props = CheckoutContext & CheckoutCallbacks & { completed?: boolean; error?: any; showCheckoutSummary?: boolean };
|
|
38
38
|
|
|
39
39
|
PaymentInner.defaultProps = {
|
|
40
40
|
completed: false,
|
|
41
|
+
showCheckoutSummary: true,
|
|
41
42
|
};
|
|
42
43
|
|
|
43
44
|
function PaymentInner({
|
|
@@ -52,6 +53,7 @@ function PaymentInner({
|
|
|
52
53
|
onError,
|
|
53
54
|
onChange,
|
|
54
55
|
action,
|
|
56
|
+
showCheckoutSummary = true,
|
|
55
57
|
}: MainProps) {
|
|
56
58
|
const { t } = useLocaleContext();
|
|
57
59
|
const { settings, session } = usePaymentContext();
|
|
@@ -60,6 +62,7 @@ function PaymentInner({
|
|
|
60
62
|
|
|
61
63
|
const defaultCurrencyId = state.checkoutSession.currency_id || state.checkoutSession.line_items[0]?.price.currency_id;
|
|
62
64
|
const defaultMethodId = paymentMethods.find((m) => m.payment_currencies.some((c) => c.id === defaultCurrencyId))?.id;
|
|
65
|
+
const hideSummaryCard = mode.endsWith('-minimal') || !showCheckoutSummary;
|
|
63
66
|
|
|
64
67
|
const methods = useForm<CheckoutFormData>({
|
|
65
68
|
defaultValues: {
|
|
@@ -155,34 +158,42 @@ function PaymentInner({
|
|
|
155
158
|
return (
|
|
156
159
|
<FormProvider {...methods}>
|
|
157
160
|
<Stack className="cko-container" sx={{ gap: { sm: mode === 'standalone' ? 0 : mode === 'inline' ? 4 : 8 } }}>
|
|
158
|
-
|
|
159
|
-
<
|
|
160
|
-
<
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
161
|
+
{!hideSummaryCard && (
|
|
162
|
+
<Fade in>
|
|
163
|
+
<Stack className="base-card cko-overview" direction="column">
|
|
164
|
+
<PaymentSummary
|
|
165
|
+
items={state.checkoutSession.line_items}
|
|
166
|
+
trialInDays={state.checkoutSession.subscription_data?.trial_period_days || 0}
|
|
167
|
+
billingThreshold={Math.max(
|
|
168
|
+
state.checkoutSession.subscription_data?.billing_threshold_amount || 0,
|
|
169
|
+
// @ts-ignore
|
|
170
|
+
state.checkoutSession.subscription_data?.min_stake_amount || 0
|
|
171
|
+
)}
|
|
172
|
+
showStaking={method.type === 'arcblock'}
|
|
173
|
+
currency={currency}
|
|
174
|
+
onUpsell={onUpsell}
|
|
175
|
+
onDownsell={onDownsell}
|
|
176
|
+
onApplyCrossSell={onApplyCrossSell}
|
|
177
|
+
onCancelCrossSell={onCancelCrossSell}
|
|
178
|
+
onChangeAmount={onChangeAmount}
|
|
179
|
+
checkoutSessionId={state.checkoutSession.id}
|
|
180
|
+
crossSellBehavior={state.checkoutSession.cross_sell_behavior}
|
|
181
|
+
donationSettings={paymentLink?.donation_settings}
|
|
182
|
+
action={action}
|
|
183
|
+
/>
|
|
184
|
+
{mode === 'standalone' && !isMobile && (
|
|
185
|
+
<CheckoutFooter className="cko-footer" sx={{ color: 'var(--foregrounds-fg-muted, #98A3B1)' }} />
|
|
167
186
|
)}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
action={action}
|
|
179
|
-
/>
|
|
180
|
-
{mode === 'standalone' && !isMobile && (
|
|
181
|
-
<CheckoutFooter className="cko-footer" sx={{ color: 'var(--foregrounds-fg-muted, #98A3B1)' }} />
|
|
182
|
-
)}
|
|
183
|
-
</Stack>
|
|
184
|
-
</Fade>
|
|
185
|
-
<Stack className="cko-payment base-card" direction="column" spacing={{ xs: 2, sm: 3 }}>
|
|
187
|
+
</Stack>
|
|
188
|
+
</Fade>
|
|
189
|
+
)}
|
|
190
|
+
<Stack
|
|
191
|
+
className="base-card cko-payment"
|
|
192
|
+
direction="column"
|
|
193
|
+
spacing={{
|
|
194
|
+
xs: 2,
|
|
195
|
+
sm: 3,
|
|
196
|
+
}}>
|
|
186
197
|
{completed && (
|
|
187
198
|
<PaymentSuccess
|
|
188
199
|
mode={mode}
|
|
@@ -225,6 +236,7 @@ function PaymentInner({
|
|
|
225
236
|
Payment.defaultProps = {
|
|
226
237
|
completed: false,
|
|
227
238
|
error: null,
|
|
239
|
+
showCheckoutSummary: true,
|
|
228
240
|
};
|
|
229
241
|
|
|
230
242
|
export default function Payment({
|
|
@@ -241,10 +253,12 @@ export default function Payment({
|
|
|
241
253
|
onChange,
|
|
242
254
|
goBack,
|
|
243
255
|
action,
|
|
256
|
+
showCheckoutSummary = true,
|
|
244
257
|
}: Props) {
|
|
245
258
|
const { t } = useLocaleContext();
|
|
246
259
|
const { refresh, livemode, setLivemode } = usePaymentContext();
|
|
247
260
|
const [delay, setDelay] = useState(false);
|
|
261
|
+
const hideSummaryCard = mode.endsWith('-minimal') || !showCheckoutSummary;
|
|
248
262
|
|
|
249
263
|
useEffect(() => {
|
|
250
264
|
setTimeout(() => {
|
|
@@ -268,15 +282,17 @@ export default function Payment({
|
|
|
268
282
|
if (!checkoutSession || !delay) {
|
|
269
283
|
return (
|
|
270
284
|
<Stack className="cko-container" sx={{ gap: { sm: mode === 'standalone' ? 0 : mode === 'inline' ? 4 : 8 } }}>
|
|
271
|
-
|
|
272
|
-
<
|
|
273
|
-
<
|
|
274
|
-
|
|
275
|
-
|
|
285
|
+
{!hideSummaryCard && (
|
|
286
|
+
<Stack className="base-card cko-overview">
|
|
287
|
+
<Box className="cko-product">
|
|
288
|
+
<OverviewSkeleton />
|
|
289
|
+
</Box>
|
|
290
|
+
{/* {mode === 'standalone' && !isMobile && (
|
|
276
291
|
<CheckoutFooter className="cko-footer" sx={{ color: 'var(--foregrounds-fg-muted, #98A3B1)' }} />
|
|
277
292
|
)} */}
|
|
278
|
-
|
|
279
|
-
|
|
293
|
+
</Stack>
|
|
294
|
+
)}
|
|
295
|
+
<Stack className="base-card cko-payment">
|
|
280
296
|
<PaymentSkeleton />
|
|
281
297
|
</Stack>
|
|
282
298
|
{/* {mode === 'standalone' && isMobile && (
|
|
@@ -317,6 +333,7 @@ export default function Payment({
|
|
|
317
333
|
goBack={goBack}
|
|
318
334
|
mode={mode}
|
|
319
335
|
action={action}
|
|
336
|
+
showCheckoutSummary={showCheckoutSummary}
|
|
320
337
|
/>
|
|
321
338
|
);
|
|
322
339
|
};
|
|
@@ -353,7 +370,7 @@ export default function Payment({
|
|
|
353
370
|
);
|
|
354
371
|
}
|
|
355
372
|
|
|
356
|
-
type MainProps = CheckoutContext & CheckoutCallbacks & { completed?: boolean };
|
|
373
|
+
type MainProps = CheckoutContext & CheckoutCallbacks & { completed?: boolean; showCheckoutSummary?: boolean };
|
|
357
374
|
|
|
358
375
|
export const Root = styled(Box)<{ mode: LiteralUnion<'standalone' | 'inline' | 'popup', string> }>`
|
|
359
376
|
box-sizing: border-box;
|
|
@@ -378,16 +395,24 @@ export const Root = styled(Box)<{ mode: LiteralUnion<'standalone' | 'inline' | '
|
|
|
378
395
|
// padding: ${(props) => (props.mode === 'standalone' ? '0 16px' : '0')};
|
|
379
396
|
}
|
|
380
397
|
|
|
398
|
+
.base-card {
|
|
399
|
+
border: none;
|
|
400
|
+
border-radius: 0;
|
|
401
|
+
padding: ${(props) => (props.mode === 'standalone' ? '100px 40px 20px' : '20px 0')};
|
|
402
|
+
box-shadow: none;
|
|
403
|
+
flex: 1;
|
|
404
|
+
max-width: 582px;
|
|
405
|
+
}
|
|
406
|
+
|
|
381
407
|
.cko-overview {
|
|
382
408
|
// width: ${(props) => (props.mode.endsWith('-minimal') ? '100%' : '400px')};
|
|
383
409
|
// min-height: ${(props) => (props.mode === 'standalone' ? '540px' : 'auto')};
|
|
384
410
|
position: relative;
|
|
385
|
-
|
|
411
|
+
flex-direction: column;
|
|
412
|
+
display: ${(props) => (props.mode.endsWith('-minimal') ? 'none' : 'flex')};
|
|
386
413
|
background: var(--backgrounds-bg-base);
|
|
387
414
|
min-height: 'auto';
|
|
388
415
|
// width: 502px;
|
|
389
|
-
display: flex;
|
|
390
|
-
flex-direction: column;
|
|
391
416
|
}
|
|
392
417
|
.cko-header {
|
|
393
418
|
left: 0;
|
|
@@ -413,15 +438,6 @@ export const Root = styled(Box)<{ mode: LiteralUnion<'standalone' | 'inline' | '
|
|
|
413
438
|
text-overflow: ellipsis;
|
|
414
439
|
}
|
|
415
440
|
|
|
416
|
-
.base-card {
|
|
417
|
-
border: none;
|
|
418
|
-
border-radius: 0;
|
|
419
|
-
padding: ${(props) => (props.mode === 'standalone' ? '100px 40px 20px' : '20px 0')};
|
|
420
|
-
box-shadow: none;
|
|
421
|
-
flex: 1;
|
|
422
|
-
max-width: 582px;
|
|
423
|
-
}
|
|
424
|
-
|
|
425
441
|
.cko-payment {
|
|
426
442
|
width: 502px;
|
|
427
443
|
// width: ${(props) => (props.mode.endsWith('-minimal') ? '100%' : '400px')};
|
|
@@ -461,7 +477,7 @@ export const Root = styled(Box)<{ mode: LiteralUnion<'standalone' | 'inline' | '
|
|
|
461
477
|
margin-bottom: 4px;
|
|
462
478
|
}
|
|
463
479
|
.MuiBox-root {
|
|
464
|
-
margin:
|
|
480
|
+
margin: 0;
|
|
465
481
|
}
|
|
466
482
|
|
|
467
483
|
.MuiFormHelperText-root {
|
|
@@ -520,9 +536,8 @@ export const Root = styled(Box)<{ mode: LiteralUnion<'standalone' | 'inline' | '
|
|
|
520
536
|
flex-direction: column;
|
|
521
537
|
align-items: center;
|
|
522
538
|
gap: 32px;
|
|
523
|
-
min-width: 350px;
|
|
524
|
-
max-width: 400px;
|
|
525
539
|
overflow: visible;
|
|
540
|
+
min-width: 200px;
|
|
526
541
|
}
|
|
527
542
|
.cko-overview {
|
|
528
543
|
width: 100%;
|
|
@@ -71,7 +71,8 @@ export default function ProductDonation({
|
|
|
71
71
|
if (event.target.checked) {
|
|
72
72
|
setState({ custom: true, input: state.selected, error: '' });
|
|
73
73
|
} else {
|
|
74
|
-
|
|
74
|
+
setPayable(true);
|
|
75
|
+
handleSelect(preset);
|
|
75
76
|
}
|
|
76
77
|
};
|
|
77
78
|
|
|
@@ -98,11 +99,16 @@ export default function ProductDonation({
|
|
|
98
99
|
...(state.selected === amount && !state.custom ? { borderColor: 'primary.main' } : {}),
|
|
99
100
|
}}>
|
|
100
101
|
<CardActionArea onClick={() => handleSelect(amount)}>
|
|
101
|
-
<Stack
|
|
102
|
+
<Stack
|
|
103
|
+
direction="row"
|
|
104
|
+
sx={{ py: 1, px: 0.5 }}
|
|
105
|
+
spacing={0.5}
|
|
106
|
+
alignItems="flex-end"
|
|
107
|
+
justifyContent="center">
|
|
102
108
|
<Typography
|
|
103
109
|
component="strong"
|
|
104
110
|
lineHeight={1}
|
|
105
|
-
variant="
|
|
111
|
+
variant="h3"
|
|
106
112
|
sx={{ fontVariantNumeric: 'tabular-nums', fontWeight: 400 }}>
|
|
107
113
|
{amount}
|
|
108
114
|
</Typography>
|
package/src/payment/summary.tsx
CHANGED