@npmtapi/embed 1.2.0 → 1.3.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 +13 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/react.cjs +11 -0
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +5 -2
- package/dist/react.d.ts +5 -2
- package/dist/react.js +11 -0
- package/dist/react.js.map +1 -1
- package/dist/{types-DHQb-NNM.d.cts → types-BIb8B1hp.d.cts} +15 -1
- package/dist/{types-DHQb-NNM.d.ts → types-BIb8B1hp.d.ts} +15 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -100,6 +100,7 @@ export function PagoPage({ clienteId }: { clienteId: string }) {
|
|
|
100
100
|
| `onPaymentSubmitted` | `(data) => void` | No | — | Callback cuando el usuario completó el formulario de Yuno y fue redirigido al callback |
|
|
101
101
|
| `onCancelled` | `() => void` | No | — | Callback cuando el usuario cierra el popup sin completar el pago |
|
|
102
102
|
| `onAutopayLoaded` | `(data) => void` | No | — | (Vista autopay) Callback con las adhesiones activas; se reinvoca cuando la lista cambia |
|
|
103
|
+
| `onAutopayActivated` | `(data) => void` | No | — | (Vista autopay) Callback cuando una nueva domiciliación queda activa (una sola vez por adhesión nueva) |
|
|
103
104
|
| `onAutopayRemoved` | `(data) => void` | No | — | (Vista autopay) Callback cuando el usuario desadhiere un medio con éxito |
|
|
104
105
|
| `onAutopayError` | `(data) => void` | No | — | (Vista autopay) Callback ante un error de carga o de desadhesión |
|
|
105
106
|
| `className` | `string` | No | — | Clases CSS del contenedor |
|
|
@@ -288,6 +289,9 @@ Pasando `view: "autopay"` el widget monta la **gestión de adhesiones**: el usua
|
|
|
288
289
|
tapipay.on("autopayLoaded", function(data) {
|
|
289
290
|
console.log("Adhesiones activas:", data.count);
|
|
290
291
|
});
|
|
292
|
+
tapipay.on("autopayActivated", function(data) {
|
|
293
|
+
console.log("Nueva adhesión activa:", data.mediaType, data.lastFour);
|
|
294
|
+
});
|
|
291
295
|
tapipay.on("autopayRemoved", function(data) {
|
|
292
296
|
console.log("Medio desadherido:", data.mediaType, data.lastFour);
|
|
293
297
|
});
|
|
@@ -309,6 +313,7 @@ export function AdhesionesPage({ clienteId }: { clienteId: string }) {
|
|
|
309
313
|
organization="acme"
|
|
310
314
|
identifier={clienteId}
|
|
311
315
|
onAutopayLoaded={(data) => console.log("Adhesiones activas:", data.count)}
|
|
316
|
+
onAutopayActivated={(data) => console.log("Nueva adhesión activa:", data.mediaType)}
|
|
312
317
|
onAutopayRemoved={(data) => console.log("Desadherido:", data.mediaType)}
|
|
313
318
|
onAutopayError={(data) => console.log("Error:", data.stage)}
|
|
314
319
|
/>
|
|
@@ -329,6 +334,12 @@ interface TapipayAutopayLoadedEvent {
|
|
|
329
334
|
}>;
|
|
330
335
|
}
|
|
331
336
|
|
|
337
|
+
interface TapipayAutopayActivatedEvent {
|
|
338
|
+
id: string; // hash opaco
|
|
339
|
+
mediaType: "card" | "bank_account";
|
|
340
|
+
lastFour: string | null; // últimos 4 dígitos
|
|
341
|
+
}
|
|
342
|
+
|
|
332
343
|
interface TapipayAutopayRemovedEvent {
|
|
333
344
|
id: string;
|
|
334
345
|
mediaType: "card" | "bank_account";
|
|
@@ -343,6 +354,8 @@ interface TapipayAutopayErrorEvent {
|
|
|
343
354
|
|
|
344
355
|
> `autopayLoaded` se dispara al cargar y **cada vez que la lista de adhesiones cambia** (tras una desadhesión, refetch o polling), así que el host puede mantener su conteo consumiendo siempre el último `payload`.
|
|
345
356
|
|
|
357
|
+
> `autopayActivated` se dispara **una sola vez por adhesión nueva**, cuando una nueva domiciliación queda activa. A diferencia de `autopayLoaded`, no se repite en refetch ni polling.
|
|
358
|
+
|
|
346
359
|
---
|
|
347
360
|
|
|
348
361
|
## Entorno de homologación
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/loader.ts"],"sourcesContent":["export { loadTapipay } from \"./loader\";\nexport type {\n\tLoadTapipayOptions,\n\tTapipayAutopayAdhesionSummary,\n\tTapipayAutopayErrorEvent,\n\tTapipayAutopayLoadedEvent,\n\tTapipayAutopayMediaType,\n\tTapipayAutopayRemovedEvent,\n\tTapipayEnvironment,\n\tTapipayInstance,\n\tTapipayOptions,\n\tTapipayPaymentCancelledEvent,\n\tTapipayPaymentSubmittedEvent,\n\tTapipayPaymentWindowOpenedEvent,\n\tTapipayView,\n} from \"./types\";\n","import type {\n\tLoadTapipayOptions,\n\tTapipayEnvironment,\n\tTapipayInstance,\n} from \"./types\";\n\nconst SDK_URLS: Record<TapipayEnvironment, string> = {\n\tproduction: \"https://app.tapipay.la/embed.js\",\n\thomo: \"https://homo.tapipay.la/embed.js\",\n};\n\n// Idempotencia por entorno\nconst loadPromises = new Map<TapipayEnvironment, Promise<TapipayInstance>>();\n\n/**\n * Carga el SDK de TapiPay de forma asíncrona inyectando el script en el DOM.\n *\n * - Idempotente por entorno: múltiples llamadas con el mismo `environment` retornan la misma Promise.\n * - Si window.tapipay ya existe (script cargado sync), resuelve inmediatamente.\n * - Compatible con React Strict Mode (doble mount/unmount).\n *\n * @example\n * // Producción (default)\n * const tapipay = await loadTapipay();\n *\n * // Homologación\n * const tapipay = await loadTapipay({ environment: 'homo' });\n *\n * tapipay.initialize({ container: \"#widget\", organization: \"acme\", identifier: \"CLI-001\" });\n */\nexport function loadTapipay(\n\toptions?: LoadTapipayOptions,\n): Promise<TapipayInstance> {\n\tconst env: TapipayEnvironment = options?.environment ?? \"production\";\n\tconst SDK_URL = SDK_URLS[env];\n\tconst SCRIPT_ID = `tapipay-embed-sdk-${env}`;\n\n\t// SSR guard\n\tif (typeof window === \"undefined\") {\n\t\treturn Promise.reject(\n\t\t\tnew Error(\"[TapiPay] loadTapipay() requires a browser environment.\"),\n\t\t);\n\t}\n\n\t// Ya cargado de forma síncrona (script tag directo)\n\tif (window.tapipay && !window.tapipay._q) {\n\t\treturn Promise.resolve(window.tapipay);\n\t}\n\n\t// Reutilizar promise existente (idempotencia por entorno)\n\tconst existing = loadPromises.get(env);\n\tif (existing) return existing;\n\n\tconst promise = new Promise<TapipayInstance>((resolve, reject) => {\n\t\t// Si ya hay un script inyectado, esperar a que cargue\n\t\tconst existingScript = document.getElementById(\n\t\t\tSCRIPT_ID,\n\t\t) as HTMLScriptElement | null;\n\n\t\tconst onLoad = () => {\n\t\t\tif (window.tapipay) {\n\t\t\t\tresolve(window.tapipay);\n\t\t\t} else {\n\t\t\t\treject(\n\t\t\t\t\tnew Error(\n\t\t\t\t\t\t\"[TapiPay] El script cargó pero window.tapipay no está definido.\",\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\t\t};\n\n\t\tconst onError = () => {\n\t\t\tloadPromises.delete(env);\n\t\t\treject(new Error(`[TapiPay] Error al cargar el SDK desde ${SDK_URL}`));\n\t\t};\n\n\t\tif (existingScript) {\n\t\t\texistingScript.addEventListener(\"load\", onLoad);\n\t\t\texistingScript.addEventListener(\"error\", onError);\n\t\t\treturn;\n\t\t}\n\n\t\tconst script = document.createElement(\"script\");\n\t\tscript.id = SCRIPT_ID;\n\t\tscript.src = SDK_URL;\n\t\tscript.async = true;\n\t\tscript.addEventListener(\"load\", onLoad);\n\t\tscript.addEventListener(\"error\", onError);\n\t\tdocument.head.appendChild(script);\n\t});\n\n\tloadPromises.set(env, promise);\n\treturn promise;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACMA,IAAM,WAA+C;AAAA,EACpD,YAAY;AAAA,EACZ,MAAM;AACP;AAGA,IAAM,eAAe,oBAAI,IAAkD;AAkBpE,SAAS,YACf,SAC2B;AAhC5B;AAiCC,QAAM,OAA0B,wCAAS,gBAAT,YAAwB;AACxD,QAAM,UAAU,SAAS,GAAG;AAC5B,QAAM,YAAY,qBAAqB,GAAG;AAG1C,MAAI,OAAO,WAAW,aAAa;AAClC,WAAO,QAAQ;AAAA,MACd,IAAI,MAAM,yDAAyD;AAAA,IACpE;AAAA,EACD;AAGA,MAAI,OAAO,WAAW,CAAC,OAAO,QAAQ,IAAI;AACzC,WAAO,QAAQ,QAAQ,OAAO,OAAO;AAAA,EACtC;AAGA,QAAM,WAAW,aAAa,IAAI,GAAG;AACrC,MAAI,SAAU,QAAO;AAErB,QAAM,UAAU,IAAI,QAAyB,CAAC,SAAS,WAAW;AAEjE,UAAM,iBAAiB,SAAS;AAAA,MAC/B;AAAA,IACD;AAEA,UAAM,SAAS,MAAM;AACpB,UAAI,OAAO,SAAS;AACnB,gBAAQ,OAAO,OAAO;AAAA,MACvB,OAAO;AACN;AAAA,UACC,IAAI;AAAA,YACH;AAAA,UACD;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAEA,UAAM,UAAU,MAAM;AACrB,mBAAa,OAAO,GAAG;AACvB,aAAO,IAAI,MAAM,0CAA0C,OAAO,EAAE,CAAC;AAAA,IACtE;AAEA,QAAI,gBAAgB;AACnB,qBAAe,iBAAiB,QAAQ,MAAM;AAC9C,qBAAe,iBAAiB,SAAS,OAAO;AAChD;AAAA,IACD;AAEA,UAAM,SAAS,SAAS,cAAc,QAAQ;AAC9C,WAAO,KAAK;AACZ,WAAO,MAAM;AACb,WAAO,QAAQ;AACf,WAAO,iBAAiB,QAAQ,MAAM;AACtC,WAAO,iBAAiB,SAAS,OAAO;AACxC,aAAS,KAAK,YAAY,MAAM;AAAA,EACjC,CAAC;AAED,eAAa,IAAI,KAAK,OAAO;AAC7B,SAAO;AACR;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/loader.ts"],"sourcesContent":["export { loadTapipay } from \"./loader\";\nexport type {\n\tLoadTapipayOptions,\n\tTapipayAutopayActivatedEvent,\n\tTapipayAutopayAdhesionSummary,\n\tTapipayAutopayErrorEvent,\n\tTapipayAutopayLoadedEvent,\n\tTapipayAutopayMediaType,\n\tTapipayAutopayRemovedEvent,\n\tTapipayEnvironment,\n\tTapipayInstance,\n\tTapipayOptions,\n\tTapipayPaymentCancelledEvent,\n\tTapipayPaymentSubmittedEvent,\n\tTapipayPaymentWindowOpenedEvent,\n\tTapipayView,\n} from \"./types\";\n","import type {\n\tLoadTapipayOptions,\n\tTapipayEnvironment,\n\tTapipayInstance,\n} from \"./types\";\n\nconst SDK_URLS: Record<TapipayEnvironment, string> = {\n\tproduction: \"https://app.tapipay.la/embed.js\",\n\thomo: \"https://homo.tapipay.la/embed.js\",\n};\n\n// Idempotencia por entorno\nconst loadPromises = new Map<TapipayEnvironment, Promise<TapipayInstance>>();\n\n/**\n * Carga el SDK de TapiPay de forma asíncrona inyectando el script en el DOM.\n *\n * - Idempotente por entorno: múltiples llamadas con el mismo `environment` retornan la misma Promise.\n * - Si window.tapipay ya existe (script cargado sync), resuelve inmediatamente.\n * - Compatible con React Strict Mode (doble mount/unmount).\n *\n * @example\n * // Producción (default)\n * const tapipay = await loadTapipay();\n *\n * // Homologación\n * const tapipay = await loadTapipay({ environment: 'homo' });\n *\n * tapipay.initialize({ container: \"#widget\", organization: \"acme\", identifier: \"CLI-001\" });\n */\nexport function loadTapipay(\n\toptions?: LoadTapipayOptions,\n): Promise<TapipayInstance> {\n\tconst env: TapipayEnvironment = options?.environment ?? \"production\";\n\tconst SDK_URL = SDK_URLS[env];\n\tconst SCRIPT_ID = `tapipay-embed-sdk-${env}`;\n\n\t// SSR guard\n\tif (typeof window === \"undefined\") {\n\t\treturn Promise.reject(\n\t\t\tnew Error(\"[TapiPay] loadTapipay() requires a browser environment.\"),\n\t\t);\n\t}\n\n\t// Ya cargado de forma síncrona (script tag directo)\n\tif (window.tapipay && !window.tapipay._q) {\n\t\treturn Promise.resolve(window.tapipay);\n\t}\n\n\t// Reutilizar promise existente (idempotencia por entorno)\n\tconst existing = loadPromises.get(env);\n\tif (existing) return existing;\n\n\tconst promise = new Promise<TapipayInstance>((resolve, reject) => {\n\t\t// Si ya hay un script inyectado, esperar a que cargue\n\t\tconst existingScript = document.getElementById(\n\t\t\tSCRIPT_ID,\n\t\t) as HTMLScriptElement | null;\n\n\t\tconst onLoad = () => {\n\t\t\tif (window.tapipay) {\n\t\t\t\tresolve(window.tapipay);\n\t\t\t} else {\n\t\t\t\treject(\n\t\t\t\t\tnew Error(\n\t\t\t\t\t\t\"[TapiPay] El script cargó pero window.tapipay no está definido.\",\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\t\t};\n\n\t\tconst onError = () => {\n\t\t\tloadPromises.delete(env);\n\t\t\treject(new Error(`[TapiPay] Error al cargar el SDK desde ${SDK_URL}`));\n\t\t};\n\n\t\tif (existingScript) {\n\t\t\texistingScript.addEventListener(\"load\", onLoad);\n\t\t\texistingScript.addEventListener(\"error\", onError);\n\t\t\treturn;\n\t\t}\n\n\t\tconst script = document.createElement(\"script\");\n\t\tscript.id = SCRIPT_ID;\n\t\tscript.src = SDK_URL;\n\t\tscript.async = true;\n\t\tscript.addEventListener(\"load\", onLoad);\n\t\tscript.addEventListener(\"error\", onError);\n\t\tdocument.head.appendChild(script);\n\t});\n\n\tloadPromises.set(env, promise);\n\treturn promise;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACMA,IAAM,WAA+C;AAAA,EACpD,YAAY;AAAA,EACZ,MAAM;AACP;AAGA,IAAM,eAAe,oBAAI,IAAkD;AAkBpE,SAAS,YACf,SAC2B;AAhC5B;AAiCC,QAAM,OAA0B,wCAAS,gBAAT,YAAwB;AACxD,QAAM,UAAU,SAAS,GAAG;AAC5B,QAAM,YAAY,qBAAqB,GAAG;AAG1C,MAAI,OAAO,WAAW,aAAa;AAClC,WAAO,QAAQ;AAAA,MACd,IAAI,MAAM,yDAAyD;AAAA,IACpE;AAAA,EACD;AAGA,MAAI,OAAO,WAAW,CAAC,OAAO,QAAQ,IAAI;AACzC,WAAO,QAAQ,QAAQ,OAAO,OAAO;AAAA,EACtC;AAGA,QAAM,WAAW,aAAa,IAAI,GAAG;AACrC,MAAI,SAAU,QAAO;AAErB,QAAM,UAAU,IAAI,QAAyB,CAAC,SAAS,WAAW;AAEjE,UAAM,iBAAiB,SAAS;AAAA,MAC/B;AAAA,IACD;AAEA,UAAM,SAAS,MAAM;AACpB,UAAI,OAAO,SAAS;AACnB,gBAAQ,OAAO,OAAO;AAAA,MACvB,OAAO;AACN;AAAA,UACC,IAAI;AAAA,YACH;AAAA,UACD;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAEA,UAAM,UAAU,MAAM;AACrB,mBAAa,OAAO,GAAG;AACvB,aAAO,IAAI,MAAM,0CAA0C,OAAO,EAAE,CAAC;AAAA,IACtE;AAEA,QAAI,gBAAgB;AACnB,qBAAe,iBAAiB,QAAQ,MAAM;AAC9C,qBAAe,iBAAiB,SAAS,OAAO;AAChD;AAAA,IACD;AAEA,UAAM,SAAS,SAAS,cAAc,QAAQ;AAC9C,WAAO,KAAK;AACZ,WAAO,MAAM;AACb,WAAO,QAAQ;AACf,WAAO,iBAAiB,QAAQ,MAAM;AACtC,WAAO,iBAAiB,SAAS,OAAO;AACxC,aAAS,KAAK,YAAY,MAAM;AAAA,EACjC,CAAC;AAED,eAAa,IAAI,KAAK,OAAO;AAC7B,SAAO;AACR;","names":[]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { L as LoadTapipayOptions, T as TapipayInstance } from './types-
|
|
2
|
-
export { a as
|
|
1
|
+
import { L as LoadTapipayOptions, T as TapipayInstance } from './types-BIb8B1hp.cjs';
|
|
2
|
+
export { a as TapipayAutopayActivatedEvent, b as TapipayAutopayAdhesionSummary, c as TapipayAutopayErrorEvent, d as TapipayAutopayLoadedEvent, e as TapipayAutopayMediaType, f as TapipayAutopayRemovedEvent, g as TapipayEnvironment, h as TapipayOptions, i as TapipayPaymentCancelledEvent, j as TapipayPaymentSubmittedEvent, k as TapipayPaymentWindowOpenedEvent, l as TapipayView } from './types-BIb8B1hp.cjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Carga el SDK de TapiPay de forma asíncrona inyectando el script en el DOM.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { L as LoadTapipayOptions, T as TapipayInstance } from './types-
|
|
2
|
-
export { a as
|
|
1
|
+
import { L as LoadTapipayOptions, T as TapipayInstance } from './types-BIb8B1hp.js';
|
|
2
|
+
export { a as TapipayAutopayActivatedEvent, b as TapipayAutopayAdhesionSummary, c as TapipayAutopayErrorEvent, d as TapipayAutopayLoadedEvent, e as TapipayAutopayMediaType, f as TapipayAutopayRemovedEvent, g as TapipayEnvironment, h as TapipayOptions, i as TapipayPaymentCancelledEvent, j as TapipayPaymentSubmittedEvent, k as TapipayPaymentWindowOpenedEvent, l as TapipayView } from './types-BIb8B1hp.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Carga el SDK de TapiPay de forma asíncrona inyectando el script en el DOM.
|
package/dist/react.cjs
CHANGED
|
@@ -113,6 +113,7 @@ function TapipayWidget({
|
|
|
113
113
|
onPaymentSubmitted,
|
|
114
114
|
onCancelled,
|
|
115
115
|
onAutopayLoaded,
|
|
116
|
+
onAutopayActivated,
|
|
116
117
|
onAutopayRemoved,
|
|
117
118
|
onAutopayError,
|
|
118
119
|
className,
|
|
@@ -123,6 +124,7 @@ function TapipayWidget({
|
|
|
123
124
|
const onPaymentSubmittedRef = (0, import_react.useRef)(onPaymentSubmitted);
|
|
124
125
|
const onCancelledRef = (0, import_react.useRef)(onCancelled);
|
|
125
126
|
const onAutopayLoadedRef = (0, import_react.useRef)(onAutopayLoaded);
|
|
127
|
+
const onAutopayActivatedRef = (0, import_react.useRef)(onAutopayActivated);
|
|
126
128
|
const onAutopayRemovedRef = (0, import_react.useRef)(onAutopayRemoved);
|
|
127
129
|
const onAutopayErrorRef = (0, import_react.useRef)(onAutopayError);
|
|
128
130
|
(0, import_react.useEffect)(() => {
|
|
@@ -137,6 +139,9 @@ function TapipayWidget({
|
|
|
137
139
|
(0, import_react.useEffect)(() => {
|
|
138
140
|
onAutopayLoadedRef.current = onAutopayLoaded;
|
|
139
141
|
}, [onAutopayLoaded]);
|
|
142
|
+
(0, import_react.useEffect)(() => {
|
|
143
|
+
onAutopayActivatedRef.current = onAutopayActivated;
|
|
144
|
+
}, [onAutopayActivated]);
|
|
140
145
|
(0, import_react.useEffect)(() => {
|
|
141
146
|
onAutopayRemovedRef.current = onAutopayRemoved;
|
|
142
147
|
}, [onAutopayRemoved]);
|
|
@@ -164,6 +169,10 @@ function TapipayWidget({
|
|
|
164
169
|
var _a;
|
|
165
170
|
(_a = onAutopayLoadedRef.current) == null ? void 0 : _a.call(onAutopayLoadedRef, data);
|
|
166
171
|
};
|
|
172
|
+
const handleAutopayActivated = (data) => {
|
|
173
|
+
var _a;
|
|
174
|
+
(_a = onAutopayActivatedRef.current) == null ? void 0 : _a.call(onAutopayActivatedRef, data);
|
|
175
|
+
};
|
|
167
176
|
const handleAutopayRemoved = (data) => {
|
|
168
177
|
var _a;
|
|
169
178
|
(_a = onAutopayRemovedRef.current) == null ? void 0 : _a.call(onAutopayRemovedRef, data);
|
|
@@ -179,6 +188,7 @@ function TapipayWidget({
|
|
|
179
188
|
instance.on("paymentSubmitted", handlePaymentSubmitted);
|
|
180
189
|
instance.on("paymentCancelled", handleCancelled);
|
|
181
190
|
instance.on("autopayLoaded", handleAutopayLoaded);
|
|
191
|
+
instance.on("autopayActivated", handleAutopayActivated);
|
|
182
192
|
instance.on("autopayRemoved", handleAutopayRemoved);
|
|
183
193
|
instance.on("autopayError", handleAutopayError);
|
|
184
194
|
instance.initialize({
|
|
@@ -197,6 +207,7 @@ function TapipayWidget({
|
|
|
197
207
|
tapipayInstance.off("paymentSubmitted", handlePaymentSubmitted);
|
|
198
208
|
tapipayInstance.off("paymentCancelled", handleCancelled);
|
|
199
209
|
tapipayInstance.off("autopayLoaded", handleAutopayLoaded);
|
|
210
|
+
tapipayInstance.off("autopayActivated", handleAutopayActivated);
|
|
200
211
|
tapipayInstance.off("autopayRemoved", handleAutopayRemoved);
|
|
201
212
|
tapipayInstance.off("autopayError", handleAutopayError);
|
|
202
213
|
tapipayInstance.destroy(container);
|
package/dist/react.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/react.tsx","../src/loader.ts"],"sourcesContent":["import { useEffect, useRef, useState } from \"react\";\nimport { loadTapipay } from \"./loader\";\nimport type {\n\tLoadTapipayOptions,\n\tTapipayAutopayErrorEvent,\n\tTapipayAutopayLoadedEvent,\n\tTapipayAutopayRemovedEvent,\n\tTapipayEnvironment,\n\tTapipayInstance,\n\tTapipayOptions,\n\tTapipayPaymentCancelledEvent,\n\tTapipayPaymentSubmittedEvent,\n\tTapipayPaymentWindowOpenedEvent,\n} from \"./types\";\n\n// ─── useTapipay hook ──────────────────────────────────────────────────────────\n\n/**\n * Hook de bajo nivel que carga el SDK y retorna la instancia.\n * Útil cuando necesitas control manual sobre initialize/destroy.\n *\n * @example\n * const { tapipay, error } = useTapipay();\n * const { tapipay, error } = useTapipay({ environment: 'homo' });\n */\nexport function useTapipay(options?: LoadTapipayOptions): {\n\ttapipay: TapipayInstance | null;\n\terror: Error | null;\n} {\n\tconst [tapipay, setTapipay] = useState<TapipayInstance | null>(null);\n\tconst [error, setError] = useState<Error | null>(null);\n\tconst environment = options?.environment;\n\n\tuseEffect(() => {\n\t\tlet cancelled = false;\n\t\tloadTapipay({ environment })\n\t\t\t.then((instance) => {\n\t\t\t\tif (!cancelled) setTapipay(instance);\n\t\t\t})\n\t\t\t.catch((err: Error) => {\n\t\t\t\tif (!cancelled) setError(err);\n\t\t\t});\n\t\treturn () => {\n\t\t\tcancelled = true;\n\t\t};\n\t}, [environment]);\n\n\treturn { tapipay, error };\n}\n\n// ─── TapipayWidget component ──────────────────────────────────────────────────\n\nexport interface TapipayWidgetProps extends Omit<TapipayOptions, \"container\"> {\n\t/** Entorno del SDK a cargar. Por defecto `'production'`. Usar `'homo'` para homologación. */\n\tenvironment?: TapipayEnvironment;\n\t/** Callback invocado cuando el popup de Yuno se abre exitosamente. */\n\tonPaymentWindowOpened?: (data: TapipayPaymentWindowOpenedEvent) => void;\n\t/** Callback invocado cuando el usuario completó el formulario de Yuno y fue redirigido al callback. */\n\tonPaymentSubmitted?: (data: TapipayPaymentSubmittedEvent) => void;\n\t/** Callback invocado cuando el usuario cierra el popup sin completar el pago. */\n\tonCancelled?: (data: TapipayPaymentCancelledEvent) => void;\n\t/** (Vista autopay) Callback con el conjunto de adhesiones activas; se reinvoca cuando la lista cambia. */\n\tonAutopayLoaded?: (data: TapipayAutopayLoadedEvent) => void;\n\t/** (Vista autopay) Callback cuando el usuario desadhiere un medio con éxito. */\n\tonAutopayRemoved?: (data: TapipayAutopayRemovedEvent) => void;\n\t/** (Vista autopay) Callback ante un error de carga de adhesiones o de desadhesión. */\n\tonAutopayError?: (data: TapipayAutopayErrorEvent) => void;\n\t/** Clases CSS adicionales para el contenedor del widget. */\n\tclassName?: string;\n\t/** Estilos inline adicionales para el contenedor del widget. */\n\tstyle?: React.CSSProperties;\n}\n\n/**\n * Componente React que encapsula el widget de pago TapiPay.\n *\n * Maneja internamente la carga del SDK, el ciclo de vida del widget\n * y el cleanup al desmontar. Compatible con React Strict Mode.\n *\n * @example\n * // Vista de pagos (default)\n * <TapipayWidget\n * organization=\"acme\"\n * identifier=\"CLI-001\"\n * externalRequestId=\"FAC-2024-001\"\n * onPaymentSubmitted={(data) => console.log(\"Pago enviado\", data)}\n * onCancelled={() => console.log(\"Pago cancelado por el usuario\")}\n * />\n *\n * @example\n * // Vista de gestión de adhesiones de autopay\n * <TapipayWidget\n * organization=\"acme\"\n * identifier=\"CLI-001\"\n * view=\"autopay\"\n * onAutopayLoaded={(data) => console.log(\"Adhesiones\", data.count)}\n * onAutopayRemoved={(data) => console.log(\"Adhesión eliminada\", data.id)}\n * />\n */\nexport function TapipayWidget({\n\torganization,\n\tidentifier,\n\texternalRequestId,\n\tselectionStrategy,\n\tview,\n\tenvironment,\n\tonPaymentWindowOpened,\n\tonPaymentSubmitted,\n\tonCancelled,\n\tonAutopayLoaded,\n\tonAutopayRemoved,\n\tonAutopayError,\n\tclassName,\n\tstyle,\n}: TapipayWidgetProps) {\n\tconst containerRef = useRef<HTMLDivElement>(null);\n\t// Refs para evitar re-renders innecesarios y closures estáticos en useEffect\n\tconst onPaymentWindowOpenedRef = useRef(onPaymentWindowOpened);\n\tconst onPaymentSubmittedRef = useRef(onPaymentSubmitted);\n\tconst onCancelledRef = useRef(onCancelled);\n\tconst onAutopayLoadedRef = useRef(onAutopayLoaded);\n\tconst onAutopayRemovedRef = useRef(onAutopayRemoved);\n\tconst onAutopayErrorRef = useRef(onAutopayError);\n\n\tuseEffect(() => {\n\t\tonPaymentWindowOpenedRef.current = onPaymentWindowOpened;\n\t}, [onPaymentWindowOpened]);\n\n\tuseEffect(() => {\n\t\tonPaymentSubmittedRef.current = onPaymentSubmitted;\n\t}, [onPaymentSubmitted]);\n\n\tuseEffect(() => {\n\t\tonCancelledRef.current = onCancelled;\n\t}, [onCancelled]);\n\n\tuseEffect(() => {\n\t\tonAutopayLoadedRef.current = onAutopayLoaded;\n\t}, [onAutopayLoaded]);\n\n\tuseEffect(() => {\n\t\tonAutopayRemovedRef.current = onAutopayRemoved;\n\t}, [onAutopayRemoved]);\n\n\tuseEffect(() => {\n\t\tonAutopayErrorRef.current = onAutopayError;\n\t}, [onAutopayError]);\n\n\tuseEffect(() => {\n\t\tif (!containerRef.current) return;\n\t\tconst container = containerRef.current;\n\n\t\tlet tapipayInstance: TapipayInstance | null = null;\n\t\tlet cancelled = false;\n\n\t\tconst handlePaymentWindowOpened = (\n\t\t\tdata: TapipayPaymentWindowOpenedEvent,\n\t\t) => {\n\t\t\tonPaymentWindowOpenedRef.current?.(data);\n\t\t};\n\t\tconst handlePaymentSubmitted = (data: TapipayPaymentSubmittedEvent) => {\n\t\t\tonPaymentSubmittedRef.current?.(data);\n\t\t};\n\t\tconst handleCancelled = (data: TapipayPaymentCancelledEvent) => {\n\t\t\tonCancelledRef.current?.(data);\n\t\t};\n\t\tconst handleAutopayLoaded = (data: TapipayAutopayLoadedEvent) => {\n\t\t\tonAutopayLoadedRef.current?.(data);\n\t\t};\n\t\tconst handleAutopayRemoved = (data: TapipayAutopayRemovedEvent) => {\n\t\t\tonAutopayRemovedRef.current?.(data);\n\t\t};\n\t\tconst handleAutopayError = (data: TapipayAutopayErrorEvent) => {\n\t\t\tonAutopayErrorRef.current?.(data);\n\t\t};\n\n\t\tloadTapipay({ environment }).then((instance) => {\n\t\t\tif (cancelled) return;\n\t\t\ttapipayInstance = instance;\n\n\t\t\tinstance.on(\"paymentWindowOpened\", handlePaymentWindowOpened);\n\t\t\tinstance.on(\"paymentSubmitted\", handlePaymentSubmitted);\n\t\t\tinstance.on(\"paymentCancelled\", handleCancelled);\n\t\t\tinstance.on(\"autopayLoaded\", handleAutopayLoaded);\n\t\t\tinstance.on(\"autopayRemoved\", handleAutopayRemoved);\n\t\t\tinstance.on(\"autopayError\", handleAutopayError);\n\n\t\t\tinstance.initialize({\n\t\t\t\tcontainer,\n\t\t\t\torganization,\n\t\t\t\tidentifier,\n\t\t\t\texternalRequestId,\n\t\t\t\tselectionStrategy,\n\t\t\t\tview,\n\t\t\t});\n\t\t});\n\n\t\treturn () => {\n\t\t\tcancelled = true;\n\t\t\tif (tapipayInstance) {\n\t\t\t\ttapipayInstance.off(\"paymentWindowOpened\", handlePaymentWindowOpened);\n\t\t\t\ttapipayInstance.off(\"paymentSubmitted\", handlePaymentSubmitted);\n\t\t\t\ttapipayInstance.off(\"paymentCancelled\", handleCancelled);\n\t\t\t\ttapipayInstance.off(\"autopayLoaded\", handleAutopayLoaded);\n\t\t\t\ttapipayInstance.off(\"autopayRemoved\", handleAutopayRemoved);\n\t\t\t\ttapipayInstance.off(\"autopayError\", handleAutopayError);\n\t\t\t\ttapipayInstance.destroy(container);\n\t\t\t}\n\t\t};\n\t\t// El widget se re-monta si cambian los parámetros de identificación o entorno\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t}, [\n\t\torganization,\n\t\tidentifier,\n\t\texternalRequestId,\n\t\tselectionStrategy,\n\t\tview,\n\t\tenvironment,\n\t]);\n\n\treturn <div ref={containerRef} className={className} style={style} />;\n}\n","import type {\n\tLoadTapipayOptions,\n\tTapipayEnvironment,\n\tTapipayInstance,\n} from \"./types\";\n\nconst SDK_URLS: Record<TapipayEnvironment, string> = {\n\tproduction: \"https://app.tapipay.la/embed.js\",\n\thomo: \"https://homo.tapipay.la/embed.js\",\n};\n\n// Idempotencia por entorno\nconst loadPromises = new Map<TapipayEnvironment, Promise<TapipayInstance>>();\n\n/**\n * Carga el SDK de TapiPay de forma asíncrona inyectando el script en el DOM.\n *\n * - Idempotente por entorno: múltiples llamadas con el mismo `environment` retornan la misma Promise.\n * - Si window.tapipay ya existe (script cargado sync), resuelve inmediatamente.\n * - Compatible con React Strict Mode (doble mount/unmount).\n *\n * @example\n * // Producción (default)\n * const tapipay = await loadTapipay();\n *\n * // Homologación\n * const tapipay = await loadTapipay({ environment: 'homo' });\n *\n * tapipay.initialize({ container: \"#widget\", organization: \"acme\", identifier: \"CLI-001\" });\n */\nexport function loadTapipay(\n\toptions?: LoadTapipayOptions,\n): Promise<TapipayInstance> {\n\tconst env: TapipayEnvironment = options?.environment ?? \"production\";\n\tconst SDK_URL = SDK_URLS[env];\n\tconst SCRIPT_ID = `tapipay-embed-sdk-${env}`;\n\n\t// SSR guard\n\tif (typeof window === \"undefined\") {\n\t\treturn Promise.reject(\n\t\t\tnew Error(\"[TapiPay] loadTapipay() requires a browser environment.\"),\n\t\t);\n\t}\n\n\t// Ya cargado de forma síncrona (script tag directo)\n\tif (window.tapipay && !window.tapipay._q) {\n\t\treturn Promise.resolve(window.tapipay);\n\t}\n\n\t// Reutilizar promise existente (idempotencia por entorno)\n\tconst existing = loadPromises.get(env);\n\tif (existing) return existing;\n\n\tconst promise = new Promise<TapipayInstance>((resolve, reject) => {\n\t\t// Si ya hay un script inyectado, esperar a que cargue\n\t\tconst existingScript = document.getElementById(\n\t\t\tSCRIPT_ID,\n\t\t) as HTMLScriptElement | null;\n\n\t\tconst onLoad = () => {\n\t\t\tif (window.tapipay) {\n\t\t\t\tresolve(window.tapipay);\n\t\t\t} else {\n\t\t\t\treject(\n\t\t\t\t\tnew Error(\n\t\t\t\t\t\t\"[TapiPay] El script cargó pero window.tapipay no está definido.\",\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\t\t};\n\n\t\tconst onError = () => {\n\t\t\tloadPromises.delete(env);\n\t\t\treject(new Error(`[TapiPay] Error al cargar el SDK desde ${SDK_URL}`));\n\t\t};\n\n\t\tif (existingScript) {\n\t\t\texistingScript.addEventListener(\"load\", onLoad);\n\t\t\texistingScript.addEventListener(\"error\", onError);\n\t\t\treturn;\n\t\t}\n\n\t\tconst script = document.createElement(\"script\");\n\t\tscript.id = SCRIPT_ID;\n\t\tscript.src = SDK_URL;\n\t\tscript.async = true;\n\t\tscript.addEventListener(\"load\", onLoad);\n\t\tscript.addEventListener(\"error\", onError);\n\t\tdocument.head.appendChild(script);\n\t});\n\n\tloadPromises.set(env, promise);\n\treturn promise;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA4C;;;ACM5C,IAAM,WAA+C;AAAA,EACpD,YAAY;AAAA,EACZ,MAAM;AACP;AAGA,IAAM,eAAe,oBAAI,IAAkD;AAkBpE,SAAS,YACf,SAC2B;AAhC5B;AAiCC,QAAM,OAA0B,wCAAS,gBAAT,YAAwB;AACxD,QAAM,UAAU,SAAS,GAAG;AAC5B,QAAM,YAAY,qBAAqB,GAAG;AAG1C,MAAI,OAAO,WAAW,aAAa;AAClC,WAAO,QAAQ;AAAA,MACd,IAAI,MAAM,yDAAyD;AAAA,IACpE;AAAA,EACD;AAGA,MAA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,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD,CAAC;AAED,SAAO,4CAAC,SAAI,KAAK,cAAc,WAAsB,OAAc;AACpE;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/react.tsx","../src/loader.ts"],"sourcesContent":["import { useEffect, useRef, useState } from \"react\";\nimport { loadTapipay } from \"./loader\";\nimport type {\n\tLoadTapipayOptions,\n\tTapipayAutopayActivatedEvent,\n\tTapipayAutopayErrorEvent,\n\tTapipayAutopayLoadedEvent,\n\tTapipayAutopayRemovedEvent,\n\tTapipayEnvironment,\n\tTapipayInstance,\n\tTapipayOptions,\n\tTapipayPaymentCancelledEvent,\n\tTapipayPaymentSubmittedEvent,\n\tTapipayPaymentWindowOpenedEvent,\n} from \"./types\";\n\n// ─── useTapipay hook ──────────────────────────────────────────────────────────\n\n/**\n * Hook de bajo nivel que carga el SDK y retorna la instancia.\n * Útil cuando necesitas control manual sobre initialize/destroy.\n *\n * @example\n * const { tapipay, error } = useTapipay();\n * const { tapipay, error } = useTapipay({ environment: 'homo' });\n */\nexport function useTapipay(options?: LoadTapipayOptions): {\n\ttapipay: TapipayInstance | null;\n\terror: Error | null;\n} {\n\tconst [tapipay, setTapipay] = useState<TapipayInstance | null>(null);\n\tconst [error, setError] = useState<Error | null>(null);\n\tconst environment = options?.environment;\n\n\tuseEffect(() => {\n\t\tlet cancelled = false;\n\t\tloadTapipay({ environment })\n\t\t\t.then((instance) => {\n\t\t\t\tif (!cancelled) setTapipay(instance);\n\t\t\t})\n\t\t\t.catch((err: Error) => {\n\t\t\t\tif (!cancelled) setError(err);\n\t\t\t});\n\t\treturn () => {\n\t\t\tcancelled = true;\n\t\t};\n\t}, [environment]);\n\n\treturn { tapipay, error };\n}\n\n// ─── TapipayWidget component ──────────────────────────────────────────────────\n\nexport interface TapipayWidgetProps extends Omit<TapipayOptions, \"container\"> {\n\t/** Entorno del SDK a cargar. Por defecto `'production'`. Usar `'homo'` para homologación. */\n\tenvironment?: TapipayEnvironment;\n\t/** Callback invocado cuando el popup de Yuno se abre exitosamente. */\n\tonPaymentWindowOpened?: (data: TapipayPaymentWindowOpenedEvent) => void;\n\t/** Callback invocado cuando el usuario completó el formulario de Yuno y fue redirigido al callback. */\n\tonPaymentSubmitted?: (data: TapipayPaymentSubmittedEvent) => void;\n\t/** Callback invocado cuando el usuario cierra el popup sin completar el pago. */\n\tonCancelled?: (data: TapipayPaymentCancelledEvent) => void;\n\t/** (Vista autopay) Callback con el conjunto de adhesiones activas; se reinvoca cuando la lista cambia. */\n\tonAutopayLoaded?: (data: TapipayAutopayLoadedEvent) => void;\n\t/** (Vista autopay) Callback cuando una nueva adhesión queda activa (una sola vez por adhesión nueva). */\n\tonAutopayActivated?: (data: TapipayAutopayActivatedEvent) => void;\n\t/** (Vista autopay) Callback cuando el usuario desadhiere un medio con éxito. */\n\tonAutopayRemoved?: (data: TapipayAutopayRemovedEvent) => void;\n\t/** (Vista autopay) Callback ante un error de carga de adhesiones o de desadhesión. */\n\tonAutopayError?: (data: TapipayAutopayErrorEvent) => void;\n\t/** Clases CSS adicionales para el contenedor del widget. */\n\tclassName?: string;\n\t/** Estilos inline adicionales para el contenedor del widget. */\n\tstyle?: React.CSSProperties;\n}\n\n/**\n * Componente React que encapsula el widget de pago TapiPay.\n *\n * Maneja internamente la carga del SDK, el ciclo de vida del widget\n * y el cleanup al desmontar. Compatible con React Strict Mode.\n *\n * @example\n * // Vista de pagos (default)\n * <TapipayWidget\n * organization=\"acme\"\n * identifier=\"CLI-001\"\n * externalRequestId=\"FAC-2024-001\"\n * onPaymentSubmitted={(data) => console.log(\"Pago enviado\", data)}\n * onCancelled={() => console.log(\"Pago cancelado por el usuario\")}\n * />\n *\n * @example\n * // Vista de gestión de adhesiones de autopay\n * <TapipayWidget\n * organization=\"acme\"\n * identifier=\"CLI-001\"\n * view=\"autopay\"\n * onAutopayLoaded={(data) => console.log(\"Adhesiones\", data.count)}\n * onAutopayActivated={(data) => console.log(\"Adhesión activada\", data.id)}\n * onAutopayRemoved={(data) => console.log(\"Adhesión eliminada\", data.id)}\n * />\n */\nexport function TapipayWidget({\n\torganization,\n\tidentifier,\n\texternalRequestId,\n\tselectionStrategy,\n\tview,\n\tenvironment,\n\tonPaymentWindowOpened,\n\tonPaymentSubmitted,\n\tonCancelled,\n\tonAutopayLoaded,\n\tonAutopayActivated,\n\tonAutopayRemoved,\n\tonAutopayError,\n\tclassName,\n\tstyle,\n}: TapipayWidgetProps) {\n\tconst containerRef = useRef<HTMLDivElement>(null);\n\t// Refs para evitar re-renders innecesarios y closures estáticos en useEffect\n\tconst onPaymentWindowOpenedRef = useRef(onPaymentWindowOpened);\n\tconst onPaymentSubmittedRef = useRef(onPaymentSubmitted);\n\tconst onCancelledRef = useRef(onCancelled);\n\tconst onAutopayLoadedRef = useRef(onAutopayLoaded);\n\tconst onAutopayActivatedRef = useRef(onAutopayActivated);\n\tconst onAutopayRemovedRef = useRef(onAutopayRemoved);\n\tconst onAutopayErrorRef = useRef(onAutopayError);\n\n\tuseEffect(() => {\n\t\tonPaymentWindowOpenedRef.current = onPaymentWindowOpened;\n\t}, [onPaymentWindowOpened]);\n\n\tuseEffect(() => {\n\t\tonPaymentSubmittedRef.current = onPaymentSubmitted;\n\t}, [onPaymentSubmitted]);\n\n\tuseEffect(() => {\n\t\tonCancelledRef.current = onCancelled;\n\t}, [onCancelled]);\n\n\tuseEffect(() => {\n\t\tonAutopayLoadedRef.current = onAutopayLoaded;\n\t}, [onAutopayLoaded]);\n\n\tuseEffect(() => {\n\t\tonAutopayActivatedRef.current = onAutopayActivated;\n\t}, [onAutopayActivated]);\n\n\tuseEffect(() => {\n\t\tonAutopayRemovedRef.current = onAutopayRemoved;\n\t}, [onAutopayRemoved]);\n\n\tuseEffect(() => {\n\t\tonAutopayErrorRef.current = onAutopayError;\n\t}, [onAutopayError]);\n\n\tuseEffect(() => {\n\t\tif (!containerRef.current) return;\n\t\tconst container = containerRef.current;\n\n\t\tlet tapipayInstance: TapipayInstance | null = null;\n\t\tlet cancelled = false;\n\n\t\tconst handlePaymentWindowOpened = (\n\t\t\tdata: TapipayPaymentWindowOpenedEvent,\n\t\t) => {\n\t\t\tonPaymentWindowOpenedRef.current?.(data);\n\t\t};\n\t\tconst handlePaymentSubmitted = (data: TapipayPaymentSubmittedEvent) => {\n\t\t\tonPaymentSubmittedRef.current?.(data);\n\t\t};\n\t\tconst handleCancelled = (data: TapipayPaymentCancelledEvent) => {\n\t\t\tonCancelledRef.current?.(data);\n\t\t};\n\t\tconst handleAutopayLoaded = (data: TapipayAutopayLoadedEvent) => {\n\t\t\tonAutopayLoadedRef.current?.(data);\n\t\t};\n\t\tconst handleAutopayActivated = (data: TapipayAutopayActivatedEvent) => {\n\t\t\tonAutopayActivatedRef.current?.(data);\n\t\t};\n\t\tconst handleAutopayRemoved = (data: TapipayAutopayRemovedEvent) => {\n\t\t\tonAutopayRemovedRef.current?.(data);\n\t\t};\n\t\tconst handleAutopayError = (data: TapipayAutopayErrorEvent) => {\n\t\t\tonAutopayErrorRef.current?.(data);\n\t\t};\n\n\t\tloadTapipay({ environment }).then((instance) => {\n\t\t\tif (cancelled) return;\n\t\t\ttapipayInstance = instance;\n\n\t\t\tinstance.on(\"paymentWindowOpened\", handlePaymentWindowOpened);\n\t\t\tinstance.on(\"paymentSubmitted\", handlePaymentSubmitted);\n\t\t\tinstance.on(\"paymentCancelled\", handleCancelled);\n\t\t\tinstance.on(\"autopayLoaded\", handleAutopayLoaded);\n\t\t\tinstance.on(\"autopayActivated\", handleAutopayActivated);\n\t\t\tinstance.on(\"autopayRemoved\", handleAutopayRemoved);\n\t\t\tinstance.on(\"autopayError\", handleAutopayError);\n\n\t\t\tinstance.initialize({\n\t\t\t\tcontainer,\n\t\t\t\torganization,\n\t\t\t\tidentifier,\n\t\t\t\texternalRequestId,\n\t\t\t\tselectionStrategy,\n\t\t\t\tview,\n\t\t\t});\n\t\t});\n\n\t\treturn () => {\n\t\t\tcancelled = true;\n\t\t\tif (tapipayInstance) {\n\t\t\t\ttapipayInstance.off(\"paymentWindowOpened\", handlePaymentWindowOpened);\n\t\t\t\ttapipayInstance.off(\"paymentSubmitted\", handlePaymentSubmitted);\n\t\t\t\ttapipayInstance.off(\"paymentCancelled\", handleCancelled);\n\t\t\t\ttapipayInstance.off(\"autopayLoaded\", handleAutopayLoaded);\n\t\t\t\ttapipayInstance.off(\"autopayActivated\", handleAutopayActivated);\n\t\t\t\ttapipayInstance.off(\"autopayRemoved\", handleAutopayRemoved);\n\t\t\t\ttapipayInstance.off(\"autopayError\", handleAutopayError);\n\t\t\t\ttapipayInstance.destroy(container);\n\t\t\t}\n\t\t};\n\t\t// El widget se re-monta si cambian los parámetros de identificación o entorno\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t}, [\n\t\torganization,\n\t\tidentifier,\n\t\texternalRequestId,\n\t\tselectionStrategy,\n\t\tview,\n\t\tenvironment,\n\t]);\n\n\treturn <div ref={containerRef} className={className} style={style} />;\n}\n","import type {\n\tLoadTapipayOptions,\n\tTapipayEnvironment,\n\tTapipayInstance,\n} from \"./types\";\n\nconst SDK_URLS: Record<TapipayEnvironment, string> = {\n\tproduction: \"https://app.tapipay.la/embed.js\",\n\thomo: \"https://homo.tapipay.la/embed.js\",\n};\n\n// Idempotencia por entorno\nconst loadPromises = new Map<TapipayEnvironment, Promise<TapipayInstance>>();\n\n/**\n * Carga el SDK de TapiPay de forma asíncrona inyectando el script en el DOM.\n *\n * - Idempotente por entorno: múltiples llamadas con el mismo `environment` retornan la misma Promise.\n * - Si window.tapipay ya existe (script cargado sync), resuelve inmediatamente.\n * - Compatible con React Strict Mode (doble mount/unmount).\n *\n * @example\n * // Producción (default)\n * const tapipay = await loadTapipay();\n *\n * // Homologación\n * const tapipay = await loadTapipay({ environment: 'homo' });\n *\n * tapipay.initialize({ container: \"#widget\", organization: \"acme\", identifier: \"CLI-001\" });\n */\nexport function loadTapipay(\n\toptions?: LoadTapipayOptions,\n): Promise<TapipayInstance> {\n\tconst env: TapipayEnvironment = options?.environment ?? \"production\";\n\tconst SDK_URL = SDK_URLS[env];\n\tconst SCRIPT_ID = `tapipay-embed-sdk-${env}`;\n\n\t// SSR guard\n\tif (typeof window === \"undefined\") {\n\t\treturn Promise.reject(\n\t\t\tnew Error(\"[TapiPay] loadTapipay() requires a browser environment.\"),\n\t\t);\n\t}\n\n\t// Ya cargado de forma síncrona (script tag directo)\n\tif (window.tapipay && !window.tapipay._q) {\n\t\treturn Promise.resolve(window.tapipay);\n\t}\n\n\t// Reutilizar promise existente (idempotencia por entorno)\n\tconst existing = loadPromises.get(env);\n\tif (existing) return existing;\n\n\tconst promise = new Promise<TapipayInstance>((resolve, reject) => {\n\t\t// Si ya hay un script inyectado, esperar a que cargue\n\t\tconst existingScript = document.getElementById(\n\t\t\tSCRIPT_ID,\n\t\t) as HTMLScriptElement | null;\n\n\t\tconst onLoad = () => {\n\t\t\tif (window.tapipay) {\n\t\t\t\tresolve(window.tapipay);\n\t\t\t} else {\n\t\t\t\treject(\n\t\t\t\t\tnew Error(\n\t\t\t\t\t\t\"[TapiPay] El script cargó pero window.tapipay no está definido.\",\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\t\t};\n\n\t\tconst onError = () => {\n\t\t\tloadPromises.delete(env);\n\t\t\treject(new Error(`[TapiPay] Error al cargar el SDK desde ${SDK_URL}`));\n\t\t};\n\n\t\tif (existingScript) {\n\t\t\texistingScript.addEventListener(\"load\", onLoad);\n\t\t\texistingScript.addEventListener(\"error\", onError);\n\t\t\treturn;\n\t\t}\n\n\t\tconst script = document.createElement(\"script\");\n\t\tscript.id = SCRIPT_ID;\n\t\tscript.src = SDK_URL;\n\t\tscript.async = true;\n\t\tscript.addEventListener(\"load\", onLoad);\n\t\tscript.addEventListener(\"error\", onError);\n\t\tdocument.head.appendChild(script);\n\t});\n\n\tloadPromises.set(env, promise);\n\treturn promise;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA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AC/C,eAAS,GAAG,iBAAiB,mBAAmB;AAChD,eAAS,GAAG,oBAAoB,sBAAsB;AACtD,eAAS,GAAG,kBAAkB,oBAAoB;AAClD,eAAS,GAAG,gBAAgB,kBAAkB;AAE9C,eAAS,WAAW;AAAA,QACnB;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACD,CAAC;AAAA,IACF,CAAC;AAED,WAAO,MAAM;AACZ,kBAAY;AACZ,UAAI,iBAAiB;AACpB,wBAAgB,IAAI,uBAAuB,yBAAyB;AACpE,wBAAgB,IAAI,oBAAoB,sBAAsB;AAC9D,wBAAgB,IAAI,oBAAoB,eAAe;AACvD,wBAAgB,IAAI,iBAAiB,mBAAmB;AACxD,wBAAgB,IAAI,oBAAoB,sBAAsB;AAC9D,wBAAgB,IAAI,kBAAkB,oBAAoB;AAC1D,wBAAgB,IAAI,gBAAgB,kBAAkB;AACtD,wBAAgB,QAAQ,SAAS;AAAA,MAClC;AAAA,IACD;AAAA,EAGD,GAAG;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD,CAAC;AAED,SAAO,4CAAC,SAAI,KAAK,cAAc,WAAsB,OAAc;AACpE;","names":[]}
|
package/dist/react.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import {
|
|
2
|
+
import { h as TapipayOptions, g as TapipayEnvironment, k as TapipayPaymentWindowOpenedEvent, j as TapipayPaymentSubmittedEvent, i as TapipayPaymentCancelledEvent, d as TapipayAutopayLoadedEvent, a as TapipayAutopayActivatedEvent, f as TapipayAutopayRemovedEvent, c as TapipayAutopayErrorEvent, L as LoadTapipayOptions, T as TapipayInstance } from './types-BIb8B1hp.cjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Hook de bajo nivel que carga el SDK y retorna la instancia.
|
|
@@ -24,6 +24,8 @@ interface TapipayWidgetProps extends Omit<TapipayOptions, "container"> {
|
|
|
24
24
|
onCancelled?: (data: TapipayPaymentCancelledEvent) => void;
|
|
25
25
|
/** (Vista autopay) Callback con el conjunto de adhesiones activas; se reinvoca cuando la lista cambia. */
|
|
26
26
|
onAutopayLoaded?: (data: TapipayAutopayLoadedEvent) => void;
|
|
27
|
+
/** (Vista autopay) Callback cuando una nueva adhesión queda activa (una sola vez por adhesión nueva). */
|
|
28
|
+
onAutopayActivated?: (data: TapipayAutopayActivatedEvent) => void;
|
|
27
29
|
/** (Vista autopay) Callback cuando el usuario desadhiere un medio con éxito. */
|
|
28
30
|
onAutopayRemoved?: (data: TapipayAutopayRemovedEvent) => void;
|
|
29
31
|
/** (Vista autopay) Callback ante un error de carga de adhesiones o de desadhesión. */
|
|
@@ -56,9 +58,10 @@ interface TapipayWidgetProps extends Omit<TapipayOptions, "container"> {
|
|
|
56
58
|
* identifier="CLI-001"
|
|
57
59
|
* view="autopay"
|
|
58
60
|
* onAutopayLoaded={(data) => console.log("Adhesiones", data.count)}
|
|
61
|
+
* onAutopayActivated={(data) => console.log("Adhesión activada", data.id)}
|
|
59
62
|
* onAutopayRemoved={(data) => console.log("Adhesión eliminada", data.id)}
|
|
60
63
|
* />
|
|
61
64
|
*/
|
|
62
|
-
declare function TapipayWidget({ organization, identifier, externalRequestId, selectionStrategy, view, environment, onPaymentWindowOpened, onPaymentSubmitted, onCancelled, onAutopayLoaded, onAutopayRemoved, onAutopayError, className, style, }: TapipayWidgetProps): react_jsx_runtime.JSX.Element;
|
|
65
|
+
declare function TapipayWidget({ organization, identifier, externalRequestId, selectionStrategy, view, environment, onPaymentWindowOpened, onPaymentSubmitted, onCancelled, onAutopayLoaded, onAutopayActivated, onAutopayRemoved, onAutopayError, className, style, }: TapipayWidgetProps): react_jsx_runtime.JSX.Element;
|
|
63
66
|
|
|
64
67
|
export { TapipayWidget, type TapipayWidgetProps, useTapipay };
|
package/dist/react.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import {
|
|
2
|
+
import { h as TapipayOptions, g as TapipayEnvironment, k as TapipayPaymentWindowOpenedEvent, j as TapipayPaymentSubmittedEvent, i as TapipayPaymentCancelledEvent, d as TapipayAutopayLoadedEvent, a as TapipayAutopayActivatedEvent, f as TapipayAutopayRemovedEvent, c as TapipayAutopayErrorEvent, L as LoadTapipayOptions, T as TapipayInstance } from './types-BIb8B1hp.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Hook de bajo nivel que carga el SDK y retorna la instancia.
|
|
@@ -24,6 +24,8 @@ interface TapipayWidgetProps extends Omit<TapipayOptions, "container"> {
|
|
|
24
24
|
onCancelled?: (data: TapipayPaymentCancelledEvent) => void;
|
|
25
25
|
/** (Vista autopay) Callback con el conjunto de adhesiones activas; se reinvoca cuando la lista cambia. */
|
|
26
26
|
onAutopayLoaded?: (data: TapipayAutopayLoadedEvent) => void;
|
|
27
|
+
/** (Vista autopay) Callback cuando una nueva adhesión queda activa (una sola vez por adhesión nueva). */
|
|
28
|
+
onAutopayActivated?: (data: TapipayAutopayActivatedEvent) => void;
|
|
27
29
|
/** (Vista autopay) Callback cuando el usuario desadhiere un medio con éxito. */
|
|
28
30
|
onAutopayRemoved?: (data: TapipayAutopayRemovedEvent) => void;
|
|
29
31
|
/** (Vista autopay) Callback ante un error de carga de adhesiones o de desadhesión. */
|
|
@@ -56,9 +58,10 @@ interface TapipayWidgetProps extends Omit<TapipayOptions, "container"> {
|
|
|
56
58
|
* identifier="CLI-001"
|
|
57
59
|
* view="autopay"
|
|
58
60
|
* onAutopayLoaded={(data) => console.log("Adhesiones", data.count)}
|
|
61
|
+
* onAutopayActivated={(data) => console.log("Adhesión activada", data.id)}
|
|
59
62
|
* onAutopayRemoved={(data) => console.log("Adhesión eliminada", data.id)}
|
|
60
63
|
* />
|
|
61
64
|
*/
|
|
62
|
-
declare function TapipayWidget({ organization, identifier, externalRequestId, selectionStrategy, view, environment, onPaymentWindowOpened, onPaymentSubmitted, onCancelled, onAutopayLoaded, onAutopayRemoved, onAutopayError, className, style, }: TapipayWidgetProps): react_jsx_runtime.JSX.Element;
|
|
65
|
+
declare function TapipayWidget({ organization, identifier, externalRequestId, selectionStrategy, view, environment, onPaymentWindowOpened, onPaymentSubmitted, onCancelled, onAutopayLoaded, onAutopayActivated, onAutopayRemoved, onAutopayError, className, style, }: TapipayWidgetProps): react_jsx_runtime.JSX.Element;
|
|
63
66
|
|
|
64
67
|
export { TapipayWidget, type TapipayWidgetProps, useTapipay };
|
package/dist/react.js
CHANGED
|
@@ -33,6 +33,7 @@ function TapipayWidget({
|
|
|
33
33
|
onPaymentSubmitted,
|
|
34
34
|
onCancelled,
|
|
35
35
|
onAutopayLoaded,
|
|
36
|
+
onAutopayActivated,
|
|
36
37
|
onAutopayRemoved,
|
|
37
38
|
onAutopayError,
|
|
38
39
|
className,
|
|
@@ -43,6 +44,7 @@ function TapipayWidget({
|
|
|
43
44
|
const onPaymentSubmittedRef = useRef(onPaymentSubmitted);
|
|
44
45
|
const onCancelledRef = useRef(onCancelled);
|
|
45
46
|
const onAutopayLoadedRef = useRef(onAutopayLoaded);
|
|
47
|
+
const onAutopayActivatedRef = useRef(onAutopayActivated);
|
|
46
48
|
const onAutopayRemovedRef = useRef(onAutopayRemoved);
|
|
47
49
|
const onAutopayErrorRef = useRef(onAutopayError);
|
|
48
50
|
useEffect(() => {
|
|
@@ -57,6 +59,9 @@ function TapipayWidget({
|
|
|
57
59
|
useEffect(() => {
|
|
58
60
|
onAutopayLoadedRef.current = onAutopayLoaded;
|
|
59
61
|
}, [onAutopayLoaded]);
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
onAutopayActivatedRef.current = onAutopayActivated;
|
|
64
|
+
}, [onAutopayActivated]);
|
|
60
65
|
useEffect(() => {
|
|
61
66
|
onAutopayRemovedRef.current = onAutopayRemoved;
|
|
62
67
|
}, [onAutopayRemoved]);
|
|
@@ -84,6 +89,10 @@ function TapipayWidget({
|
|
|
84
89
|
var _a;
|
|
85
90
|
(_a = onAutopayLoadedRef.current) == null ? void 0 : _a.call(onAutopayLoadedRef, data);
|
|
86
91
|
};
|
|
92
|
+
const handleAutopayActivated = (data) => {
|
|
93
|
+
var _a;
|
|
94
|
+
(_a = onAutopayActivatedRef.current) == null ? void 0 : _a.call(onAutopayActivatedRef, data);
|
|
95
|
+
};
|
|
87
96
|
const handleAutopayRemoved = (data) => {
|
|
88
97
|
var _a;
|
|
89
98
|
(_a = onAutopayRemovedRef.current) == null ? void 0 : _a.call(onAutopayRemovedRef, data);
|
|
@@ -99,6 +108,7 @@ function TapipayWidget({
|
|
|
99
108
|
instance.on("paymentSubmitted", handlePaymentSubmitted);
|
|
100
109
|
instance.on("paymentCancelled", handleCancelled);
|
|
101
110
|
instance.on("autopayLoaded", handleAutopayLoaded);
|
|
111
|
+
instance.on("autopayActivated", handleAutopayActivated);
|
|
102
112
|
instance.on("autopayRemoved", handleAutopayRemoved);
|
|
103
113
|
instance.on("autopayError", handleAutopayError);
|
|
104
114
|
instance.initialize({
|
|
@@ -117,6 +127,7 @@ function TapipayWidget({
|
|
|
117
127
|
tapipayInstance.off("paymentSubmitted", handlePaymentSubmitted);
|
|
118
128
|
tapipayInstance.off("paymentCancelled", handleCancelled);
|
|
119
129
|
tapipayInstance.off("autopayLoaded", handleAutopayLoaded);
|
|
130
|
+
tapipayInstance.off("autopayActivated", handleAutopayActivated);
|
|
120
131
|
tapipayInstance.off("autopayRemoved", handleAutopayRemoved);
|
|
121
132
|
tapipayInstance.off("autopayError", handleAutopayError);
|
|
122
133
|
tapipayInstance.destroy(container);
|
package/dist/react.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/react.tsx"],"sourcesContent":["import { useEffect, useRef, useState } from \"react\";\nimport { loadTapipay } from \"./loader\";\nimport type {\n\tLoadTapipayOptions,\n\tTapipayAutopayErrorEvent,\n\tTapipayAutopayLoadedEvent,\n\tTapipayAutopayRemovedEvent,\n\tTapipayEnvironment,\n\tTapipayInstance,\n\tTapipayOptions,\n\tTapipayPaymentCancelledEvent,\n\tTapipayPaymentSubmittedEvent,\n\tTapipayPaymentWindowOpenedEvent,\n} from \"./types\";\n\n// ─── useTapipay hook ──────────────────────────────────────────────────────────\n\n/**\n * Hook de bajo nivel que carga el SDK y retorna la instancia.\n * Útil cuando necesitas control manual sobre initialize/destroy.\n *\n * @example\n * const { tapipay, error } = useTapipay();\n * const { tapipay, error } = useTapipay({ environment: 'homo' });\n */\nexport function useTapipay(options?: LoadTapipayOptions): {\n\ttapipay: TapipayInstance | null;\n\terror: Error | null;\n} {\n\tconst [tapipay, setTapipay] = useState<TapipayInstance | null>(null);\n\tconst [error, setError] = useState<Error | null>(null);\n\tconst environment = options?.environment;\n\n\tuseEffect(() => {\n\t\tlet cancelled = false;\n\t\tloadTapipay({ environment })\n\t\t\t.then((instance) => {\n\t\t\t\tif (!cancelled) setTapipay(instance);\n\t\t\t})\n\t\t\t.catch((err: Error) => {\n\t\t\t\tif (!cancelled) setError(err);\n\t\t\t});\n\t\treturn () => {\n\t\t\tcancelled = true;\n\t\t};\n\t}, [environment]);\n\n\treturn { tapipay, error };\n}\n\n// ─── TapipayWidget component ──────────────────────────────────────────────────\n\nexport interface TapipayWidgetProps extends Omit<TapipayOptions, \"container\"> {\n\t/** Entorno del SDK a cargar. Por defecto `'production'`. Usar `'homo'` para homologación. */\n\tenvironment?: TapipayEnvironment;\n\t/** Callback invocado cuando el popup de Yuno se abre exitosamente. */\n\tonPaymentWindowOpened?: (data: TapipayPaymentWindowOpenedEvent) => void;\n\t/** Callback invocado cuando el usuario completó el formulario de Yuno y fue redirigido al callback. */\n\tonPaymentSubmitted?: (data: TapipayPaymentSubmittedEvent) => void;\n\t/** Callback invocado cuando el usuario cierra el popup sin completar el pago. */\n\tonCancelled?: (data: TapipayPaymentCancelledEvent) => void;\n\t/** (Vista autopay) Callback con el conjunto de adhesiones activas; se reinvoca cuando la lista cambia. */\n\tonAutopayLoaded?: (data: TapipayAutopayLoadedEvent) => void;\n\t/** (Vista autopay) Callback cuando el usuario desadhiere un medio con éxito. */\n\tonAutopayRemoved?: (data: TapipayAutopayRemovedEvent) => void;\n\t/** (Vista autopay) Callback ante un error de carga de adhesiones o de desadhesión. */\n\tonAutopayError?: (data: TapipayAutopayErrorEvent) => void;\n\t/** Clases CSS adicionales para el contenedor del widget. */\n\tclassName?: string;\n\t/** Estilos inline adicionales para el contenedor del widget. */\n\tstyle?: React.CSSProperties;\n}\n\n/**\n * Componente React que encapsula el widget de pago TapiPay.\n *\n * Maneja internamente la carga del SDK, el ciclo de vida del widget\n * y el cleanup al desmontar. Compatible con React Strict Mode.\n *\n * @example\n * // Vista de pagos (default)\n * <TapipayWidget\n * organization=\"acme\"\n * identifier=\"CLI-001\"\n * externalRequestId=\"FAC-2024-001\"\n * onPaymentSubmitted={(data) => console.log(\"Pago enviado\", data)}\n * onCancelled={() => console.log(\"Pago cancelado por el usuario\")}\n * />\n *\n * @example\n * // Vista de gestión de adhesiones de autopay\n * <TapipayWidget\n * organization=\"acme\"\n * identifier=\"CLI-001\"\n * view=\"autopay\"\n * onAutopayLoaded={(data) => console.log(\"Adhesiones\", data.count)}\n * onAutopayRemoved={(data) => console.log(\"Adhesión eliminada\", data.id)}\n * />\n */\nexport function TapipayWidget({\n\torganization,\n\tidentifier,\n\texternalRequestId,\n\tselectionStrategy,\n\tview,\n\tenvironment,\n\tonPaymentWindowOpened,\n\tonPaymentSubmitted,\n\tonCancelled,\n\tonAutopayLoaded,\n\tonAutopayRemoved,\n\tonAutopayError,\n\tclassName,\n\tstyle,\n}: TapipayWidgetProps) {\n\tconst containerRef = useRef<HTMLDivElement>(null);\n\t// Refs para evitar re-renders innecesarios y closures estáticos en useEffect\n\tconst onPaymentWindowOpenedRef = useRef(onPaymentWindowOpened);\n\tconst onPaymentSubmittedRef = useRef(onPaymentSubmitted);\n\tconst onCancelledRef = useRef(onCancelled);\n\tconst onAutopayLoadedRef = useRef(onAutopayLoaded);\n\tconst onAutopayRemovedRef = useRef(onAutopayRemoved);\n\tconst onAutopayErrorRef = useRef(onAutopayError);\n\n\tuseEffect(() => {\n\t\tonPaymentWindowOpenedRef.current = onPaymentWindowOpened;\n\t}, [onPaymentWindowOpened]);\n\n\tuseEffect(() => {\n\t\tonPaymentSubmittedRef.current = onPaymentSubmitted;\n\t}, [onPaymentSubmitted]);\n\n\tuseEffect(() => {\n\t\tonCancelledRef.current = onCancelled;\n\t}, [onCancelled]);\n\n\tuseEffect(() => {\n\t\tonAutopayLoadedRef.current = onAutopayLoaded;\n\t}, [onAutopayLoaded]);\n\n\tuseEffect(() => {\n\t\tonAutopayRemovedRef.current = onAutopayRemoved;\n\t}, [onAutopayRemoved]);\n\n\tuseEffect(() => {\n\t\tonAutopayErrorRef.current = onAutopayError;\n\t}, [onAutopayError]);\n\n\tuseEffect(() => {\n\t\tif (!containerRef.current) return;\n\t\tconst container = containerRef.current;\n\n\t\tlet tapipayInstance: TapipayInstance | null = null;\n\t\tlet cancelled = false;\n\n\t\tconst handlePaymentWindowOpened = (\n\t\t\tdata: TapipayPaymentWindowOpenedEvent,\n\t\t) => {\n\t\t\tonPaymentWindowOpenedRef.current?.(data);\n\t\t};\n\t\tconst handlePaymentSubmitted = (data: TapipayPaymentSubmittedEvent) => {\n\t\t\tonPaymentSubmittedRef.current?.(data);\n\t\t};\n\t\tconst handleCancelled = (data: TapipayPaymentCancelledEvent) => {\n\t\t\tonCancelledRef.current?.(data);\n\t\t};\n\t\tconst handleAutopayLoaded = (data: TapipayAutopayLoadedEvent) => {\n\t\t\tonAutopayLoadedRef.current?.(data);\n\t\t};\n\t\tconst handleAutopayRemoved = (data: TapipayAutopayRemovedEvent) => {\n\t\t\tonAutopayRemovedRef.current?.(data);\n\t\t};\n\t\tconst handleAutopayError = (data: TapipayAutopayErrorEvent) => {\n\t\t\tonAutopayErrorRef.current?.(data);\n\t\t};\n\n\t\tloadTapipay({ environment }).then((instance) => {\n\t\t\tif (cancelled) return;\n\t\t\ttapipayInstance = instance;\n\n\t\t\tinstance.on(\"paymentWindowOpened\", handlePaymentWindowOpened);\n\t\t\tinstance.on(\"paymentSubmitted\", handlePaymentSubmitted);\n\t\t\tinstance.on(\"paymentCancelled\", handleCancelled);\n\t\t\tinstance.on(\"autopayLoaded\", handleAutopayLoaded);\n\t\t\tinstance.on(\"autopayRemoved\", handleAutopayRemoved);\n\t\t\tinstance.on(\"autopayError\", handleAutopayError);\n\n\t\t\tinstance.initialize({\n\t\t\t\tcontainer,\n\t\t\t\torganization,\n\t\t\t\tidentifier,\n\t\t\t\texternalRequestId,\n\t\t\t\tselectionStrategy,\n\t\t\t\tview,\n\t\t\t});\n\t\t});\n\n\t\treturn () => {\n\t\t\tcancelled = true;\n\t\t\tif (tapipayInstance) {\n\t\t\t\ttapipayInstance.off(\"paymentWindowOpened\", handlePaymentWindowOpened);\n\t\t\t\ttapipayInstance.off(\"paymentSubmitted\", handlePaymentSubmitted);\n\t\t\t\ttapipayInstance.off(\"paymentCancelled\", handleCancelled);\n\t\t\t\ttapipayInstance.off(\"autopayLoaded\", handleAutopayLoaded);\n\t\t\t\ttapipayInstance.off(\"autopayRemoved\", handleAutopayRemoved);\n\t\t\t\ttapipayInstance.off(\"autopayError\", handleAutopayError);\n\t\t\t\ttapipayInstance.destroy(container);\n\t\t\t}\n\t\t};\n\t\t// El widget se re-monta si cambian los parámetros de identificación o entorno\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t}, [\n\t\torganization,\n\t\tidentifier,\n\t\texternalRequestId,\n\t\tselectionStrategy,\n\t\tview,\n\t\tenvironment,\n\t]);\n\n\treturn <div ref={containerRef} className={className} style={style} />;\n}\n"],"mappings":";;;;;AAAA,SAAS,WAAW,QAAQ,gBAAgB;AA4NpC;AAnMD,SAAS,WAAW,SAGzB;AACD,QAAM,CAAC,SAAS,UAAU,IAAI,SAAiC,IAAI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AAgB,IAAI,oBAAoB,eAAe;AACvD,wBAAgB,IAAI,iBAAiB,mBAAmB;AACxD,wBAAgB,IAAI,kBAAkB,oBAAoB;AAC1D,wBAAgB,IAAI,gBAAgB,kBAAkB;AACtD,wBAAgB,QAAQ,SAAS;AAAA,MAClC;AAAA,IACD;AAAA,EAGD,GAAG;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD,CAAC;AAED,SAAO,oBAAC,SAAI,KAAK,cAAc,WAAsB,OAAc;AACpE;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/react.tsx"],"sourcesContent":["import { useEffect, useRef, useState } from \"react\";\nimport { loadTapipay } from \"./loader\";\nimport type {\n\tLoadTapipayOptions,\n\tTapipayAutopayActivatedEvent,\n\tTapipayAutopayErrorEvent,\n\tTapipayAutopayLoadedEvent,\n\tTapipayAutopayRemovedEvent,\n\tTapipayEnvironment,\n\tTapipayInstance,\n\tTapipayOptions,\n\tTapipayPaymentCancelledEvent,\n\tTapipayPaymentSubmittedEvent,\n\tTapipayPaymentWindowOpenedEvent,\n} from \"./types\";\n\n// ─── useTapipay hook ──────────────────────────────────────────────────────────\n\n/**\n * Hook de bajo nivel que carga el SDK y retorna la instancia.\n * Útil cuando necesitas control manual sobre initialize/destroy.\n *\n * @example\n * const { tapipay, error } = useTapipay();\n * const { tapipay, error } = useTapipay({ environment: 'homo' });\n */\nexport function useTapipay(options?: LoadTapipayOptions): {\n\ttapipay: TapipayInstance | null;\n\terror: Error | null;\n} {\n\tconst [tapipay, setTapipay] = useState<TapipayInstance | null>(null);\n\tconst [error, setError] = useState<Error | null>(null);\n\tconst environment = options?.environment;\n\n\tuseEffect(() => {\n\t\tlet cancelled = false;\n\t\tloadTapipay({ environment })\n\t\t\t.then((instance) => {\n\t\t\t\tif (!cancelled) setTapipay(instance);\n\t\t\t})\n\t\t\t.catch((err: Error) => {\n\t\t\t\tif (!cancelled) setError(err);\n\t\t\t});\n\t\treturn () => {\n\t\t\tcancelled = true;\n\t\t};\n\t}, [environment]);\n\n\treturn { tapipay, error };\n}\n\n// ─── TapipayWidget component ──────────────────────────────────────────────────\n\nexport interface TapipayWidgetProps extends Omit<TapipayOptions, \"container\"> {\n\t/** Entorno del SDK a cargar. Por defecto `'production'`. Usar `'homo'` para homologación. */\n\tenvironment?: TapipayEnvironment;\n\t/** Callback invocado cuando el popup de Yuno se abre exitosamente. */\n\tonPaymentWindowOpened?: (data: TapipayPaymentWindowOpenedEvent) => void;\n\t/** Callback invocado cuando el usuario completó el formulario de Yuno y fue redirigido al callback. */\n\tonPaymentSubmitted?: (data: TapipayPaymentSubmittedEvent) => void;\n\t/** Callback invocado cuando el usuario cierra el popup sin completar el pago. */\n\tonCancelled?: (data: TapipayPaymentCancelledEvent) => void;\n\t/** (Vista autopay) Callback con el conjunto de adhesiones activas; se reinvoca cuando la lista cambia. */\n\tonAutopayLoaded?: (data: TapipayAutopayLoadedEvent) => void;\n\t/** (Vista autopay) Callback cuando una nueva adhesión queda activa (una sola vez por adhesión nueva). */\n\tonAutopayActivated?: (data: TapipayAutopayActivatedEvent) => void;\n\t/** (Vista autopay) Callback cuando el usuario desadhiere un medio con éxito. */\n\tonAutopayRemoved?: (data: TapipayAutopayRemovedEvent) => void;\n\t/** (Vista autopay) Callback ante un error de carga de adhesiones o de desadhesión. */\n\tonAutopayError?: (data: TapipayAutopayErrorEvent) => void;\n\t/** Clases CSS adicionales para el contenedor del widget. */\n\tclassName?: string;\n\t/** Estilos inline adicionales para el contenedor del widget. */\n\tstyle?: React.CSSProperties;\n}\n\n/**\n * Componente React que encapsula el widget de pago TapiPay.\n *\n * Maneja internamente la carga del SDK, el ciclo de vida del widget\n * y el cleanup al desmontar. Compatible con React Strict Mode.\n *\n * @example\n * // Vista de pagos (default)\n * <TapipayWidget\n * organization=\"acme\"\n * identifier=\"CLI-001\"\n * externalRequestId=\"FAC-2024-001\"\n * onPaymentSubmitted={(data) => console.log(\"Pago enviado\", data)}\n * onCancelled={() => console.log(\"Pago cancelado por el usuario\")}\n * />\n *\n * @example\n * // Vista de gestión de adhesiones de autopay\n * <TapipayWidget\n * organization=\"acme\"\n * identifier=\"CLI-001\"\n * view=\"autopay\"\n * onAutopayLoaded={(data) => console.log(\"Adhesiones\", data.count)}\n * onAutopayActivated={(data) => console.log(\"Adhesión activada\", data.id)}\n * onAutopayRemoved={(data) => console.log(\"Adhesión eliminada\", data.id)}\n * />\n */\nexport function TapipayWidget({\n\torganization,\n\tidentifier,\n\texternalRequestId,\n\tselectionStrategy,\n\tview,\n\tenvironment,\n\tonPaymentWindowOpened,\n\tonPaymentSubmitted,\n\tonCancelled,\n\tonAutopayLoaded,\n\tonAutopayActivated,\n\tonAutopayRemoved,\n\tonAutopayError,\n\tclassName,\n\tstyle,\n}: TapipayWidgetProps) {\n\tconst containerRef = useRef<HTMLDivElement>(null);\n\t// Refs para evitar re-renders innecesarios y closures estáticos en useEffect\n\tconst onPaymentWindowOpenedRef = useRef(onPaymentWindowOpened);\n\tconst onPaymentSubmittedRef = useRef(onPaymentSubmitted);\n\tconst onCancelledRef = useRef(onCancelled);\n\tconst onAutopayLoadedRef = useRef(onAutopayLoaded);\n\tconst onAutopayActivatedRef = useRef(onAutopayActivated);\n\tconst onAutopayRemovedRef = useRef(onAutopayRemoved);\n\tconst onAutopayErrorRef = useRef(onAutopayError);\n\n\tuseEffect(() => {\n\t\tonPaymentWindowOpenedRef.current = onPaymentWindowOpened;\n\t}, [onPaymentWindowOpened]);\n\n\tuseEffect(() => {\n\t\tonPaymentSubmittedRef.current = onPaymentSubmitted;\n\t}, [onPaymentSubmitted]);\n\n\tuseEffect(() => {\n\t\tonCancelledRef.current = onCancelled;\n\t}, [onCancelled]);\n\n\tuseEffect(() => {\n\t\tonAutopayLoadedRef.current = onAutopayLoaded;\n\t}, [onAutopayLoaded]);\n\n\tuseEffect(() => {\n\t\tonAutopayActivatedRef.current = onAutopayActivated;\n\t}, [onAutopayActivated]);\n\n\tuseEffect(() => {\n\t\tonAutopayRemovedRef.current = onAutopayRemoved;\n\t}, [onAutopayRemoved]);\n\n\tuseEffect(() => {\n\t\tonAutopayErrorRef.current = onAutopayError;\n\t}, [onAutopayError]);\n\n\tuseEffect(() => {\n\t\tif (!containerRef.current) return;\n\t\tconst container = containerRef.current;\n\n\t\tlet tapipayInstance: TapipayInstance | null = null;\n\t\tlet cancelled = false;\n\n\t\tconst handlePaymentWindowOpened = (\n\t\t\tdata: TapipayPaymentWindowOpenedEvent,\n\t\t) => {\n\t\t\tonPaymentWindowOpenedRef.current?.(data);\n\t\t};\n\t\tconst handlePaymentSubmitted = (data: TapipayPaymentSubmittedEvent) => {\n\t\t\tonPaymentSubmittedRef.current?.(data);\n\t\t};\n\t\tconst handleCancelled = (data: TapipayPaymentCancelledEvent) => {\n\t\t\tonCancelledRef.current?.(data);\n\t\t};\n\t\tconst handleAutopayLoaded = (data: TapipayAutopayLoadedEvent) => {\n\t\t\tonAutopayLoadedRef.current?.(data);\n\t\t};\n\t\tconst handleAutopayActivated = (data: TapipayAutopayActivatedEvent) => {\n\t\t\tonAutopayActivatedRef.current?.(data);\n\t\t};\n\t\tconst handleAutopayRemoved = (data: TapipayAutopayRemovedEvent) => {\n\t\t\tonAutopayRemovedRef.current?.(data);\n\t\t};\n\t\tconst handleAutopayError = (data: TapipayAutopayErrorEvent) => {\n\t\t\tonAutopayErrorRef.current?.(data);\n\t\t};\n\n\t\tloadTapipay({ environment }).then((instance) => {\n\t\t\tif (cancelled) return;\n\t\t\ttapipayInstance = instance;\n\n\t\t\tinstance.on(\"paymentWindowOpened\", handlePaymentWindowOpened);\n\t\t\tinstance.on(\"paymentSubmitted\", handlePaymentSubmitted);\n\t\t\tinstance.on(\"paymentCancelled\", handleCancelled);\n\t\t\tinstance.on(\"autopayLoaded\", handleAutopayLoaded);\n\t\t\tinstance.on(\"autopayActivated\", handleAutopayActivated);\n\t\t\tinstance.on(\"autopayRemoved\", handleAutopayRemoved);\n\t\t\tinstance.on(\"autopayError\", handleAutopayError);\n\n\t\t\tinstance.initialize({\n\t\t\t\tcontainer,\n\t\t\t\torganization,\n\t\t\t\tidentifier,\n\t\t\t\texternalRequestId,\n\t\t\t\tselectionStrategy,\n\t\t\t\tview,\n\t\t\t});\n\t\t});\n\n\t\treturn () => {\n\t\t\tcancelled = true;\n\t\t\tif (tapipayInstance) {\n\t\t\t\ttapipayInstance.off(\"paymentWindowOpened\", handlePaymentWindowOpened);\n\t\t\t\ttapipayInstance.off(\"paymentSubmitted\", handlePaymentSubmitted);\n\t\t\t\ttapipayInstance.off(\"paymentCancelled\", handleCancelled);\n\t\t\t\ttapipayInstance.off(\"autopayLoaded\", handleAutopayLoaded);\n\t\t\t\ttapipayInstance.off(\"autopayActivated\", handleAutopayActivated);\n\t\t\t\ttapipayInstance.off(\"autopayRemoved\", handleAutopayRemoved);\n\t\t\t\ttapipayInstance.off(\"autopayError\", handleAutopayError);\n\t\t\t\ttapipayInstance.destroy(container);\n\t\t\t}\n\t\t};\n\t\t// El widget se re-monta si cambian los parámetros de identificación o entorno\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t}, [\n\t\torganization,\n\t\tidentifier,\n\t\texternalRequestId,\n\t\tselectionStrategy,\n\t\tview,\n\t\tenvironment,\n\t]);\n\n\treturn <div ref={containerRef} className={className} style={style} />;\n}\n"],"mappings":";;;;;AAAA,SAAS,WAAW,QAAQ,gBAAgB;AA2OpC;AAjND,SAAS,WAAW,SAGzB;AACD,QAAM,CAAC,SAAS,UAAU,IAAI,SAAiC,IAAI;AACnE,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAuB,IAAI;AACrD,QAAM,cAAc,mCAAS;AAE7B,YAAU,MAAM;AACf,QAAI,YAAY;AAChB,gBAAY,EAAE,YAAY,CAAC,EACzB,KAAK,CAAC,aAAa;AACnB,UAAI,CAAC,UAAW,YAAW,QAAQ;AAAA,IACpC,CAAC,EACA,MAAM,CAAC,QAAe;AACtB,UAAI,CAAC,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Ae;AACvD,wBAAgB,IAAI,iBAAiB,mBAAmB;AACxD,wBAAgB,IAAI,oBAAoB,sBAAsB;AAC9D,wBAAgB,IAAI,kBAAkB,oBAAoB;AAC1D,wBAAgB,IAAI,gBAAgB,kBAAkB;AACtD,wBAAgB,QAAQ,SAAS;AAAA,MAClC;AAAA,IACD;AAAA,EAGD,GAAG;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD,CAAC;AAED,SAAO,oBAAC,SAAI,KAAK,cAAc,WAAsB,OAAc;AACpE;","names":[]}
|
|
@@ -94,6 +94,18 @@ interface TapipayAutopayLoadedEvent {
|
|
|
94
94
|
/** Resumen mínimo por adhesión activa. */
|
|
95
95
|
adhesions: TapipayAutopayAdhesionSummary[];
|
|
96
96
|
}
|
|
97
|
+
/**
|
|
98
|
+
* Payload del evento autopayActivated.
|
|
99
|
+
* Una nueva adhesión quedó activa (se dispara una sola vez por adhesión nueva).
|
|
100
|
+
*/
|
|
101
|
+
interface TapipayAutopayActivatedEvent {
|
|
102
|
+
/** Hash opaco del identificador de la adhesión activada. */
|
|
103
|
+
id: string;
|
|
104
|
+
/** Tipo de medio de la adhesión activada. */
|
|
105
|
+
mediaType: TapipayAutopayMediaType;
|
|
106
|
+
/** Últimos 4 dígitos del medio activado. `null` si no aplica. */
|
|
107
|
+
lastFour: string | null;
|
|
108
|
+
}
|
|
97
109
|
/**
|
|
98
110
|
* Payload del evento autopayRemoved.
|
|
99
111
|
* El usuario desadhirió un medio con éxito.
|
|
@@ -127,12 +139,14 @@ interface TapipayInstance {
|
|
|
127
139
|
on(event: "paymentSubmitted", handler: (data: TapipayPaymentSubmittedEvent) => void): void;
|
|
128
140
|
on(event: "paymentCancelled", handler: (data: TapipayPaymentCancelledEvent) => void): void;
|
|
129
141
|
on(event: "autopayLoaded", handler: (data: TapipayAutopayLoadedEvent) => void): void;
|
|
142
|
+
on(event: "autopayActivated", handler: (data: TapipayAutopayActivatedEvent) => void): void;
|
|
130
143
|
on(event: "autopayRemoved", handler: (data: TapipayAutopayRemovedEvent) => void): void;
|
|
131
144
|
on(event: "autopayError", handler: (data: TapipayAutopayErrorEvent) => void): void;
|
|
132
145
|
off(event: "paymentWindowOpened", handler: (data: TapipayPaymentWindowOpenedEvent) => void): void;
|
|
133
146
|
off(event: "paymentSubmitted", handler: (data: TapipayPaymentSubmittedEvent) => void): void;
|
|
134
147
|
off(event: "paymentCancelled", handler: (data: TapipayPaymentCancelledEvent) => void): void;
|
|
135
148
|
off(event: "autopayLoaded", handler: (data: TapipayAutopayLoadedEvent) => void): void;
|
|
149
|
+
off(event: "autopayActivated", handler: (data: TapipayAutopayActivatedEvent) => void): void;
|
|
136
150
|
off(event: "autopayRemoved", handler: (data: TapipayAutopayRemovedEvent) => void): void;
|
|
137
151
|
off(event: "autopayError", handler: (data: TapipayAutopayErrorEvent) => void): void;
|
|
138
152
|
off(event: string, handler: (...args: unknown[]) => unknown): void;
|
|
@@ -145,4 +159,4 @@ declare global {
|
|
|
145
159
|
}
|
|
146
160
|
}
|
|
147
161
|
|
|
148
|
-
export type { LoadTapipayOptions as L, TapipayInstance as T,
|
|
162
|
+
export type { LoadTapipayOptions as L, TapipayInstance as T, TapipayAutopayActivatedEvent as a, TapipayAutopayAdhesionSummary as b, TapipayAutopayErrorEvent as c, TapipayAutopayLoadedEvent as d, TapipayAutopayMediaType as e, TapipayAutopayRemovedEvent as f, TapipayEnvironment as g, TapipayOptions as h, TapipayPaymentCancelledEvent as i, TapipayPaymentSubmittedEvent as j, TapipayPaymentWindowOpenedEvent as k, TapipayView as l };
|
|
@@ -94,6 +94,18 @@ interface TapipayAutopayLoadedEvent {
|
|
|
94
94
|
/** Resumen mínimo por adhesión activa. */
|
|
95
95
|
adhesions: TapipayAutopayAdhesionSummary[];
|
|
96
96
|
}
|
|
97
|
+
/**
|
|
98
|
+
* Payload del evento autopayActivated.
|
|
99
|
+
* Una nueva adhesión quedó activa (se dispara una sola vez por adhesión nueva).
|
|
100
|
+
*/
|
|
101
|
+
interface TapipayAutopayActivatedEvent {
|
|
102
|
+
/** Hash opaco del identificador de la adhesión activada. */
|
|
103
|
+
id: string;
|
|
104
|
+
/** Tipo de medio de la adhesión activada. */
|
|
105
|
+
mediaType: TapipayAutopayMediaType;
|
|
106
|
+
/** Últimos 4 dígitos del medio activado. `null` si no aplica. */
|
|
107
|
+
lastFour: string | null;
|
|
108
|
+
}
|
|
97
109
|
/**
|
|
98
110
|
* Payload del evento autopayRemoved.
|
|
99
111
|
* El usuario desadhirió un medio con éxito.
|
|
@@ -127,12 +139,14 @@ interface TapipayInstance {
|
|
|
127
139
|
on(event: "paymentSubmitted", handler: (data: TapipayPaymentSubmittedEvent) => void): void;
|
|
128
140
|
on(event: "paymentCancelled", handler: (data: TapipayPaymentCancelledEvent) => void): void;
|
|
129
141
|
on(event: "autopayLoaded", handler: (data: TapipayAutopayLoadedEvent) => void): void;
|
|
142
|
+
on(event: "autopayActivated", handler: (data: TapipayAutopayActivatedEvent) => void): void;
|
|
130
143
|
on(event: "autopayRemoved", handler: (data: TapipayAutopayRemovedEvent) => void): void;
|
|
131
144
|
on(event: "autopayError", handler: (data: TapipayAutopayErrorEvent) => void): void;
|
|
132
145
|
off(event: "paymentWindowOpened", handler: (data: TapipayPaymentWindowOpenedEvent) => void): void;
|
|
133
146
|
off(event: "paymentSubmitted", handler: (data: TapipayPaymentSubmittedEvent) => void): void;
|
|
134
147
|
off(event: "paymentCancelled", handler: (data: TapipayPaymentCancelledEvent) => void): void;
|
|
135
148
|
off(event: "autopayLoaded", handler: (data: TapipayAutopayLoadedEvent) => void): void;
|
|
149
|
+
off(event: "autopayActivated", handler: (data: TapipayAutopayActivatedEvent) => void): void;
|
|
136
150
|
off(event: "autopayRemoved", handler: (data: TapipayAutopayRemovedEvent) => void): void;
|
|
137
151
|
off(event: "autopayError", handler: (data: TapipayAutopayErrorEvent) => void): void;
|
|
138
152
|
off(event: string, handler: (...args: unknown[]) => unknown): void;
|
|
@@ -145,4 +159,4 @@ declare global {
|
|
|
145
159
|
}
|
|
146
160
|
}
|
|
147
161
|
|
|
148
|
-
export type { LoadTapipayOptions as L, TapipayInstance as T,
|
|
162
|
+
export type { LoadTapipayOptions as L, TapipayInstance as T, TapipayAutopayActivatedEvent as a, TapipayAutopayAdhesionSummary as b, TapipayAutopayErrorEvent as c, TapipayAutopayLoadedEvent as d, TapipayAutopayMediaType as e, TapipayAutopayRemovedEvent as f, TapipayEnvironment as g, TapipayOptions as h, TapipayPaymentCancelledEvent as i, TapipayPaymentSubmittedEvent as j, TapipayPaymentWindowOpenedEvent as k, TapipayView as l };
|