All files / src/components/Merchants/CreateMerchantPanel/helpers index.ts

100% Statements 20/20
100% Branches 14/14
100% Functions 3/3
100% Lines 19/19

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61      70x 7x   1x   1x   1x   1x   1x   1x   1x       70x         3x 1x   2x                             70x     4x 3x 3x         2x   1x      
import { customInstance } from "@services/api";
import { MERCHANT_PERMALINK_FIELD } from "constants/constants";
 
export const getMerchantErrorParam = (param: string) => {
  switch (param) {
    case "owner.phoneNumber":
      return "Primary Account Holder Contact phone";
    case "slug":
      return MERCHANT_PERMALINK_FIELD;
    case "imageURL":
      return "Avatar image";
    case "billingDescriptor":
      return "Billing Descriptor";
    case "legalEntity.taxIDNumber":
      return "Federal Tax ID";
    case "legalEntity.principals.taxIDNumber":
      return "Business Owner Tax ID";
    default:
      return "Input";
  }
};
 
export const getMerchantErrorMessage = (
  param: string,
  code: string,
  message: string,
) => {
  if (code === "duplicate" && param === "slug")
    return `The provided ${MERCHANT_PERMALINK_FIELD} value is already taken.`;
 
  return message;
};
 
/**
 * Fetches all principals (business owners) for a given legal entity.
 *
 * NOTE: Used exclusively in the merchant creation flow (CreateMerchantPanel).
 *
 * We intentionally call the generic `/legal-entities/{id}/principals` endpoint
 * instead of the merchant-scoped one so that we can retrieve principals even
 * when the linked Business Profile belongs to a different acquirer's merchant
 * tree. The merchant-scoped endpoint would return an empty result in that case,
 * causing Business Owners to not be pre-populated when a cross-acquirer BP is
 * linked during merchant creation (GB-21200).
 */
export const getLegalEntityPrincipals = async (
  legalEntityID: number,
) => {
  if (!legalEntityID) return [];
  try {
    const { data: principals = [] } = await customInstance({
      url: `/legal-entities/${legalEntityID}/principals`,
      method: "GET",
    });
 
    return principals;
  } catch (error) {
    return [];
  }
};