@bigz-app/booking-widget 0.1.21 → 0.1.22

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.
@@ -9179,14 +9179,39 @@
9179
9179
  return;
9180
9180
  }
9181
9181
  // First, confirm the payment with Stripe
9182
+ const confirmParams = {
9183
+ return_url: "https://bigz.surfschule-zingst.de/booking/success",
9184
+ };
9185
+ // Ensure return_url is properly formatted and doesn't contain fragment identifiers
9186
+ try {
9187
+ const url = new URL(confirmParams.return_url);
9188
+ // Remove any fragment identifiers that might cause issues
9189
+ url.hash = "";
9190
+ confirmParams.return_url = url.toString();
9191
+ }
9192
+ catch (e) {
9193
+ console.warn("[PAYMENT_FORM] Invalid return_url, using fallback:", confirmParams.return_url);
9194
+ // Fallback to current origin if URL parsing fails
9195
+ confirmParams.return_url = window.location.origin + window.location.pathname;
9196
+ }
9197
+ console.log("[PAYMENT_FORM] Confirming payment with params:", {
9198
+ paymentIntentId: clientSecret.split("_secret_")[0],
9199
+ return_url: confirmParams.return_url,
9200
+ redirect: "if_required",
9201
+ });
9182
9202
  const { error, paymentIntent } = await stripe.confirmPayment({
9183
9203
  elements,
9184
- confirmParams: {
9185
- return_url: window.location.href,
9186
- },
9204
+ confirmParams,
9187
9205
  redirect: "if_required",
9188
9206
  });
9189
9207
  if (error) {
9208
+ console.error("[PAYMENT_FORM] Payment confirmation error:", {
9209
+ type: error.type,
9210
+ code: error.code,
9211
+ message: error.message,
9212
+ decline_code: error.decline_code,
9213
+ payment_intent: error.payment_intent,
9214
+ });
9190
9215
  if (error.type === "card_error" || error.type === "validation_error") {
9191
9216
  setPaymentError(error.message || "Zahlungsfehler");
9192
9217
  }
@@ -9383,16 +9408,41 @@
9383
9408
  const endpoint = isConnectMode
9384
9409
  ? "/booking/create-payment-intent"
9385
9410
  : "/booking-proxy/create-payment-intent";
9386
- // Build request data
9411
+ // Build request data with validation
9387
9412
  const requestData = {
9388
9413
  eventInstanceId: config.eventInstanceId || eventDetails.id,
9389
9414
  organizationId: config.organizationId, // Required for payment intent creation
9390
- amount: totalAmount,
9415
+ amount: Math.round(totalAmount), // Ensure integer (should already be in cents)
9391
9416
  currency: "eur",
9392
- participants: formData.participants.filter((p) => p.name.trim()),
9417
+ participants: formData.participants.filter((p) => p.name?.trim()),
9393
9418
  discountCode: discountCode?.code,
9394
- customerEmail: formData.customerEmail,
9419
+ customerEmail: formData.customerEmail?.trim(),
9395
9420
  };
9421
+ // Validate required fields
9422
+ if (!requestData.eventInstanceId) {
9423
+ throw new Error("Event instance ID is required");
9424
+ }
9425
+ if (!requestData.organizationId) {
9426
+ throw new Error("Organization ID is required");
9427
+ }
9428
+ if (!requestData.amount || requestData.amount <= 0) {
9429
+ throw new Error("Valid amount is required");
9430
+ }
9431
+ if (!requestData.participants || requestData.participants.length === 0) {
9432
+ throw new Error("At least one participant is required");
9433
+ }
9434
+ if (!requestData.customerEmail) {
9435
+ throw new Error("Customer email is required");
9436
+ }
9437
+ console.log("[PAYMENT_FORM] Creating payment intent:", {
9438
+ endpoint,
9439
+ mode: isConnectMode ? "connect" : "apikey",
9440
+ amount: requestData.amount,
9441
+ currency: requestData.currency,
9442
+ participantCount: requestData.participants.length,
9443
+ organizationId: requestData.organizationId,
9444
+ eventInstanceId: requestData.eventInstanceId,
9445
+ });
9396
9446
  // Add mode-specific fields
9397
9447
  if (!isConnectMode) {
9398
9448
  // ApiKey mode needs additional fields
@@ -9408,14 +9458,25 @@
9408
9458
  });
