PluginProbe
HyperPay Payments / trunk
HyperPay Payments vtrunk
6.6.0 trunk 1.7 1.8 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.1.0 2.2.0 2.3.0 2.3.1 2.3.2 2.3.3 3.0.0 3.0.5 4.0.0 4.0.2 All 34 releases
hyperpay-gateways / src / assets / js / ExpressComponent.jsx

ExpressComponent.jsx in HyperPay Payments trunk, at src/assets/js/ExpressComponent.jsx

51 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import React, { useState, useEffect, useRef } from 'react';
2 import { Helmet } from 'react-helmet';
3 import { clearUpCopyAndPay, generateOptions, useFetch } from './Helpers';
4
5 const ExpressComponent = React.memo((props) => {
6 const [checkoutId, setCheckoutId] = useState(null);
7 const shippingMethod = useRef(null);
8 const containerRef = useRef(null);
9
10 useEffect(() => {
11 useFetch('hyperpay_prepare_checkout')
12 .get('')
13 .then((res) => {
14 const id = res.data;
15 window.wpwlOptions = generateOptions(props, shippingMethod, id);
16 setCheckoutId(id);
17 });
18
19 return () => clearUpCopyAndPay();
20 }, []);
21
22 useEffect(() => {
23 if (!checkoutId || !containerRef.current) {
24 return;
25 }
26
27 containerRef.current.innerHTML = '';
28
29 const form = document.createElement('form');
30 form.className = 'paymentWidgets';
31 form.setAttribute('data-brands', props.setting.brands);
32
33 containerRef.current.appendChild(form);
34 }, [checkoutId]);
35
36 return (
37 <div>
38 {checkoutId && (
39 <>
40 <div ref={containerRef}></div>
41
42 <Helmet>
43 <script src={`${props.setting.script_url}${checkoutId}`}></script>
44 </Helmet>
45 </>
46 )}
47 </div>
48 );
49 }, () => true);
50
51 export default ExpressComponent;