@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.d.cts CHANGED
@@ -283,11 +283,19 @@ interface StripePaymentFormProps {
283
283
  mode?: 'checkout' | 'validate-only';
284
284
  /** "elements" for PaymentElement, "embedded" for Stripe Embedded Checkout */
285
285
  variant?: 'elements' | 'embedded';
286
- /** Called on successful payment */
286
+ /** Page key to redirect to after successful embedded checkout (required for embedded variant) */
287
+ successPageKey?: string;
288
+ /** Enable Stripe automatic tax calculation (embedded variant only) */
289
+ automaticTax?: boolean;
290
+ /** Enable Stripe managed payments — Stripe controls tax, payment methods, etc. (embedded variant only, forces embedded mode) */
291
+ managedPayments?: boolean;
292
+ /** Allow promotion codes in checkout (embedded variant only) */
293
+ allowPromotionCodes?: boolean;
294
+ /** Called on successful payment (elements variant only — embedded uses returnUrl redirect) */
287
295
  onSuccess?: () => void;
288
- /** Called on payment error */
296
+ /** Called on payment error (elements variant only) */
289
297
  onError?: (error: string) => void;
290
- /** Called when the Stripe form is ready to accept submissions */
298
+ /** Called when the Stripe form is ready to accept submissions (elements variant only) */
291
299
  onReady?: () => void;
292
300
  /** Additional CSS class */
293
301
  className?: string;
package/dist/index.d.ts CHANGED
@@ -283,11 +283,19 @@ interface StripePaymentFormProps {
283
283
  mode?: 'checkout' | 'validate-only';
284
284
  /** "elements" for PaymentElement, "embedded" for Stripe Embedded Checkout */
285
285
  variant?: 'elements' | 'embedded';
286
- /** Called on successful payment */
286
+ /** Page key to redirect to after successful embedded checkout (required for embedded variant) */
287
+ successPageKey?: string;
288
+ /** Enable Stripe automatic tax calculation (embedded variant only) */
289
+ automaticTax?: boolean;
290
+ /** Enable Stripe managed payments — Stripe controls tax, payment methods, etc. (embedded variant only, forces embedded mode) */
291
+ managedPayments?: boolean;
292
+ /** Allow promotion codes in checkout (embedded variant only) */
293
+ allowPromotionCodes?: boolean;
294
+ /** Called on successful payment (elements variant only — embedded uses returnUrl redirect) */
287
295
  onSuccess?: () => void;
288
- /** Called on payment error */
296
+ /** Called on payment error (elements variant only) */
289
297
  onError?: (error: string) => void;
290
- /** Called when the Stripe form is ready to accept submissions */
298
+ /** Called when the Stripe form is ready to accept submissions (elements variant only) */
291
299
  onReady?: () => void;
292
300
  /** Additional CSS class */
293
301
  className?: string;
package/dist/index.js CHANGED
@@ -1395,6 +1395,10 @@ var RealStripePaymentForm = 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 = forwardRef(
1402
1406
  appearance,
1403
1407
  layout
1404
1408
  }, ref) {
1405
- const { campaignId, tracker, variableStore, products } = useFunnelContext();
1409
+ const { campaignId, tracker, variableStore, products, router } = useFunnelContext();
1406
1410
  const [email] = useVariable("user.email");
1407
1411
  const validateOnly = mode === "validate-only";
1408
1412
  const product = useMemo(() => {
@@ -1429,18 +1433,36 @@ var RealStripePaymentForm = 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 = 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__ */ jsx("div", { className, style: { padding: "20px", textAlign: "center", color: "#6b7280" }, children: "Loading payment form..." });
1488
1510
  }
@@ -1500,16 +1522,7 @@ var RealStripePaymentForm = forwardRef(
1500
1522
  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__ */ jsx(EmbeddedCheckout, {})
1514
1527
  }
1515
1528
  ) });