@stigg/react-sdk 4.13.1 → 4.13.2

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/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "4.13.1",
2
+ "version": "4.13.2",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -6,6 +6,8 @@ type StripeElementsProps = {
6
6
  elements: StripeElements | null;
7
7
  };
8
8
 
9
+ const FAILED_PAYMENT_COLLECTION_STATUSES = [PaymentCollection.Failed, PaymentCollection.Processing];
10
+
9
11
  export async function handleStripeFormValidations({ elements }: Pick<StripeElementsProps, 'elements'>) {
10
12
  if (!elements) {
11
13
  const errorMessage = 'Stripe elements not initialized';
@@ -30,19 +32,20 @@ export async function handleStripeNextAction({
30
32
  applySubscriptionResults: ApplySubscriptionResults;
31
33
  stripe: Stripe | null;
32
34
  }) {
33
- const paymentIntentClientSecret = applySubscriptionResults?.subscription?.latestInvoice?.paymentSecret;
34
- if (
35
- stripe &&
36
- paymentIntentClientSecret &&
37
- applySubscriptionResults?.subscription?.paymentCollection === PaymentCollection.ActionRequired
38
- ) {
35
+ const subscription = applySubscriptionResults?.subscription;
36
+ const paymentIntentClientSecret = subscription?.latestInvoice?.paymentSecret;
37
+ const paymentCollection = subscription?.paymentCollection;
38
+
39
+ if (stripe && paymentIntentClientSecret && paymentCollection === PaymentCollection.ActionRequired) {
39
40
  const { error: NextActionError } = await stripe.handleNextAction({ clientSecret: paymentIntentClientSecret });
40
41
  if (NextActionError) {
41
42
  return { errorMessage: NextActionError.message || '' };
42
43
  }
44
+ } else if (paymentCollection && FAILED_PAYMENT_COLLECTION_STATUSES.includes(paymentCollection)) {
45
+ return { errorMessage: subscription?.latestInvoice?.errorMessage || 'An error occurred - try again later' };
43
46
  }
44
47
 
45
- return { subscription: applySubscriptionResults?.subscription };
48
+ return { subscription };
46
49
  }
47
50
 
48
51
  async function handleStripeSetup({
@@ -163,7 +163,7 @@ export function PlanOfferingButton({
163
163
  buttonProps.intentionType = SubscribeIntentionType.CHANGE_BILLING_PERIOD;
164
164
  }
165
165
  } else if (isCustomPrice) {
166
- buttonProps.title = custom;
166
+ buttonProps.title = typeof custom === 'function' ? custom({ plan, selectedBillingPeriod: billingPeriod }) : custom;
167
167
  buttonProps.intentionType = SubscribeIntentionType.REQUEST_CUSTOM_PLAN_ACCESS;
168
168
  }
169
169
 
@@ -1,3 +1,3 @@
1
1
  export { PaywallContainer as Paywall, PaywallContainerProps as PaywallProps } from './PaywallContainer';
2
2
  export { PaywallPlan, OnPlanSelectedCallbackFn, SubscribeIntentionType } from './types';
3
- export { PaywallLocalization, PlanPriceText } from './paywallTextOverrides';
3
+ export { PaywallLocalization, PlanPriceText, CurrentPlanParams } from './paywallTextOverrides';
@@ -13,6 +13,11 @@ import { PaywallPlan } from './types';
13
13
 
14
14
  export { PlanPriceText } from '../utils/getPlanPrice';
15
15
 
16
+ export type CurrentPlanParams = {
17
+ plan: Plan;
18
+ selectedBillingPeriod: BillingPeriod;
19
+ };
20
+
16
21
  export type PaywallLocalization = {
17
22
  highlightChip: string;
18
23
  entitlementsTitle?: (plan: PaywallPlan) => string;
@@ -20,7 +25,7 @@ export type PaywallLocalization = {
20
25
  upgrade: string | ((plan: PaywallPlan) => string);
21
26
  downgrade: string | ((plan: PaywallPlan) => string);
22
27
  startTrial: (plan: PaywallPlan) => string;
23
- custom: string;
28
+ custom: ((data: CurrentPlanParams) => string) | string;
24
29
  currentPlan: string;
25
30
  startNew: string;
26
31
  switchToBillingPeriod: (billingPeriod: BillingPeriod) => string;
@@ -30,7 +35,7 @@ export type PaywallLocalization = {
30
35
  startingAtCaption: string;
31
36
  billingPeriod?: (billingPeriod: BillingPeriod) => string;
32
37
  pricePeriod: (billingPeriod: BillingPeriod) => string;
33
- custom: string;
38
+ custom: ((data: CurrentPlanParams) => string) | string;
34
39
  priceNotSet: string;
35
40
  free: PlanPriceText | ((currency?: PaywallCurrency) => PlanPriceText);
36
41
  paid?: (priceData: {
@@ -26,7 +26,10 @@ export function getPlanPrice(
26
26
  return paywallLocale.price.free;
27
27
  case PricingType.Custom:
28
28
  return {
29
- price: paywallLocale.price.custom,
29
+ price:
30
+ typeof paywallLocale.price.custom === 'function'
31
+ ? paywallLocale.price.custom({ plan, selectedBillingPeriod: billingPeriod })
32
+ : paywallLocale.price.custom,
30
33
  };
31
34
  case PricingType.Paid: {
32
35
  const planPrices = plan.pricePoints.filter((pricePoint) => pricePoint.billingPeriod === billingPeriod);
package/src/index.ts CHANGED
@@ -9,6 +9,7 @@ export {
9
9
  SubscribeIntentionType,
10
10
  PaywallLocalization,
11
11
  PlanPriceText,
12
+ CurrentPlanParams,
12
13
  } from './components/paywall';
13
14
  export {
14
15
  CustomerPortalProvider,