| 1 |
|
| 2 |
import { Helmet } from "react-helmet"; |
| 3 |
import { useState, useEffect, useRef } from 'react' |
| 4 |
import { clearUpCopyAndPay, generateOptions, useFetch } from './Helpers'; |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
const ApplePay = React.memo((props) => { |
| 9 |
|
| 10 |
const [checkoutId, setCheckoutId] = useState(null) |
| 11 |
const shippingMethod = useRef(null) |
| 12 |
|
| 13 |
useEffect(() => { |
| 14 |
useFetch("hyperpay_prepare_checkout") |
| 15 |
.get("").then(res => { |
| 16 |
setCheckoutId(res.data) |
| 17 |
window.wpwlOptions = generateOptions(props, shippingMethod, res.data); |
| 18 |
}) |
| 19 |
|
| 20 |
return clearUpCopyAndPay() |
| 21 |
|
| 22 |
}, []) |
| 23 |
|
| 24 |
|
| 25 |
return ( |
| 26 |
<div> |
| 27 |
{checkoutId && <div> |
| 28 |
<form action="" className="paymentWidgets" data-brands={props.setting.brands}></form> |
| 29 |
<Helmet> |
| 30 |
<script src={`https://eu-test.oppwa.com/v1/paymentWidgets.js?checkoutId=${checkoutId}`}></script> |
| 31 |
</Helmet> |
| 32 |
</div> |
| 33 |
} |
| 34 |
</div> |
| 35 |
) |
| 36 |
|
| 37 |
}, () => true) |
| 38 |
|
| 39 |
|
| 40 |
export default ApplePay |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|