@stigg/react-sdk 6.9.0 → 6.10.0
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/checkout/CheckoutProvider.d.ts +1 -0
- package/dist/components/checkout/hooks/useCheckoutModel.d.ts +2 -0
- package/dist/components/checkout/steps/payment/PaymentMethods.d.ts +2 -2
- package/dist/components/checkout/steps/payment/PaymentStep.d.ts +1 -1
- package/dist/components/checkout/steps/payment/zuora/ZuoraPaymentForm.d.ts +3 -0
- package/dist/components/checkout/steps/payment/zuora/index.d.ts +3 -0
- package/dist/components/checkout/steps/payment/zuora/useZuoraIntegration.d.ts +5 -0
- package/dist/components/checkout/steps/payment/zuora/useZuoraSubmit.d.ts +11 -0
- package/dist/components/checkout/steps/payment/zuora/zuora.utils.d.ts +34 -0
- package/dist/react-sdk.cjs.development.js +589 -49
- package/dist/react-sdk.cjs.development.js.map +1 -1
- package/dist/react-sdk.cjs.production.min.js +1 -1
- package/dist/react-sdk.cjs.production.min.js.map +1 -1
- package/dist/react-sdk.esm.js +589 -49
- package/dist/react-sdk.esm.js.map +1 -1
- package/package.json +2 -2
- package/src/components/checkout/CheckoutContainer.tsx +19 -3
- package/src/components/checkout/CheckoutProvider.tsx +2 -0
- package/src/components/checkout/hooks/useCheckoutModel.ts +14 -3
- package/src/components/checkout/steps/payment/PaymentMethods.tsx +15 -2
- package/src/components/checkout/steps/payment/PaymentStep.tsx +8 -1
- package/src/components/checkout/steps/payment/stripe/useStripeIntegration.ts +5 -1
- package/src/components/checkout/steps/payment/zuora/ZuoraPaymentForm.tsx +128 -0
- package/src/components/checkout/steps/payment/zuora/index.ts +11 -0
- package/src/components/checkout/steps/payment/zuora/useZuoraIntegration.ts +56 -0
- package/src/components/checkout/steps/payment/zuora/useZuoraSubmit.ts +125 -0
- package/src/components/checkout/steps/payment/zuora/zuora.utils.ts +72 -0
- package/src/components/checkout/summary/CheckoutSummary.tsx +71 -44
|
@@ -21,6 +21,8 @@ import {
|
|
|
21
21
|
} from '../hooks';
|
|
22
22
|
import { PromotionCodeSection } from '../promotionCode';
|
|
23
23
|
import { useSubmit } from '../steps/payment/stripe';
|
|
24
|
+
import { useZuoraIntegration } from '../steps/payment/zuora/useZuoraIntegration';
|
|
25
|
+
import { useZuoraSubmit } from '../steps/payment/zuora/useZuoraSubmit';
|
|
24
26
|
import { CheckoutContainerProps } from '../CheckoutContainer';
|
|
25
27
|
import { CheckoutCaptions } from './components/CheckoutCaptions';
|
|
26
28
|
import {
|
|
@@ -113,10 +115,10 @@ export const CheckoutSummary = ({
|
|
|
113
115
|
isWidgetWatermarkEnabled,
|
|
114
116
|
}: CheckoutContainerProps & { isFreeDowngrade: boolean; isWidgetWatermarkEnabled: boolean }) => {
|
|
115
117
|
const [isCheckoutCompletedSuccessfully, setIsCheckoutCompletedSuccessfully] = useState(false);
|
|
116
|
-
const { setErrorMessage } = usePaymentStepModel();
|
|
118
|
+
const { setErrorMessage, useNewPaymentMethod } = usePaymentStepModel();
|
|
117
119
|
const progressBar = useProgressBarModel();
|
|
118
120
|
const subscription = useSubscriptionModel();
|
|
119
|
-
const { checkoutState, checkoutLocalization } = useCheckoutModel();
|
|
121
|
+
const { checkoutState, checkoutLocalization, checkoutSuccess, widgetState } = useCheckoutModel();
|
|
120
122
|
const { plan, activeSubscription } = checkoutState || {};
|
|
121
123
|
const planPrices = useChargesSort(
|
|
122
124
|
plan?.pricePoints?.filter((price) => price.billingPeriod === subscription.billingPeriod) || [],
|
|
@@ -124,10 +126,13 @@ export const CheckoutSummary = ({
|
|
|
124
126
|
const [baseCharges, usageCharges] = partition(planPrices, (price) => price.pricingModel === BillingModel.FlatFee);
|
|
125
127
|
const [baseCharge] = baseCharges || [];
|
|
126
128
|
const isLastStep = isFreeDowngrade || (progressBar.isCheckoutComplete && progressBar.isLastStep);
|
|
129
|
+
const { isZuoraIntegration } = useZuoraIntegration();
|
|
130
|
+
|
|
131
|
+
const isCheckoutCompleted = isCheckoutCompletedSuccessfully || checkoutSuccess;
|
|
127
132
|
|
|
128
133
|
const { subscriptionPreview, isFetchingSubscriptionPreview } = usePreviewSubscription({ onMockCheckoutPreview });
|
|
129
134
|
|
|
130
|
-
const { handleSubmit, isLoading } = useSubmit({
|
|
135
|
+
const { handleSubmit: handleStripeSubmit, isLoading: isStripeLoading } = useSubmit({
|
|
131
136
|
isMocked: !!onMockCheckoutPreview, // This is a hack to make the submit button work with mocked data
|
|
132
137
|
disableSuccessAnimation,
|
|
133
138
|
onCheckout,
|
|
@@ -138,12 +143,29 @@ export const CheckoutSummary = ({
|
|
|
138
143
|
},
|
|
139
144
|
});
|
|
140
145
|
|
|
146
|
+
const { handleZuoraSubmit } = useZuoraSubmit({
|
|
147
|
+
onCheckout,
|
|
148
|
+
onCheckoutCompleted,
|
|
149
|
+
disableSuccessAnimation,
|
|
150
|
+
onSuccess: () => {
|
|
151
|
+
progressBar.markStepAsCompleted(progressBar.progressBarState.activeStep);
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
|
|
141
155
|
const handleCheckout = async (e: any) => {
|
|
142
|
-
if (
|
|
156
|
+
if (isCheckoutCompleted) {
|
|
143
157
|
return;
|
|
144
158
|
}
|
|
145
159
|
|
|
146
|
-
|
|
160
|
+
let result;
|
|
161
|
+
|
|
162
|
+
if (isZuoraIntegration && !useNewPaymentMethod) {
|
|
163
|
+
result = await handleZuoraSubmit();
|
|
164
|
+
} else {
|
|
165
|
+
result = await handleStripeSubmit(e);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const { errorMessage } = result || {};
|
|
147
169
|
if (errorMessage) {
|
|
148
170
|
setErrorMessage(errorMessage);
|
|
149
171
|
setIsCheckoutCompletedSuccessfully(false);
|
|
@@ -152,6 +174,9 @@ export const CheckoutSummary = ({
|
|
|
152
174
|
}
|
|
153
175
|
};
|
|
154
176
|
|
|
177
|
+
// This is sad
|
|
178
|
+
const isLoading = isZuoraIntegration && !useNewPaymentMethod ? widgetState.readOnly : isStripeLoading;
|
|
179
|
+
|
|
155
180
|
const onCheckoutClick = async (e: any): Promise<void> => {
|
|
156
181
|
if (isLoading) {
|
|
157
182
|
return;
|
|
@@ -167,7 +192,7 @@ export const CheckoutSummary = ({
|
|
|
167
192
|
const { immediateInvoice, recurringInvoice } = subscriptionPreview || {};
|
|
168
193
|
const checkoutHasChanges =
|
|
169
194
|
!!subscriptionPreview && (!!immediateInvoice?.proration || !!subscriptionPreview.hasScheduledUpdates);
|
|
170
|
-
const showPromotionCodeLine = !disablePromotionCode && !isFreeDowngrade;
|
|
195
|
+
const showPromotionCodeLine = !disablePromotionCode && !isFreeDowngrade && !isZuoraIntegration;
|
|
171
196
|
const showDiscountLine = !!recurringInvoice?.discountDetails && !isFreeDowngrade;
|
|
172
197
|
const hasDiscounts = showPromotionCodeLine || showDiscountLine;
|
|
173
198
|
|
|
@@ -376,50 +401,52 @@ export const CheckoutSummary = ({
|
|
|
376
401
|
billingPeriod={subscription.billingPeriod}
|
|
377
402
|
/>
|
|
378
403
|
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
404
|
+
{(!isLastStep || !isZuoraIntegration || (isZuoraIntegration && !useNewPaymentMethod)) && (
|
|
405
|
+
<Button
|
|
406
|
+
$success={isCheckoutCompleted}
|
|
407
|
+
$error={isLastStep && isFreeDowngrade}
|
|
408
|
+
disabled={
|
|
409
|
+
isLoading ||
|
|
410
|
+
isFetchingSubscriptionPreview ||
|
|
411
|
+
progressBar.progressBarState.isDisabled ||
|
|
412
|
+
(isLastStep && !checkoutHasChanges)
|
|
413
|
+
}
|
|
414
|
+
className="stigg-checkout-summary-cta-button"
|
|
415
|
+
sx={{ textTransform: 'none', borderRadius: '10px', marginTop: '24px', height: '36px' }}
|
|
416
|
+
variant="contained"
|
|
417
|
+
size="medium"
|
|
418
|
+
onClick={(e: any) => {
|
|
419
|
+
void onCheckoutClick(e);
|
|
420
|
+
}}
|
|
421
|
+
fullWidth>
|
|
422
|
+
<Typography
|
|
423
|
+
className="stigg-checkout-summary-cta-button-text"
|
|
424
|
+
variant="h3"
|
|
425
|
+
color="white"
|
|
426
|
+
style={{ display: 'flex' }}>
|
|
427
|
+
{isCheckoutCompleted ? (
|
|
428
|
+
<Icon icon="Check" style={{ display: 'contents' }} />
|
|
429
|
+
) : isLoading || isFetchingSubscriptionPreview ? (
|
|
430
|
+
<CircularProgress size={20} sx={{ color: 'white' }} />
|
|
431
|
+
) : (
|
|
432
|
+
resolveCheckoutButtonText({
|
|
433
|
+
isLastStep,
|
|
434
|
+
checkoutHasChanges,
|
|
435
|
+
isFreeDowngrade,
|
|
436
|
+
checkoutLocalization,
|
|
437
|
+
isPlanUpdate: !!activeSubscription && activeSubscription?.plan.id === plan?.id,
|
|
438
|
+
})
|
|
439
|
+
)}
|
|
440
|
+
</Typography>
|
|
441
|
+
</Button>
|
|
442
|
+
)}
|
|
416
443
|
</SummaryCard>
|
|
417
444
|
<PoweredByStigg
|
|
418
445
|
source="checkout"
|
|
419
446
|
showWatermark={isWidgetWatermarkEnabled}
|
|
420
447
|
style={{ marginTop: 8, display: 'flex', justifyContent: 'center' }}
|
|
421
448
|
/>
|
|
422
|
-
{!disableSuccessAnimation &&
|
|
449
|
+
{!disableSuccessAnimation && isCheckoutCompleted && (
|
|
423
450
|
<CheckoutSuccess checkoutLocalization={checkoutLocalization} />
|
|
424
451
|
)}
|
|
425
452
|
</SummaryContainer>
|