@appfunnel-dev/sdk 0.8.0 → 0.9.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/index.cjs +32 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -3
- package/dist/index.d.ts +11 -3
- package/dist/index.js +32 -19
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1395,6 +1395,10 @@ var RealStripePaymentForm = react.forwardRef(
|
|
|
1395
1395
|
productId,
|
|
1396
1396
|
mode = "checkout",
|
|
1397
1397
|
variant = "elements",
|
|
1398
|
+
successPageKey,
|
|
1399
|
+
automaticTax = false,
|
|
1400
|
+
managedPayments = false,
|
|
1401
|
+
allowPromotionCodes = false,
|
|
1398
1402
|
onSuccess,
|
|
1399
1403
|
onError,
|
|
1400
1404
|
onReady,
|
|
@@ -1402,7 +1406,7 @@ var RealStripePaymentForm = react.forwardRef(
|
|
|
1402
1406
|
appearance,
|
|
1403
1407
|
layout
|
|
1404
1408
|
}, ref) {
|
|
1405
|
-
const { campaignId, tracker, variableStore, products } = chunkEVUYCLVY_cjs.useFunnelContext();
|
|
1409
|
+
const { campaignId, tracker, variableStore, products, router } = chunkEVUYCLVY_cjs.useFunnelContext();
|
|
1406
1410
|
const [email] = useVariable("user.email");
|
|
1407
1411
|
const validateOnly = mode === "validate-only";
|
|
1408
1412
|
const product = react.useMemo(() => {
|
|
@@ -1429,18 +1433,36 @@ var RealStripePaymentForm = react.forwardRef(
|
|
|
1429
1433
|
const createIntent = async () => {
|
|
1430
1434
|
try {
|
|
1431
1435
|
if (variant === "embedded") {
|
|
1436
|
+
const origin = typeof window !== "undefined" ? window.location.origin : "";
|
|
1437
|
+
let returnUrl = origin + "/";
|
|
1438
|
+
if (successPageKey) {
|
|
1439
|
+
const pageUrl = router.getPageUrl(successPageKey);
|
|
1440
|
+
returnUrl = `${origin}${pageUrl}?checkout=success&session_id={CHECKOUT_SESSION_ID}`;
|
|
1441
|
+
}
|
|
1442
|
+
const apiCheckoutMode = managedPayments ? "embedded" : variant;
|
|
1443
|
+
const body = {
|
|
1444
|
+
campaignId,
|
|
1445
|
+
sessionId: tracker.getSessionId(),
|
|
1446
|
+
customerEmail: email,
|
|
1447
|
+
priceId: product.storePriceId,
|
|
1448
|
+
returnUrl,
|
|
1449
|
+
checkoutMode: apiCheckoutMode,
|
|
1450
|
+
automaticTax,
|
|
1451
|
+
managedPayments,
|
|
1452
|
+
allowPromotionCodes
|
|
1453
|
+
};
|
|
1454
|
+
if (product.hasTrial && product.trialDays > 0) {
|
|
1455
|
+
body.trialPeriodDays = product.trialDays;
|
|
1456
|
+
if (product.paidTrial && product.trialStorePriceId) {
|
|
1457
|
+
body.paidTrialPriceId = product.trialStorePriceId;
|
|
1458
|
+
}
|
|
1459
|
+
}
|
|
1432
1460
|
const response = await fetch(
|
|
1433
1461
|
`${API_BASE_URL2}/campaign/${campaignId}/stripe/checkout-session`,
|
|
1434
1462
|
{
|
|
1435
1463
|
method: "POST",
|
|
1436
1464
|
headers: { "Content-Type": "application/json" },
|
|
1437
|
-
body: JSON.stringify(
|
|
1438
|
-
campaignId,
|
|
1439
|
-
sessionId: tracker.getSessionId(),
|
|
1440
|
-
customerEmail: email,
|
|
1441
|
-
priceId: product.storePriceId,
|
|
1442
|
-
trialPeriodDays: product.hasTrial ? product.trialDays : void 0
|
|
1443
|
-
})
|
|
1465
|
+
body: JSON.stringify(body)
|
|
1444
1466
|
}
|
|
1445
1467
|
);
|
|
1446
1468
|
const result = await response.json();
|
|
@@ -1482,7 +1504,7 @@ var RealStripePaymentForm = react.forwardRef(
|
|
|
1482
1504
|
}
|
|
1483
1505
|
};
|
|
1484
1506
|
createIntent();
|
|
1485
|
-
}, [email, campaignId, product, paymentMode, validateOnly, variant, tracker, variableStore]);
|
|
1507
|
+
}, [email, campaignId, product, paymentMode, validateOnly, variant, successPageKey, automaticTax, managedPayments, allowPromotionCodes, router, tracker, variableStore]);
|
|
1486
1508
|
if (isLoading) {
|
|
1487
1509
|
return /* @__PURE__ */ jsxRuntime.jsx("div", { className, style: { padding: "20px", textAlign: "center", color: "#6b7280" }, children: "Loading payment form..." });
|
|
1488
1510
|
}
|
|
@@ -1500,16 +1522,7 @@ var RealStripePaymentForm = react.forwardRef(
|
|
|
1500
1522
|
reactStripeJs.EmbeddedCheckoutProvider,
|
|
1501
1523
|
{
|
|
1502
1524
|
stripe: stripePromise,
|
|
1503
|
-
options: {
|
|
1504
|
-
clientSecret,
|
|
1505
|
-
onComplete: () => {
|
|
1506
|
-
tracker.track("purchase.complete", {
|
|
1507
|
-
amount: product?.rawPrice ? product.rawPrice / 100 : 0,
|
|
1508
|
-
currency: product?.currencyCode || "USD"
|
|
1509
|
-
});
|
|
1510
|
-
onSuccess?.();
|
|
1511
|
-
}
|
|
1512
|
-
},
|
|
1525
|
+
options: { clientSecret },
|
|
1513
1526
|
children: /* @__PURE__ */ jsxRuntime.jsx(reactStripeJs.EmbeddedCheckout, {})
|
|
1514
1527
|
}
|
|
1515
1528
|
) });
|