@@ -86,7 +86,7 @@ export async function action({ request }: Route.ActionArgs) {
8686 const token = formData . get ( "token" ) as string ;
8787
8888 const body = {
89- amount : 2000 ,
89+ amount : 2000 , // TODO: Calculate total dynamically
9090 currency_code : "PEN" ,
9191 email : shippingDetails . email ,
9292 source_id : token ,
@@ -97,14 +97,15 @@ export async function action({ request }: Route.ActionArgs) {
9797 method : "POST" ,
9898 headers : {
9999 "content-type" : "application/json" ,
100- Authorization : `Bearer sk_test_EC8oOLd3ZiCTKqjN` ,
100+ Authorization : `Bearer sk_test_EC8oOLd3ZiCTKqjN` , // TODO: Use environment variable
101101 } ,
102102 body : JSON . stringify ( body ) ,
103103 } ) ;
104104
105105 if ( ! response . ok ) {
106106 const errorData = await response . json ( ) ;
107107 console . error ( "Error creating charge:" , errorData ) ;
108+ // TODO: Handle error appropriately
108109 throw new Error ( "Error processing payment" ) ;
109110 }
110111
@@ -118,7 +119,7 @@ export async function action({ request }: Route.ActionArgs) {
118119
119120 // TODO
120121 // @ts -expect-error Arreglar el tipo de shippingDetails
121- const { id : orderId } = await createOrder ( items , shippingDetails ) ;
122+ const { id : orderId } = await createOrder ( items , shippingDetails ) ; // TODO: Add payment information to the order
122123
123124 await deleteRemoteCart ( request ) ;
124125 const session = await getSession ( request . headers . get ( "Cookie" ) ) ;
@@ -155,6 +156,7 @@ export default function Checkout({ loaderData }: Route.ComponentProps) {
155156 const navigation = useNavigation ( ) ;
156157 const submit = useSubmit ( ) ;
157158 const loading = navigation . state === "submitting" ;
159+
158160 const [ culqui , setCulqui ] = useState < CulqiInstance | null > ( null ) ;
159161 const scriptRef = useRef < HTMLScriptElement | null > ( null ) ;
160162
@@ -221,13 +223,18 @@ export default function Checkout({ loaderData }: Route.ComponentProps) {
221223 . then ( ( CulqiCheckout ) => {
222224 const config = {
223225 settings : {
224- currency : "USD " ,
226+ currency : "PEN " ,
225227 amount : total * 100 ,
226228 } ,
227229 client : {
228230 email : user ?. email ,
229231 } ,
230- options : { } ,
232+ options : {
233+ paymentMethods : {
234+ tarjeta : true ,
235+ yape : false ,
236+ } ,
237+ } ,
231238 appearance : { } ,
232239 } ;
233240
@@ -297,14 +304,14 @@ export default function Checkout({ loaderData }: Route.ComponentProps) {
297304 < div className = "flex text-sm font-medium gap-4 items-center self-end" >
298305 < p > { quantity } </ p >
299306 < X className = "w-4 h-4" />
300- < p > $ { product . price . toFixed ( 2 ) } </ p >
307+ < p > S/ { product . price . toFixed ( 2 ) } </ p >
301308 </ div >
302309 </ div >
303310 </ div >
304311 ) ) }
305312 < div className = "flex justify-between p-6 text-base font-medium" >
306313 < p > Total</ p >
307- < p > $ { total . toFixed ( 2 ) } </ p >
314+ < p > S/ { total . toFixed ( 2 ) } </ p >
308315 </ div >
309316 </ div >
310317 </ div >
0 commit comments