2023-02-02 22:58:44 +00:00
|
|
|
import React, { useEffect, useState } from 'react'
|
2023-02-02 21:19:52 +00:00
|
|
|
import './pix.css'
|
|
|
|
import { useProduct } from 'vtex.product-context'
|
2023-01-12 16:56:35 +00:00
|
|
|
|
2023-02-02 22:58:44 +00:00
|
|
|
const Pix = () => {
|
|
|
|
const [valuePix, setValuePix] = useState(0)
|
|
|
|
|
2023-02-02 21:19:52 +00:00
|
|
|
const productContext = useProduct()
|
|
|
|
|
2023-02-07 13:51:12 +00:00
|
|
|
const total = (valuePix * 0.1 - valuePix / 100) / 10
|
|
|
|
|
2023-02-02 22:58:44 +00:00
|
|
|
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])
|
2023-02-02 21:19:52 +00:00
|
|
|
|
2023-01-12 16:56:35 +00:00
|
|
|
return (
|
2023-02-02 21:19:52 +00:00
|
|
|
<div className="pix-container">
|
|
|
|
<img
|
2023-02-02 22:58:44 +00:00
|
|
|
className="pix-image"
|
2023-02-10 15:33:41 +00:00
|
|
|
src="https://agenciamagma.vteximg.com.br/arquivos/pixIcon-filipequintanilha.png"
|
2023-02-02 21:19:52 +00:00
|
|
|
alt="pix"
|
|
|
|
/>
|
2023-02-02 22:58:44 +00:00
|
|
|
|
|
|
|
<div className="preco-wrapper">
|
|
|
|
<h2 className="preco-pix">
|
2023-02-07 13:51:12 +00:00
|
|
|
{total.toLocaleString('pt-br', {
|
2023-02-02 22:58:44 +00:00
|
|
|
style: 'currency',
|
|
|
|
currency: 'BRL',
|
|
|
|
})}
|
|
|
|
</h2>
|
|
|
|
<p className="desconto-pix">10% de desconto</p>
|
|
|
|
</div>
|
2023-02-02 21:19:52 +00:00
|
|
|
</div>
|
2023-01-12 16:56:35 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2023-02-02 22:58:44 +00:00
|
|
|
export default Pix
|