@flopay/react 0.5.10 → 0.5.11
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 +76 -50
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +76 -50
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -752,12 +752,6 @@ function PayPalButtonInner({
|
|
|
752
752
|
const redirectStatus = params.get("redirect_status");
|
|
753
753
|
if (!paymentIntentId || !clientSecret) return;
|
|
754
754
|
paypalResumeAttempted.current = true;
|
|
755
|
-
console.info("[FloPay debug] PayPal resume effect firing", {
|
|
756
|
-
paymentIntentId,
|
|
757
|
-
redirectStatus,
|
|
758
|
-
currentSessionId: sessionId,
|
|
759
|
-
url: window.location.href
|
|
760
|
-
});
|
|
761
755
|
const cleanedUrl = new URL(window.location.href);
|
|
762
756
|
cleanedUrl.searchParams.delete("payment_intent");
|
|
763
757
|
cleanedUrl.searchParams.delete("payment_intent_client_secret");
|
|
@@ -1317,11 +1311,6 @@ function SplitCardFormInner({
|
|
|
1317
1311
|
const effectiveAccount = mergeAccountPatch(resolvedAccount, overrides?.accountPatch);
|
|
1318
1312
|
const resolvedCompletionPaymentMethodId = overrides?.completionPaymentMethodId ?? resolveTokenizedPaymentMethodId(tokenizedBody);
|
|
1319
1313
|
const requestTokenizedBody = tokenizedBody.originalPaymentMethodId ? { ...tokenizedBody, originalPaymentMethodId: void 0 } : tokenizedBody;
|
|
1320
|
-
console.info("[FloPay debug] processPaymentInternal -> POST /process", {
|
|
1321
|
-
sessionId: effectiveSessionId,
|
|
1322
|
-
paymentIntentId: tokenizedBody.threeDSecureActionResultTokenId,
|
|
1323
|
-
isPaypal: tokenizedBody.isPaypal
|
|
1324
|
-
});
|
|
1325
1314
|
try {
|
|
1326
1315
|
const response = await fetch(`${baseUrl}/v1/checkouts/sessions/process`, {
|
|
1327
1316
|
method: "POST",
|
|
@@ -3124,6 +3113,30 @@ function FloPayCheckout({
|
|
|
3124
3113
|
);
|
|
3125
3114
|
}
|
|
3126
3115
|
const paymentMethodId = typeof paymentIntent.payment_method === "string" ? paymentIntent.payment_method : paymentIntent.payment_method?.id;
|
|
3116
|
+
if (resumeState.sessionId) {
|
|
3117
|
+
const resumeApi = new PaymentAPI2(resolvedBillingUrl);
|
|
3118
|
+
const resumeSessionResult = await resumeApi.getUnifiedCheckoutSession(resumeState.sessionId);
|
|
3119
|
+
const resumeSession = resumeSessionResult.data.session;
|
|
3120
|
+
if (resumeSession && resumeSession.status !== "complete") {
|
|
3121
|
+
const processResult = await processSavedPaymentForMode({
|
|
3122
|
+
billingApiUrl: resolvedBillingUrl,
|
|
3123
|
+
sessionId: resumeState.sessionId,
|
|
3124
|
+
session: resumeSession,
|
|
3125
|
+
tokenizedData: {
|
|
3126
|
+
id: paymentMethodId ?? paymentIntent.id,
|
|
3127
|
+
type: "card",
|
|
3128
|
+
threeDSecureActionResultTokenId: paymentIntent.id,
|
|
3129
|
+
isPaypal: true
|
|
3130
|
+
}
|
|
3131
|
+
});
|
|
3132
|
+
if (processResult.type !== "success") {
|
|
3133
|
+
throw Object.assign(
|
|
3134
|
+
new FloPayError4("Failed to finalize PayPal payment.", "api_error"),
|
|
3135
|
+
{ checkoutMethod: "paypal" }
|
|
3136
|
+
);
|
|
3137
|
+
}
|
|
3138
|
+
}
|
|
3139
|
+
}
|
|
3127
3140
|
if (resumeState.sessionId) markSessionRecentlyCompleted(resumeState.sessionId);
|
|
3128
3141
|
setModeOverlayStatus("success");
|
|
3129
3142
|
await sleep(PROCESSING_OVERLAY_SUCCESS_DELAY_MS);
|
|
@@ -3197,42 +3210,24 @@ function FloPayCheckout({
|
|
|
3197
3210
|
const api = new PaymentAPI2(resolvedBillingUrl);
|
|
3198
3211
|
let sid = typeof window !== "undefined" ? window.sessionStorage.getItem(cacheKey) : null;
|
|
3199
3212
|
let realResult = null;
|
|
3200
|
-
console.info("[FloPay debug] resolveInlineSession enter", {
|
|
3201
|
-
cacheKey,
|
|
3202
|
-
cachedSid: sid,
|
|
3203
|
-
url: typeof window !== "undefined" ? window.location.href : null
|
|
3204
|
-
});
|
|
3205
3213
|
if (sid) {
|
|
3206
3214
|
try {
|
|
3207
3215
|
realResult = await api.getUnifiedCheckoutSession(sid);
|
|
3208
3216
|
const status = realResult.data.session?.status;
|
|
3209
|
-
console.info("[FloPay debug] resolveInlineSession cache hit", {
|
|
3210
|
-
cacheKey,
|
|
3211
|
-
sid,
|
|
3212
|
-
status,
|
|
3213
|
-
recentlyCompleted: wasSessionRecentlyCompleted(sid)
|
|
3214
|
-
});
|
|
3215
3217
|
if (status === "complete") {
|
|
3216
3218
|
if (wasSessionRecentlyCompleted(sid)) {
|
|
3217
|
-
console.info("[FloPay debug] resolveInlineSession reuse-completed", { sid });
|
|
3218
3219
|
return { sid, result: realResult };
|
|
3219
3220
|
}
|
|
3220
|
-
console.warn("[FloPay debug] resolveInlineSession clearing stale complete cache", { sid });
|
|
3221
3221
|
if (typeof window !== "undefined") window.sessionStorage.removeItem(cacheKey);
|
|
3222
3222
|
sid = null;
|
|
3223
3223
|
realResult = null;
|
|
3224
3224
|
}
|
|
3225
|
-
} catch
|
|
3226
|
-
console.warn("[FloPay debug] resolveInlineSession getUnifiedCheckoutSession threw", { sid, err });
|
|
3225
|
+
} catch {
|
|
3227
3226
|
if (typeof window !== "undefined") window.sessionStorage.removeItem(cacheKey);
|
|
3228
3227
|
sid = null;
|
|
3229
3228
|
}
|
|
3230
3229
|
}
|
|
3231
3230
|
if (!sid) {
|
|
3232
|
-
console.warn("[FloPay debug] resolveInlineSession POSTing /v1/checkouts/sessions", {
|
|
3233
|
-
cacheKey,
|
|
3234
|
-
url: typeof window !== "undefined" ? window.location.href : null
|
|
3235
|
-
});
|
|
3236
3231
|
const paramsWithAnalytics = {
|
|
3237
3232
|
...params,
|
|
3238
3233
|
avsCheck: !!enableAVS,
|
|
@@ -3257,16 +3252,10 @@ function FloPayCheckout({
|
|
|
3257
3252
|
const mergedParams = mergeInlineSessionPatch(baseParams, patch);
|
|
3258
3253
|
const cacheKey = hashCreateParams(mergedParams);
|
|
3259
3254
|
let promise = sessionInflightMap.get(cacheKey);
|
|
3260
|
-
const inflightHit = !!promise;
|
|
3261
3255
|
if (!promise) {
|
|
3262
3256
|
promise = resolveInlineSession(mergedParams, cacheKey);
|
|
3263
3257
|
sessionInflightMap.set(cacheKey, promise);
|
|
3264
3258
|
}
|
|
3265
|
-
console.info("[FloPay debug] bootstrapInlineSession", {
|
|
3266
|
-
cacheKey,
|
|
3267
|
-
inflightHit,
|
|
3268
|
-
url: typeof window !== "undefined" ? window.location.href : null
|
|
3269
|
-
});
|
|
3270
3259
|
let resolved;
|
|
3271
3260
|
try {
|
|
3272
3261
|
resolved = await promise;
|
|
@@ -4893,6 +4882,10 @@ function FloPayAutomaticPaymentButton({
|
|
|
4893
4882
|
floPayErr = normalizeSavedPaymentError(intentRecoveryErr);
|
|
4894
4883
|
}
|
|
4895
4884
|
}
|
|
4885
|
+
const inResumeWindow = typeof window !== "undefined" && new URLSearchParams(window.location.search).has("payment_intent_client_secret") && !!readPayPalResumeState2();
|
|
4886
|
+
if (floPayErr.code === "payment_intent_unexpected_state" && inResumeWindow) {
|
|
4887
|
+
return;
|
|
4888
|
+
}
|
|
4896
4889
|
await showError(floPayErr, {
|
|
4897
4890
|
emitDecline: true,
|
|
4898
4891
|
method: floPayErr.checkoutMethod ?? DEFAULT_SAVED_PAYMENT_DECLINE_METHOD
|
|
@@ -5064,25 +5057,58 @@ function FloPayAutomaticPaymentButton({
|
|
|
5064
5057
|
);
|
|
5065
5058
|
}
|
|
5066
5059
|
const resultStatus = mapPayPalIntentStatusToPaymentResult(paymentIntent?.status);
|
|
5067
|
-
if (paymentIntent
|
|
5068
|
-
const paymentMethodId2 = typeof paymentIntent.payment_method === "string" ? paymentIntent.payment_method : paymentIntent.payment_method?.id;
|
|
5069
|
-
await showSuccess({
|
|
5070
|
-
result: {
|
|
5071
|
-
status: resultStatus,
|
|
5072
|
-
paymentIntentId: paymentIntent.id,
|
|
5073
|
-
paymentMethodId: paymentMethodId2,
|
|
5074
|
-
checkoutMethod: "paypal"
|
|
5075
|
-
},
|
|
5076
|
-
session: null,
|
|
5077
|
-
sessionId: resumeState.sessionId,
|
|
5078
|
-
autoCompleted: false
|
|
5079
|
-
});
|
|
5080
|
-
} else {
|
|
5060
|
+
if (!paymentIntent || resultStatus === "failed") {
|
|
5081
5061
|
throw Object.assign(
|
|
5082
5062
|
new FloPayError7("PayPal payment was not completed. Please try again.", "api_error"),
|
|
5083
5063
|
{ checkoutMethod: "paypal" }
|
|
5084
5064
|
);
|
|
5085
5065
|
}
|
|
5066
|
+
const paymentMethodId2 = typeof paymentIntent.payment_method === "string" ? paymentIntent.payment_method : paymentIntent.payment_method?.id;
|
|
5067
|
+
if (!resumeState.sessionId) {
|
|
5068
|
+
throw Object.assign(
|
|
5069
|
+
new FloPayError7("Missing session id on PayPal resume.", "api_error"),
|
|
5070
|
+
{ checkoutMethod: "paypal" }
|
|
5071
|
+
);
|
|
5072
|
+
}
|
|
5073
|
+
const api = new PaymentAPI3(resolvedBillingUrl);
|
|
5074
|
+
const sessionResult = await api.getUnifiedCheckoutSession(resumeState.sessionId);
|
|
5075
|
+
const resumeSession = sessionResult.data.session;
|
|
5076
|
+
if (!resumeSession) {
|
|
5077
|
+
throw Object.assign(
|
|
5078
|
+
new FloPayError7("Could not load session to capture PayPal payment.", "api_error"),
|
|
5079
|
+
{ checkoutMethod: "paypal" }
|
|
5080
|
+
);
|
|
5081
|
+
}
|
|
5082
|
+
if (resumeSession.status !== "complete") {
|
|
5083
|
+
const processResult = await processSavedPaymentForMode({
|
|
5084
|
+
billingApiUrl: resolvedBillingUrl,
|
|
5085
|
+
sessionId: resumeState.sessionId,
|
|
5086
|
+
session: resumeSession,
|
|
5087
|
+
tokenizedData: {
|
|
5088
|
+
id: paymentMethodId2 ?? paymentIntent.id,
|
|
5089
|
+
type: "card",
|
|
5090
|
+
threeDSecureActionResultTokenId: paymentIntent.id,
|
|
5091
|
+
isPaypal: true
|
|
5092
|
+
}
|
|
5093
|
+
});
|
|
5094
|
+
if (processResult.type !== "success") {
|
|
5095
|
+
throw Object.assign(
|
|
5096
|
+
new FloPayError7("Failed to finalize PayPal payment.", "api_error"),
|
|
5097
|
+
{ checkoutMethod: "paypal" }
|
|
5098
|
+
);
|
|
5099
|
+
}
|
|
5100
|
+
}
|
|
5101
|
+
await showSuccess({
|
|
5102
|
+
result: {
|
|
5103
|
+
status: resultStatus,
|
|
5104
|
+
paymentIntentId: paymentIntent.id,
|
|
5105
|
+
paymentMethodId: paymentMethodId2,
|
|
5106
|
+
checkoutMethod: "paypal"
|
|
5107
|
+
},
|
|
5108
|
+
session: resumeSession,
|
|
5109
|
+
sessionId: resumeState.sessionId,
|
|
5110
|
+
autoCompleted: false
|
|
5111
|
+
});
|
|
5086
5112
|
} catch (err) {
|
|
5087
5113
|
const floPayErr = normalizeSavedPaymentError(err);
|
|
5088
5114
|
await showError(floPayErr, {
|