@suportepos/split-checkout 0.5.5 → 0.5.7

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.es.js CHANGED
@@ -21697,10 +21697,9 @@ function SplitCheckoutForm({
21697
21697
  onResponse,
21698
21698
  uuid,
21699
21699
  resumo,
21700
- parcelas
21700
+ parcelas,
21701
+ urlApi
21701
21702
  }) {
21702
- const apiUrl = producao ? "https://api-conciliapos.suportepos.com.br" : "https://api-conciliapos-stag.suportepos.com.br";
21703
- useMediaQuery("(max-width:900px)");
21704
21703
  const [step, setStep] = useState("card");
21705
21704
  const maskCard = (v) => v.replace(/\D/g, "").trim();
21706
21705
  const maskExpiry = (v) => v.replace(/\D/g, "").slice(0, 6).replace(/(\d{2})(\d{0,4})/, (m, mm, yyyy) => yyyy ? `${mm}/${yyyy}` : mm);
@@ -21715,6 +21714,8 @@ function SplitCheckoutForm({
21715
21714
  const [cvv, setCvv] = useState("");
21716
21715
  const [installments, setInstallments] = useState(1);
21717
21716
  const [accessToken, setAccessToken] = useState("");
21717
+ const [bandeiras, setBandeiras] = useState([]);
21718
+ const [bandeiraDetectada, setBandeiraDetectada] = useState("MASTERCARD");
21718
21719
  const [cep, setCep] = useState(cliente?.cep ? maskCEP(cliente.cep) : "");
21719
21720
  const [address, setAddress] = useState(cliente?.endereco ?? "");
21720
21721
  const [number, setNumber] = useState(cliente?.numero ?? "");
@@ -21742,7 +21743,10 @@ function SplitCheckoutForm({
21742
21743
  document.body.appendChild(script);
21743
21744
  script.onload = async () => {
21744
21745
  try {
21745
- const res = await fetch(`${apiUrl}/api/token-cartao?merchantId=${merchantId}&producao=${producao}`);
21746
+ const resBandeiras = await fetch(`${urlApi}/api/bandeiras?merchantId=${merchantId}&producao=${producao}`);
21747
+ const dataBandeiras = await resBandeiras.json();
21748
+ setBandeiras(dataBandeiras);
21749
+ const res = await fetch(`${urlApi}/api/token-cartao?merchantId=${merchantId}&producao=${producao}`);
21746
21750
  const data = await res.json();
21747
21751
  setAccessToken(data?.access_token);
21748
21752
  } catch (err) {
@@ -21753,6 +21757,20 @@ function SplitCheckoutForm({
21753
21757
  document.body.removeChild(script);
21754
21758
  };
21755
21759
  }, []);
21760
+ useEffect(() => {
21761
+ const bin = cardNumber.replace(/\D/g, "").slice(0, 6);
21762
+ if (bin.length === 6) {
21763
+ const binInt = parseInt(bin);
21764
+ const encontrada = bandeiras.find(
21765
+ (b) => binInt >= parseInt(b.bin_inicial) && binInt <= parseInt(b.bin_final)
21766
+ );
21767
+ if (encontrada) {
21768
+ setBandeiraDetectada(encontrada.bandeira);
21769
+ } else {
21770
+ setBandeiraDetectada("MASTERCARD");
21771
+ }
21772
+ }
21773
+ }, [cardNumber, bandeiras]);
21756
21774
  function validateCard() {
21757
21775
  const e = {};
21758
21776
  if (cardNumber.replace(/\D/g, "").length < 15) e.cardNumber = "Número inválido";
@@ -21807,7 +21825,7 @@ function SplitCheckoutForm({
21807
21825
  const rawCep = masked.replace(/\D/g, "");
21808
21826
  if (rawCep.length === 8) {
21809
21827
  try {
21810
- const res = await fetch(`${apiUrl}/api/cep/${rawCep}?merchantId=${merchantId}`);
21828
+ const res = await fetch(`${urlApi}/api/cep/${rawCep}?merchantId=${merchantId}`);
21811
21829
  const data = await res.json();
21812
21830
  if (!data.error) {
21813
21831
  setAddress(data.street || "");
@@ -21821,6 +21839,12 @@ function SplitCheckoutForm({
21821
21839
  }
21822
21840
  }
21823
21841
  };
21842
+ const fieldLabels = {
21843
+ "bp-sop-cardnumber": "Número do cartão",
21844
+ "bp-sop-cardholdername": "Nome como está no cartão",
21845
+ "bp-sop-cardexpirationdat": "Vencimento",
21846
+ "bp-sop-cardcvv": "CVV"
21847
+ };
21824
21848
  const handleFinalSubmit = async () => {
21825
21849
  if (!validateBuyer()) return;
21826
21850
  setLoading(true);
@@ -21834,7 +21858,7 @@ function SplitCheckoutForm({
21834
21858
  cvvrequired: true,
21835
21859
  onSuccess: async (response) => {
21836
21860
  try {
21837
- const res = await fetch(`${apiUrl}/api/pagar`, {
21861
+ const res = await fetch(`${urlApi}/api/pagar`, {
21838
21862
  method: "POST",
21839
21863
  headers: { "Content-Type": "application/json" },
21840
21864
  body: JSON.stringify({
@@ -21858,26 +21882,29 @@ function SplitCheckoutForm({
21858
21882
  cidade: city,
21859
21883
  estado: uf,
21860
21884
  producao,
21861
- uuid
21885
+ uuid,
21886
+ bandeira: bandeiraDetectada
21862
21887
  })
21863
21888
  });
21864
21889
  const result = await res.json();
21865
21890
  onResponse?.(result);
21866
21891
  } catch (err) {
21867
21892
  console.error("Erro chamando backend:", err);
21868
- onResponse?.({ sucesso: false, mensagem: "Erro ao comunicar backend" });
21893
+ onResponse?.({ sucesso: false, mensagem: "100 - Erro ao comunicar backend" });
21869
21894
  } finally {
21870
21895
  setLoading(false);
21871
21896
  }
21872
21897
  },
21873
21898
  onError: (err) => {
21874
- console.error("Erro SOP:", err);
21875
- onResponse?.({ sucesso: false, mensagem: "Erro SOP" });
21899
+ onResponse?.({ sucesso: false, mensagem: "101 - Dados do cartão inválidos. Verifique e tente novamente." });
21876
21900
  setLoading(false);
21877
21901
  },
21878
21902
  onInvalid: (fields) => {
21879
- console.warn("Campos inválidos:", fields);
21880
- onResponse?.({ sucesso: false, mensagem: "Campos inválidos" });
21903
+ const message = `102 - Campos inválidos: ${fields.map((e) => {
21904
+ const label = fieldLabels[e.Field] ?? e.Field;
21905
+ return `${label} - ${e.Message}`;
21906
+ }).join(", ")}`;
21907
+ onResponse?.({ sucesso: false, mensagem: message });
21881
21908
  setLoading(false);
21882
21909
  }
21883
21910
  };
@@ -22184,9 +22211,9 @@ function SplitPixForm({
22184
22211
  onBack,
22185
22212
  onResponse,
22186
22213
  uuid,
22187
- resumo
22214
+ resumo,
22215
+ urlApi
22188
22216
  }) {
22189
- const apiUrl = producao ? "https://api-conciliapos.suportepos.com.br" : "https://api-conciliapos-stag.suportepos.com.br";
22190
22217
  useMediaQuery("(max-width:900px)");
22191
22218
  const [copied, setCopied] = useState(false);
22192
22219
  const [buyerName, setBuyerName] = useState(cliente?.nomeComprador ?? "");
@@ -22224,7 +22251,7 @@ function SplitPixForm({
22224
22251
  if (!validate()) return;
22225
22252
  setLoading(true);
22226
22253
  try {
22227
- const res = await fetch(apiUrl + "/api/pix", {
22254
+ const res = await fetch(urlApi + "/api/pix", {
22228
22255
  method: "POST",
22229
22256
  headers: { "Content-Type": "application/json" },
22230
22257
  body: JSON.stringify({
@@ -22255,7 +22282,7 @@ function SplitPixForm({
22255
22282
  if (!validate()) return;
22256
22283
  setLoading(true);
22257
22284
  try {
22258
- const res = await fetch(apiUrl + "/api/pix/consultar", {
22285
+ const res = await fetch(urlApi + "/api/pix/consultar", {
22259
22286
  method: "POST",
22260
22287
  headers: { "Content-Type": "application/json" },
22261
22288
  body: JSON.stringify({
@@ -22462,6 +22489,7 @@ function CheckoutFlowContent({
22462
22489
  useTheme();
22463
22490
  const primaryButtons = [];
22464
22491
  const listItems = [];
22492
+ const apiUrl = producao ? "https://api-conciliapos.suportepos.com.br" : "https://api-conciliapos-stag.suportepos.com.br";
22465
22493
  if (paymentEnabled?.creditCard) {
22466
22494
  listItems.push(
22467
22495
  /* @__PURE__ */ jsxRuntimeExports.jsxs(ListItemButton, { onClick: () => setStep("card"), sx: {
@@ -22527,7 +22555,8 @@ function CheckoutFlowContent({
22527
22555
  onResponse,
22528
22556
  uuid,
22529
22557
  resumo,
22530
- parcelas
22558
+ parcelas,
22559
+ urlApi: apiUrl
22531
22560
  }
22532
22561
  );
22533
22562
  }
@@ -22546,7 +22575,8 @@ function CheckoutFlowContent({
22546
22575
  onBack: () => setStep("select"),
22547
22576
  onResponse,
22548
22577
  uuid,
22549
- resumo
22578
+ resumo,
22579
+ urlApi: apiUrl
22550
22580
  }
22551
22581
  );
22552
22582
  }