@flopay/react 0.5.1 → 0.5.3

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.mjs CHANGED
@@ -245,7 +245,8 @@ import {
245
245
  getStateOptions,
246
246
  COUNTRY_OPTIONS,
247
247
  resolveAVSConfig,
248
- isAVSFieldVisible
248
+ isAVSFieldVisible,
249
+ getStateFromPostalCode
249
250
  } from "@flopay/shared";
250
251
  import { forwardRef, useCallback, useContext as useContext3, useEffect as useEffect3, useImperativeHandle, useMemo as useMemo2, useRef as useRef2, useState as useState2 } from "react";
251
252
 
@@ -1232,12 +1233,17 @@ function SplitCardFormInner({
1232
1233
  lastName: effectiveAccount.lastName ?? fullName.trim().split(/\s+/).slice(1).join(" ") ?? "",
1233
1234
  ...avsConfig ? (() => {
1234
1235
  const c = selectedCountryRef.current;
1236
+ const stateVisible = isAVSFieldVisible(avsConfig.state, c);
1237
+ const line1Visible = isAVSFieldVisible(avsConfig.address_line_1, c);
1238
+ const zipVisible = isAVSFieldVisible(avsConfig.postal_code, c);
1239
+ const derivedState = line1Visible && !stateVisible && zipVisible ? getStateFromPostalCode(c, zipCodeRef.current ?? "") : null;
1240
+ const stateValue2 = stateVisible ? stateRef.current : derivedState;
1235
1241
  return {
1236
1242
  country: c,
1237
- ...isAVSFieldVisible(avsConfig.postal_code, c) && zipCodeRef.current ? { zip: zipCodeRef.current } : {},
1243
+ ...zipVisible && zipCodeRef.current ? { zip: zipCodeRef.current } : {},
1238
1244
  ...isAVSFieldVisible(avsConfig.city, c) && cityRef.current ? { city: cityRef.current } : {},
1239
- ...isAVSFieldVisible(avsConfig.state, c) && stateRef.current ? { state: stateRef.current } : {},
1240
- ...isAVSFieldVisible(avsConfig.address_line_1, c) && addressLine1Ref.current ? { addressLine1: addressLine1Ref.current } : {},
1245
+ ...stateValue2 ? { state: stateValue2 } : {},
1246
+ ...line1Visible && addressLine1Ref.current ? { addressLine1: addressLine1Ref.current } : {},
1241
1247
  ...isAVSFieldVisible(avsConfig.address_line_2, c) && addressLine2Ref.current ? { addressLine2: addressLine2Ref.current } : {}
1242
1248
  };
1243
1249
  })() : {}
@@ -1292,7 +1298,12 @@ function SplitCardFormInner({
1292
1298
  if (avsConfig && isAVSFieldVisible(avsConfig.address_line_1, retryCC) && addressLine1Ref.current.trim()) retryBillingAddress["line1"] = addressLine1Ref.current.trim();
1293
1299
  if (avsConfig && isAVSFieldVisible(avsConfig.address_line_2, retryCC) && addressLine2Ref.current.trim()) retryBillingAddress["line2"] = addressLine2Ref.current.trim();
1294
1300
  if (avsConfig && isAVSFieldVisible(avsConfig.city, retryCC) && cityRef.current.trim()) retryBillingAddress["city"] = cityRef.current.trim();
1295
- if (avsConfig && isAVSFieldVisible(avsConfig.state, retryCC) && stateRef.current.trim()) retryBillingAddress["state"] = stateRef.current.trim();
1301
+ if (avsConfig && isAVSFieldVisible(avsConfig.state, retryCC) && stateRef.current.trim()) {
1302
+ retryBillingAddress["state"] = stateRef.current.trim();
1303
+ } else if (avsConfig && isAVSFieldVisible(avsConfig.address_line_1, retryCC) && !isAVSFieldVisible(avsConfig.state, retryCC) && isAVSFieldVisible(avsConfig.postal_code, retryCC)) {
1304
+ const derivedRetryState = getStateFromPostalCode(retryCC, zipCodeRef.current.trim());
1305
+ if (derivedRetryState) retryBillingAddress["state"] = derivedRetryState;
1306
+ }
1296
1307
  const result = await flopay.confirmPayment({
1297
1308
  clientSecret: secret,
1298
1309
  returnUrl: window.location.href,
@@ -1487,7 +1498,12 @@ function SplitCardFormInner({
1487
1498
  if (avsConfig && isAVSFieldVisible(avsConfig.address_line_1, cc) && addressLine1Ref.current.trim()) billingAddress["line1"] = addressLine1Ref.current.trim();
1488
1499
  if (avsConfig && isAVSFieldVisible(avsConfig.address_line_2, cc) && addressLine2Ref.current.trim()) billingAddress["line2"] = addressLine2Ref.current.trim();
1489
1500
  if (avsConfig && isAVSFieldVisible(avsConfig.city, cc) && cityRef.current.trim()) billingAddress["city"] = cityRef.current.trim();
1490
- if (avsConfig && isAVSFieldVisible(avsConfig.state, cc) && stateRef.current.trim()) billingAddress["state"] = stateRef.current.trim();
1501
+ if (avsConfig && isAVSFieldVisible(avsConfig.state, cc) && stateRef.current.trim()) {
1502
+ billingAddress["state"] = stateRef.current.trim();
1503
+ } else if (avsConfig && isAVSFieldVisible(avsConfig.address_line_1, cc) && !isAVSFieldVisible(avsConfig.state, cc) && isAVSFieldVisible(avsConfig.postal_code, cc)) {
1504
+ const derivedSubmitState = getStateFromPostalCode(cc, zipCodeRef.current.trim());
1505
+ if (derivedSubmitState) billingAddress["state"] = derivedSubmitState;
1506
+ }
1491
1507
  const billingDetails = {
1492
1508
  ...resolvedAccount.email ? { email: resolvedAccount.email } : {},
1493
1509
  ...fullName.trim() ? { name: fullName.trim() } : {},
@@ -3004,7 +3020,6 @@ function FloPayCheckout({
3004
3020
  cancelUrl: params?.cancelUrl,
3005
3021
  i: params?.items?.map((x) => `${x.providerItemId}:${x.totalAmount}:${x.overrideAmount ?? ""}:${x.quantity ?? 1}`).sort(),
3006
3022
  s: params?.subscriptions?.map((x) => `${x.providerPlanId}:${x.totalAmount}:${x.overrideAmount ?? ""}:${x.quantity ?? 1}`).sort(),
3007
- account: params?.account,
3008
3023
  couponCodes: params?.couponCodes,
3009
3024
  tagsData: params?.tagsData,
3010
3025
  utmMetadata: params?.utmMetadata,
@@ -3162,7 +3177,8 @@ function FloPayCheckout({
3162
3177
  };
3163
3178
  }
3164
3179
  (async () => {
3165
- const shouldAutoProcessInlineSession = effectiveCreateSessionMode === "auto" && !autoCheckoutAttempted.current;
3180
+ const hasPayPalRedirectParams = typeof window !== "undefined" && new URLSearchParams(window.location.search).has("payment_intent");
3181
+ const shouldAutoProcessInlineSession = effectiveCreateSessionMode === "auto" && !autoCheckoutAttempted.current && !hasPayPalRedirectParams;
3166
3182
  if (shouldAutoProcessInlineSession) {
3167
3183
  setModeError(null);
3168
3184
  setModeOverlayError(null);
@@ -3540,8 +3556,6 @@ function FloPayCheckout({
3540
3556
  country: session?.customer?.country,
3541
3557
  city: session?.customer?.city,
3542
3558
  state: session?.customer?.state,
3543
- addressLine1: session?.customer?.line1,
3544
- addressLine2: session?.customer?.line2,
3545
3559
  onCountryChange,
3546
3560
  onZipChange,
3547
3561
  avsCheck: !!enableAVS,