Repository navigation
feat(PaymentButton): createCheckout inyectable; url y publicToken deprecados - #6
Merged
Merged
Conversation
…oken
PaymentButton accepts createCheckout: () => Promise<{ checkoutId }> so the
checkout can be created by the merchant's backend and the credential never
reaches the browser. url, publicToken and checkoutData become optional and
deprecated; the prop types require one mode or the other. Without
createCheckout the behavior is unchanged, apart from a one-time
development warning pointing to the README.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #5
Problema
PaymentButtoncrea el checkout desde el navegador conaxios.post(url, checkoutData, { headers: { Authorization: Bearer <publicToken> } }). El token viaja en el bundle y el cliente decide el monto que envía. No había forma de delegar la creación del checkout en el backend del comercio, que es donde debe vivir la credencial.Qué cambia
src/components/PaymentButton.tsxcreateCheckout: () => Promise<{ checkoutId: string }>. Cuando está presente, el botón la llama en lugar delPOST, muestra el spinner mientras la promesa está pendiente y usa elcheckoutIddevuelto igual que antes (openSandbox, reinicio del guard de resultado,onSuccess({ checkoutId })). Un rechazo va aonErrory no abre el iframe.InjectedCheckout | LegacyCheckout<T>, combinada concheckoutyregistration.url,publicTokenycheckoutDatallevan@deprecatedy TypeScript exige un modo completo, sin mezclar los dos.createCheckoutelPOSTes idéntico al de 3.0.1. Lo único nuevo es unconsole.warnpor instancia, fuera deproduction, en el primer clic, con enlace al README.startCheckout; su nombre público sigue siendocreateCheckout.url/publicToken/checkoutDatamarcados como deprecados, sección nueva "Crear el checkout desde tu backend" con un ejemplo, y los ejemplos de uso migrados acreateCheckout.minor→ 3.1.0.Uso
Evidencia
Tests nuevos en
src/components/PaymentButton.test.tsx, escritos antes del código. Con elPaymentButton.tsxdemain(la implementación revertida), fallan los cinco que pide el issue:Con la implementación restaurada:
Un sexto test,
does not warn when createCheckout is injected, sirve de guarda y ya pasaba contramain, así que no cuenta como evidencia rojo/verde. Los 13 tests anteriores del archivo pasan sin cambios.yarn ci(build de Tailwind +tsc,prettier --check, vitest), local: exit 0,Test Files 3 passed (3),Tests 29 passed (29). El repo no tiene script de lint:yarn cies la puerta completa.tscexcluye los archivos de test.Tipos: lo verifiqué con un archivo temporal (sin commitear) que pasa
tsc --noEmit. Acepta 4 formas: modo inyectado, legadocheckout, legadoregistrationsincart, e inyectado con render-prop. Rechaza 3, marcadas con@ts-expect-error: ningún modo, legado sinpublicToken, ycreateCheckoutjunto conurl.Detalles
console.warnque cuenta el test existentewarns once when a pending message arrives without a handler, y ese test debía pasar sin cambios. El aviso es por instancia (useRef), igual que el aviso deonPendingTransaction.e.source. El issue la marca como no bloqueante y el comportamiento sigue igual que en 3.0.1.Releaseabrechore: version packages; al mergear ese PR se publica 3.1.0. Después hay que comprobarnpm view @insoutt/datafast-react@3.1.0. El issue pide que se cierre cuando 3.1.0 esté en npm, peroCloses #5lo cierra al mergear este PR.ELI5
Antes, el botón de pago le pedía al navegador que creara el cobro con una llave que cualquiera podía ver. Ahora el botón le pregunta a tu propio servidor, que guarda la llave, y sólo recibe el número del cobro. La forma antigua sigue funcionando por ahora, pero avisa que va a desaparecer.