@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.
Files changed (28) hide show
  1. package/dist/components/checkout/CheckoutProvider.d.ts +1 -0
  2. package/dist/components/checkout/hooks/useCheckoutModel.d.ts +2 -0
  3. package/dist/components/checkout/steps/payment/PaymentMethods.d.ts +2 -2
  4. package/dist/components/checkout/steps/payment/PaymentStep.d.ts +1 -1
  5. package/dist/components/checkout/steps/payment/zuora/ZuoraPaymentForm.d.ts +3 -0
  6. package/dist/components/checkout/steps/payment/zuora/index.d.ts +3 -0
  7. package/dist/components/checkout/steps/payment/zuora/useZuoraIntegration.d.ts +5 -0
  8. package/dist/components/checkout/steps/payment/zuora/useZuoraSubmit.d.ts +11 -0
  9. package/dist/components/checkout/steps/payment/zuora/zuora.utils.d.ts +34 -0
  10. package/dist/react-sdk.cjs.development.js +589 -49
  11. package/dist/react-sdk.cjs.development.js.map +1 -1
  12. package/dist/react-sdk.cjs.production.min.js +1 -1
  13. package/dist/react-sdk.cjs.production.min.js.map +1 -1
  14. package/dist/react-sdk.esm.js +589 -49
  15. package/dist/react-sdk.esm.js.map +1 -1
  16. package/package.json +2 -2
  17. package/src/components/checkout/CheckoutContainer.tsx +19 -3
  18. package/src/components/checkout/CheckoutProvider.tsx +2 -0
  19. package/src/components/checkout/hooks/useCheckoutModel.ts +14 -3
  20. package/src/components/checkout/steps/payment/PaymentMethods.tsx +15 -2
  21. package/src/components/checkout/steps/payment/PaymentStep.tsx +8 -1
  22. package/src/components/checkout/steps/payment/stripe/useStripeIntegration.ts +5 -1
  23. package/src/components/checkout/steps/payment/zuora/ZuoraPaymentForm.tsx +128 -0
  24. package/src/components/checkout/steps/payment/zuora/index.ts +11 -0
  25. package/src/components/checkout/steps/payment/zuora/useZuoraIntegration.ts +56 -0
  26. package/src/components/checkout/steps/payment/zuora/useZuoraSubmit.ts +125 -0
  27. package/src/components/checkout/steps/payment/zuora/zuora.utils.ts +72 -0
  28. 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 (isCheckoutCompletedSuccessfully) {
156
+ if (isCheckoutCompleted) {
143
157
  return;
144
158
  }
145
159
 
146
- const { errorMessage } = (await handleSubmit(e)) || {};
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
- <Button
380
- $success={isCheckoutCompletedSuccessfully}
381
- $error={isLastStep && isFreeDowngrade}
382
- disabled={
383
- isLoading ||
384
- isFetchingSubscriptionPreview ||
385
- progressBar.progressBarState.isDisabled ||
386
- (isLastStep && !checkoutHasChanges)
387
- }
388
- className="stigg-checkout-summary-cta-button"
389
- sx={{ textTransform: 'none', borderRadius: '10px', marginTop: '24px', height: '36px' }}
390
- variant="contained"
391
- size="medium"
392
- onClick={(e: any) => {
393
- void onCheckoutClick(e);
394
- }}
395
- fullWidth>
396
- <Typography
397
- className="stigg-checkout-summary-cta-button-text"
398
- variant="h3"
399
- color="white"
400
- style={{ display: 'flex' }}>
401
- {isCheckoutCompletedSuccessfully ? (
402
- <Icon icon="Check" style={{ display: 'contents' }} />
403
- ) : isLoading || isFetchingSubscriptionPreview ? (
404
- <CircularProgress size={20} sx={{ color: 'white' }} />
405
- ) : (
406
- resolveCheckoutButtonText({
407
- isLastStep,
408
- checkoutHasChanges,
409
- isFreeDowngrade,
410
- checkoutLocalization,
411
- isPlanUpdate: !!activeSubscription && activeSubscription?.plan.id === plan?.id,
412
- })
413
- )}
414
- </Typography>
415
- </Button>
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 && isCheckoutCompletedSuccessfully && (
449
+ {!disableSuccessAnimation && isCheckoutCompleted && (
423
450
  <CheckoutSuccess checkoutLocalization={checkoutLocalization} />
424
451
  )}
425
452
  </SummaryContainer>