import React, { useEffect, useState } from 'react' import './pix.css' import { useProduct } from 'vtex.product-context' const Pix = () => { const [valuePix, setValuePix] = useState(0) const productContext = useProduct() const total = (valuePix * 0.1 - valuePix / 100) / 10 const objectPass = [ { id: productContext?.selectedItem?.itemId, quantity: 1, seller: productContext?.selectedItem?.sellers[0].sellerId, }, ] async function request() { const response = await fetch('/api/checkout/pub/orderForms/simulation', { method: 'POST', headers: { 'content-type': 'application/json', }, body: JSON.stringify({ items: objectPass, country: 'BRA', postalCode: '', }), }) const data = await response.json() const getPix = data.paymentData.installmentOptions.find( (elemento: { paymentName: string }) => { return elemento.paymentName === 'Pix' } ) setValuePix(getPix.value) console.log(getPix) } useEffect(() => { request() }, [productContext?.selectedItem]) return (
pix

{total.toLocaleString('pt-br', { style: 'currency', currency: 'BRL', })}

10% de desconto

) } export default Pix