@schematichq/schematic-components 2.8.1 → 2.8.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/dist/schematic-components.cjs.js +117 -120
- package/dist/schematic-components.esm.js +117 -120
- package/package.json +3 -3
|
@@ -5165,6 +5165,54 @@ function shouldCollectBillingAddress(collectAddressSetting, financeData) {
|
|
|
5165
5165
|
return isBillingAddressRequiredForTax(financeData);
|
|
5166
5166
|
}
|
|
5167
5167
|
|
|
5168
|
+
// src/utils/api/checkout.ts
|
|
5169
|
+
function buildPayInAdvanceRequestBody(entitlements, period) {
|
|
5170
|
+
return entitlements.reduce(
|
|
5171
|
+
(acc, { meteredMonthlyPrice, meteredYearlyPrice, quantity }) => {
|
|
5172
|
+
const priceId = (period === "year" ? meteredYearlyPrice : meteredMonthlyPrice)?.priceId;
|
|
5173
|
+
if (priceId) {
|
|
5174
|
+
acc.push({
|
|
5175
|
+
priceId,
|
|
5176
|
+
quantity
|
|
5177
|
+
});
|
|
5178
|
+
}
|
|
5179
|
+
return acc;
|
|
5180
|
+
},
|
|
5181
|
+
[]
|
|
5182
|
+
);
|
|
5183
|
+
}
|
|
5184
|
+
function buildAddOnRequestBody(addOns, period, shouldTrial, addOnPayInAdvanceEntitlements) {
|
|
5185
|
+
return addOns.reduce((acc, addOn) => {
|
|
5186
|
+
if (addOn.isSelected && !shouldTrial) {
|
|
5187
|
+
const addOnPrice = getAddOnPrice(addOn, period);
|
|
5188
|
+
const addOnPriceId = addOnPrice?.id;
|
|
5189
|
+
if (addOnPriceId && (addOnPrice?.price || addOnPayInAdvanceEntitlements.some(
|
|
5190
|
+
(e2) => e2.priceBehavior === EntitlementPriceBehavior.PayInAdvance
|
|
5191
|
+
))) {
|
|
5192
|
+
acc.push({
|
|
5193
|
+
addOnId: addOn.id,
|
|
5194
|
+
priceId: addOnPriceId
|
|
5195
|
+
});
|
|
5196
|
+
}
|
|
5197
|
+
}
|
|
5198
|
+
return acc;
|
|
5199
|
+
}, []);
|
|
5200
|
+
}
|
|
5201
|
+
function buildCreditBundlesRequestBody(creditBundles) {
|
|
5202
|
+
return creditBundles.reduce(
|
|
5203
|
+
(acc, { id, count }) => {
|
|
5204
|
+
if (count > 0) {
|
|
5205
|
+
acc.push({
|
|
5206
|
+
bundleId: id,
|
|
5207
|
+
quantity: count
|
|
5208
|
+
});
|
|
5209
|
+
}
|
|
5210
|
+
return acc;
|
|
5211
|
+
},
|
|
5212
|
+
[]
|
|
5213
|
+
);
|
|
5214
|
+
}
|
|
5215
|
+
|
|
5168
5216
|
// src/utils/api/credit.ts
|
|
5169
5217
|
function getResetCadencePeriod(cadence) {
|
|
5170
5218
|
switch (cadence) {
|
|
@@ -12368,7 +12416,7 @@ var reducer = (state, action) => {
|
|
|
12368
12416
|
// src/context/EmbedProvider.tsx
|
|
12369
12417
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
12370
12418
|
var getCustomHeaders = (sessionId) => ({
|
|
12371
|
-
"X-Schematic-Components-Version": "2.8.
|
|
12419
|
+
"X-Schematic-Components-Version": "2.8.2",
|
|
12372
12420
|
"X-Schematic-Session-ID": sessionId
|
|
12373
12421
|
});
|
|
12374
12422
|
var EmbedProvider = ({
|
|
@@ -15874,63 +15922,34 @@ var CheckoutDialog = ({ top }) => {
|
|
|
15874
15922
|
setError(void 0);
|
|
15875
15923
|
setCharges(void 0);
|
|
15876
15924
|
setIsLoading(true);
|
|
15877
|
-
const
|
|
15878
|
-
|
|
15879
|
-
|
|
15880
|
-
|
|
15881
|
-
|
|
15882
|
-
|
|
15883
|
-
|
|
15884
|
-
priceId: addOnPriceId
|
|
15885
|
-
});
|
|
15886
|
-
}
|
|
15887
|
-
}
|
|
15888
|
-
return acc;
|
|
15889
|
-
},
|
|
15890
|
-
[]
|
|
15925
|
+
const resolvedPayInAdvanceEntitlements = updates.payInAdvanceEntitlements || payInAdvanceEntitlements;
|
|
15926
|
+
const resolvedAddOnPayInAdvanceEntitlements = updates.addOnPayInAdvanceEntitlements || addOnPayInAdvanceEntitlements;
|
|
15927
|
+
const resolvedAddOns = updates.addOns || addOns;
|
|
15928
|
+
const resolvedCreditBundles = updates.creditBundles || creditBundles;
|
|
15929
|
+
const planPayInAdvanceRequestBody = buildPayInAdvanceRequestBody(
|
|
15930
|
+
resolvedPayInAdvanceEntitlements,
|
|
15931
|
+
period
|
|
15891
15932
|
);
|
|
15892
|
-
const
|
|
15893
|
-
|
|
15894
|
-
|
|
15895
|
-
if (priceId) {
|
|
15896
|
-
acc.push({
|
|
15897
|
-
priceId,
|
|
15898
|
-
quantity
|
|
15899
|
-
});
|
|
15900
|
-
}
|
|
15901
|
-
return acc;
|
|
15902
|
-
},
|
|
15903
|
-
[]
|
|
15933
|
+
const addOnPayInAdvanceRequestBody = buildPayInAdvanceRequestBody(
|
|
15934
|
+
resolvedAddOnPayInAdvanceEntitlements,
|
|
15935
|
+
period
|
|
15904
15936
|
);
|
|
15905
|
-
const
|
|
15906
|
-
|
|
15907
|
-
|
|
15908
|
-
|
|
15909
|
-
|
|
15910
|
-
|
|
15911
|
-
|
|
15912
|
-
|
|
15913
|
-
}
|
|
15914
|
-
return acc;
|
|
15915
|
-
},
|
|
15916
|
-
[]
|
|
15937
|
+
const addOnRequestBody = buildAddOnRequestBody(
|
|
15938
|
+
resolvedAddOns,
|
|
15939
|
+
period,
|
|
15940
|
+
shouldTrial,
|
|
15941
|
+
resolvedAddOnPayInAdvanceEntitlements
|
|
15942
|
+
);
|
|
15943
|
+
const creditBundlesRequestBody = buildCreditBundlesRequestBody(
|
|
15944
|
+
resolvedCreditBundles
|
|
15917
15945
|
);
|
|
15918
|
-
const creditBundlesRequestBody = (updates.creditBundles || creditBundles).reduce((acc, { id, count }) => {
|
|
15919
|
-
if (count > 0) {
|
|
15920
|
-
acc.push({
|
|
15921
|
-
bundleId: id,
|
|
15922
|
-
quantity: count
|
|
15923
|
-
});
|
|
15924
|
-
}
|
|
15925
|
-
return acc;
|
|
15926
|
-
}, []);
|
|
15927
15946
|
try {
|
|
15928
15947
|
const response = await previewCheckout({
|
|
15929
15948
|
newPlanId: plan.id,
|
|
15930
15949
|
newPriceId: planPriceId,
|
|
15931
15950
|
addOnIds: addOnRequestBody,
|
|
15932
15951
|
payInAdvance: [
|
|
15933
|
-
...
|
|
15952
|
+
...planPayInAdvanceRequestBody,
|
|
15934
15953
|
...addOnPayInAdvanceRequestBody
|
|
15935
15954
|
],
|
|
15936
15955
|
creditBundles: creditBundlesRequestBody,
|
|
@@ -15995,7 +16014,7 @@ var CheckoutDialog = ({ top }) => {
|
|
|
15995
16014
|
planPeriod,
|
|
15996
16015
|
selectedPlan,
|
|
15997
16016
|
payInAdvanceEntitlements,
|
|
15998
|
-
|
|
16017
|
+
addOnPayInAdvanceEntitlements,
|
|
15999
16018
|
addOns,
|
|
16000
16019
|
creditBundles,
|
|
16001
16020
|
shouldTrial,
|
|
@@ -16083,25 +16102,31 @@ var CheckoutDialog = ({ top }) => {
|
|
|
16083
16102
|
...addOn,
|
|
16084
16103
|
...addOn.id === id && { isSelected: !addOn.isSelected }
|
|
16085
16104
|
}));
|
|
16086
|
-
const updatedAddOnEntitlements = updated.filter((addOn) => addOn.isSelected).flatMap(
|
|
16087
|
-
(
|
|
16088
|
-
|
|
16089
|
-
|
|
16090
|
-
|
|
16091
|
-
|
|
16092
|
-
|
|
16093
|
-
|
|
16094
|
-
|
|
16095
|
-
|
|
16105
|
+
const updatedAddOnEntitlements = updated.filter((addOn) => addOn.isSelected).flatMap((addOn) => {
|
|
16106
|
+
return addOn.entitlements.filter((entitlement) => !!entitlement.priceBehavior).map((source) => {
|
|
16107
|
+
const found = addOnUsageBasedEntitlements.find(
|
|
16108
|
+
(current) => current.id === source.id
|
|
16109
|
+
);
|
|
16110
|
+
return {
|
|
16111
|
+
...source,
|
|
16112
|
+
allocation: found?.allocation ?? source.valueNumeric ?? 0,
|
|
16113
|
+
usage: found?.usage ?? 0,
|
|
16114
|
+
quantity: found?.quantity ?? 1
|
|
16115
|
+
};
|
|
16116
|
+
});
|
|
16117
|
+
});
|
|
16096
16118
|
setAddOnUsageBasedEntitlements(updatedAddOnEntitlements);
|
|
16119
|
+
const updatedAddOnPayInAdvanceEntitlements = updatedAddOnEntitlements.filter(
|
|
16120
|
+
(entitlement) => entitlement.priceBehavior === EntitlementPriceBehavior.PayInAdvance
|
|
16121
|
+
);
|
|
16097
16122
|
handlePreviewCheckout({
|
|
16098
16123
|
addOns: updated,
|
|
16099
|
-
addOnPayInAdvanceEntitlements:
|
|
16124
|
+
addOnPayInAdvanceEntitlements: updatedAddOnPayInAdvanceEntitlements
|
|
16100
16125
|
});
|
|
16101
16126
|
return updated;
|
|
16102
16127
|
});
|
|
16103
16128
|
},
|
|
16104
|
-
[handlePreviewCheckout]
|
|
16129
|
+
[handlePreviewCheckout, addOnUsageBasedEntitlements]
|
|
16105
16130
|
);
|
|
16106
16131
|
const updateUsageBasedEntitlementQuantity = (0, import_react32.useCallback)(
|
|
16107
16132
|
(id, updatedQuantity) => {
|
|
@@ -16146,8 +16171,11 @@ var CheckoutDialog = ({ top }) => {
|
|
|
16146
16171
|
quantity: updatedQuantity
|
|
16147
16172
|
} : entitlement
|
|
16148
16173
|
);
|
|
16174
|
+
const updatedAddOnPayInAdvanceEntitlements = updated.filter(
|
|
16175
|
+
(entitlement) => entitlement.priceBehavior === EntitlementPriceBehavior.PayInAdvance
|
|
16176
|
+
);
|
|
16149
16177
|
handlePreviewCheckout({
|
|
16150
|
-
addOnPayInAdvanceEntitlements:
|
|
16178
|
+
addOnPayInAdvanceEntitlements: updatedAddOnPayInAdvanceEntitlements
|
|
16151
16179
|
});
|
|
16152
16180
|
return updated;
|
|
16153
16181
|
});
|
|
@@ -16467,6 +16495,7 @@ var CheckoutDialog = ({ top }) => {
|
|
|
16467
16495
|
addOns,
|
|
16468
16496
|
usageBasedEntitlements,
|
|
16469
16497
|
addOnUsageBasedEntitlements,
|
|
16498
|
+
addOnPayInAdvanceEntitlements,
|
|
16470
16499
|
creditBundles,
|
|
16471
16500
|
charges,
|
|
16472
16501
|
checkoutStage,
|
|
@@ -17361,7 +17390,7 @@ var EntitlementRow = (props) => {
|
|
|
17361
17390
|
" ",
|
|
17362
17391
|
getFeatureName(feature, softLimit)
|
|
17363
17392
|
] }) : feature.name }) }),
|
|
17364
|
-
/* @__PURE__ */ (0, import_jsx_runtime31.jsx)(Box, { $whiteSpace: "nowrap", children: priceBehavior === EntitlementPriceBehavior.PayInAdvance && !tiered ? /* @__PURE__ */ (0, import_jsx_runtime31.jsxs)(Text, { children: [
|
|
17393
|
+
/* @__PURE__ */ (0, import_jsx_runtime31.jsx)(Box, { $whiteSpace: "nowrap", $lineHeight: 1, children: priceBehavior === EntitlementPriceBehavior.PayInAdvance && !tiered ? /* @__PURE__ */ (0, import_jsx_runtime31.jsxs)(Text, { children: [
|
|
17365
17394
|
formatCurrency((price ?? 0) * quantity, currency),
|
|
17366
17395
|
/* @__PURE__ */ (0, import_jsx_runtime31.jsxs)("sub", { children: [
|
|
17367
17396
|
"/",
|
|
@@ -17475,6 +17504,7 @@ var SubscriptionSidebar = (0, import_react39.forwardRef)(
|
|
|
17475
17504
|
creditBundles = [],
|
|
17476
17505
|
usageBasedEntitlements,
|
|
17477
17506
|
addOnUsageBasedEntitlements = [],
|
|
17507
|
+
addOnPayInAdvanceEntitlements = [],
|
|
17478
17508
|
charges,
|
|
17479
17509
|
checkoutStage,
|
|
17480
17510
|
checkoutStages,
|
|
@@ -17701,70 +17731,37 @@ var SubscriptionSidebar = (0, import_react39.forwardRef)(
|
|
|
17701
17731
|
);
|
|
17702
17732
|
const handleCheckout = (0, import_react39.useCallback)(async () => {
|
|
17703
17733
|
const planId = selectedPlan?.id;
|
|
17704
|
-
const
|
|
17734
|
+
const planPriceId = (planPeriod === "year" ? selectedPlan?.yearlyPrice : selectedPlan?.monthlyPrice)?.id;
|
|
17705
17735
|
try {
|
|
17706
|
-
if (!planId || !
|
|
17736
|
+
if (!planId || !planPriceId) {
|
|
17707
17737
|
throw new Error(t2("Selected plan or associated price is missing."));
|
|
17708
17738
|
}
|
|
17709
17739
|
setError(void 0);
|
|
17710
17740
|
setIsLoading(true);
|
|
17711
|
-
const
|
|
17712
|
-
|
|
17713
|
-
|
|
17714
|
-
if (priceId2) {
|
|
17715
|
-
acc.push({
|
|
17716
|
-
priceId: priceId2,
|
|
17717
|
-
quantity
|
|
17718
|
-
});
|
|
17719
|
-
}
|
|
17720
|
-
return acc;
|
|
17721
|
-
},
|
|
17722
|
-
[]
|
|
17741
|
+
const planPayInAdvanceRequestBody = buildPayInAdvanceRequestBody(
|
|
17742
|
+
payInAdvanceEntitlements,
|
|
17743
|
+
planPeriod
|
|
17723
17744
|
);
|
|
17724
|
-
const
|
|
17725
|
-
|
|
17726
|
-
|
|
17727
|
-
(acc, { meteredMonthlyPrice, meteredYearlyPrice, quantity }) => {
|
|
17728
|
-
const priceId2 = (planPeriod === "year" ? meteredYearlyPrice : meteredMonthlyPrice)?.priceId;
|
|
17729
|
-
if (priceId2) {
|
|
17730
|
-
acc.push({
|
|
17731
|
-
priceId: priceId2,
|
|
17732
|
-
quantity
|
|
17733
|
-
});
|
|
17734
|
-
}
|
|
17735
|
-
return acc;
|
|
17736
|
-
},
|
|
17737
|
-
[]
|
|
17745
|
+
const addOnPayInAdvanceRequestBody = buildPayInAdvanceRequestBody(
|
|
17746
|
+
addOnPayInAdvanceEntitlements,
|
|
17747
|
+
planPeriod
|
|
17738
17748
|
);
|
|
17739
|
-
const
|
|
17749
|
+
const addOnRequestBody = buildAddOnRequestBody(
|
|
17750
|
+
addOns,
|
|
17751
|
+
planPeriod,
|
|
17752
|
+
shouldTrial,
|
|
17753
|
+
addOnPayInAdvanceEntitlements
|
|
17754
|
+
);
|
|
17755
|
+
const creditBundlesRequestBody = buildCreditBundlesRequestBody(creditBundles);
|
|
17740
17756
|
const checkoutResponseFromBackend = await checkout({
|
|
17741
17757
|
newPlanId: planId,
|
|
17742
|
-
newPriceId:
|
|
17743
|
-
addOnIds:
|
|
17744
|
-
|
|
17745
|
-
|
|
17746
|
-
|
|
17747
|
-
|
|
17748
|
-
|
|
17749
|
-
priceId: addOnPriceId
|
|
17750
|
-
});
|
|
17751
|
-
}
|
|
17752
|
-
}
|
|
17753
|
-
return acc;
|
|
17754
|
-
}, []),
|
|
17755
|
-
payInAdvance: allPayInAdvance,
|
|
17756
|
-
creditBundles: creditBundles.reduce(
|
|
17757
|
-
(acc, { id, count }) => {
|
|
17758
|
-
if (count > 0) {
|
|
17759
|
-
acc.push({
|
|
17760
|
-
bundleId: id,
|
|
17761
|
-
quantity: count
|
|
17762
|
-
});
|
|
17763
|
-
}
|
|
17764
|
-
return acc;
|
|
17765
|
-
},
|
|
17766
|
-
[]
|
|
17767
|
-
),
|
|
17758
|
+
newPriceId: planPriceId,
|
|
17759
|
+
addOnIds: addOnRequestBody,
|
|
17760
|
+
payInAdvance: [
|
|
17761
|
+
...planPayInAdvanceRequestBody,
|
|
17762
|
+
...addOnPayInAdvanceRequestBody
|
|
17763
|
+
],
|
|
17764
|
+
creditBundles: creditBundlesRequestBody,
|
|
17768
17765
|
skipTrial: !shouldTrial,
|
|
17769
17766
|
...paymentMethodId && { paymentMethodId },
|
|
17770
17767
|
...promoCode && { promoCode }
|
|
@@ -17815,7 +17812,7 @@ var SubscriptionSidebar = (0, import_react39.forwardRef)(
|
|
|
17815
17812
|
setIsLoading,
|
|
17816
17813
|
setLayout,
|
|
17817
17814
|
payInAdvanceEntitlements,
|
|
17818
|
-
|
|
17815
|
+
addOnPayInAdvanceEntitlements,
|
|
17819
17816
|
shouldTrial,
|
|
17820
17817
|
promoCode,
|
|
17821
17818
|
finishCheckout
|
|
@@ -5083,6 +5083,54 @@ function shouldCollectBillingAddress(collectAddressSetting, financeData) {
|
|
|
5083
5083
|
return isBillingAddressRequiredForTax(financeData);
|
|
5084
5084
|
}
|
|
5085
5085
|
|
|
5086
|
+
// src/utils/api/checkout.ts
|
|
5087
|
+
function buildPayInAdvanceRequestBody(entitlements, period) {
|
|
5088
|
+
return entitlements.reduce(
|
|
5089
|
+
(acc, { meteredMonthlyPrice, meteredYearlyPrice, quantity }) => {
|
|
5090
|
+
const priceId = (period === "year" ? meteredYearlyPrice : meteredMonthlyPrice)?.priceId;
|
|
5091
|
+
if (priceId) {
|
|
5092
|
+
acc.push({
|
|
5093
|
+
priceId,
|
|
5094
|
+
quantity
|
|
5095
|
+
});
|
|
5096
|
+
}
|
|
5097
|
+
return acc;
|
|
5098
|
+
},
|
|
5099
|
+
[]
|
|
5100
|
+
);
|
|
5101
|
+
}
|
|
5102
|
+
function buildAddOnRequestBody(addOns, period, shouldTrial, addOnPayInAdvanceEntitlements) {
|
|
5103
|
+
return addOns.reduce((acc, addOn) => {
|
|
5104
|
+
if (addOn.isSelected && !shouldTrial) {
|
|
5105
|
+
const addOnPrice = getAddOnPrice(addOn, period);
|
|
5106
|
+
const addOnPriceId = addOnPrice?.id;
|
|
5107
|
+
if (addOnPriceId && (addOnPrice?.price || addOnPayInAdvanceEntitlements.some(
|
|
5108
|
+
(e2) => e2.priceBehavior === EntitlementPriceBehavior.PayInAdvance
|
|
5109
|
+
))) {
|
|
5110
|
+
acc.push({
|
|
5111
|
+
addOnId: addOn.id,
|
|
5112
|
+
priceId: addOnPriceId
|
|
5113
|
+
});
|
|
5114
|
+
}
|
|
5115
|
+
}
|
|
5116
|
+
return acc;
|
|
5117
|
+
}, []);
|
|
5118
|
+
}
|
|
5119
|
+
function buildCreditBundlesRequestBody(creditBundles) {
|
|
5120
|
+
return creditBundles.reduce(
|
|
5121
|
+
(acc, { id, count }) => {
|
|
5122
|
+
if (count > 0) {
|
|
5123
|
+
acc.push({
|
|
5124
|
+
bundleId: id,
|
|
5125
|
+
quantity: count
|
|
5126
|
+
});
|
|
5127
|
+
}
|
|
5128
|
+
return acc;
|
|
5129
|
+
},
|
|
5130
|
+
[]
|
|
5131
|
+
);
|
|
5132
|
+
}
|
|
5133
|
+
|
|
5086
5134
|
// src/utils/api/credit.ts
|
|
5087
5135
|
function getResetCadencePeriod(cadence) {
|
|
5088
5136
|
switch (cadence) {
|
|
@@ -12286,7 +12334,7 @@ var reducer = (state, action) => {
|
|
|
12286
12334
|
// src/context/EmbedProvider.tsx
|
|
12287
12335
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
12288
12336
|
var getCustomHeaders = (sessionId) => ({
|
|
12289
|
-
"X-Schematic-Components-Version": "2.8.
|
|
12337
|
+
"X-Schematic-Components-Version": "2.8.2",
|
|
12290
12338
|
"X-Schematic-Session-ID": sessionId
|
|
12291
12339
|
});
|
|
12292
12340
|
var EmbedProvider = ({
|
|
@@ -15811,63 +15859,34 @@ var CheckoutDialog = ({ top }) => {
|
|
|
15811
15859
|
setError(void 0);
|
|
15812
15860
|
setCharges(void 0);
|
|
15813
15861
|
setIsLoading(true);
|
|
15814
|
-
const
|
|
15815
|
-
|
|
15816
|
-
|
|
15817
|
-
|
|
15818
|
-
|
|
15819
|
-
|
|
15820
|
-
|
|
15821
|
-
priceId: addOnPriceId
|
|
15822
|
-
});
|
|
15823
|
-
}
|
|
15824
|
-
}
|
|
15825
|
-
return acc;
|
|
15826
|
-
},
|
|
15827
|
-
[]
|
|
15862
|
+
const resolvedPayInAdvanceEntitlements = updates.payInAdvanceEntitlements || payInAdvanceEntitlements;
|
|
15863
|
+
const resolvedAddOnPayInAdvanceEntitlements = updates.addOnPayInAdvanceEntitlements || addOnPayInAdvanceEntitlements;
|
|
15864
|
+
const resolvedAddOns = updates.addOns || addOns;
|
|
15865
|
+
const resolvedCreditBundles = updates.creditBundles || creditBundles;
|
|
15866
|
+
const planPayInAdvanceRequestBody = buildPayInAdvanceRequestBody(
|
|
15867
|
+
resolvedPayInAdvanceEntitlements,
|
|
15868
|
+
period
|
|
15828
15869
|
);
|
|
15829
|
-
const
|
|
15830
|
-
|
|
15831
|
-
|
|
15832
|
-
if (priceId) {
|
|
15833
|
-
acc.push({
|
|
15834
|
-
priceId,
|
|
15835
|
-
quantity
|
|
15836
|
-
});
|
|
15837
|
-
}
|
|
15838
|
-
return acc;
|
|
15839
|
-
},
|
|
15840
|
-
[]
|
|
15870
|
+
const addOnPayInAdvanceRequestBody = buildPayInAdvanceRequestBody(
|
|
15871
|
+
resolvedAddOnPayInAdvanceEntitlements,
|
|
15872
|
+
period
|
|
15841
15873
|
);
|
|
15842
|
-
const
|
|
15843
|
-
|
|
15844
|
-
|
|
15845
|
-
|
|
15846
|
-
|
|
15847
|
-
|
|
15848
|
-
|
|
15849
|
-
|
|
15850
|
-
}
|
|
15851
|
-
return acc;
|
|
15852
|
-
},
|
|
15853
|
-
[]
|
|
15874
|
+
const addOnRequestBody = buildAddOnRequestBody(
|
|
15875
|
+
resolvedAddOns,
|
|
15876
|
+
period,
|
|
15877
|
+
shouldTrial,
|
|
15878
|
+
resolvedAddOnPayInAdvanceEntitlements
|
|
15879
|
+
);
|
|
15880
|
+
const creditBundlesRequestBody = buildCreditBundlesRequestBody(
|
|
15881
|
+
resolvedCreditBundles
|
|
15854
15882
|
);
|
|
15855
|
-
const creditBundlesRequestBody = (updates.creditBundles || creditBundles).reduce((acc, { id, count }) => {
|
|
15856
|
-
if (count > 0) {
|
|
15857
|
-
acc.push({
|
|
15858
|
-
bundleId: id,
|
|
15859
|
-
quantity: count
|
|
15860
|
-
});
|
|
15861
|
-
}
|
|
15862
|
-
return acc;
|
|
15863
|
-
}, []);
|
|
15864
15883
|
try {
|
|
15865
15884
|
const response = await previewCheckout({
|
|
15866
15885
|
newPlanId: plan.id,
|
|
15867
15886
|
newPriceId: planPriceId,
|
|
15868
15887
|
addOnIds: addOnRequestBody,
|
|
15869
15888
|
payInAdvance: [
|
|
15870
|
-
...
|
|
15889
|
+
...planPayInAdvanceRequestBody,
|
|
15871
15890
|
...addOnPayInAdvanceRequestBody
|
|
15872
15891
|
],
|
|
15873
15892
|
creditBundles: creditBundlesRequestBody,
|
|
@@ -15932,7 +15951,7 @@ var CheckoutDialog = ({ top }) => {
|
|
|
15932
15951
|
planPeriod,
|
|
15933
15952
|
selectedPlan,
|
|
15934
15953
|
payInAdvanceEntitlements,
|
|
15935
|
-
|
|
15954
|
+
addOnPayInAdvanceEntitlements,
|
|
15936
15955
|
addOns,
|
|
15937
15956
|
creditBundles,
|
|
15938
15957
|
shouldTrial,
|
|
@@ -16020,25 +16039,31 @@ var CheckoutDialog = ({ top }) => {
|
|
|
16020
16039
|
...addOn,
|
|
16021
16040
|
...addOn.id === id && { isSelected: !addOn.isSelected }
|
|
16022
16041
|
}));
|
|
16023
|
-
const updatedAddOnEntitlements = updated.filter((addOn) => addOn.isSelected).flatMap(
|
|
16024
|
-
(
|
|
16025
|
-
|
|
16026
|
-
|
|
16027
|
-
|
|
16028
|
-
|
|
16029
|
-
|
|
16030
|
-
|
|
16031
|
-
|
|
16032
|
-
|
|
16042
|
+
const updatedAddOnEntitlements = updated.filter((addOn) => addOn.isSelected).flatMap((addOn) => {
|
|
16043
|
+
return addOn.entitlements.filter((entitlement) => !!entitlement.priceBehavior).map((source) => {
|
|
16044
|
+
const found = addOnUsageBasedEntitlements.find(
|
|
16045
|
+
(current) => current.id === source.id
|
|
16046
|
+
);
|
|
16047
|
+
return {
|
|
16048
|
+
...source,
|
|
16049
|
+
allocation: found?.allocation ?? source.valueNumeric ?? 0,
|
|
16050
|
+
usage: found?.usage ?? 0,
|
|
16051
|
+
quantity: found?.quantity ?? 1
|
|
16052
|
+
};
|
|
16053
|
+
});
|
|
16054
|
+
});
|
|
16033
16055
|
setAddOnUsageBasedEntitlements(updatedAddOnEntitlements);
|
|
16056
|
+
const updatedAddOnPayInAdvanceEntitlements = updatedAddOnEntitlements.filter(
|
|
16057
|
+
(entitlement) => entitlement.priceBehavior === EntitlementPriceBehavior.PayInAdvance
|
|
16058
|
+
);
|
|
16034
16059
|
handlePreviewCheckout({
|
|
16035
16060
|
addOns: updated,
|
|
16036
|
-
addOnPayInAdvanceEntitlements:
|
|
16061
|
+
addOnPayInAdvanceEntitlements: updatedAddOnPayInAdvanceEntitlements
|
|
16037
16062
|
});
|
|
16038
16063
|
return updated;
|
|
16039
16064
|
});
|
|
16040
16065
|
},
|
|
16041
|
-
[handlePreviewCheckout]
|
|
16066
|
+
[handlePreviewCheckout, addOnUsageBasedEntitlements]
|
|
16042
16067
|
);
|
|
16043
16068
|
const updateUsageBasedEntitlementQuantity = useCallback7(
|
|
16044
16069
|
(id, updatedQuantity) => {
|
|
@@ -16083,8 +16108,11 @@ var CheckoutDialog = ({ top }) => {
|
|
|
16083
16108
|
quantity: updatedQuantity
|
|
16084
16109
|
} : entitlement
|
|
16085
16110
|
);
|
|
16111
|
+
const updatedAddOnPayInAdvanceEntitlements = updated.filter(
|
|
16112
|
+
(entitlement) => entitlement.priceBehavior === EntitlementPriceBehavior.PayInAdvance
|
|
16113
|
+
);
|
|
16086
16114
|
handlePreviewCheckout({
|
|
16087
|
-
addOnPayInAdvanceEntitlements:
|
|
16115
|
+
addOnPayInAdvanceEntitlements: updatedAddOnPayInAdvanceEntitlements
|
|
16088
16116
|
});
|
|
16089
16117
|
return updated;
|
|
16090
16118
|
});
|
|
@@ -16404,6 +16432,7 @@ var CheckoutDialog = ({ top }) => {
|
|
|
16404
16432
|
addOns,
|
|
16405
16433
|
usageBasedEntitlements,
|
|
16406
16434
|
addOnUsageBasedEntitlements,
|
|
16435
|
+
addOnPayInAdvanceEntitlements,
|
|
16407
16436
|
creditBundles,
|
|
16408
16437
|
charges,
|
|
16409
16438
|
checkoutStage,
|
|
@@ -17310,7 +17339,7 @@ var EntitlementRow = (props) => {
|
|
|
17310
17339
|
" ",
|
|
17311
17340
|
getFeatureName(feature, softLimit)
|
|
17312
17341
|
] }) : feature.name }) }),
|
|
17313
|
-
/* @__PURE__ */ jsx30(Box, { $whiteSpace: "nowrap", children: priceBehavior === EntitlementPriceBehavior.PayInAdvance && !tiered ? /* @__PURE__ */ jsxs21(Text, { children: [
|
|
17342
|
+
/* @__PURE__ */ jsx30(Box, { $whiteSpace: "nowrap", $lineHeight: 1, children: priceBehavior === EntitlementPriceBehavior.PayInAdvance && !tiered ? /* @__PURE__ */ jsxs21(Text, { children: [
|
|
17314
17343
|
formatCurrency((price ?? 0) * quantity, currency),
|
|
17315
17344
|
/* @__PURE__ */ jsxs21("sub", { children: [
|
|
17316
17345
|
"/",
|
|
@@ -17424,6 +17453,7 @@ var SubscriptionSidebar = forwardRef7(
|
|
|
17424
17453
|
creditBundles = [],
|
|
17425
17454
|
usageBasedEntitlements,
|
|
17426
17455
|
addOnUsageBasedEntitlements = [],
|
|
17456
|
+
addOnPayInAdvanceEntitlements = [],
|
|
17427
17457
|
charges,
|
|
17428
17458
|
checkoutStage,
|
|
17429
17459
|
checkoutStages,
|
|
@@ -17650,70 +17680,37 @@ var SubscriptionSidebar = forwardRef7(
|
|
|
17650
17680
|
);
|
|
17651
17681
|
const handleCheckout = useCallback9(async () => {
|
|
17652
17682
|
const planId = selectedPlan?.id;
|
|
17653
|
-
const
|
|
17683
|
+
const planPriceId = (planPeriod === "year" ? selectedPlan?.yearlyPrice : selectedPlan?.monthlyPrice)?.id;
|
|
17654
17684
|
try {
|
|
17655
|
-
if (!planId || !
|
|
17685
|
+
if (!planId || !planPriceId) {
|
|
17656
17686
|
throw new Error(t2("Selected plan or associated price is missing."));
|
|
17657
17687
|
}
|
|
17658
17688
|
setError(void 0);
|
|
17659
17689
|
setIsLoading(true);
|
|
17660
|
-
const
|
|
17661
|
-
|
|
17662
|
-
|
|
17663
|
-
if (priceId2) {
|
|
17664
|
-
acc.push({
|
|
17665
|
-
priceId: priceId2,
|
|
17666
|
-
quantity
|
|
17667
|
-
});
|
|
17668
|
-
}
|
|
17669
|
-
return acc;
|
|
17670
|
-
},
|
|
17671
|
-
[]
|
|
17690
|
+
const planPayInAdvanceRequestBody = buildPayInAdvanceRequestBody(
|
|
17691
|
+
payInAdvanceEntitlements,
|
|
17692
|
+
planPeriod
|
|
17672
17693
|
);
|
|
17673
|
-
const
|
|
17674
|
-
|
|
17675
|
-
|
|
17676
|
-
(acc, { meteredMonthlyPrice, meteredYearlyPrice, quantity }) => {
|
|
17677
|
-
const priceId2 = (planPeriod === "year" ? meteredYearlyPrice : meteredMonthlyPrice)?.priceId;
|
|
17678
|
-
if (priceId2) {
|
|
17679
|
-
acc.push({
|
|
17680
|
-
priceId: priceId2,
|
|
17681
|
-
quantity
|
|
17682
|
-
});
|
|
17683
|
-
}
|
|
17684
|
-
return acc;
|
|
17685
|
-
},
|
|
17686
|
-
[]
|
|
17694
|
+
const addOnPayInAdvanceRequestBody = buildPayInAdvanceRequestBody(
|
|
17695
|
+
addOnPayInAdvanceEntitlements,
|
|
17696
|
+
planPeriod
|
|
17687
17697
|
);
|
|
17688
|
-
const
|
|
17698
|
+
const addOnRequestBody = buildAddOnRequestBody(
|
|
17699
|
+
addOns,
|
|
17700
|
+
planPeriod,
|
|
17701
|
+
shouldTrial,
|
|
17702
|
+
addOnPayInAdvanceEntitlements
|
|
17703
|
+
);
|
|
17704
|
+
const creditBundlesRequestBody = buildCreditBundlesRequestBody(creditBundles);
|
|
17689
17705
|
const checkoutResponseFromBackend = await checkout({
|
|
17690
17706
|
newPlanId: planId,
|
|
17691
|
-
newPriceId:
|
|
17692
|
-
addOnIds:
|
|
17693
|
-
|
|
17694
|
-
|
|
17695
|
-
|
|
17696
|
-
|
|
17697
|
-
|
|
17698
|
-
priceId: addOnPriceId
|
|
17699
|
-
});
|
|
17700
|
-
}
|
|
17701
|
-
}
|
|
17702
|
-
return acc;
|
|
17703
|
-
}, []),
|
|
17704
|
-
payInAdvance: allPayInAdvance,
|
|
17705
|
-
creditBundles: creditBundles.reduce(
|
|
17706
|
-
(acc, { id, count }) => {
|
|
17707
|
-
if (count > 0) {
|
|
17708
|
-
acc.push({
|
|
17709
|
-
bundleId: id,
|
|
17710
|
-
quantity: count
|
|
17711
|
-
});
|
|
17712
|
-
}
|
|
17713
|
-
return acc;
|
|
17714
|
-
},
|
|
17715
|
-
[]
|
|
17716
|
-
),
|
|
17707
|
+
newPriceId: planPriceId,
|
|
17708
|
+
addOnIds: addOnRequestBody,
|
|
17709
|
+
payInAdvance: [
|
|
17710
|
+
...planPayInAdvanceRequestBody,
|
|
17711
|
+
...addOnPayInAdvanceRequestBody
|
|
17712
|
+
],
|
|
17713
|
+
creditBundles: creditBundlesRequestBody,
|
|
17717
17714
|
skipTrial: !shouldTrial,
|
|
17718
17715
|
...paymentMethodId && { paymentMethodId },
|
|
17719
17716
|
...promoCode && { promoCode }
|
|
@@ -17764,7 +17761,7 @@ var SubscriptionSidebar = forwardRef7(
|
|
|
17764
17761
|
setIsLoading,
|
|
17765
17762
|
setLayout,
|
|
17766
17763
|
payInAdvanceEntitlements,
|
|
17767
|
-
|
|
17764
|
+
addOnPayInAdvanceEntitlements,
|
|
17768
17765
|
shouldTrial,
|
|
17769
17766
|
promoCode,
|
|
17770
17767
|
finishCheckout
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@schematichq/schematic-components",
|
|
3
|
-
"version": "2.8.
|
|
3
|
+
"version": "2.8.2",
|
|
4
4
|
"main": "dist/schematic-components.cjs.js",
|
|
5
5
|
"module": "dist/schematic-components.esm.js",
|
|
6
6
|
"types": "dist/schematic-components.d.ts",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@schematichq/schematic-icons": "^0.5.2",
|
|
37
37
|
"@stripe/stripe-js": "^8.11.0",
|
|
38
|
-
"i18next": "^25.10.
|
|
38
|
+
"i18next": "^25.10.9",
|
|
39
39
|
"lodash": "^4.17.23",
|
|
40
40
|
"pako": "^2.1.0",
|
|
41
41
|
"react-i18next": "16.1.6",
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"eslint-plugin-react": "^7.37.5",
|
|
66
66
|
"eslint-plugin-react-hooks": "^7.0.1",
|
|
67
67
|
"globals": "^17.4.0",
|
|
68
|
-
"happy-dom": "^20.8.
|
|
68
|
+
"happy-dom": "^20.8.8",
|
|
69
69
|
"jsdom": "^29.0.1",
|
|
70
70
|
"msw": "^2.12.14",
|
|
71
71
|
"prettier": "^3.8.1",
|