@akinon/pz-flow-payment 1.97.0 → 1.98.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/CHANGELOG.md +6 -0
- package/package.json +1 -1
- package/src/views/index.tsx +24 -9
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
package/src/views/index.tsx
CHANGED
|
@@ -59,6 +59,7 @@ export default function FlowPayment({
|
|
|
59
59
|
const flowComponentRef = useRef<any>(null);
|
|
60
60
|
const lastAmountRef = useRef<string | null>(null);
|
|
61
61
|
const isInitializingRef = useRef<boolean>(false);
|
|
62
|
+
const walletPaymentInitialized = useRef<boolean>(false);
|
|
62
63
|
|
|
63
64
|
// Memoize the amount to track actual changes
|
|
64
65
|
const currentAmount = useMemo(() => {
|
|
@@ -81,7 +82,11 @@ export default function FlowPayment({
|
|
|
81
82
|
return;
|
|
82
83
|
}
|
|
83
84
|
|
|
84
|
-
|
|
85
|
+
// FIX: Only call setWalletPaymentPage if not already initialized
|
|
86
|
+
if (!walletPaymentInitialized.current) {
|
|
87
|
+
walletPaymentInitialized.current = true;
|
|
88
|
+
dispatch(checkoutApi.endpoints.setWalletPaymentPage.initiate({}));
|
|
89
|
+
}
|
|
85
90
|
};
|
|
86
91
|
|
|
87
92
|
const initFlowPaymentWebComponents = async ({
|
|
@@ -118,16 +123,24 @@ export default function FlowPayment({
|
|
|
118
123
|
container.innerHTML = '';
|
|
119
124
|
}
|
|
120
125
|
|
|
121
|
-
//
|
|
126
|
+
// FIX: Use existing payment session instead of making another API call
|
|
122
127
|
let paymentSession = preOrder.context_extras;
|
|
123
128
|
|
|
124
|
-
if
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
walletPaymentResponse
|
|
130
|
-
|
|
129
|
+
// Only get fresh payment data if we don't have a valid session
|
|
130
|
+
if (!paymentSession && lastAmountRef.current !== currentAmount) {
|
|
131
|
+
// Check if another call is already in progress
|
|
132
|
+
if (!walletPaymentInitialized.current) {
|
|
133
|
+
walletPaymentInitialized.current = true;
|
|
134
|
+
const walletPaymentResponse = await dispatch(
|
|
135
|
+
checkoutApi.endpoints.setWalletPaymentPage.initiate({})
|
|
136
|
+
).unwrap();
|
|
137
|
+
paymentSession =
|
|
138
|
+
walletPaymentResponse?.pre_order?.context_extras ||
|
|
139
|
+
preOrder.context_extras;
|
|
140
|
+
} else {
|
|
141
|
+
// Use existing context_extras if another call was already made
|
|
142
|
+
paymentSession = preOrder.context_extras;
|
|
143
|
+
}
|
|
131
144
|
}
|
|
132
145
|
|
|
133
146
|
// Update the last amount reference after getting fresh data
|
|
@@ -192,6 +205,8 @@ export default function FlowPayment({
|
|
|
192
205
|
console.warn('Error destroying flow component on unmount:', error);
|
|
193
206
|
}
|
|
194
207
|
}
|
|
208
|
+
// Reset initialization flag on unmount
|
|
209
|
+
walletPaymentInitialized.current = false;
|
|
195
210
|
};
|
|
196
211
|
}, []);
|
|
197
212
|
|