Add card fields component (WIP)

This commit is contained in:
Emili Castells Guasch 2024-05-15 17:37:02 +02:00
parent 0862e5fb3d
commit e3ac190849
4 changed files with 70 additions and 54 deletions

View file

@ -0,0 +1,33 @@
import {useEffect} from '@wordpress/element';
import {usePayPalCardFields} from "@paypal/react-paypal-js";
export const CheckoutHandler = ({onPaymentSetup, responseTypes}) => {
const {cardFieldsForm} = usePayPalCardFields();
useEffect(() => {
const unsubscribe = onPaymentSetup(async () => {
cardFieldsForm.submit()
.then(() => {
return {
type: responseTypes.SUCCESS,
meta: {
paymentMethodData: {
foo: 'bar',
}
}
};
})
.catch((err) => {
return {
type: responseTypes.ERROR,
message: err
}
});
})
return unsubscribe
}, [onPaymentSetup, cardFieldsForm]);
return null
}