create-brainerce-store 1.19.0 → 1.20.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.
@@ -0,0 +1,59 @@
1
+ 'use client';
2
+
3
+ import { useEffect } from 'react';
4
+ import { useSearchParams } from 'next/navigation';
5
+ import { Suspense } from 'react';
6
+ import { LoadingSpinner } from '@/components/shared/loading-spinner';
7
+
8
+ /**
9
+ * Lightweight callback page for iframe-based payment providers (e.g. CardCom).
10
+ *
11
+ * After the customer pays on the provider's hosted page (rendered inside an
12
+ * iframe on the checkout page), the provider redirects *inside the iframe* to
13
+ * this page. We extract the relevant query params and send them to the parent
14
+ * window via postMessage so the checkout page can verify the payment
15
+ * server-side and proceed to order confirmation.
16
+ */
17
+ function PaymentCompleteContent() {
18
+ const searchParams = useSearchParams();
19
+
20
+ useEffect(() => {
21
+ // Only send postMessage when running inside an iframe
22
+ if (window.parent === window) {
23
+ // Not in iframe — fallback: redirect to order-confirmation directly
24
+ const checkoutId = searchParams.get('checkout_id');
25
+ if (checkoutId) {
26
+ window.location.href = `/order-confirmation?${searchParams.toString()}`;
27
+ }
28
+ return;
29
+ }
30
+
31
+ // Collect all query params from the provider redirect
32
+ const data: Record<string, string> = {};
33
+ searchParams.forEach((value, key) => {
34
+ data[key] = value;
35
+ });
36
+
37
+ window.parent.postMessage({ type: 'brainerce:payment-complete', data }, window.location.origin);
38
+ }, [searchParams]);
39
+
40
+ return (
41
+ <div className="flex min-h-[200px] items-center justify-center">
42
+ <LoadingSpinner size="lg" />
43
+ </div>
44
+ );
45
+ }
46
+
47
+ export default function PaymentCompletePage() {
48
+ return (
49
+ <Suspense
50
+ fallback={
51
+ <div className="flex min-h-[200px] items-center justify-center">
52
+ <LoadingSpinner size="lg" />
53
+ </div>
54
+ }
55
+ >
56
+ <PaymentCompleteContent />
57
+ </Suspense>
58
+ );
59
+ }