@flopay/react 0.5.0 → 0.5.2

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.d.cts CHANGED
@@ -456,6 +456,14 @@ interface SplitCardFormProps {
456
456
  country?: string;
457
457
  /** Pre-filled ZIP/postal code for AVS. */
458
458
  zip?: string;
459
+ /** Pre-filled street address (line 1) for AVS. Typically from a partner GeoIP / profile lookup. */
460
+ addressLine1?: string;
461
+ /** Pre-filled apt/suite/unit (line 2) for AVS. */
462
+ addressLine2?: string;
463
+ /** Pre-filled city for AVS. Typically from a partner GeoIP / profile lookup. */
464
+ city?: string;
465
+ /** Pre-filled state/province for AVS. Typically from a partner GeoIP / profile lookup. */
466
+ state?: string;
459
467
  /** Callback when AVS country changes. */
460
468
  onCountryChange?: (country: string) => void;
461
469
  /** Callback when AVS ZIP/postal code changes. */
package/dist/index.d.ts CHANGED
@@ -456,6 +456,14 @@ interface SplitCardFormProps {
456
456
  country?: string;
457
457
  /** Pre-filled ZIP/postal code for AVS. */
458
458
  zip?: string;
459
+ /** Pre-filled street address (line 1) for AVS. Typically from a partner GeoIP / profile lookup. */
460
+ addressLine1?: string;
461
+ /** Pre-filled apt/suite/unit (line 2) for AVS. */
462
+ addressLine2?: string;
463
+ /** Pre-filled city for AVS. Typically from a partner GeoIP / profile lookup. */
464
+ city?: string;
465
+ /** Pre-filled state/province for AVS. Typically from a partner GeoIP / profile lookup. */
466
+ state?: string;
459
467
  /** Callback when AVS country changes. */
460
468
  onCountryChange?: (country: string) => void;
461
469
  /** Callback when AVS ZIP/postal code changes. */
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
 
@@ -1022,6 +1023,10 @@ function SplitCardFormInner({
1022
1023
  avsLayout: avsLayoutProp = "row",
1023
1024
  country: countryProp,
1024
1025
  zip: zipProp,
1026
+ addressLine1: addressLine1Prop,
1027
+ addressLine2: addressLine2Prop,
1028
+ city: cityProp,
1029
+ state: stateProp,
1025
1030
  onCountryChange,
1026
1031
  onZipChange,
1027
1032
  avsCheck: avsCheckProp,
@@ -1042,17 +1047,17 @@ function SplitCardFormInner({
1042
1047
  const [is3DSActive, setIs3DSActive] = useState2(false);
1043
1048
  const [selectedCountry, setSelectedCountry] = useState2(countryProp ?? "US");
1044
1049
  const [zipCode, setZipCode] = useState2(zipProp ?? "");
1045
- const [addressLine1, setAddressLine1] = useState2("");
1046
- const [addressLine2, setAddressLine2] = useState2("");
1047
- const [city, setCity] = useState2("");
1048
- const [stateValue, setStateValue] = useState2("");
1050
+ const [addressLine1, setAddressLine1] = useState2(addressLine1Prop ?? "");
1051
+ const [addressLine2, setAddressLine2] = useState2(addressLine2Prop ?? "");
1052
+ const [city, setCity] = useState2(cityProp ?? "");
1053
+ const [stateValue, setStateValue] = useState2(stateProp ?? "");
1049
1054
  const [accountPatch, setAccountPatch] = useState2({});
1050
1055
  const zipCodeRef = useRef2(zipProp ?? "");
1051
1056
  const selectedCountryRef = useRef2(countryProp ?? "US");
1052
- const addressLine1Ref = useRef2("");
1053
- const addressLine2Ref = useRef2("");
1054
- const cityRef = useRef2("");
1055
- const stateRef = useRef2("");
1057
+ const addressLine1Ref = useRef2(addressLine1Prop ?? "");
1058
+ const addressLine2Ref = useRef2(addressLine2Prop ?? "");
1059
+ const cityRef = useRef2(cityProp ?? "");
1060
+ const stateRef = useRef2(stateProp ?? "");
1056
1061
  const avsConfig = useMemo2(() => resolveAVSConfig(enableAVSProp), [enableAVSProp]);
1057
1062
  const enableAVS = avsConfig !== null;
1058
1063
  const [viewState, setViewState] = useState2(initialCardOpen ? "card" : "buttons");
@@ -1228,12 +1233,17 @@ function SplitCardFormInner({
1228
1233
  lastName: effectiveAccount.lastName ?? fullName.trim().split(/\s+/).slice(1).join(" ") ?? "",
1229
1234
  ...avsConfig ? (() => {
1230
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;
1231
1241
  return {
1232
1242
  country: c,
1233
- ...isAVSFieldVisible(avsConfig.postal_code, c) && zipCodeRef.current ? { zip: zipCodeRef.current } : {},
1243
+ ...zipVisible && zipCodeRef.current ? { zip: zipCodeRef.current } : {},
1234
1244
  ...isAVSFieldVisible(avsConfig.city, c) && cityRef.current ? { city: cityRef.current } : {},
1235
- ...isAVSFieldVisible(avsConfig.state, c) && stateRef.current ? { state: stateRef.current } : {},
1236
- ...isAVSFieldVisible(avsConfig.address_line_1, c) && addressLine1Ref.current ? { addressLine1: addressLine1Ref.current } : {},
1245
+ ...stateValue2 ? { state: stateValue2 } : {},
1246
+ ...line1Visible && addressLine1Ref.current ? { addressLine1: addressLine1Ref.current } : {},
1237
1247
  ...isAVSFieldVisible(avsConfig.address_line_2, c) && addressLine2Ref.current ? { addressLine2: addressLine2Ref.current } : {}
1238
1248
  };
1239
1249
  })() : {}
@@ -1288,7 +1298,12 @@ function SplitCardFormInner({
1288
1298
  if (avsConfig && isAVSFieldVisible(avsConfig.address_line_1, retryCC) && addressLine1Ref.current.trim()) retryBillingAddress["line1"] = addressLine1Ref.current.trim();
1289
1299
  if (avsConfig && isAVSFieldVisible(avsConfig.address_line_2, retryCC) && addressLine2Ref.current.trim()) retryBillingAddress["line2"] = addressLine2Ref.current.trim();
1290
1300
  if (avsConfig && isAVSFieldVisible(avsConfig.city, retryCC) && cityRef.current.trim()) retryBillingAddress["city"] = cityRef.current.trim();
1291
- 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
+ }
1292
1307
  const result = await flopay.confirmPayment({
1293
1308
  clientSecret: secret,
1294
1309
  returnUrl: window.location.href,
@@ -1483,7 +1498,12 @@ function SplitCardFormInner({
1483
1498
  if (avsConfig && isAVSFieldVisible(avsConfig.address_line_1, cc) && addressLine1Ref.current.trim()) billingAddress["line1"] = addressLine1Ref.current.trim();
1484
1499
  if (avsConfig && isAVSFieldVisible(avsConfig.address_line_2, cc) && addressLine2Ref.current.trim()) billingAddress["line2"] = addressLine2Ref.current.trim();
1485
1500
  if (avsConfig && isAVSFieldVisible(avsConfig.city, cc) && cityRef.current.trim()) billingAddress["city"] = cityRef.current.trim();
1486
- 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
+ }
1487
1507
  const billingDetails = {
1488
1508
  ...resolvedAccount.email ? { email: resolvedAccount.email } : {},
1489
1509
  ...fullName.trim() ? { name: fullName.trim() } : {},
@@ -3534,6 +3554,8 @@ function FloPayCheckout({
3534
3554
  enableAVS,
3535
3555
  avsLayout,
3536
3556
  country: session?.customer?.country,
3557
+ city: session?.customer?.city,
3558
+ state: session?.customer?.state,
3537
3559
  onCountryChange,
3538
3560
  onZipChange,
3539
3561
  avsCheck: !!enableAVS,