9409
9459
  const data = await response.json();
9410
9460
  if (response.ok) {
9461
+ console.log("[PAYMENT_FORM] Payment intent created successfully:", {
9462
+ hasClientSecret: !!data.clientSecret,
9463
+ clientSecretPrefix: `${data.clientSecret?.substring(0, 20)}...`,
9464
+ });
9411
9465
  setClientSecret(data.clientSecret);
9412
9466
  }
9413
9467
  else {
9468
+ console.error("[PAYMENT_FORM] Payment intent creation failed:", {
9469
+ status: response.status,
9470
+ error: data.error,
9471
+ details: data.details,
9472
+ requestData: { ...requestData, customerEmail: "[redacted]" },
9473
+ });
9414
9474
  setPaymentError(data.error || "Fehler beim Erstellen der Zahlungsabsicht");
9415
9475
  }
9416
9476
  }
9417
9477
  catch (err) {
9418
- setPaymentError("Fehler beim Erstellen der Zahlungsabsicht");
9478
+ console.error("[PAYMENT_FORM] Payment intent creation error:", err);
9479
+ setPaymentError(err.message || "Fehler beim Erstellen der Zahlungsabsicht");
9419
9480
  }
9420
9481
  finally {
9421
9482
  setIsCreatingPaymentIntent(false);
@@ -11678,6 +11739,25 @@
11678
11739
  if (data.connectedAccountId) {
11679
11740
  stripeOptions.stripeAccount = data.connectedAccountId;
11680
11741
  }
11742
+ // Add options to prevent sandbox warnings in vanilla JS environments
11743
+ if (typeof window !== "undefined" && window.document) {
11744
+ // Check if we're in a potential iframe or restricted environment
11745
+ try {
11746
+ // Test if we can access parent window (this will throw in sandbox)
11747
+ const hasParentAccess = window.parent === window || window.parent.location.href;
11748
+ // Add apiVersion to ensure compatibility
11749
+ stripeOptions.apiVersion = "2025-02-24.acacia";
11750
+ // For vanilla JS builds, explicitly set betas to empty array to avoid issues
11751
+ if (!stripeOptions.betas) {
11752
+ stripeOptions.betas = [];
11753
+ }
11754
+ }
11755
+ catch (e) {
11756
+ // We're likely in a sandboxed environment, add specific options
11757
+ console.warn("[WIDGET] Detected restricted environment, adjusting Stripe options");
11758
+ stripeOptions.betas = [];
11759
+ }
11760
+ }
11681
11761
  setStripePromise(loadStripe(data.stripePublishableKey, stripeOptions));
11682
11762
  }
11683
11763
  // If only one instance, skip to booking
@@ -11719,6 +11799,25 @@
11719
11799
  if (data.connectedAccountId) {
11720
11800
  stripeOptions.stripeAccount = data.connectedAccountId;
11721
11801
  }
11802
+ // Add options to prevent sandbox warnings in vanilla JS environments
11803
+ if (typeof window !== "undefined" && window.document) {
11804
+ // Check if we're in a potential iframe or restricted environment
11805
+ try {
11806
+ // Test if we can access parent window (this will throw in sandbox)
11807
+ const hasParentAccess = window.parent === window || window.parent.location.href;
11808
+ // Add apiVersion to ensure compatibility
11809
+ stripeOptions.apiVersion = "2025-02-24.acacia";
11810
+ // For vanilla JS builds, explicitly set betas to empty array to avoid issues
11811
+ if (!stripeOptions.betas) {
11812
+ stripeOptions.betas = [];
11813
+ }
11814
+ }
11815
+ catch (e) {
11816
+ // We're likely in a sandboxed environment, add specific options
11817
+ console.warn("[WIDGET] Detected restricted environment, adjusting Stripe options");
11818
+ stripeOptions.betas = [];
11819
+ }
11820
+ }
11722
11821
  setStripePromise(loadStripe(data.stripePublishableKey, stripeOptions));
11723
11822
  }
11724
11823
  }