Add place order logic (WIP)

This commit is contained in:
Emili Castells Guasch 2024-05-20 16:37:11 +02:00
parent 4b3cd53f73
commit e93e9db3be
6 changed files with 115 additions and 20 deletions

View file

@ -1,23 +1,12 @@
import {useEffect} from '@wordpress/element';
import {usePayPalCardFields} from "@paypal/react-paypal-js";
export const CheckoutHandler = ({onPaymentSetup, responseTypes}) => {
export const CheckoutHandler = ({getCardFieldsForm}) => {
const {cardFieldsForm} = usePayPalCardFields();
useEffect(() => {
const unsubscribe = onPaymentSetup(async () => {
await cardFieldsForm.submit()
.catch((error) => {
console.error(error)
return {
type: responseTypes.ERROR,
}
});
})
return unsubscribe
}, [onPaymentSetup, cardFieldsForm]);
getCardFieldsForm(cardFieldsForm)
}, []);
return null
}