@asteby/storefront-react 0.18.0 → 0.20.0

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/payments.cjs CHANGED
@@ -146,6 +146,7 @@ function sanitizeMercadoPagoFormData(data) {
146
146
  function mercadoPagoBricksAdapter(options = {}) {
147
147
  const allowed = options.allowedSdkOrigins ?? ["https://sdk.mercadopago.com"];
148
148
  const getSdk = options.getSdk ?? (() => typeof window !== "undefined" ? window.MercadoPago : void 0);
149
+ const retryDelay = options.collectRetryDelayMs ?? 400;
149
150
  const getDevice = options.getDeviceSessionId ?? (() => typeof window !== "undefined" ? window.MP_DEVICE_SESSION_ID : void 0);
150
151
  return {
151
152
  kind: MERCADOPAGO_BRICKS_KIND,
@@ -187,9 +188,21 @@ function mercadoPagoBricksAdapter(options = {}) {
187
188
  return {
188
189
  async collect() {
189
190
  if (gone) throw new Error("payment form is unmounted");
190
- const raw = await controller.getFormData();
191
- const provider_data = sanitizeMercadoPagoFormData(raw);
192
- if (!provider_data.token) throw new Error("payment form incomplete");
191
+ const read = async () => {
192
+ const raw = await controller.getFormData();
193
+ const data = sanitizeMercadoPagoFormData(raw);
194
+ if (!data.token) throw new Error("payment form incomplete");
195
+ return data;
196
+ };
197
+ let provider_data;
198
+ try {
199
+ provider_data = await read();
200
+ } catch (first) {
201
+ if (gone) throw first;
202
+ await new Promise((r) => setTimeout(r, retryDelay));
203
+ if (gone) throw first;
204
+ provider_data = await read();
205
+ }
193
206
  const device = getDevice();
194
207
  return { provider_data, ...typeof device === "string" && device ? { device_session_id: device } : {} };
195
208
  },
@@ -919,15 +932,21 @@ function useEmbeddedPayment(options) {
919
932
  setError(null);
920
933
  setOutcome(null);
921
934
  emit({ type: "submit" });
935
+ const withdrawn = () => !alive.current || form.current !== m;
936
+ const settle = () => {
937
+ if (alive.current) setStatus((s) => s === "processing" ? "idle" : s);
938
+ };
922
939
  let data;
923
940
  try {
924
941
  data = await m.collect();
925
942
  } catch {
943
+ if (withdrawn()) return settle();
926
944
  emit({ type: "tokenize_error" });
927
945
  setError({ kind: "generic", message: live.current.msgs["error.card_data"], retrySameAttempt: false, canRetry: true });
928
946
  setStatus("ready");
929
947
  return;
930
948
  }
949
+ if (withdrawn()) return settle();
931
950
  const attempt = readAttempt();
932
951
  setAttemptId(attempt);
933
952
  await send(data, attempt, total);