@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.cjs
CHANGED
|
@@ -789,12 +789,6 @@ function PayPalButtonInner({
|
|
|
789
789
|
const redirectStatus = params.get("redirect_status");
|
|
790
790
|
if (!paymentIntentId || !clientSecret) return;
|
|
791
791
|
paypalResumeAttempted.current = true;
|
|
792
|
-
console.info("[FloPay debug] PayPal resume effect firing", {
|
|
793
|
-
paymentIntentId,
|
|
794
|
-
redirectStatus,
|
|
795
|
-
currentSessionId: sessionId,
|
|
796
|
-
url: window.location.href
|
|
797
|
-
});
|
|
798
792
|
const cleanedUrl = new URL(window.location.href);
|
|
799
793
|
cleanedUrl.searchParams.delete("payment_intent");
|
|
800
794
|
cleanedUrl.searchParams.delete("payment_intent_client_secret");
|
|
@@ -1354,11 +1348,6 @@ function SplitCardFormInner({
|
|
|
1354
1348
|
const effectiveAccount = mergeAccountPatch(resolvedAccount, overrides?.accountPatch);
|
|
1355
1349
|
const resolvedCompletionPaymentMethodId = overrides?.completionPaymentMethodId ?? resolveTokenizedPaymentMethodId(tokenizedBody);
|
|
1356
1350
|
const requestTokenizedBody = tokenizedBody.originalPaymentMethodId ? { ...tokenizedBody, originalPaymentMethodId: void 0 } : tokenizedBody;
|
|
1357
|
-
console.info("[FloPay debug] processPaymentInternal -> POST /process", {
|
|
1358
|
-
sessionId: effectiveSessionId,
|
|
1359
|
-
paymentIntentId: tokenizedBody.threeDSecureActionResultTokenId,
|
|
1360
|
-
isPaypal: tokenizedBody.isPaypal
|
|
1361
|
-
});
|
|
1362
1351
|
try {
|
|
1363
1352
|
const response = await fetch(`${baseUrl}/v1/checkouts/sessions/process`, {
|
|
1364
1353
|
method: "POST",
|
|
@@ -3161,11 +3150,37 @@ function FloPayCheckout({
|
|
|
3161
3150
|
);
|
|
3162
3151
|
}
|
|
3163
3152
|
const paymentMethodId = typeof paymentIntent.payment_method === "string" ? paymentIntent.payment_method : paymentIntent.payment_method?.id;
|
|
3153
|
+
let finalResultStatus = resultStatus;
|
|
3154
|
+
if (resumeState.sessionId) {
|
|
3155
|
+
const resumeApi = new import_js2.PaymentAPI(resolvedBillingUrl);
|
|
3156
|
+
const resumeSessionResult = await resumeApi.getUnifiedCheckoutSession(resumeState.sessionId);
|
|
3157
|
+
const resumeSession = resumeSessionResult.data.session;
|
|
3158
|
+
if (resumeSession && resumeSession.status !== "complete") {
|
|
3159
|
+
const processResult = await processSavedPaymentForMode({
|
|
3160
|
+
billingApiUrl: resolvedBillingUrl,
|
|
3161
|
+
sessionId: resumeState.sessionId,
|
|
3162
|
+
session: resumeSession,
|
|
3163
|
+
tokenizedData: {
|
|
3164
|
+
id: paymentMethodId ?? paymentIntent.id,
|
|
3165
|
+
type: "card",
|
|
3166
|
+
threeDSecureActionResultTokenId: paymentIntent.id,
|
|
3167
|
+
isPaypal: true
|
|
3168
|
+
}
|
|
3169
|
+
});
|
|
3170
|
+
if (processResult.type !== "success") {
|
|
3171
|
+
throw Object.assign(
|
|
3172
|
+
new import_shared7.FloPayError("Failed to finalize PayPal payment.", "api_error"),
|
|
3173
|
+
{ checkoutMethod: "paypal" }
|
|
3174
|
+
);
|
|
3175
|
+
}
|
|
3176
|
+
finalResultStatus = processResult.result.status;
|
|
3177
|
+
}
|
|
3178
|
+
}
|
|
3164
3179
|
if (resumeState.sessionId) markSessionRecentlyCompleted(resumeState.sessionId);
|
|
3165
3180
|
setModeOverlayStatus("success");
|
|
3166
3181
|
await sleep(PROCESSING_OVERLAY_SUCCESS_DELAY_MS);
|
|
3167
3182
|
onCompleteRef.current?.({
|
|
3168
|
-
status:
|
|
3183
|
+
status: finalResultStatus,
|
|
3169
3184
|
paymentIntentId: paymentIntent.id,
|
|
3170
3185
|
paymentMethodId,
|
|
3171
3186
|
checkoutMethod: "paypal"
|
|
@@ -3234,42 +3249,24 @@ function FloPayCheckout({
|
|
|
3234
3249
|
const api = new import_js2.PaymentAPI(resolvedBillingUrl);
|
|
3235
3250
|
let sid = typeof window !== "undefined" ? window.sessionStorage.getItem(cacheKey) : null;
|
|
3236
3251
|
let realResult = null;
|
|
3237
|
-
console.info("[FloPay debug] resolveInlineSession enter", {
|
|
3238
|
-
cacheKey,
|
|
3239
|
-
cachedSid: sid,
|
|
3240
|
-
url: typeof window !== "undefined" ? window.location.href : null
|
|
3241
|
-
});
|
|
3242
3252
|
if (sid) {
|
|
3243
3253
|
try {
|
|
3244
3254
|
realResult = await api.getUnifiedCheckoutSession(sid);
|
|
3245
3255
|
const status = realResult.data.session?.status;
|
|
3246
|
-
console.info("[FloPay debug] resolveInlineSession cache hit", {
|
|
3247
|
-
cacheKey,
|
|
3248
|
-
sid,
|
|
3249
|
-
status,
|
|
3250
|
-
recentlyCompleted: wasSessionRecentlyCompleted(sid)
|
|
3251
|
-
});
|
|
3252
3256
|
if (status === "complete") {
|
|
3253
3257
|
if (wasSessionRecentlyCompleted(sid)) {
|
|
3254
|
-
console.info("[FloPay debug] resolveInlineSession reuse-completed", { sid });
|
|
3255
3258
|
return { sid, result: realResult };
|
|
3256
3259
|
}
|
|
3257
|
-
console.warn("[FloPay debug] resolveInlineSession clearing stale complete cache", { sid });
|
|
3258
3260
|
if (typeof window !== "undefined") window.sessionStorage.removeItem(cacheKey);
|
|
3259
3261
|
sid = null;
|
|
3260
3262
|
realResult = null;
|
|
3261
3263
|
}
|
|
3262
|
-
} catch
|
|
3263
|
-
console.warn("[FloPay debug] resolveInlineSession getUnifiedCheckoutSession threw", { sid, err });
|
|
3264
|
+
} catch {
|
|
3264
3265
|
if (typeof window !== "undefined") window.sessionStorage.removeItem(cacheKey);
|
|
3265
3266
|
sid = null;
|
|
3266
3267
|
}
|
|
3267
3268
|
}
|
|
3268
3269
|
if (!sid) {
|
|
3269
|
-
console.warn("[FloPay debug] resolveInlineSession POSTing /v1/checkouts/sessions", {
|
|
3270
|
-
cacheKey,
|
|
3271
|
-
url: typeof window !== "undefined" ? window.location.href : null
|
|
3272
|
-
});
|
|
3273
3270
|
const paramsWithAnalytics = {
|
|
3274
3271
|
...params,
|
|
3275
3272
|
avsCheck: !!enableAVS,
|
|
@@ -3294,16 +3291,10 @@ function FloPayCheckout({
|
|
|
3294
3291
|
const mergedParams = mergeInlineSessionPatch(baseParams, patch);
|
|
3295
3292
|
const cacheKey = hashCreateParams(mergedParams);
|
|
3296
3293
|
let promise = sessionInflightMap.get(cacheKey);
|
|
3297
|
-
const inflightHit = !!promise;
|
|
3298
3294
|
if (!promise) {
|
|
3299
3295
|
promise = resolveInlineSession(mergedParams, cacheKey);
|
|
3300
3296
|
sessionInflightMap.set(cacheKey, promise);
|
|
3301
3297
|
}
|
|
3302
|
-
console.info("[FloPay debug] bootstrapInlineSession", {
|
|
3303
|
-
cacheKey,
|
|
3304
|
-
inflightHit,
|
|
3305
|
-
url: typeof window !== "undefined" ? window.location.href : null
|
|
3306
|
-
});
|
|
3307
3298
|
let resolved;
|
|
3308
3299
|
try {
|
|
3309
3300
|
resolved = await promise;
|
|
@@ -4930,6 +4921,10 @@ function FloPayAutomaticPaymentButton({
|
|
|
4930
4921
|
floPayErr = normalizeSavedPaymentError(intentRecoveryErr);
|
|
4931
4922
|
}
|
|
4932
4923
|
}
|
|
4924
|
+
const inResumeWindow = typeof window !== "undefined" && new URLSearchParams(window.location.search).has("payment_intent_client_secret") && !!readPayPalResumeState2();
|
|
4925
|
+
if (floPayErr.code === "payment_intent_unexpected_state" && inResumeWindow) {
|
|
4926
|
+
return;
|
|
4927
|
+
}
|
|
4933
4928
|
await showError(floPayErr, {
|
|
4934
4929
|
emitDecline: true,
|
|
4935
4930
|
method: floPayErr.checkoutMethod ?? DEFAULT_SAVED_PAYMENT_DECLINE_METHOD
|
|
@@ -5101,25 +5096,67 @@ function FloPayAutomaticPaymentButton({
|
|
|
5101
5096
|
);
|
|
5102
5097
|
}
|
|
5103
5098
|
const resultStatus = mapPayPalIntentStatusToPaymentResult(paymentIntent?.status);
|
|
5104
|
-
if (paymentIntent
|
|
5105
|
-
const paymentMethodId2 = typeof paymentIntent.payment_method === "string" ? paymentIntent.payment_method : paymentIntent.payment_method?.id;
|
|
5106
|
-
await showSuccess({
|
|
5107
|
-
result: {
|
|
5108
|
-
status: resultStatus,
|
|
5109
|
-
paymentIntentId: paymentIntent.id,
|
|
5110
|
-
paymentMethodId: paymentMethodId2,
|
|
5111
|
-
checkoutMethod: "paypal"
|
|
5112
|
-
},
|
|
5113
|
-
session: null,
|
|
5114
|
-
sessionId: resumeState.sessionId,
|
|
5115
|
-
autoCompleted: false
|
|
5116
|
-
});
|
|
5117
|
-
} else {
|
|
5099
|
+
if (!paymentIntent || resultStatus === "failed") {
|
|
5118
5100
|
throw Object.assign(
|
|
5119
5101
|
new import_shared10.FloPayError("PayPal payment was not completed. Please try again.", "api_error"),
|
|
5120
5102
|
{ checkoutMethod: "paypal" }
|
|
5121
5103
|
);
|
|
5122
5104
|
}
|
|
5105
|
+
const paymentMethodId2 = typeof paymentIntent.payment_method === "string" ? paymentIntent.payment_method : paymentIntent.payment_method?.id;
|
|
5106
|
+
if (!resumeState.sessionId) {
|
|
5107
|
+
throw Object.assign(
|
|
5108
|
+
new import_shared10.FloPayError("Missing session id on PayPal resume.", "api_error"),
|
|
5109
|
+
{ checkoutMethod: "paypal" }
|
|
5110
|
+
);
|
|
5111
|
+
}
|
|
5112
|
+
const api = new import_js3.PaymentAPI(resolvedBillingUrl);
|
|
5113
|
+
const sessionResult = await api.getUnifiedCheckoutSession(resumeState.sessionId);
|
|
5114
|
+
let resumeSession = sessionResult.data.session;
|
|
5115
|
+
if (!resumeSession) {
|
|
5116
|
+
throw Object.assign(
|
|
5117
|
+
new import_shared10.FloPayError("Could not load session to capture PayPal payment.", "api_error"),
|
|
5118
|
+
{ checkoutMethod: "paypal" }
|
|
5119
|
+
);
|
|
5120
|
+
}
|
|
5121
|
+
let finalResultStatus = resultStatus;
|
|
5122
|
+
if (resumeSession.status !== "complete") {
|
|
5123
|
+
const processResult = await processSavedPaymentForMode({
|
|
5124
|
+
billingApiUrl: resolvedBillingUrl,
|
|
5125
|
+
sessionId: resumeState.sessionId,
|
|
5126
|
+
session: resumeSession,
|
|
5127
|
+
tokenizedData: {
|
|
5128
|
+
id: paymentMethodId2 ?? paymentIntent.id,
|
|
5129
|
+
type: "card",
|
|
5130
|
+
threeDSecureActionResultTokenId: paymentIntent.id,
|
|
5131
|
+
isPaypal: true
|
|
5132
|
+
}
|
|
5133
|
+
});
|
|
5134
|
+
if (processResult.type !== "success") {
|
|
5135
|
+
throw Object.assign(
|
|
5136
|
+
new import_shared10.FloPayError("Failed to finalize PayPal payment.", "api_error"),
|
|
5137
|
+
{ checkoutMethod: "paypal" }
|
|
5138
|
+
);
|
|
5139
|
+
}
|
|
5140
|
+
finalResultStatus = processResult.result.status;
|
|
5141
|
+
try {
|
|
5142
|
+
const refreshed = await api.getUnifiedCheckoutSession(resumeState.sessionId);
|
|
5143
|
+
if (refreshed.data.session) {
|
|
5144
|
+
resumeSession = refreshed.data.session;
|
|
5145
|
+
}
|
|
5146
|
+
} catch {
|
|
5147
|
+
}
|
|
5148
|
+
}
|
|
5149
|
+
await showSuccess({
|
|
5150
|
+
result: {
|
|
5151
|
+
status: finalResultStatus,
|
|
5152
|
+
paymentIntentId: paymentIntent.id,
|
|
5153
|
+
paymentMethodId: paymentMethodId2,
|
|
5154
|
+
checkoutMethod: "paypal"
|
|
5155
|
+
},
|
|
5156
|
+
session: resumeSession,
|
|
5157
|
+
sessionId: resumeState.sessionId,
|
|
5158
|
+
autoCompleted: false
|
|
5159
|
+
});
|
|
5123
5160
|
} catch (err) {
|
|
5124
5161
|
const floPayErr = normalizeSavedPaymentError(err);
|
|
5125
5162
|
await showError(floPayErr, {
|