@flopay/react 0.5.10 → 0.5.12
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 +88 -51
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +88 -51
- 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,11 +3113,37 @@ function FloPayCheckout({
|
|
|
3124
3113
|
);
|
|
3125
3114
|
}
|
|
3126
3115
|
const paymentMethodId = typeof paymentIntent.payment_method === "string" ? paymentIntent.payment_method : paymentIntent.payment_method?.id;
|
|
3116
|
+
let finalResultStatus = resultStatus;
|
|
3117
|
+
if (resumeState.sessionId) {
|
|
3118
|
+
const resumeApi = new PaymentAPI2(resolvedBillingUrl);
|
|
3119
|
+
const resumeSessionResult = await resumeApi.getUnifiedCheckoutSession(resumeState.sessionId);
|
|
3120
|
+
const resumeSession = resumeSessionResult.data.session;
|
|
3121
|
+
if (resumeSession && resumeSession.status !== "complete") {
|
|
3122
|
+
const processResult = await processSavedPaymentForMode({
|
|
3123
|
+
billingApiUrl: resolvedBillingUrl,
|
|
3124
|
+
sessionId: resumeState.sessionId,
|
|
3125
|
+
session: resumeSession,
|
|
3126
|
+
tokenizedData: {
|
|
3127
|
+
id: paymentMethodId ?? paymentIntent.id,
|
|
3128
|
+
type: "card",
|
|
3129
|
+
threeDSecureActionResultTokenId: paymentIntent.id,
|
|
3130
|
+
isPaypal: true
|
|
3131
|
+
}
|
|
3132
|
+
});
|
|
3133
|
+
if (processResult.type !== "success") {
|
|
3134
|
+
throw Object.assign(
|
|
3135
|
+
new FloPayError4("Failed to finalize PayPal payment.", "api_error"),
|
|
3136
|
+
{ checkoutMethod: "paypal" }
|
|
3137
|
+
);
|
|
3138
|
+
}
|
|
3139
|
+
finalResultStatus = processResult.result.status;
|
|
3140
|
+
}
|
|
3141
|
+
}
|
|
3127
3142
|
if (resumeState.sessionId) markSessionRecentlyCompleted(resumeState.sessionId);
|
|
3128
3143
|
setModeOverlayStatus("success");
|
|
3129
3144
|
await sleep(PROCESSING_OVERLAY_SUCCESS_DELAY_MS);
|
|
3130
3145
|
onCompleteRef.current?.({
|
|
3131
|
-
status:
|
|
3146
|
+
status: finalResultStatus,
|
|
3132
3147
|
paymentIntentId: paymentIntent.id,
|
|
3133
3148
|
paymentMethodId,
|
|
3134
3149
|
checkoutMethod: "paypal"
|
|
@@ -3197,42 +3212,24 @@ function FloPayCheckout({
|
|
|
3197
3212
|
const api = new PaymentAPI2(resolvedBillingUrl);
|
|
3198
3213
|
let sid = typeof window !== "undefined" ? window.sessionStorage.getItem(cacheKey) : null;
|
|
3199
3214
|
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
3215
|
if (sid) {
|
|
3206
3216
|
try {
|
|
3207
3217
|
realResult = await api.getUnifiedCheckoutSession(sid);
|
|
3208
3218
|
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
3219
|
if (status === "complete") {
|
|
3216
3220
|
if (wasSessionRecentlyCompleted(sid)) {
|
|
3217
|
-
console.info("[FloPay debug] resolveInlineSession reuse-completed", { sid });
|
|
3218
3221
|
return { sid, result: realResult };
|
|
3219
3222
|
}
|
|
3220
|
-
console.warn("[FloPay debug] resolveInlineSession clearing stale complete cache", { sid });
|
|
3221
3223
|
if (typeof window !== "undefined") window.sessionStorage.removeItem(cacheKey);
|
|
3222
3224
|
sid = null;
|
|
3223
3225
|
realResult = null;
|
|
3224
3226
|
}
|
|
3225
|
-
} catch
|
|
3226
|
-
console.warn("[FloPay debug] resolveInlineSession getUnifiedCheckoutSession threw", { sid, err });
|
|
3227
|
+
} catch {
|
|
3227
3228
|
if (typeof window !== "undefined") window.sessionStorage.removeItem(cacheKey);
|
|
3228
3229
|
sid = null;
|
|
3229
3230
|
}
|
|
3230
3231
|
}
|
|
3231
3232
|
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
3233
|
const paramsWithAnalytics = {
|
|
3237
3234
|
...params,
|
|
3238
3235
|
avsCheck: !!enableAVS,
|
|
@@ -3257,16 +3254,10 @@ function FloPayCheckout({
|
|
|
3257
3254
|
const mergedParams = mergeInlineSessionPatch(baseParams, patch);
|
|
3258
3255
|
const cacheKey = hashCreateParams(mergedParams);
|
|
3259
3256
|
let promise = sessionInflightMap.get(cacheKey);
|
|
3260
|
-
const inflightHit = !!promise;
|
|
3261
3257
|
if (!promise) {
|
|
3262
3258
|
promise = resolveInlineSession(mergedParams, cacheKey);
|
|
3263
3259
|
sessionInflightMap.set(cacheKey, promise);
|
|
3264
3260
|
}
|
|
3265
|
-
console.info("[FloPay debug] bootstrapInlineSession", {
|
|
3266
|
-
cacheKey,
|
|
3267
|
-
inflightHit,
|
|
3268
|
-
url: typeof window !== "undefined" ? window.location.href : null
|
|
3269
|
-
});
|
|
3270
3261
|
let resolved;
|
|
3271
3262
|
try {
|
|
3272
3263
|
resolved = await promise;
|
|
@@ -4893,6 +4884,10 @@ function FloPayAutomaticPaymentButton({
|
|
|
4893
4884
|
floPayErr = normalizeSavedPaymentError(intentRecoveryErr);
|
|
4894
4885
|
}
|
|
4895
4886
|
}
|
|
4887
|
+
const inResumeWindow = typeof window !== "undefined" && new URLSearchParams(window.location.search).has("payment_intent_client_secret") && !!readPayPalResumeState2();
|
|
4888
|
+
if (floPayErr.code === "payment_intent_unexpected_state" && inResumeWindow) {
|
|
4889
|
+
return;
|
|
4890
|
+
}
|
|
4896
4891
|
await showError(floPayErr, {
|
|
4897
4892
|
emitDecline: true,
|
|
4898
4893
|
method: floPayErr.checkoutMethod ?? DEFAULT_SAVED_PAYMENT_DECLINE_METHOD
|
|
@@ -5064,25 +5059,67 @@ function FloPayAutomaticPaymentButton({
|
|
|
5064
5059
|
);
|
|
5065
5060
|
}
|
|
5066
5061
|
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 {
|
|
5062
|
+
if (!paymentIntent || resultStatus === "failed") {
|
|
5081
5063
|
throw Object.assign(
|
|
5082
5064
|
new FloPayError7("PayPal payment was not completed. Please try again.", "api_error"),
|
|
5083
5065
|
{ checkoutMethod: "paypal" }
|
|
5084
5066
|
);
|
|
5085
5067
|
}
|
|
5068
|
+
const paymentMethodId2 = typeof paymentIntent.payment_method === "string" ? paymentIntent.payment_method : paymentIntent.payment_method?.id;
|
|
5069
|
+
if (!resumeState.sessionId) {
|
|
5070
|
+
throw Object.assign(
|
|
5071
|
+
new FloPayError7("Missing session id on PayPal resume.", "api_error"),
|
|
5072
|
+
{ checkoutMethod: "paypal" }
|
|
5073
|
+
);
|
|
5074
|
+
}
|
|
5075
|
+
const api = new PaymentAPI3(resolvedBillingUrl);
|
|
5076
|
+
const sessionResult = await api.getUnifiedCheckoutSession(resumeState.sessionId);
|
|
5077
|
+
let resumeSession = sessionResult.data.session;
|
|
5078
|
+
if (!resumeSession) {
|
|
5079
|
+
throw Object.assign(
|
|
5080
|
+
new FloPayError7("Could not load session to capture PayPal payment.", "api_error"),
|
|
5081
|
+
{ checkoutMethod: "paypal" }
|
|
5082
|
+
);
|
|
5083
|
+
}
|
|
5084
|
+
let finalResultStatus = resultStatus;
|
|
5085
|
+
if (resumeSession.status !== "complete") {
|
|
5086
|
+
const processResult = await processSavedPaymentForMode({
|
|
5087
|
+
billingApiUrl: resolvedBillingUrl,
|
|
5088
|
+
sessionId: resumeState.sessionId,
|
|
5089
|
+
session: resumeSession,
|
|
5090
|
+
tokenizedData: {
|
|
5091
|
+
id: paymentMethodId2 ?? paymentIntent.id,
|
|
5092
|
+
type: "card",
|
|
5093
|
+
threeDSecureActionResultTokenId: paymentIntent.id,
|
|
5094
|
+
isPaypal: true
|
|
5095
|
+
}
|
|
5096
|
+
});
|
|
5097
|
+
if (processResult.type !== "success") {
|
|
5098
|
+
throw Object.assign(
|
|
5099
|
+
new FloPayError7("Failed to finalize PayPal payment.", "api_error"),
|
|
5100
|
+
{ checkoutMethod: "paypal" }
|
|
5101
|
+
);
|
|
5102
|
+
}
|
|
5103
|
+
finalResultStatus = processResult.result.status;
|
|
5104
|
+
try {
|
|
5105
|
+
const refreshed = await api.getUnifiedCheckoutSession(resumeState.sessionId);
|
|
5106
|
+
if (refreshed.data.session) {
|
|
5107
|
+
resumeSession = refreshed.data.session;
|
|
5108
|
+
}
|
|
5109
|
+
} catch {
|
|
5110
|
+
}
|
|
5111
|
+
}
|
|
5112
|
+
await showSuccess({
|
|
5113
|
+
result: {
|
|
5114
|
+
status: finalResultStatus,
|
|
5115
|
+
paymentIntentId: paymentIntent.id,
|
|
5116
|
+
paymentMethodId: paymentMethodId2,
|
|
5117
|
+
checkoutMethod: "paypal"
|
|
5118
|
+
},
|
|
5119
|
+
session: resumeSession,
|
|
5120
|
+
sessionId: resumeState.sessionId,
|
|
5121
|
+
autoCompleted: false
|
|
5122
|
+
});
|
|
5086
5123
|
} catch (err) {
|
|
5087
5124
|
const floPayErr = normalizeSavedPaymentError(err);
|
|
5088
5125
|
await showError(floPayErr, {
|