mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Run eslint autofix
This commit is contained in:
parent
36a13f6500
commit
11105d913b
141 changed files with 14160 additions and 11825 deletions
|
@ -1,87 +1,95 @@
|
|||
import {useEffect, useState} from '@wordpress/element';
|
||||
import { useEffect, useState } from '@wordpress/element';
|
||||
|
||||
import {
|
||||
PayPalScriptProvider,
|
||||
PayPalCardFieldsProvider,
|
||||
PayPalCardFieldsForm,
|
||||
} from "@paypal/react-paypal-js";
|
||||
PayPalScriptProvider,
|
||||
PayPalCardFieldsProvider,
|
||||
PayPalCardFieldsForm,
|
||||
} from '@paypal/react-paypal-js';
|
||||
|
||||
import {CheckoutHandler} from "./checkout-handler";
|
||||
import {createOrder, onApprove} from "../card-fields-config";
|
||||
import {cartHasSubscriptionProducts} from "../Helper/Subscription";
|
||||
import { CheckoutHandler } from './checkout-handler';
|
||||
import { createOrder, onApprove } from '../card-fields-config';
|
||||
import { cartHasSubscriptionProducts } from '../Helper/Subscription';
|
||||
|
||||
export function CardFields({config, eventRegistration, emitResponse, components}) {
|
||||
const {onPaymentSetup} = eventRegistration;
|
||||
const {responseTypes} = emitResponse;
|
||||
const { PaymentMethodIcons } = components;
|
||||
export function CardFields( {
|
||||
config,
|
||||
eventRegistration,
|
||||
emitResponse,
|
||||
components,
|
||||
} ) {
|
||||
const { onPaymentSetup } = eventRegistration;
|
||||
const { responseTypes } = emitResponse;
|
||||
const { PaymentMethodIcons } = components;
|
||||
|
||||
const [cardFieldsForm, setCardFieldsForm] = useState();
|
||||
const getCardFieldsForm = (cardFieldsForm) => {
|
||||
setCardFieldsForm(cardFieldsForm)
|
||||
}
|
||||
const [ cardFieldsForm, setCardFieldsForm ] = useState();
|
||||
const getCardFieldsForm = ( cardFieldsForm ) => {
|
||||
setCardFieldsForm( cardFieldsForm );
|
||||
};
|
||||
|
||||
const getSavePayment = (savePayment) => {
|
||||
localStorage.setItem('ppcp-save-card-payment', savePayment);
|
||||
}
|
||||
const getSavePayment = ( savePayment ) => {
|
||||
localStorage.setItem( 'ppcp-save-card-payment', savePayment );
|
||||
};
|
||||
|
||||
const hasSubscriptionProducts = cartHasSubscriptionProducts(config.scriptData);
|
||||
useEffect(() => {
|
||||
localStorage.removeItem('ppcp-save-card-payment');
|
||||
const hasSubscriptionProducts = cartHasSubscriptionProducts(
|
||||
config.scriptData
|
||||
);
|
||||
useEffect( () => {
|
||||
localStorage.removeItem( 'ppcp-save-card-payment' );
|
||||
|
||||
if(hasSubscriptionProducts) {
|
||||
localStorage.setItem('ppcp-save-card-payment', 'true');
|
||||
}
|
||||
if ( hasSubscriptionProducts ) {
|
||||
localStorage.setItem( 'ppcp-save-card-payment', 'true' );
|
||||
}
|
||||
}, [ hasSubscriptionProducts ] );
|
||||
|
||||
}, [hasSubscriptionProducts])
|
||||
useEffect(
|
||||
() =>
|
||||
onPaymentSetup( () => {
|
||||
async function handlePaymentProcessing() {
|
||||
await cardFieldsForm.submit().catch( ( error ) => {
|
||||
return {
|
||||
type: responseTypes.ERROR,
|
||||
};
|
||||
} );
|
||||
|
||||
useEffect(
|
||||
() =>
|
||||
onPaymentSetup(() => {
|
||||
async function handlePaymentProcessing() {
|
||||
await cardFieldsForm.submit()
|
||||
.catch((error) => {
|
||||
return {
|
||||
type: responseTypes.ERROR,
|
||||
}
|
||||
});
|
||||
return {
|
||||
type: responseTypes.SUCCESS,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
type: responseTypes.SUCCESS,
|
||||
}
|
||||
}
|
||||
return handlePaymentProcessing();
|
||||
} ),
|
||||
[ onPaymentSetup, cardFieldsForm ]
|
||||
);
|
||||
|
||||
return handlePaymentProcessing();
|
||||
}),
|
||||
[onPaymentSetup, cardFieldsForm]
|
||||
);
|
||||
|
||||
return (
|
||||
<>
|
||||
<PayPalScriptProvider
|
||||
options={{
|
||||
clientId: config.scriptData.client_id,
|
||||
components: "card-fields",
|
||||
dataNamespace: 'ppcp-block-card-fields',
|
||||
}}
|
||||
>
|
||||
<PayPalCardFieldsProvider
|
||||
createOrder={createOrder}
|
||||
onApprove={onApprove}
|
||||
onError={(err) => {
|
||||
console.error(err);
|
||||
}}
|
||||
>
|
||||
<PayPalCardFieldsForm/>
|
||||
<PaymentMethodIcons icons={config.card_icons} align="left" />
|
||||
<CheckoutHandler
|
||||
getCardFieldsForm={getCardFieldsForm}
|
||||
getSavePayment={getSavePayment}
|
||||
hasSubscriptionProducts={hasSubscriptionProducts}
|
||||
saveCardText={config.save_card_text}
|
||||
is_vaulting_enabled={config.is_vaulting_enabled}
|
||||
/>
|
||||
</PayPalCardFieldsProvider>
|
||||
</PayPalScriptProvider>
|
||||
</>
|
||||
)
|
||||
return (
|
||||
<>
|
||||
<PayPalScriptProvider
|
||||
options={ {
|
||||
clientId: config.scriptData.client_id,
|
||||
components: 'card-fields',
|
||||
dataNamespace: 'ppcp-block-card-fields',
|
||||
} }
|
||||
>
|
||||
<PayPalCardFieldsProvider
|
||||
createOrder={ createOrder }
|
||||
onApprove={ onApprove }
|
||||
onError={ ( err ) => {
|
||||
console.error( err );
|
||||
} }
|
||||
>
|
||||
<PayPalCardFieldsForm />
|
||||
<PaymentMethodIcons
|
||||
icons={ config.card_icons }
|
||||
align="left"
|
||||
/>
|
||||
<CheckoutHandler
|
||||
getCardFieldsForm={ getCardFieldsForm }
|
||||
getSavePayment={ getSavePayment }
|
||||
hasSubscriptionProducts={ hasSubscriptionProducts }
|
||||
saveCardText={ config.save_card_text }
|
||||
is_vaulting_enabled={ config.is_vaulting_enabled }
|
||||
/>
|
||||
</PayPalCardFieldsProvider>
|
||||
</PayPalScriptProvider>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue