@asteby/storefront-react 0.8.0 → 0.9.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/README.md +38 -1
- package/dist/choices-DEPE9KRq.d.cts +130 -0
- package/dist/choices-DEPE9KRq.d.ts +130 -0
- package/dist/chunk-ISEOCKIR.js +160 -0
- package/dist/chunk-ISEOCKIR.js.map +1 -0
- package/dist/payments-server.cjs +369 -0
- package/dist/payments-server.cjs.map +1 -0
- package/dist/payments-server.d.cts +145 -0
- package/dist/payments-server.d.ts +145 -0
- package/dist/payments-server.js +191 -0
- package/dist/payments-server.js.map +1 -0
- package/dist/payments.cjs +429 -2
- package/dist/payments.cjs.map +1 -1
- package/dist/payments.css +30 -0
- package/dist/payments.d.cts +122 -21
- package/dist/payments.d.ts +122 -21
- package/dist/payments.js +291 -36
- package/dist/payments.js.map +1 -1
- package/package.json +12 -1
package/dist/payments.cjs
CHANGED
|
@@ -730,10 +730,10 @@ function paymentCsp(clients, options = {}) {
|
|
|
730
730
|
const dir = (name, values) => `${name} ${values.join(" ")}`;
|
|
731
731
|
const parts = [
|
|
732
732
|
"default-src 'self'",
|
|
733
|
-
dir("script-src", ["'self'", ...nonce ? [`'nonce-${nonce}'`] : [], ...origins(sdkOrigins, ...pick("script"), options.extra?.script)]),
|
|
733
|
+
dir("script-src", ["'self'", ...(options.scriptHashes ?? []).filter((h) => /^'sha(256|384|512)-[A-Za-z0-9+/=]+'$/.test(h)), ...nonce ? [`'nonce-${nonce}'`] : [], ...origins(sdkOrigins, ...pick("script"), options.extra?.script)]),
|
|
734
734
|
dir("frame-src", origins(...pick("frame"), options.extra?.frame).length ? origins(...pick("frame"), options.extra?.frame) : ["'none'"]),
|
|
735
735
|
dir("connect-src", ["'self'", ...origins(...pick("connect"), options.extra?.connect)]),
|
|
736
|
-
dir("img-src", ["'self'", "data:", ...origins(...pick("img"), options.extra?.img)]),
|
|
736
|
+
dir("img-src", ["'self'", "data:", ...options.imgHttps ? ["https:"] : [], ...origins(...pick("img"), options.extra?.img)]),
|
|
737
737
|
"style-src 'self' 'unsafe-inline'",
|
|
738
738
|
dir("form-action", ["'self'", ...origins(...pick("form"), options.extra?.form)]),
|
|
739
739
|
"frame-ancestors 'none'",
|
|
@@ -746,21 +746,448 @@ function paymentCsp(clients, options = {}) {
|
|
|
746
746
|
function paymentCspHeaderName(reportOnly) {
|
|
747
747
|
return reportOnly ? "Content-Security-Policy-Report-Only" : "Content-Security-Policy";
|
|
748
748
|
}
|
|
749
|
+
function paymentCspMode(value, production) {
|
|
750
|
+
const raw = (value ?? "").trim().toLowerCase();
|
|
751
|
+
if (raw === "off" || raw === "report-only" || raw === "enforce") return raw;
|
|
752
|
+
return production ? "report-only" : "off";
|
|
753
|
+
}
|
|
754
|
+
function paymentNonce() {
|
|
755
|
+
const bytes = new Uint8Array(16);
|
|
756
|
+
crypto.getRandomValues(bytes);
|
|
757
|
+
let bin = "";
|
|
758
|
+
for (const b of bytes) bin += String.fromCharCode(b);
|
|
759
|
+
return btoa(bin);
|
|
760
|
+
}
|
|
761
|
+
function paymentCspHeaders(clients, options) {
|
|
762
|
+
if (options.mode === "off") return {};
|
|
763
|
+
return { [paymentCspHeaderName(options.mode === "report-only")]: paymentCsp(clients, options) };
|
|
764
|
+
}
|
|
765
|
+
function paymentNonceFromHeaders(headers) {
|
|
766
|
+
const csp = headers.get("Content-Security-Policy") ?? headers.get("Content-Security-Policy-Report-Only") ?? "";
|
|
767
|
+
return /'nonce-([A-Za-z0-9+/=_-]+)'/.exec(csp)?.[1];
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
// src/payments/payment-method.messages.ts
|
|
771
|
+
var ES = {
|
|
772
|
+
legend: "M\xE9todo de pago",
|
|
773
|
+
pay: "Pagar",
|
|
774
|
+
placeOrder: "Realizar el pedido",
|
|
775
|
+
payRedirect: "Continuar al pago",
|
|
776
|
+
continue: "Continuar",
|
|
777
|
+
retryAddress: "Guardar direcci\xF3n y continuar",
|
|
778
|
+
processing: "Procesando\u2026",
|
|
779
|
+
redirectNote: "Te llevamos a la p\xE1gina del proveedor para terminar el pago y regresas aqu\xED.",
|
|
780
|
+
cashPoints: "Elige d\xF3nde pagar en efectivo",
|
|
781
|
+
cashMore: "Ver m\xE1s puntos de pago",
|
|
782
|
+
cashNote: "Al hacer el pedido te damos una ficha con la referencia y la fecha l\xEDmite. El pedido se confirma cuando pagas.",
|
|
783
|
+
secureCard: "Tus datos de tarjeta los captura directamente nuestro proveedor de pagos; la tienda nunca los ve.",
|
|
784
|
+
pickDeliveryFirst: "Elige primero la entrega para ver el total y pagar con tarjeta.",
|
|
785
|
+
updatingTotal: "Actualizando el total\u2026",
|
|
786
|
+
syncFailed: "No pudimos actualizar el total con tu entrega. Puedes continuar al sitio del proveedor para pagar con tarjeta.",
|
|
787
|
+
rebuildCart: "Volver a armar mi carrito",
|
|
788
|
+
noPaymentTitle: "Por ahora no hay formas de pago disponibles",
|
|
789
|
+
noPayment: "Intenta de nuevo en unos minutos o escr\xEDbenos para completar tu pedido.",
|
|
790
|
+
paymentNote: "El pago se procesa de forma segura con nuestro proveedor de pagos.",
|
|
791
|
+
options: {
|
|
792
|
+
card: "Tarjeta de cr\xE9dito o d\xE9bito",
|
|
793
|
+
cash: "Efectivo",
|
|
794
|
+
wallet: "Cuenta del proveedor de pagos",
|
|
795
|
+
credits: "Pagos sin tarjeta"
|
|
796
|
+
}
|
|
797
|
+
};
|
|
798
|
+
var EN = {
|
|
799
|
+
legend: "Payment method",
|
|
800
|
+
pay: "Pay",
|
|
801
|
+
placeOrder: "Place order",
|
|
802
|
+
payRedirect: "Continue to payment",
|
|
803
|
+
continue: "Continue",
|
|
804
|
+
retryAddress: "Save address and continue",
|
|
805
|
+
processing: "Processing\u2026",
|
|
806
|
+
redirectNote: "We'll take you to the provider's page to finish paying, then bring you back here.",
|
|
807
|
+
cashPoints: "Choose where to pay in cash",
|
|
808
|
+
cashMore: "Show more payment points",
|
|
809
|
+
cashNote: "When you place the order you get a slip with the reference and the deadline. The order is confirmed once you pay.",
|
|
810
|
+
secureCard: "Your card details are captured directly by our payment provider; the shop never sees them.",
|
|
811
|
+
pickDeliveryFirst: "Choose delivery first to see the total and pay by card.",
|
|
812
|
+
updatingTotal: "Updating the total\u2026",
|
|
813
|
+
syncFailed: "We couldn't update the total with your delivery. You can continue to the provider's site to pay by card.",
|
|
814
|
+
rebuildCart: "Rebuild my cart",
|
|
815
|
+
noPaymentTitle: "No payment methods are available right now",
|
|
816
|
+
noPayment: "Try again in a few minutes or contact us to complete your order.",
|
|
817
|
+
paymentNote: "Payment is processed securely by our payment provider.",
|
|
818
|
+
options: {
|
|
819
|
+
card: "Credit or debit card",
|
|
820
|
+
cash: "Cash",
|
|
821
|
+
wallet: "Payment provider account",
|
|
822
|
+
credits: "Pay without a card"
|
|
823
|
+
}
|
|
824
|
+
};
|
|
825
|
+
function paymentMethodMessages(locale, overrides) {
|
|
826
|
+
const base = (locale ?? "es-MX").toLowerCase().startsWith("en") ? EN : ES;
|
|
827
|
+
if (!overrides) return base;
|
|
828
|
+
const { options, ...rest } = overrides;
|
|
829
|
+
return { ...base, ...rest, options: { ...base.options, ...options } };
|
|
830
|
+
}
|
|
831
|
+
var PAYMENT_CHOICE_FIELD = "payment_choice";
|
|
832
|
+
var CASH_POINT_FIELD = "cash_point";
|
|
833
|
+
function formFields(form) {
|
|
834
|
+
const out = {};
|
|
835
|
+
if (!form) return out;
|
|
836
|
+
for (const [k, v] of new FormData(form).entries()) if (typeof v === "string") out[k] = v;
|
|
837
|
+
return out;
|
|
838
|
+
}
|
|
839
|
+
var useHydrated = () => react.useSyncExternalStore(
|
|
840
|
+
() => () => {
|
|
841
|
+
},
|
|
842
|
+
() => true,
|
|
843
|
+
() => false
|
|
844
|
+
);
|
|
845
|
+
function PaymentMethodSection(props) {
|
|
846
|
+
const {
|
|
847
|
+
choices,
|
|
848
|
+
amount,
|
|
849
|
+
scope,
|
|
850
|
+
formRef,
|
|
851
|
+
payUrl,
|
|
852
|
+
statusUrl,
|
|
853
|
+
delivery = "",
|
|
854
|
+
deliveryReady = true,
|
|
855
|
+
syncDelivery,
|
|
856
|
+
addressFirst = false,
|
|
857
|
+
retryAddress = false,
|
|
858
|
+
blocked = false,
|
|
859
|
+
busy = false,
|
|
860
|
+
invalid,
|
|
861
|
+
nonce,
|
|
862
|
+
methodLabel,
|
|
863
|
+
icons,
|
|
864
|
+
renderAmount,
|
|
865
|
+
rebuildHref,
|
|
866
|
+
renderLink,
|
|
867
|
+
onDone,
|
|
868
|
+
onAmountChanged,
|
|
869
|
+
onEvent,
|
|
870
|
+
classNames: cx = {},
|
|
871
|
+
testIds = {},
|
|
872
|
+
hideSubmit,
|
|
873
|
+
brickProps
|
|
874
|
+
} = props;
|
|
875
|
+
const locale = useResolvedLocale(props.locale);
|
|
876
|
+
const m = react.useMemo(() => paymentMethodMessages(locale, props.messages), [locale, props.messages]);
|
|
877
|
+
const hydrated = useHydrated();
|
|
878
|
+
const [choiceValue2, setChoiceValue] = react.useState(props.defaultChoice ?? choices.defaultValue);
|
|
879
|
+
const selected = choices.choices.find((c) => c.value === choiceValue2) ?? null;
|
|
880
|
+
const noPayment = choices.choices.length === 0;
|
|
881
|
+
const tid = (k) => testIds[k] ? { "data-testid": testIds[k] } : {};
|
|
882
|
+
const [fallback, setFallback] = react.useState(false);
|
|
883
|
+
const [ready, setReady] = react.useState(false);
|
|
884
|
+
const [processing, setProcessing] = react.useState(false);
|
|
885
|
+
const [expired, setExpired] = react.useState(false);
|
|
886
|
+
const brick = react.useRef(null);
|
|
887
|
+
const cardChosen = selected?.mode === "card" && !retryAddress && !addressFirst;
|
|
888
|
+
const cardActive = hydrated && cardChosen && !fallback;
|
|
889
|
+
const wantSync = cardActive && deliveryReady && Boolean(syncDelivery);
|
|
890
|
+
const [sync, setSync] = react.useState(null);
|
|
891
|
+
const syncRef = react.useRef(syncDelivery);
|
|
892
|
+
syncRef.current = syncDelivery;
|
|
893
|
+
react.useEffect(() => {
|
|
894
|
+
if (!wantSync || !syncRef.current) return;
|
|
895
|
+
if (sync?.key === delivery && sync.ok) return;
|
|
896
|
+
let cancelled = false;
|
|
897
|
+
syncRef.current(delivery).then(
|
|
898
|
+
(ok) => !cancelled && setSync({ key: delivery, ok }),
|
|
899
|
+
() => !cancelled && setSync({ key: delivery, ok: false })
|
|
900
|
+
);
|
|
901
|
+
return () => {
|
|
902
|
+
cancelled = true;
|
|
903
|
+
};
|
|
904
|
+
}, [wantSync, delivery]);
|
|
905
|
+
const settled = sync?.key === delivery;
|
|
906
|
+
const synced = !syncDelivery || settled && sync.ok;
|
|
907
|
+
const syncFailed = wantSync && settled && !sync.ok;
|
|
908
|
+
const brickReady = cardActive && deliveryReady && synced && !syncFailed;
|
|
909
|
+
const transport = react.useMemo(
|
|
910
|
+
() => props.transport ?? createFetchTransport(payUrl, {
|
|
911
|
+
...statusUrl ? { refreshUrl: statusUrl } : {},
|
|
912
|
+
buildBody: (request) => ({ ...request, fields: formFields(formRef.current) })
|
|
913
|
+
}),
|
|
914
|
+
[props.transport, payUrl, statusUrl, formRef]
|
|
915
|
+
);
|
|
916
|
+
const handleEvent = (e) => {
|
|
917
|
+
if (e.type === "form_ready") setReady(true);
|
|
918
|
+
if (e.type === "submit") setProcessing(true);
|
|
919
|
+
if (e.type === "tokenize_error" || e.type === "retry") setProcessing(e.type === "retry");
|
|
920
|
+
if (e.type === "result" && e.status === "rejected") setProcessing(false);
|
|
921
|
+
if (e.type === "error") {
|
|
922
|
+
setProcessing(false);
|
|
923
|
+
if (e.kind === "price_mismatch") onAmountChanged?.();
|
|
924
|
+
if (e.kind === "expired") setExpired(true);
|
|
925
|
+
}
|
|
926
|
+
onEvent?.(e);
|
|
927
|
+
};
|
|
928
|
+
const total = renderAmount ? renderAmount(amount) : storefront.formatMoney(amount, locale);
|
|
929
|
+
const label = retryAddress ? m.retryAddress : addressFirst ? m.continue : selected?.mode === "plain" || !selected ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
930
|
+
m.pay,
|
|
931
|
+
" ",
|
|
932
|
+
total
|
|
933
|
+
] }) : selected.mode === "redirect" || selected.mode === "card" && (fallback || syncFailed) ? m.payRedirect : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
934
|
+
m.placeOrder,
|
|
935
|
+
" ",
|
|
936
|
+
total
|
|
937
|
+
] });
|
|
938
|
+
function onPayClick(event) {
|
|
939
|
+
if (!cardActive || syncFailed) return;
|
|
940
|
+
event.preventDefault();
|
|
941
|
+
const form = formRef.current;
|
|
942
|
+
if (form && !form.reportValidity()) return;
|
|
943
|
+
if (brickReady) void brick.current?.submit();
|
|
944
|
+
}
|
|
945
|
+
const cardNotice = (k, node) => k === "syncFailed" ? /* @__PURE__ */ jsxRuntime.jsx("p", { role: "alert", className: cx.alert, "data-sf-pay-notice": "sync-failed", ...tid("syncFailed"), children: node }) : /* @__PURE__ */ jsxRuntime.jsx("p", { role: "status", className: cx.status, "data-sf-pay-notice": k, ...k === "syncing" ? tid("syncing") : {}, children: node });
|
|
946
|
+
const Link = renderLink ?? (({ href, className, children, testId }) => /* @__PURE__ */ jsxRuntime.jsx("a", { href, className, ...testId ? { "data-testid": testId } : {}, children }));
|
|
947
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("fieldset", { id: "pago", className: cx.root, "data-sf-pay-method": true, children: [
|
|
948
|
+
/* @__PURE__ */ jsxRuntime.jsx("legend", { className: cx.legend, children: m.legend }),
|
|
949
|
+
choices.choices.map((choice) => {
|
|
950
|
+
const { label: rowLabel, hint } = rowText(choice, m, methodLabel);
|
|
951
|
+
const checked = choice.value === choiceValue2;
|
|
952
|
+
const icon = icons?.[choice.option ?? "plain"];
|
|
953
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cx.choice, "data-sf-pay-choice": true, children: [
|
|
954
|
+
/* @__PURE__ */ jsxRuntime.jsxs("label", { className: cx.radioLabel, children: [
|
|
955
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
956
|
+
"input",
|
|
957
|
+
{
|
|
958
|
+
type: "radio",
|
|
959
|
+
name: PAYMENT_CHOICE_FIELD,
|
|
960
|
+
value: choice.value,
|
|
961
|
+
checked,
|
|
962
|
+
onChange: () => setChoiceValue(choice.value),
|
|
963
|
+
"aria-invalid": invalid?.has("payment_method") || void 0,
|
|
964
|
+
"data-mode": choice.mode,
|
|
965
|
+
required: true,
|
|
966
|
+
className: cx.radio,
|
|
967
|
+
...tid("method")
|
|
968
|
+
}
|
|
969
|
+
),
|
|
970
|
+
icon ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: cx.icon, "aria-hidden": "true", children: icon }) : null,
|
|
971
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: cx.labelText, children: [
|
|
972
|
+
rowLabel,
|
|
973
|
+
hint ? /* @__PURE__ */ jsxRuntime.jsxs("span", { className: cx.hint, children: [
|
|
974
|
+
" ",
|
|
975
|
+
hint
|
|
976
|
+
] }) : null
|
|
977
|
+
] })
|
|
978
|
+
] }),
|
|
979
|
+
/* @__PURE__ */ jsxRuntime.jsx(ChoicePanel, { choice, m, invalid, cx, tid, hidden: hydrated && !checked })
|
|
980
|
+
] }, choice.value);
|
|
981
|
+
}),
|
|
982
|
+
noPayment ? /* @__PURE__ */ jsxRuntime.jsxs("div", { role: "alert", className: cx.alert, "data-sf-pay-notice": "no-payment", ...tid("noPayment"), children: [
|
|
983
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { children: /* @__PURE__ */ jsxRuntime.jsx("strong", { children: m.noPaymentTitle }) }),
|
|
984
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { children: m.noPayment })
|
|
985
|
+
] }) : null,
|
|
986
|
+
cardChosen && hydrated && choices.cardClient ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cx.brickWrap, "data-sf-pay-card": true, ...tid("card"), children: [
|
|
987
|
+
fallback ? null : !deliveryReady ? cardNotice("pickDelivery", m.pickDeliveryFirst) : syncFailed ? cardNotice("syncFailed", m.syncFailed) : !synced ? cardNotice("syncing", m.updatingTotal) : null,
|
|
988
|
+
brickReady || fallback ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
989
|
+
PaymentBrick,
|
|
990
|
+
{
|
|
991
|
+
...brickProps,
|
|
992
|
+
ref: brick,
|
|
993
|
+
client: choices.cardClient,
|
|
994
|
+
amount,
|
|
995
|
+
transport,
|
|
996
|
+
...nonce ? { nonce } : {},
|
|
997
|
+
locale,
|
|
998
|
+
...scope ? { scope } : {},
|
|
999
|
+
enabled: brickReady,
|
|
1000
|
+
...cx.brick ? { className: cx.brick } : {},
|
|
1001
|
+
onEvent: handleEvent,
|
|
1002
|
+
onFallback: () => setFallback(true),
|
|
1003
|
+
onResult: (o) => {
|
|
1004
|
+
if (o.kind === "approved" || o.kind === "in_review" || o.kind === "voucher") onDone(o);
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
) : null,
|
|
1008
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: cx.note, children: m.secureCard }),
|
|
1009
|
+
expired && rebuildHref ? Link({ href: rebuildHref, ...cx.rebuild ? { className: cx.rebuild } : {}, children: m.rebuildCart, ...testIds.rebuild ? { testId: testIds.rebuild } : {} }) : null
|
|
1010
|
+
] }) : null,
|
|
1011
|
+
noPayment || choices.choices.some((c) => c.option) ? null : /* @__PURE__ */ jsxRuntime.jsx("p", { className: cx.note, children: m.paymentNote }),
|
|
1012
|
+
hideSubmit ? null : /* @__PURE__ */ jsxRuntime.jsx(
|
|
1013
|
+
"button",
|
|
1014
|
+
{
|
|
1015
|
+
type: "submit",
|
|
1016
|
+
onClick: onPayClick,
|
|
1017
|
+
className: cx.submit,
|
|
1018
|
+
disabled: busy || blocked,
|
|
1019
|
+
"aria-disabled": blocked || brickReady && (!ready || processing) || void 0,
|
|
1020
|
+
"aria-busy": processing || void 0,
|
|
1021
|
+
"data-sf-pay-method-submit": true,
|
|
1022
|
+
...tid("submit"),
|
|
1023
|
+
children: busy || processing ? m.processing : label
|
|
1024
|
+
}
|
|
1025
|
+
)
|
|
1026
|
+
] });
|
|
1027
|
+
}
|
|
1028
|
+
function rowText(choice, m, methodLabel) {
|
|
1029
|
+
if (choice.mode === "plain") return methodLabel ? methodLabel(choice.methodKey) : { label: choice.methodKey };
|
|
1030
|
+
return { label: choice.label ?? (choice.option ? m.options[choice.option] : void 0) ?? choice.option ?? choice.methodKey };
|
|
1031
|
+
}
|
|
1032
|
+
function ChoicePanel({
|
|
1033
|
+
choice,
|
|
1034
|
+
m,
|
|
1035
|
+
invalid,
|
|
1036
|
+
cx,
|
|
1037
|
+
tid,
|
|
1038
|
+
hidden
|
|
1039
|
+
}) {
|
|
1040
|
+
if (choice.mode === "redirect") {
|
|
1041
|
+
return /* @__PURE__ */ jsxRuntime.jsx("p", { className: cx.panel, hidden, "data-sf-pay-panel": "redirect", ...tid("redirectNote"), children: m.redirectNote });
|
|
1042
|
+
}
|
|
1043
|
+
if (choice.mode !== "cash") return null;
|
|
1044
|
+
const main = choice.points.filter((p) => p.group === "main");
|
|
1045
|
+
const more = choice.points.filter((p) => p.group !== "main");
|
|
1046
|
+
const row = (p, i, first) => /* @__PURE__ */ jsxRuntime.jsxs("label", { className: cx.cashPoint, "data-sf-pay-point": true, children: [
|
|
1047
|
+
/* @__PURE__ */ jsxRuntime.jsx("input", { type: "radio", name: CASH_POINT_FIELD, value: p.id, defaultChecked: first && i === 0, className: cx.cashPointInput, "aria-invalid": invalid?.has("cash_point") || void 0 }),
|
|
1048
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { children: p.label })
|
|
1049
|
+
] }, p.id);
|
|
1050
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cx.panel, hidden, "data-sf-pay-panel": "cash", ...tid("cash"), children: [
|
|
1051
|
+
/* @__PURE__ */ jsxRuntime.jsxs("fieldset", { children: [
|
|
1052
|
+
/* @__PURE__ */ jsxRuntime.jsx("legend", { children: m.cashPoints }),
|
|
1053
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { "data-sf-pay-points": true, children: main.map((p, i) => row(p, i, true)) }),
|
|
1054
|
+
more.length ? /* @__PURE__ */ jsxRuntime.jsxs("details", { children: [
|
|
1055
|
+
/* @__PURE__ */ jsxRuntime.jsx("summary", { className: cx.cashMore, style: { minHeight: 44 }, children: m.cashMore }),
|
|
1056
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { "data-sf-pay-points": true, children: more.map((p, i) => row(p, i, false)) })
|
|
1057
|
+
] }) : null
|
|
1058
|
+
] }),
|
|
1059
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: cx.note, children: m.cashNote })
|
|
1060
|
+
] });
|
|
1061
|
+
}
|
|
1062
|
+
|
|
1063
|
+
// src/payments/choices.ts
|
|
1064
|
+
var SEP = "|";
|
|
1065
|
+
function choiceValue(methodKey, option) {
|
|
1066
|
+
return option ? `${methodKey}${SEP}${option}` : methodKey;
|
|
1067
|
+
}
|
|
1068
|
+
function parseChoice(value) {
|
|
1069
|
+
const raw = (value ?? "").trim();
|
|
1070
|
+
if (!raw) return null;
|
|
1071
|
+
const i = raw.lastIndexOf(SEP);
|
|
1072
|
+
if (i === -1) return { methodKey: raw, option: null };
|
|
1073
|
+
const option = raw.slice(i + 1);
|
|
1074
|
+
if (option !== "card" && option !== "cash" && option !== "wallet" && option !== "credits") return null;
|
|
1075
|
+
return { methodKey: raw.slice(0, i), option };
|
|
1076
|
+
}
|
|
1077
|
+
function modeOf(option) {
|
|
1078
|
+
if (option.redirect || option.key === "wallet" || option.key === "credits") return "redirect";
|
|
1079
|
+
return option.key === "cash" ? "cash" : "card";
|
|
1080
|
+
}
|
|
1081
|
+
function buildPayChoices(methods, options = {}) {
|
|
1082
|
+
const hidden = new Set(options.hide ?? []);
|
|
1083
|
+
const choices = [];
|
|
1084
|
+
let cardClient = null;
|
|
1085
|
+
let defaultValue = null;
|
|
1086
|
+
for (const method of methods) {
|
|
1087
|
+
if (hidden.has(method.key)) continue;
|
|
1088
|
+
const opts = method.options ?? [];
|
|
1089
|
+
if (opts.length === 0) {
|
|
1090
|
+
const value = choiceValue(method.key, null);
|
|
1091
|
+
choices.push({ value, methodKey: method.key, option: null, mode: "plain", label: null, points: [], maxInstallments: null });
|
|
1092
|
+
if (method.default && !defaultValue) defaultValue = value;
|
|
1093
|
+
continue;
|
|
1094
|
+
}
|
|
1095
|
+
opts.forEach((option, i) => {
|
|
1096
|
+
const mode = modeOf(option);
|
|
1097
|
+
const value = choiceValue(method.key, option.key);
|
|
1098
|
+
choices.push({
|
|
1099
|
+
value,
|
|
1100
|
+
methodKey: method.key,
|
|
1101
|
+
option: option.key,
|
|
1102
|
+
mode,
|
|
1103
|
+
label: option.label?.trim() || null,
|
|
1104
|
+
points: option.key === "cash" ? option.points ?? [] : [],
|
|
1105
|
+
maxInstallments: option.max_installments ?? null
|
|
1106
|
+
});
|
|
1107
|
+
if (mode === "card" && method.client && !cardClient) cardClient = method.client;
|
|
1108
|
+
if (method.default && i === 0 && !defaultValue) defaultValue = value;
|
|
1109
|
+
});
|
|
1110
|
+
}
|
|
1111
|
+
const usable = choices.map((c) => c.mode === "card" && !cardClient ? { ...c, mode: "redirect" } : c);
|
|
1112
|
+
return { choices: usable, cardClient, defaultValue: defaultValue ?? usable[0]?.value ?? null };
|
|
1113
|
+
}
|
|
1114
|
+
function cashProviderData(points, pointId) {
|
|
1115
|
+
const point = points.find((p) => p.id === pointId) ?? (pointId ? null : points[0]);
|
|
1116
|
+
if (!point) return null;
|
|
1117
|
+
return {
|
|
1118
|
+
payment_method_id: point.payment_method_id,
|
|
1119
|
+
...point.payment_point ? { payment_point: point.payment_point } : {}
|
|
1120
|
+
};
|
|
1121
|
+
}
|
|
1122
|
+
function checkoutToAttempt(result) {
|
|
1123
|
+
const { checkout, payment, order } = result;
|
|
1124
|
+
const action = payment.action ?? null;
|
|
1125
|
+
const base = { checkout, ...order ? { order } : {} };
|
|
1126
|
+
const status = (checkout.status ?? "").toLowerCase();
|
|
1127
|
+
if (status === "paid" || status === "converted") return { ...base, payment: { provider: payment.provider, status: "paid", outcome: "approved" } };
|
|
1128
|
+
if (status === "cancelled" || status === "canceled") return { ...base, payment: { provider: payment.provider, status: "cancelled" } };
|
|
1129
|
+
if (status === "expired") return { ...base, payment: { provider: payment.provider, status: "expired" } };
|
|
1130
|
+
if (status === "failed") {
|
|
1131
|
+
const decline = payment.decline_code ?? "declined";
|
|
1132
|
+
return { ...base, payment: { provider: payment.provider, status: "failed", outcome: "rejected", decline_code: decline, retryable: true } };
|
|
1133
|
+
}
|
|
1134
|
+
if (action?.type === "challenge") return { ...base, payment: { provider: payment.provider, status: "requires_action", outcome: "challenge", action } };
|
|
1135
|
+
return { ...base, payment: { provider: payment.provider, status: "pending", outcome: "pending", action: action ?? { type: "none" } } };
|
|
1136
|
+
}
|
|
1137
|
+
function payErrorResponse(err) {
|
|
1138
|
+
const status = typeof err.status === "number" && err.status >= 400 ? err.status : 503;
|
|
1139
|
+
let code = err.code ?? "server_error";
|
|
1140
|
+
if (status === 409 && err.field === "payment_in_progress") code = "payment_in_progress";
|
|
1141
|
+
if (status === 429) code = "too_many_attempts";
|
|
1142
|
+
if (status === 422 && err.field === "expected_total") code = "price_mismatch";
|
|
1143
|
+
return { status, body: { error: { code, message: err.message ?? "", ...err.details !== void 0 ? { details: err.details } : {} } } };
|
|
1144
|
+
}
|
|
1145
|
+
function voucherRows(voucher, labels, locale) {
|
|
1146
|
+
if (!voucher) return [];
|
|
1147
|
+
const rows = [];
|
|
1148
|
+
if (voucher.payment_point) rows.push([labels.point, String(voucher.payment_point).slice(0, 60)]);
|
|
1149
|
+
if (voucher.reference) rows.push([labels.reference, String(voucher.reference).slice(0, 80)]);
|
|
1150
|
+
if (voucher.clabe) rows.push([labels.clabe, String(voucher.clabe).slice(0, 40)]);
|
|
1151
|
+
if (voucher.barcode) rows.push([labels.barcode, String(voucher.barcode).slice(0, 80)]);
|
|
1152
|
+
if (voucher.expires_at) {
|
|
1153
|
+
const d = new Date(voucher.expires_at);
|
|
1154
|
+
if (!Number.isNaN(d.getTime())) {
|
|
1155
|
+
rows.push([labels.expires, new Intl.DateTimeFormat(locale, { dateStyle: "long", timeStyle: "short", timeZone: "UTC" }).format(d) + " UTC"]);
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1158
|
+
return rows;
|
|
1159
|
+
}
|
|
749
1160
|
|
|
1161
|
+
exports.CASH_POINT_FIELD = CASH_POINT_FIELD;
|
|
750
1162
|
exports.MERCADOPAGO_BRICKS_KIND = MERCADOPAGO_BRICKS_KIND;
|
|
1163
|
+
exports.PAYMENT_CHOICE_FIELD = PAYMENT_CHOICE_FIELD;
|
|
751
1164
|
exports.PAYMENT_THEME_TOKENS = PAYMENT_THEME_TOKENS;
|
|
752
1165
|
exports.PaymentBrick = PaymentBrick;
|
|
753
1166
|
exports.PaymentChallenge = PaymentChallenge;
|
|
754
1167
|
exports.PaymentHttpError = PaymentHttpError;
|
|
1168
|
+
exports.PaymentMethodSection = PaymentMethodSection;
|
|
755
1169
|
exports.VoucherCard = VoucherCard;
|
|
1170
|
+
exports.buildPayChoices = buildPayChoices;
|
|
1171
|
+
exports.cashProviderData = cashProviderData;
|
|
1172
|
+
exports.checkoutToAttempt = checkoutToAttempt;
|
|
1173
|
+
exports.choiceValue = choiceValue;
|
|
756
1174
|
exports.createFetchTransport = createFetchTransport;
|
|
1175
|
+
exports.formFields = formFields;
|
|
757
1176
|
exports.loadPaymentSdk = loadPaymentSdk;
|
|
758
1177
|
exports.mercadoPagoBricksAdapter = mercadoPagoBricksAdapter;
|
|
1178
|
+
exports.parseChoice = parseChoice;
|
|
1179
|
+
exports.payErrorResponse = payErrorResponse;
|
|
759
1180
|
exports.paymentCsp = paymentCsp;
|
|
760
1181
|
exports.paymentCspHeaderName = paymentCspHeaderName;
|
|
1182
|
+
exports.paymentCspHeaders = paymentCspHeaders;
|
|
1183
|
+
exports.paymentCspMode = paymentCspMode;
|
|
1184
|
+
exports.paymentMethodMessages = paymentMethodMessages;
|
|
1185
|
+
exports.paymentNonce = paymentNonce;
|
|
1186
|
+
exports.paymentNonceFromHeaders = paymentNonceFromHeaders;
|
|
761
1187
|
exports.readPaymentTheme = readPaymentTheme;
|
|
762
1188
|
exports.resetPaymentSdkCache = resetPaymentSdkCache;
|
|
763
1189
|
exports.sanitizeMercadoPagoFormData = sanitizeMercadoPagoFormData;
|
|
764
1190
|
exports.useEmbeddedPayment = useEmbeddedPayment;
|
|
1191
|
+
exports.voucherRows = voucherRows;
|
|
765
1192
|
//# sourceMappingURL=payments.cjs.map
|
|
766
1193
|
//# sourceMappingURL=payments.cjs.map
|