11import { zodResolver } from "@hookform/resolvers/zod" ;
22import { X } from "lucide-react" ;
3+ import { useEffect , useState } from "react" ;
34import { useForm } from "react-hook-form" ;
45import { redirect , useNavigation , useSubmit } from "react-router" ;
56import { z } from "zod" ;
@@ -116,6 +117,7 @@ export default function Checkout({ loaderData }: Route.ComponentProps) {
116117 const navigation = useNavigation ( ) ;
117118 const submit = useSubmit ( ) ;
118119 const loading = navigation . state === "submitting" ;
120+ const [ Culqui , setCulqui ] = useState ( null ) ;
119121
120122 const {
121123 register,
@@ -138,14 +140,95 @@ export default function Checkout({ loaderData }: Route.ComponentProps) {
138140 mode : "onTouched" ,
139141 } ) ;
140142
143+ useEffect ( ( ) => {
144+ const script = document . createElement ( "script" ) ;
145+ script . src = "https://js.culqi.com/checkout-js" ;
146+ script . async = true ;
147+ script . onload = ( ) => {
148+ // Aqui ya existe window.CulqiCheckout
149+ const settings = {
150+ title : "FullStock" ,
151+ currency : "USD" ,
152+ amount : total * 100 , // Este parámetro es requerido para realizar pagos yape(80.00)
153+ // order: "ord_live_d1P0Tu1n7Od4nZdp", // Este parámetro es requerido para realizar pagos con pagoEfectivo, billeteras y Cuotéalo
154+ // xculqirsaid: "Inserta aquí el id de tu llave pública RSA",
155+ // rsapublickey: "Inserta aquí tu llave pública RSA",
156+ } ;
157+
158+ const paymentMethods = {
159+ // las opciones se ordenan según se configuren
160+ tarjeta : true ,
161+ yape : false ,
162+ billetera : false ,
163+ bancaMovil : false ,
164+ agente : false ,
165+ cuotealo : false ,
166+ } ;
167+
168+ const options = {
169+ lang : "auto" ,
170+ installments : true , // Habilitar o deshabilitar el campo de cuotas
171+ modal : true ,
172+ // container: "#culqi-container", // Opcional - Div donde quieres cargar el checkout
173+ paymentMethods : paymentMethods ,
174+ paymentMethodsSort : Object . keys ( paymentMethods ) , // las opciones se ordenan según se configuren en paymentMethods
175+ } ;
176+
177+ const appearance = {
178+ theme : "default" ,
179+ hiddenCulqiLogo : false ,
180+ hiddenBannerContent : false ,
181+ hiddenBanner : false ,
182+ hiddenToolBarAmount : false ,
183+ hiddenEmail : false ,
184+ menuType : "select" , // sidebar / sliderTop / select
185+ buttonCardPayText : "Pagar" , //
186+ logo : null , // 'http://www.childrensociety.ms/wp-content/uploads/2019/11/MCS-Logo-2019-no-text.jpg',
187+ defaultStyle : {
188+ bannerColor : "blue" , // hexadecimal
189+ buttonBackground : "yellow" , // hexadecimal
190+ menuColor : "pink" , // hexadecimal
191+ linksColor : "green" , // hexadecimal
192+ buttonTextColor : "blue" , // hexadecimal
193+ priceColor : "red" ,
194+ } ,
195+ } ;
196+
197+ const config = {
198+ settings,
199+ // client,
200+ options,
201+ appearance,
202+ } ;
203+
204+ const publicKey = "pk_test_Ws4NXfH95QXlZgaz" ;
205+ // @ts -ignore
206+ const Culqi = new window . CulqiCheckout ( publicKey , config ) ;
207+
208+ setCulqui ( Culqi ) ;
209+
210+ console . log ( "Script loaded" ) ;
211+ } ;
212+
213+ document . body . appendChild ( script ) ;
214+
215+ // Cleanup function
216+ return ( ) => {
217+ document . body . removeChild ( script ) ;
218+ } ;
219+ } , [ ] ) ;
220+
141221 async function onSubmit ( formData : CheckoutForm ) {
142- submit (
143- {
144- shippingDetailsJson : JSON . stringify ( formData ) ,
145- cartItemsJson : JSON . stringify ( cart . items ) ,
146- } ,
147- { method : "POST" }
148- ) ;
222+ // submit(
223+ // {
224+ // shippingDetailsJson: JSON.stringify(formData),
225+ // cartItemsJson: JSON.stringify(cart.items),
226+ // },
227+ // { method: "POST" }
228+ // );
229+ if ( Culqui ) {
230+ Culqui . open ( ) ;
231+ }
149232 }
150233
151234 return (
0 commit comments