mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-08-30 05:00:51 +08:00
🔀 Merge branch 'trunk'
# Conflicts: # modules/ppcp-settings/resources/js/Components/ReusableComponents/SettingsBlocks/PaymentMethodItemBlock.js # modules/ppcp-settings/resources/js/Components/Screens/Settings/Tabs/TabOverview.js
This commit is contained in:
commit
d2cab43c8f
17 changed files with 826 additions and 337 deletions
|
@ -39,7 +39,7 @@ class SavePaymentMethodsApplies {
|
|||
string $country
|
||||
) {
|
||||
$this->allowed_countries = $allowed_countries;
|
||||
$this->country = $country;
|
||||
$this->country = $country;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -33,13 +33,17 @@ const FeatureSettingsBlock = ( { title, description, ...props } ) => {
|
|||
</Button>
|
||||
);
|
||||
|
||||
return button.urls ? (
|
||||
<a href={ button.urls.live } key={ button.text }>
|
||||
{ buttonElement }
|
||||
</a>
|
||||
) : (
|
||||
buttonElement
|
||||
);
|
||||
// If there's a URL (either direct or in urls object), wrap in anchor tag
|
||||
if ( button.url || button.urls ) {
|
||||
const href = button.urls ? button.urls.live : button.url;
|
||||
return (
|
||||
<a href={ href } key={ button.text }>
|
||||
{ buttonElement }
|
||||
</a>
|
||||
);
|
||||
}
|
||||
|
||||
return buttonElement;
|
||||
};
|
||||
|
||||
return (
|
||||
|
|
|
@ -4,32 +4,26 @@ import SettingsBlock from '../SettingsBlock';
|
|||
import PaymentMethodIcon from '../PaymentMethodIcon';
|
||||
import data from '../../../utils/data';
|
||||
|
||||
// TODO: A reusable component should not depend external data. Change this to a prop.
|
||||
import { hasSettings } from '../../Screens/Overview/TabSettingsElements/Blocks/PaymentMethods';
|
||||
|
||||
const PaymentMethodItemBlock = ( {
|
||||
id,
|
||||
title,
|
||||
description,
|
||||
icon,
|
||||
paymentMethod,
|
||||
onTriggerModal,
|
||||
onSelect,
|
||||
isSelected,
|
||||
} ) => {
|
||||
// Only show settings icon if this method has fields configured
|
||||
const hasModal = hasSettings( id );
|
||||
|
||||
return (
|
||||
<SettingsBlock className="ppcp-r-settings-block__payment-methods__item">
|
||||
<div className="ppcp-r-settings-block__payment-methods__item__inner">
|
||||
<div className="ppcp-r-settings-block__payment-methods__item__title-wrapper">
|
||||
<PaymentMethodIcon icons={ [ icon ] } type={ icon } />
|
||||
<PaymentMethodIcon
|
||||
icons={ [ paymentMethod.icon ] }
|
||||
type={ paymentMethod.icon }
|
||||
/>
|
||||
<span className="ppcp-r-settings-block__payment-methods__item__title">
|
||||
{ title }
|
||||
{ paymentMethod.itemTitle }
|
||||
</span>
|
||||
</div>
|
||||
<p className="ppcp-r-settings-block__payment-methods__item__description">
|
||||
{ description }
|
||||
{ paymentMethod.itemDescription }
|
||||
</p>
|
||||
<div className="ppcp-r-settings-block__payment-methods__item__footer">
|
||||
<ToggleControl
|
||||
|
@ -37,7 +31,7 @@ const PaymentMethodItemBlock = ( {
|
|||
checked={ isSelected }
|
||||
onChange={ onSelect }
|
||||
/>
|
||||
{ hasModal && onTriggerModal && (
|
||||
{ paymentMethod?.fields && onTriggerModal && (
|
||||
<div
|
||||
className="ppcp-r-settings-block__payment-methods__item__settings"
|
||||
onClick={ onTriggerModal }
|
||||
|
|
|
@ -27,7 +27,7 @@ const PaymentMethodsBlock = ( {
|
|||
{ paymentMethods.map( ( paymentMethod ) => (
|
||||
<PaymentMethodItemBlock
|
||||
key={ paymentMethod.id }
|
||||
{ ...paymentMethod }
|
||||
paymentMethod={ paymentMethod }
|
||||
isSelected={ paymentMethod.enabled }
|
||||
onSelect={ ( checked ) =>
|
||||
handleSelect( paymentMethod, checked )
|
||||
|
|
|
@ -5,6 +5,7 @@ import { PaymentMethodsBlock } from '../../ReusableComponents/SettingsBlocks';
|
|||
import { PaymentHooks } from '../../../data';
|
||||
import { useActiveModal } from '../../../data/common/hooks';
|
||||
import Modal from './TabSettingsElements/Blocks/Modal';
|
||||
import { usePaymentMethods } from '../../../data/payment/hooks';
|
||||
|
||||
const TabPaymentMethods = () => {
|
||||
const { paymentMethodsPayPalCheckout } =
|
||||
|
@ -14,6 +15,8 @@ const TabPaymentMethods = () => {
|
|||
const { paymentMethodsAlternative } =
|
||||
PaymentHooks.usePaymentMethodsAlternative();
|
||||
|
||||
const { setPersistent } = usePaymentMethods();
|
||||
|
||||
const { activeModal, setActiveModal } = useActiveModal();
|
||||
|
||||
const getActiveMethod = () => {
|
||||
|
@ -89,11 +92,37 @@ const TabPaymentMethods = () => {
|
|||
method={ getActiveMethod() }
|
||||
setModalIsVisible={ () => setActiveModal( null ) }
|
||||
onSave={ ( methodId, settings ) => {
|
||||
console.log(
|
||||
'Saving settings for:',
|
||||
methodId,
|
||||
settings
|
||||
);
|
||||
setPersistent( methodId, {
|
||||
...getActiveMethod(),
|
||||
title: settings.checkoutPageTitle,
|
||||
description: settings.checkoutPageDescription,
|
||||
} );
|
||||
|
||||
if ( 'paypalShowLogo' in settings ) {
|
||||
setPersistent(
|
||||
'paypalShowLogo',
|
||||
settings.paypalShowLogo
|
||||
);
|
||||
}
|
||||
if ( 'threeDSecure' in settings ) {
|
||||
setPersistent(
|
||||
'threeDSecure',
|
||||
settings.threeDSecure
|
||||
);
|
||||
}
|
||||
if ( 'fastlaneCardholderName' in settings ) {
|
||||
setPersistent(
|
||||
'fastlaneCardholderName',
|
||||
settings.fastlaneCardholderName
|
||||
);
|
||||
}
|
||||
if ( 'fastlaneDisplayWatermark' in settings ) {
|
||||
setPersistent(
|
||||
'fastlaneDisplayWatermark',
|
||||
settings.fastlaneDisplayWatermark
|
||||
);
|
||||
}
|
||||
|
||||
setActiveModal( null );
|
||||
} }
|
||||
/>
|
||||
|
|
|
@ -7,23 +7,49 @@ import {
|
|||
} from '@wordpress/components';
|
||||
import { useState } from '@wordpress/element';
|
||||
import PaymentMethodModal from '../../../../ReusableComponents/PaymentMethodModal';
|
||||
import { getPaymentMethods } from './PaymentMethods';
|
||||
import {
|
||||
usePaymentMethods,
|
||||
usePaymentMethodsModal,
|
||||
} from '../../../../../data/payment/hooks';
|
||||
|
||||
const Modal = ( { method, setModalIsVisible, onSave } ) => {
|
||||
const { paymentMethods } = usePaymentMethods();
|
||||
const {
|
||||
paypalShowLogo,
|
||||
threeDSecure,
|
||||
fastlaneCardholderName,
|
||||
fastlaneDisplayWatermark,
|
||||
} = usePaymentMethodsModal();
|
||||
|
||||
const [ settings, setSettings ] = useState( () => {
|
||||
if ( ! method?.id ) {
|
||||
return {};
|
||||
}
|
||||
|
||||
const methodConfig = getPaymentMethods( method );
|
||||
const methodConfig = paymentMethods.find( ( i ) => i.id === method.id );
|
||||
if ( ! methodConfig?.fields ) {
|
||||
return {};
|
||||
}
|
||||
|
||||
const initialSettings = {};
|
||||
Object.entries( methodConfig.fields ).forEach( ( [ key, field ] ) => {
|
||||
initialSettings[ key ] = field.default;
|
||||
switch ( key ) {
|
||||
case 'checkoutPageTitle':
|
||||
initialSettings[ key ] = methodConfig.title;
|
||||
break;
|
||||
case 'checkoutPageDescription':
|
||||
initialSettings[ key ] = methodConfig.description;
|
||||
break;
|
||||
default:
|
||||
initialSettings[ key ] = field.default;
|
||||
}
|
||||
} );
|
||||
|
||||
initialSettings.paypalShowLogo = paypalShowLogo;
|
||||
initialSettings.threeDSecure = threeDSecure;
|
||||
initialSettings.fastlaneCardholderName = fastlaneCardholderName;
|
||||
initialSettings.fastlaneDisplayWatermark = fastlaneDisplayWatermark;
|
||||
|
||||
return initialSettings;
|
||||
} );
|
||||
|
||||
|
@ -31,7 +57,7 @@ const Modal = ( { method, setModalIsVisible, onSave } ) => {
|
|||
return null;
|
||||
}
|
||||
|
||||
const methodConfig = getPaymentMethods( method );
|
||||
const methodConfig = paymentMethods.find( ( i ) => i.id === method.id );
|
||||
if ( ! methodConfig?.fields ) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -1,173 +0,0 @@
|
|||
import { __, sprintf } from '@wordpress/i18n';
|
||||
|
||||
const createStandardFields = ( methodId, defaultTitle ) => ( {
|
||||
checkoutPageTitle: {
|
||||
type: 'text',
|
||||
default: defaultTitle,
|
||||
label: __( 'Checkout page title', 'woocommerce-paypal-payments' ),
|
||||
},
|
||||
checkoutPageDescription: {
|
||||
type: 'text',
|
||||
default: sprintf(
|
||||
/* translators: %s: payment method title */
|
||||
__( 'Pay with %s', 'woocommerce-paypal-payments' ),
|
||||
defaultTitle
|
||||
),
|
||||
label: __( 'Checkout page description', 'woocommerce-paypal-payments' ),
|
||||
},
|
||||
} );
|
||||
|
||||
const paymentMethods = {
|
||||
// PayPal Checkout methods
|
||||
'ppcp-gateway': {
|
||||
fields: {
|
||||
...createStandardFields( 'paypal', 'PayPal' ),
|
||||
showLogo: {
|
||||
type: 'toggle',
|
||||
default: false,
|
||||
label: __( 'Show logo', 'woocommerce-paypal-payments' ),
|
||||
},
|
||||
},
|
||||
},
|
||||
credit_and_debit_card_payments: {
|
||||
fields: createStandardFields(
|
||||
'credit_and_debit_card_payments',
|
||||
__(
|
||||
'Credit and debit card payments',
|
||||
'woocommerce-paypal-payments'
|
||||
)
|
||||
),
|
||||
},
|
||||
|
||||
// Online Card Payments
|
||||
advanced_credit_and_debit_card_payments: {
|
||||
fields: {
|
||||
...createStandardFields(
|
||||
'advanced_credit_and_debit_card_payments',
|
||||
__(
|
||||
'Advanced Credit and Debit Card Payments',
|
||||
'woocommerce-paypal-payments'
|
||||
)
|
||||
),
|
||||
threeDSecure: {
|
||||
type: 'radio',
|
||||
default: 'no-3d-secure',
|
||||
label: __( '3D Secure', 'woocommerce-paypal-payments' ),
|
||||
description: __(
|
||||
'Authenticate cardholders through their card issuers to reduce fraud and improve transaction security. Successful 3D Secure authentication can shift liability for fraudulent chargebacks to the card issuer.',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
options: [
|
||||
{
|
||||
label: __(
|
||||
'No 3D Secure',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
value: 'no-3d-secure',
|
||||
},
|
||||
{
|
||||
label: __(
|
||||
'Only when required',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
value: 'only-required-3d-secure',
|
||||
},
|
||||
{
|
||||
label: __(
|
||||
'Always require 3D Secure',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
value: 'always-3d-secure',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
fastlane: {
|
||||
fields: {
|
||||
...createStandardFields( 'fastlane', 'Fastlane by PayPal' ),
|
||||
cardholderName: {
|
||||
type: 'toggle',
|
||||
default: false,
|
||||
label: __(
|
||||
'Display cardholder name',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
},
|
||||
displayWatermark: {
|
||||
type: 'toggle',
|
||||
default: false,
|
||||
label: __(
|
||||
'Display Fastlane Watermark',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
// Digital Wallets
|
||||
apple_pay: {
|
||||
fields: createStandardFields( 'apple_pay', 'Apple Pay' ),
|
||||
},
|
||||
google_pay: {
|
||||
fields: createStandardFields( 'google_pay', 'Google Pay' ),
|
||||
},
|
||||
|
||||
// Alternative Payment Methods
|
||||
bancontact: {
|
||||
fields: createStandardFields( 'bancontact', 'Bancontact' ),
|
||||
},
|
||||
ideal: {
|
||||
fields: createStandardFields( 'ideal', 'iDEAL' ),
|
||||
},
|
||||
eps: {
|
||||
fields: createStandardFields( 'eps', 'eps' ),
|
||||
},
|
||||
blik: {
|
||||
fields: createStandardFields( 'blik', 'BLIK' ),
|
||||
},
|
||||
mybank: {
|
||||
fields: createStandardFields( 'mybank', 'MyBank' ),
|
||||
},
|
||||
przelewy24: {
|
||||
fields: createStandardFields( 'przelewy24', 'Przelewy24' ),
|
||||
},
|
||||
trustly: {
|
||||
fields: createStandardFields( 'trustly', 'Trustly' ),
|
||||
},
|
||||
multibanco: {
|
||||
fields: createStandardFields( 'multibanco', 'Multibanco' ),
|
||||
},
|
||||
pui: {
|
||||
fields: createStandardFields( 'pui', 'Pay upon Invoice' ),
|
||||
},
|
||||
oxxo: {
|
||||
fields: createStandardFields( 'oxxo', 'OXXO' ),
|
||||
},
|
||||
};
|
||||
|
||||
// Function to get configuration for a payment method
|
||||
export const getPaymentMethods = ( method ) => {
|
||||
if ( ! method?.id ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// If method has specific config, return it
|
||||
if ( paymentMethods[ method.id ] ) {
|
||||
return {
|
||||
...paymentMethods[ method.id ],
|
||||
icon: method.icon,
|
||||
};
|
||||
}
|
||||
|
||||
// Return standard config for new payment methods
|
||||
return {
|
||||
fields: createStandardFields( method.id, method.title ),
|
||||
icon: method.icon,
|
||||
};
|
||||
};
|
||||
|
||||
// Function to check if a method has settings defined
|
||||
export const hasSettings = ( methodId ) => {
|
||||
return Boolean( methodId && paymentMethods[ methodId ] );
|
||||
};
|
|
@ -39,10 +39,7 @@ const Features = {
|
|||
{
|
||||
type: 'tertiary',
|
||||
text: __( 'Learn more', 'woocommerce-paypal-payments' ),
|
||||
urls: {
|
||||
sandbox: '#',
|
||||
live: '#',
|
||||
},
|
||||
url: 'https://developer.paypal.com/studio/checkout/standard',
|
||||
class: 'small-button',
|
||||
},
|
||||
],
|
||||
|
@ -88,10 +85,7 @@ const Features = {
|
|||
{
|
||||
type: 'tertiary',
|
||||
text: __( 'Learn more', 'woocommerce-paypal-payments' ),
|
||||
urls: {
|
||||
sandbox: '#',
|
||||
live: '#',
|
||||
},
|
||||
url: 'https://developer.paypal.com/studio/checkout/advanced',
|
||||
class: 'small-button',
|
||||
},
|
||||
],
|
||||
|
@ -122,20 +116,14 @@ const Features = {
|
|||
{
|
||||
type: 'secondary',
|
||||
text: __( 'Apply', 'woocommerce-paypal-payments' ),
|
||||
urls: {
|
||||
sandbox: '#',
|
||||
live: '#',
|
||||
},
|
||||
url: 'https://developer.paypal.com/docs/checkout/apm/',
|
||||
showWhen: 'disabled',
|
||||
class: 'small-button',
|
||||
},
|
||||
{
|
||||
type: 'tertiary',
|
||||
text: __( 'Learn more', 'woocommerce-paypal-payments' ),
|
||||
urls: {
|
||||
sandbox: '#',
|
||||
live: '#',
|
||||
},
|
||||
url: 'https://developer.paypal.com/docs/checkout/apm/',
|
||||
class: 'small-button',
|
||||
},
|
||||
],
|
||||
|
@ -176,10 +164,7 @@ const Features = {
|
|||
{
|
||||
type: 'tertiary',
|
||||
text: __( 'Learn more', 'woocommerce-paypal-payments' ),
|
||||
urls: {
|
||||
sandbox: '#',
|
||||
live: '#',
|
||||
},
|
||||
url: 'https://developer.paypal.com/docs/checkout/apm/google-pay/',
|
||||
class: 'small-button',
|
||||
},
|
||||
],
|
||||
|
@ -240,10 +225,7 @@ const Features = {
|
|||
{
|
||||
type: 'tertiary',
|
||||
text: __( 'Learn more', 'woocommerce-paypal-payments' ),
|
||||
urls: {
|
||||
sandbox: '#',
|
||||
live: '#',
|
||||
},
|
||||
url: 'https://developer.paypal.com/docs/checkout/apm/apple-pay/',
|
||||
class: 'small-button',
|
||||
},
|
||||
],
|
||||
|
@ -283,10 +265,7 @@ const Features = {
|
|||
{
|
||||
type: 'tertiary',
|
||||
text: __( 'Learn more', 'woocommerce-paypal-payments' ),
|
||||
urls: {
|
||||
sandbox: '#',
|
||||
live: '#',
|
||||
},
|
||||
url: 'https://developer.paypal.com/studio/checkout/pay-later/us',
|
||||
class: 'small-button',
|
||||
},
|
||||
],
|
|
@ -1,29 +1,30 @@
|
|||
import { __ } from '@wordpress/i18n';
|
||||
import { __, sprintf } from '@wordpress/i18n';
|
||||
import { useState, useMemo } from '@wordpress/element';
|
||||
import { Button, Icon } from '@wordpress/components';
|
||||
import { useDispatch } from '@wordpress/data';
|
||||
import { reusableBlock } from '@wordpress/icons';
|
||||
import { store as noticesStore } from '@wordpress/notices';
|
||||
|
||||
import SettingsCard from '../../ReusableComponents/SettingsCard';
|
||||
import {
|
||||
TodoSettingsBlock,
|
||||
FeatureSettingsBlock,
|
||||
} from '../../ReusableComponents/SettingsBlocks';
|
||||
import { TITLE_BADGE_POSITIVE } from '../../ReusableComponents/TitleBadge';
|
||||
import { useMerchantInfo } from '../../../data/common/hooks';
|
||||
import { STORE_NAME } from '../../../data/common';
|
||||
import Features from './TabSettingsElements/Blocks/Features';
|
||||
import { todosData } from '../Settings/todo-items';
|
||||
} from '../../../ReusableComponents/SettingsBlocks';
|
||||
import SettingsCard from '../../../ReusableComponents/SettingsCard';
|
||||
import { TITLE_BADGE_POSITIVE } from '../../../ReusableComponents/TitleBadge';
|
||||
import { useMerchantInfo } from '../../../../data/common/hooks';
|
||||
import { STORE_NAME } from '../../../../data/common';
|
||||
import Features from '../Components/Overview/Features';
|
||||
import { todosData } from '../todo-items';
|
||||
|
||||
import {
|
||||
NOTIFICATION_ERROR,
|
||||
NOTIFICATION_SUCCESS,
|
||||
} from '../../ReusableComponents/Icons';
|
||||
} from '../../../ReusableComponents/Icons';
|
||||
|
||||
const TabOverview = () => {
|
||||
const [ isRefreshing, setIsRefreshing ] = useState( false );
|
||||
|
||||
const { merchant, merchantFeatures } = useMerchantInfo();
|
||||
const { merchant, features: merchantFeatures } = useMerchantInfo();
|
||||
const { refreshFeatureStatuses, setActiveModal } =
|
||||
useDispatch( STORE_NAME );
|
||||
const { createSuccessNotice, createErrorNotice } =
|
|
@ -1,6 +1,6 @@
|
|||
import { __ } from '@wordpress/i18n';
|
||||
|
||||
import TabOverview from '../../Overview/TabOverview';
|
||||
import TabOverview from './TabOverview';
|
||||
import TabPaymentMethods from '../../Overview/TabPaymentMethods';
|
||||
import TabSettings from './TabSettings';
|
||||
import TabStyling from './TabStyling';
|
||||
|
|
|
@ -133,6 +133,7 @@ export const useWebhooks = () => {
|
|||
checkWebhookSimulationState,
|
||||
};
|
||||
};
|
||||
|
||||
export const useMerchantInfo = () => {
|
||||
const { isReady, merchant, features } = useHooks();
|
||||
const { refreshMerchantData } = useDispatch( STORE_NAME );
|
||||
|
|
|
@ -45,6 +45,12 @@ const defaultTransient = Object.freeze( {
|
|||
google_pay: {
|
||||
enabled: false,
|
||||
},
|
||||
alternative_payment_methods: {
|
||||
enabled: false,
|
||||
},
|
||||
pay_later_messaging: {
|
||||
enabled: false,
|
||||
},
|
||||
} ),
|
||||
|
||||
webhooks: Object.freeze( [] ),
|
||||
|
|
|
@ -56,6 +56,14 @@ const useHooks = () => {
|
|||
const pui = usePersistent( 'ppcp-pay-upon-invoice-gateway' );
|
||||
const oxxo = usePersistent( 'ppcp-oxxo-gateway' );
|
||||
|
||||
// Custom modal data.
|
||||
const paypalShowLogo = usePersistent( 'paypalShowLogo' );
|
||||
const threeDSecure = usePersistent( 'threeDSecure' );
|
||||
const fastlaneCardholderName = usePersistent( 'fastlaneCardholderName' );
|
||||
const fastlaneDisplayWatermark = usePersistent(
|
||||
'fastlaneDisplayWatermark'
|
||||
);
|
||||
|
||||
return {
|
||||
persist,
|
||||
isReady,
|
||||
|
@ -78,6 +86,10 @@ const useHooks = () => {
|
|||
multibanco,
|
||||
pui,
|
||||
oxxo,
|
||||
paypalShowLogo,
|
||||
threeDSecure,
|
||||
fastlaneCardholderName,
|
||||
fastlaneDisplayWatermark,
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -87,10 +99,68 @@ export const useStore = () => {
|
|||
};
|
||||
|
||||
export const usePaymentMethods = () => {
|
||||
const { setPersistent } = useHooks();
|
||||
const {
|
||||
setPersistent,
|
||||
paypal,
|
||||
venmo,
|
||||
payLater,
|
||||
creditCard,
|
||||
advancedCreditCard,
|
||||
fastlane,
|
||||
applePay,
|
||||
googlePay,
|
||||
bancontact,
|
||||
blik,
|
||||
eps,
|
||||
ideal,
|
||||
mybank,
|
||||
p24,
|
||||
trustly,
|
||||
multibanco,
|
||||
pui,
|
||||
oxxo,
|
||||
} = useHooks();
|
||||
|
||||
const paymentMethods = [
|
||||
paypal,
|
||||
venmo,
|
||||
payLater,
|
||||
creditCard,
|
||||
advancedCreditCard,
|
||||
fastlane,
|
||||
applePay,
|
||||
googlePay,
|
||||
bancontact,
|
||||
blik,
|
||||
eps,
|
||||
ideal,
|
||||
mybank,
|
||||
p24,
|
||||
trustly,
|
||||
multibanco,
|
||||
pui,
|
||||
oxxo,
|
||||
];
|
||||
|
||||
return {
|
||||
setPersistent,
|
||||
paymentMethods,
|
||||
};
|
||||
};
|
||||
|
||||
export const usePaymentMethodsModal = () => {
|
||||
const {
|
||||
paypalShowLogo,
|
||||
threeDSecure,
|
||||
fastlaneCardholderName,
|
||||
fastlaneDisplayWatermark,
|
||||
} = useHooks();
|
||||
|
||||
return {
|
||||
paypalShowLogo,
|
||||
threeDSecure,
|
||||
fastlaneCardholderName,
|
||||
fastlaneDisplayWatermark,
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -37,6 +37,10 @@ const defaultPersistent = Object.freeze( {
|
|||
'ppcp-multibanco': {},
|
||||
'ppcp-pay-upon-invoice-gateway': {},
|
||||
'ppcp-oxxo-gateway': {},
|
||||
paypalShowLogo: false,
|
||||
threeDSecure: 'no-3d-secure',
|
||||
fastlaneCardholderName: false,
|
||||
fastlaneDisplayWatermark: false,
|
||||
} );
|
||||
|
||||
// Reducer logic.
|
||||
|
|
|
@ -76,6 +76,9 @@ return array(
|
|||
$container->get( 'settings.service.sanitizer' )
|
||||
);
|
||||
},
|
||||
'settings.data.payment' => static function ( ContainerInterface $container ) : PaymentSettings {
|
||||
return new PaymentSettings();
|
||||
},
|
||||
'settings.rest.onboarding' => static function ( ContainerInterface $container ) : OnboardingRestEndpoint {
|
||||
return new OnboardingRestEndpoint( $container->get( 'settings.data.onboarding' ) );
|
||||
},
|
||||
|
@ -83,7 +86,7 @@ return array(
|
|||
return new CommonRestEndpoint( $container->get( 'settings.data.general' ) );
|
||||
},
|
||||
'settings.rest.payment' => static function ( ContainerInterface $container ) : PaymentRestEndpoint {
|
||||
return new PaymentRestEndpoint();
|
||||
return new PaymentRestEndpoint( $container->get( 'settings.data.payment' ) );
|
||||
},
|
||||
'settings.rest.styling' => static function ( ContainerInterface $container ) : StylingRestEndpoint {
|
||||
return new StylingRestEndpoint(
|
||||
|
|
113
modules/ppcp-settings/src/Data/PaymentSettings.php
Normal file
113
modules/ppcp-settings/src/Data/PaymentSettings.php
Normal file
|
@ -0,0 +1,113 @@
|
|||
<?php
|
||||
/**
|
||||
* Payment methods settings class
|
||||
*
|
||||
* @package WooCommerce\PayPalCommerce\Settings\Data
|
||||
*/
|
||||
|
||||
declare( strict_types = 1 );
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Settings\Data;
|
||||
|
||||
/**
|
||||
* Class PaymentSettings
|
||||
*/
|
||||
class PaymentSettings extends AbstractDataModel {
|
||||
|
||||
/**
|
||||
* Option key where profile details are stored.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected const OPTION_KEY = 'woocommerce-ppcp-data-payment';
|
||||
|
||||
/**
|
||||
* Get default values for the model.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function get_defaults(): array {
|
||||
return array(
|
||||
'paypal_show_logo' => false,
|
||||
'three_d_secure' => 'no-3d-secure',
|
||||
'fastlane_cardholder_name' => false,
|
||||
'fastlane_display_watermark' => false,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get PayPal show logo.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function get_paypal_show_logo(): bool {
|
||||
return (bool) $this->data['paypal_show_logo'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get 3DSecure.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_three_d_secure(): string {
|
||||
return $this->data['three_d_secure'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Fastlane cardholder name.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function get_fastlane_cardholder_name(): bool {
|
||||
return (bool) $this->data['fastlane_cardholder_name'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Fastlane display watermark.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function get_fastlane_display_watermark(): bool {
|
||||
return (bool) $this->data['fastlane_display_watermark'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set PayPal show logo.
|
||||
*
|
||||
* @param bool $value The value.
|
||||
* @return void
|
||||
*/
|
||||
public function set_paypal_show_logo( bool $value ): void {
|
||||
$this->data['paypal_show_logo'] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set 3DSecure.
|
||||
*
|
||||
* @param string $value The value.
|
||||
* @return void
|
||||
*/
|
||||
public function set_three_d_secure( string $value ): void {
|
||||
$this->data['three_d_secure'] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Fastlane cardholder name.
|
||||
*
|
||||
* @param bool $value The value.
|
||||
* @return void
|
||||
*/
|
||||
public function set_fastlane_cardholder_name( bool $value ): void {
|
||||
$this->data['fastlane_cardholder_name'] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Fastlane display watermark.
|
||||
*
|
||||
* @param bool $value The value.
|
||||
* @return void
|
||||
*/
|
||||
public function set_fastlane_display_watermark( bool $value ): void {
|
||||
$this->data['fastlane_display_watermark'] = $value;
|
||||
}
|
||||
}
|
|
@ -18,6 +18,7 @@ use WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods\MultibancoGateway;
|
|||
use WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods\MyBankGateway;
|
||||
use WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods\P24Gateway;
|
||||
use WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods\TrustlyGateway;
|
||||
use WooCommerce\PayPalCommerce\Settings\Data\PaymentSettings;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\CardButtonGateway;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\OXXO\OXXO;
|
||||
|
@ -43,6 +44,46 @@ class PaymentRestEndpoint extends RestEndpoint {
|
|||
*/
|
||||
protected $rest_base = 'payment';
|
||||
|
||||
/**
|
||||
* The settings instance.
|
||||
*
|
||||
* @var PaymentSettings
|
||||
*/
|
||||
protected PaymentSettings $settings;
|
||||
|
||||
/**
|
||||
* Field mapping for request to profile transformation.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private array $field_map = array(
|
||||
'paypal_show_logo' => array(
|
||||
'js_name' => 'paypalShowLogo',
|
||||
'sanitize' => 'to_boolean',
|
||||
),
|
||||
'three_d_secure' => array(
|
||||
'js_name' => 'threeDSecure',
|
||||
'sanitize' => 'sanitize_text_field',
|
||||
),
|
||||
'fastlane_cardholder_name' => array(
|
||||
'js_name' => 'fastlaneCardholderName',
|
||||
'sanitize' => 'to_boolean',
|
||||
),
|
||||
'fastlane_display_watermark' => array(
|
||||
'js_name' => 'fastlaneDisplayWatermark',
|
||||
'sanitize' => 'to_boolean',
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param PaymentSettings $settings The settings instance.
|
||||
*/
|
||||
public function __construct( PaymentSettings $settings ) {
|
||||
$this->settings = $settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Field mapping for request to profile transformation.
|
||||
*
|
||||
|
@ -52,176 +93,507 @@ class PaymentRestEndpoint extends RestEndpoint {
|
|||
return array(
|
||||
// PayPal checkout.
|
||||
PayPalGateway::ID => array(
|
||||
'id' => 'ppcp-gateway',
|
||||
'title' => __( 'PayPal', 'woocommerce-paypal-payments' ),
|
||||
'description' => __(
|
||||
'id' => PayPalGateway::ID,
|
||||
'title' => __( 'PayPal', 'woocommerce-paypal-payments' ),
|
||||
'description' => __(
|
||||
'Our all-in-one checkout solution lets you offer PayPal, Venmo, Pay Later options, and more to help maximize conversion.',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
'icon' => 'payment-method-paypal',
|
||||
'icon' => 'payment-method-paypal',
|
||||
'itemTitle' => __( 'PayPal', 'woocommerce-paypal-payments' ),
|
||||
'itemDescription' => __(
|
||||
'Our all-in-one checkout solution lets you offer PayPal, Venmo, Pay Later options, and more to help maximize conversion.',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
'fields' => array(
|
||||
'checkoutPageTitle' => array(
|
||||
'type' => 'text',
|
||||
'default' => $this->getPaymentTitle( PayPalGateway::ID ) ?? '',
|
||||
'label' => __( 'Checkout page title', 'woocommerce-paypal-payments' ),
|
||||
),
|
||||
'checkoutPageDescription' => array(
|
||||
'type' => 'text',
|
||||
'default' => $this->getPaymentDescription( PayPalGateway::ID ) ?? '',
|
||||
'label' => __( 'Checkout page description', 'woocommerce-paypal-payments' ),
|
||||
),
|
||||
'paypalShowLogo' => array(
|
||||
'type' => 'toggle',
|
||||
'default' => $this->settings->get_paypal_show_logo(),
|
||||
'label' => __( 'Show logo', 'woocommerce-paypal-payments' ),
|
||||
),
|
||||
),
|
||||
),
|
||||
'venmo' => array(
|
||||
'id' => 'venmo',
|
||||
'title' => __( 'Venmo', 'woocommerce-paypal-payments' ),
|
||||
'description' => __(
|
||||
'id' => 'venmo',
|
||||
'itemTitle' => __( 'Venmo', 'woocommerce-paypal-payments' ),
|
||||
'itemDescription' => __(
|
||||
'Offer Venmo at checkout to millions of active users.',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
'icon' => 'payment-method-venmo',
|
||||
'icon' => 'payment-method-venmo',
|
||||
),
|
||||
'pay-later' => array(
|
||||
'id' => 'paypal_credit',
|
||||
'title' => __( 'Pay Later', 'woocommerce-paypal-payments' ),
|
||||
'description' => __(
|
||||
'id' => 'pay-later',
|
||||
'itemTitle' => __( 'Pay Later', 'woocommerce-paypal-payments' ),
|
||||
'itemDescription' => __(
|
||||
'Get paid in full at checkout while giving your customers the flexibility to pay in installments over time with no late fees.',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
'icon' => 'payment-method-paypal',
|
||||
'icon' => 'payment-method-paypal',
|
||||
),
|
||||
CardButtonGateway::ID => array(
|
||||
'id' => 'credit_and_debit_card_payments',
|
||||
'title' => __(
|
||||
'id' => CardButtonGateway::ID,
|
||||
'title' => __(
|
||||
'Credit and debit card payments',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
'description' => __(
|
||||
'description' => __(
|
||||
"Accept all major credit and debit cards - even if your customer doesn't have a PayPal account.",
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
'icon' => 'payment-method-cards',
|
||||
'icon' => 'payment-method-cards',
|
||||
'itemTitle' => __(
|
||||
'Credit and debit card payments',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
'itemDescription' => __(
|
||||
"Accept all major credit and debit cards - even if your customer doesn't have a PayPal account.",
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
'fields' => array(
|
||||
'checkoutPageTitle' => array(
|
||||
'type' => 'text',
|
||||
'default' => $this->getPaymentTitle( CardButtonGateway::ID ) ?? '',
|
||||
'label' => __( 'Checkout page title', 'woocommerce-paypal-payments' ),
|
||||
),
|
||||
'checkoutPageDescription' => array(
|
||||
'type' => 'text',
|
||||
'default' => $this->getPaymentDescription( CardButtonGateway::ID ) ?? '',
|
||||
'label' => __( 'Checkout page description', 'woocommerce-paypal-payments' ),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Online card Payments.
|
||||
CreditCardGateway::ID => array(
|
||||
'id' => 'advanced_credit_and_debit_card_payments',
|
||||
'title' => __(
|
||||
'id' => CreditCardGateway::ID,
|
||||
'title' => __(
|
||||
'Advanced Credit and Debit Card Payments',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
'description' => __(
|
||||
'description' => __(
|
||||
"Present custom credit and debit card fields to your payers so they can pay with credit and debit cards using your site's branding.",
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
'icon' => 'payment-method-advanced-cards',
|
||||
'icon' => 'payment-method-advanced-cards',
|
||||
'itemTitle' => __(
|
||||
'Advanced Credit and Debit Card Payments',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
'itemDescription' => __(
|
||||
"Present custom credit and debit card fields to your payers so they can pay with credit and debit cards using your site's branding.",
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
'fields' => array(
|
||||
'checkoutPageTitle' => array(
|
||||
'type' => 'text',
|
||||
'default' => $this->getPaymentTitle( CreditCardGateway::ID ) ?? '',
|
||||
'label' => __( 'Checkout page title', 'woocommerce-paypal-payments' ),
|
||||
),
|
||||
'checkoutPageDescription' => array(
|
||||
'type' => 'text',
|
||||
'default' => $this->getPaymentDescription( CreditCardGateway::ID ) ?? '',
|
||||
'label' => __( 'Checkout page description', 'woocommerce-paypal-payments' ),
|
||||
),
|
||||
'threeDSecure' => array(
|
||||
'type' => 'radio',
|
||||
'default' => $this->settings->get_three_d_secure(),
|
||||
'label' => __( '3D Secure', 'woocommerce-paypal-payments' ),
|
||||
'description' => __(
|
||||
'Authenticate cardholders through their card issuers to reduce fraud and improve transaction security. Successful 3D Secure authentication can shift liability for fraudulent chargebacks to the card issuer.',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
'options' => array(
|
||||
array(
|
||||
'label' => __(
|
||||
'No 3D Secure',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
'value' => 'no-3d-secure',
|
||||
),
|
||||
array(
|
||||
'label' => __(
|
||||
'Only when required',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
'value' => 'only-required-3d-secure',
|
||||
),
|
||||
array(
|
||||
'label' => __(
|
||||
'Always require 3D Secure',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
'value' => 'always-3d-secure',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
AxoGateway::ID => array(
|
||||
'id' => 'fastlane',
|
||||
'title' => __( 'Fastlane by PayPal', 'woocommerce-paypal-payments' ),
|
||||
'description' => __(
|
||||
'id' => AxoGateway::ID,
|
||||
'title' => __( 'Fastlane by PayPal', 'woocommerce-paypal-payments' ),
|
||||
'description' => __(
|
||||
"Tap into the scale and trust of PayPal's customer network to recognize shoppers and make guest checkout more seamless than ever.",
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
'icon' => 'payment-method-fastlane',
|
||||
'icon' => 'payment-method-fastlane',
|
||||
'itemTitle' => __( 'Fastlane by PayPal', 'woocommerce-paypal-payments' ),
|
||||
'itemDescription' => __(
|
||||
"Tap into the scale and trust of PayPal's customer network to recognize shoppers and make guest checkout more seamless than ever.",
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
'fields' => array(
|
||||
'checkoutPageTitle' => array(
|
||||
'type' => 'text',
|
||||
'default' => $this->getPaymentTitle( AxoGateway::ID ) ?? '',
|
||||
'label' => __( 'Checkout page title', 'woocommerce-paypal-payments' ),
|
||||
),
|
||||
'checkoutPageDescription' => array(
|
||||
'type' => 'text',
|
||||
'default' => $this->getPaymentDescription( AxoGateway::ID ) ?? '',
|
||||
'label' => __( 'Checkout page description', 'woocommerce-paypal-payments' ),
|
||||
),
|
||||
'fastlaneCardholderName' => array(
|
||||
'type' => 'toggle',
|
||||
'default' => $this->settings->get_fastlane_cardholder_name(),
|
||||
'label' => __(
|
||||
'Display cardholder name',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
),
|
||||
'fastlaneDisplayWatermark' => array(
|
||||
'type' => 'toggle',
|
||||
'default' => $this->settings->get_fastlane_display_watermark(),
|
||||
'label' => __(
|
||||
'Display Fastlane Watermark',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
ApplePayGateway::ID => array(
|
||||
'id' => 'apple_pay',
|
||||
'title' => __( 'Apple Pay', 'woocommerce-paypal-payments' ),
|
||||
'description' => __(
|
||||
'id' => ApplePayGateway::ID,
|
||||
'title' => __( 'Apple Pay', 'woocommerce-paypal-payments' ),
|
||||
'description' => __(
|
||||
'Allow customers to pay via their Apple Pay digital wallet.',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
'icon' => 'payment-method-apple-pay',
|
||||
'icon' => 'payment-method-apple-pay',
|
||||
'itemTitle' => __( 'Apple Pay', 'woocommerce-paypal-payments' ),
|
||||
'itemDescription' => __(
|
||||
'Allow customers to pay via their Apple Pay digital wallet.',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
'fields' => array(
|
||||
'checkoutPageTitle' => array(
|
||||
'type' => 'text',
|
||||
'default' => $this->getPaymentTitle( ApplePayGateway::ID ) ?? '',
|
||||
'label' => __( 'Checkout page title', 'woocommerce-paypal-payments' ),
|
||||
),
|
||||
'checkoutPageDescription' => array(
|
||||
'type' => 'text',
|
||||
'default' => $this->getPaymentDescription( ApplePayGateway::ID ) ?? '',
|
||||
'label' => __( 'Checkout page description', 'woocommerce-paypal-payments' ),
|
||||
),
|
||||
),
|
||||
),
|
||||
GooglePayGateway::ID => array(
|
||||
'id' => 'google_pay',
|
||||
'title' => __( 'Google Pay', 'woocommerce-paypal-payments' ),
|
||||
'description' => __(
|
||||
'id' => GooglePayGateway::ID,
|
||||
'title' => __( 'Google Pay', 'woocommerce-paypal-payments' ),
|
||||
'description' => __(
|
||||
'Allow customers to pay via their Google Pay digital wallet.',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
'icon' => 'payment-method-google-pay',
|
||||
'icon' => 'payment-method-google-pay',
|
||||
'itemTitle' => __( 'Google Pay', 'woocommerce-paypal-payments' ),
|
||||
'itemDescription' => __(
|
||||
'Allow customers to pay via their Google Pay digital wallet.',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
'fields' => array(
|
||||
'checkoutPageTitle' => array(
|
||||
'type' => 'text',
|
||||
'default' => $this->getPaymentTitle( GooglePayGateway::ID ) ?? '',
|
||||
'label' => __( 'Checkout page title', 'woocommerce-paypal-payments' ),
|
||||
),
|
||||
'checkoutPageDescription' => array(
|
||||
'type' => 'text',
|
||||
'default' => $this->getPaymentDescription( GooglePayGateway::ID ) ?? '',
|
||||
'label' => __( 'Checkout page description', 'woocommerce-paypal-payments' ),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Alternative payment methods.
|
||||
BancontactGateway::ID => array(
|
||||
'id' => 'bancontact',
|
||||
'title' => __( 'Bancontact', 'woocommerce-paypal-payments' ),
|
||||
'description' => __(
|
||||
'id' => BancontactGateway::ID,
|
||||
'title' => __( 'Bancontact', 'woocommerce-paypal-payments' ),
|
||||
'description' => __(
|
||||
'Bancontact is the most widely used, accepted and trusted electronic payment method in Belgium. Bancontact makes it possible to pay directly through the online payment systems of all major Belgian banks.',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
'icon' => 'payment-method-bancontact',
|
||||
'icon' => 'payment-method-bancontact',
|
||||
'itemTitle' => __( 'Bancontact', 'woocommerce-paypal-payments' ),
|
||||
'itemDescription' => __(
|
||||
'Bancontact is the most widely used, accepted and trusted electronic payment method in Belgium. Bancontact makes it possible to pay directly through the online payment systems of all major Belgian banks.',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
'fields' => array(
|
||||
'checkoutPageTitle' => array(
|
||||
'type' => 'text',
|
||||
'default' => $this->getPaymentTitle( BancontactGateway::ID ) ?? '',
|
||||
'label' => __( 'Checkout page title', 'woocommerce-paypal-payments' ),
|
||||
),
|
||||
'checkoutPageDescription' => array(
|
||||
'type' => 'text',
|
||||
'default' => $this->getPaymentDescription( BancontactGateway::ID ) ?? '',
|
||||
'label' => __( 'Checkout page description', 'woocommerce-paypal-payments' ),
|
||||
),
|
||||
),
|
||||
),
|
||||
BlikGateway::ID => array(
|
||||
'id' => 'blik',
|
||||
'title' => __( 'BLIK', 'woocommerce-paypal-payments' ),
|
||||
'description' => __(
|
||||
'id' => BlikGateway::ID,
|
||||
'title' => __( 'BLIK', 'woocommerce-paypal-payments' ),
|
||||
'description' => __(
|
||||
'A widely used mobile payment method in Poland, allowing Polish customers to pay directly via their banking apps. Transactions are processed in PLN.',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
'icon' => 'payment-method-blik',
|
||||
'icon' => 'payment-method-blik',
|
||||
'itemTitle' => __( 'BLIK', 'woocommerce-paypal-payments' ),
|
||||
'itemDescription' => __(
|
||||
'A widely used mobile payment method in Poland, allowing Polish customers to pay directly via their banking apps. Transactions are processed in PLN.',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
'fields' => array(
|
||||
'checkoutPageTitle' => array(
|
||||
'type' => 'text',
|
||||
'default' => $this->getPaymentTitle( BlikGateway::ID ) ?? '',
|
||||
'label' => __( 'Checkout page title', 'woocommerce-paypal-payments' ),
|
||||
),
|
||||
'checkoutPageDescription' => array(
|
||||
'type' => 'text',
|
||||
'default' => $this->getPaymentDescription( BlikGateway::ID ) ?? '',
|
||||
'label' => __( 'Checkout page description', 'woocommerce-paypal-payments' ),
|
||||
),
|
||||
),
|
||||
),
|
||||
EPSGateway::ID => array(
|
||||
'id' => 'eps',
|
||||
'title' => __( 'eps', 'woocommerce-paypal-payments' ),
|
||||
'description' => __(
|
||||
'id' => EPSGateway::ID,
|
||||
'title' => __( 'eps', 'woocommerce-paypal-payments' ),
|
||||
'description' => __(
|
||||
'An online payment method in Austria, enabling Austrian buyers to make secure payments directly through their bank accounts. Transactions are processed in EUR.',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
'icon' => 'payment-method-eps',
|
||||
'icon' => 'payment-method-eps',
|
||||
'itemTitle' => __( 'eps', 'woocommerce-paypal-payments' ),
|
||||
'itemDescription' => __(
|
||||
'An online payment method in Austria, enabling Austrian buyers to make secure payments directly through their bank accounts. Transactions are processed in EUR.',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
'fields' => array(
|
||||
'checkoutPageTitle' => array(
|
||||
'type' => 'text',
|
||||
'default' => $this->getPaymentTitle( EPSGateway::ID ) ?? '',
|
||||
'label' => __( 'Checkout page title', 'woocommerce-paypal-payments' ),
|
||||
),
|
||||
'checkoutPageDescription' => array(
|
||||
'type' => 'text',
|
||||
'default' => $this->getPaymentDescription( EPSGateway::ID ) ?? '',
|
||||
'label' => __( 'Checkout page description', 'woocommerce-paypal-payments' ),
|
||||
),
|
||||
),
|
||||
),
|
||||
IDealGateway::ID => array(
|
||||
'id' => 'ideal',
|
||||
'title' => __( 'iDEAL', 'woocommerce-paypal-payments' ),
|
||||
'description' => __(
|
||||
'id' => IDealGateway::ID,
|
||||
'title' => __( 'iDEAL', 'woocommerce-paypal-payments' ),
|
||||
'description' => __(
|
||||
'iDEAL is a payment method in the Netherlands that allows buyers to select their issuing bank from a list of options.',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
'icon' => 'payment-method-ideal',
|
||||
'icon' => 'payment-method-ideal',
|
||||
'itemTitle' => __( 'iDEAL', 'woocommerce-paypal-payments' ),
|
||||
'itemDescription' => __(
|
||||
'iDEAL is a payment method in the Netherlands that allows buyers to select their issuing bank from a list of options.',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
'fields' => array(
|
||||
'checkoutPageTitle' => array(
|
||||
'type' => 'text',
|
||||
'default' => $this->getPaymentTitle( IDealGateway::ID ) ?? '',
|
||||
'label' => __( 'Checkout page title', 'woocommerce-paypal-payments' ),
|
||||
),
|
||||
'checkoutPageDescription' => array(
|
||||
'type' => 'text',
|
||||
'default' => $this->getPaymentDescription( IDealGateway::ID ) ?? '',
|
||||
'label' => __( 'Checkout page description', 'woocommerce-paypal-payments' ),
|
||||
),
|
||||
),
|
||||
),
|
||||
MyBankGateway::ID => array(
|
||||
'id' => 'mybank',
|
||||
'title' => __( 'MyBank', 'woocommerce-paypal-payments' ),
|
||||
'description' => __(
|
||||
'id' => MyBankGateway::ID,
|
||||
'title' => __( 'MyBank', 'woocommerce-paypal-payments' ),
|
||||
'description' => __(
|
||||
'A European online banking payment solution primarily used in Italy, enabling customers to make secure bank transfers during checkout. Transactions are processed in EUR.',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
'icon' => 'payment-method-mybank',
|
||||
'icon' => 'payment-method-mybank',
|
||||
'itemTitle' => __( 'MyBank', 'woocommerce-paypal-payments' ),
|
||||
'itemDescription' => __(
|
||||
'A European online banking payment solution primarily used in Italy, enabling customers to make secure bank transfers during checkout. Transactions are processed in EUR.',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
'fields' => array(
|
||||
'checkoutPageTitle' => array(
|
||||
'type' => 'text',
|
||||
'default' => $this->getPaymentTitle( MyBankGateway::ID ) ?? '',
|
||||
'label' => __( 'Checkout page title', 'woocommerce-paypal-payments' ),
|
||||
),
|
||||
'checkoutPageDescription' => array(
|
||||
'type' => 'text',
|
||||
'default' => $this->getPaymentDescription( MyBankGateway::ID ) ?? '',
|
||||
'label' => __( 'Checkout page description', 'woocommerce-paypal-payments' ),
|
||||
),
|
||||
),
|
||||
),
|
||||
P24Gateway::ID => array(
|
||||
'id' => 'przelewy24',
|
||||
'title' => __( 'Przelewy24', 'woocommerce-paypal-payments' ),
|
||||
'description' => __(
|
||||
'id' => P24Gateway::ID,
|
||||
'title' => __( 'Przelewy24', 'woocommerce-paypal-payments' ),
|
||||
'description' => __(
|
||||
'A popular online payment gateway in Poland, offering various payment options for Polish customers. Transactions can be processed in PLN or EUR.',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
'icon' => 'payment-method-przelewy24',
|
||||
'icon' => 'payment-method-przelewy24',
|
||||
'itemTitle' => __( 'Przelewy24', 'woocommerce-paypal-payments' ),
|
||||
'itemDescription' => __(
|
||||
'A popular online payment gateway in Poland, offering various payment options for Polish customers. Transactions can be processed in PLN or EUR.',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
'fields' => array(
|
||||
'checkoutPageTitle' => array(
|
||||
'type' => 'text',
|
||||
'default' => $this->getPaymentTitle( P24Gateway::ID ) ?? '',
|
||||
'label' => __( 'Checkout page title', 'woocommerce-paypal-payments' ),
|
||||
),
|
||||
'checkoutPageDescription' => array(
|
||||
'type' => 'text',
|
||||
'default' => $this->getPaymentDescription( P24Gateway::ID ) ?? '',
|
||||
'label' => __( 'Checkout page description', 'woocommerce-paypal-payments' ),
|
||||
),
|
||||
),
|
||||
),
|
||||
TrustlyGateway::ID => array(
|
||||
'id' => 'trustly',
|
||||
'title' => __( 'Trustly', 'woocommerce-paypal-payments' ),
|
||||
'description' => __(
|
||||
'id' => TrustlyGateway::ID,
|
||||
'title' => __( 'Trustly', 'woocommerce-paypal-payments' ),
|
||||
'description' => __(
|
||||
'A European payment method that allows buyers to make payments directly from their bank accounts, suitable for customers across multiple European countries. Supported currencies include EUR, DKK, SEK, GBP, and NOK.',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
'icon' => 'payment-method-trustly',
|
||||
'icon' => 'payment-method-trustly',
|
||||
'itemTitle' => __( 'Trustly', 'woocommerce-paypal-payments' ),
|
||||
'itemDescription' => __(
|
||||
'A European payment method that allows buyers to make payments directly from their bank accounts, suitable for customers across multiple European countries. Supported currencies include EUR, DKK, SEK, GBP, and NOK.',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
'fields' => array(
|
||||
'checkoutPageTitle' => array(
|
||||
'type' => 'text',
|
||||
'default' => $this->getPaymentTitle( TrustlyGateway::ID ) ?? '',
|
||||
'label' => __( 'Checkout page title', 'woocommerce-paypal-payments' ),
|
||||
),
|
||||
'checkoutPageDescription' => array(
|
||||
'type' => 'text',
|
||||
'default' => $this->getPaymentDescription( TrustlyGateway::ID ) ?? '',
|
||||
'label' => __( 'Checkout page description', 'woocommerce-paypal-payments' ),
|
||||
),
|
||||
),
|
||||
),
|
||||
MultibancoGateway::ID => array(
|
||||
'id' => 'multibanco',
|
||||
'title' => __( 'Multibanco', 'woocommerce-paypal-payments' ),
|
||||
'description' => __(
|
||||
'id' => MultibancoGateway::ID,
|
||||
'title' => __( 'Multibanco', 'woocommerce-paypal-payments' ),
|
||||
'description' => __(
|
||||
'An online payment method in Portugal, enabling Portuguese buyers to make secure payments directly through their bank accounts. Transactions are processed in EUR.',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
'icon' => 'payment-method-multibanco',
|
||||
'icon' => 'payment-method-multibanco',
|
||||
'itemTitle' => __( 'Multibanco', 'woocommerce-paypal-payments' ),
|
||||
'itemDescription' => __(
|
||||
'An online payment method in Portugal, enabling Portuguese buyers to make secure payments directly through their bank accounts. Transactions are processed in EUR.',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
'fields' => array(
|
||||
'checkoutPageTitle' => array(
|
||||
'type' => 'text',
|
||||
'default' => $this->getPaymentTitle( MultibancoGateway::ID ) ?? '',
|
||||
'label' => __( 'Checkout page title', 'woocommerce-paypal-payments' ),
|
||||
),
|
||||
'checkoutPageDescription' => array(
|
||||
'type' => 'text',
|
||||
'default' => $this->getPaymentDescription( MultibancoGateway::ID ) ?? '',
|
||||
'label' => __( 'Checkout page description', 'woocommerce-paypal-payments' ),
|
||||
),
|
||||
),
|
||||
),
|
||||
PayUponInvoiceGateway::ID => array(
|
||||
'id' => 'pui',
|
||||
'title' => __( 'Pay upon Invoice', 'woocommerce-paypal-payments' ),
|
||||
'description' => __(
|
||||
'id' => PayUponInvoiceGateway::ID,
|
||||
'title' => __( 'Pay upon Invoice', 'woocommerce-paypal-payments' ),
|
||||
'description' => __(
|
||||
'Pay upon Invoice is an invoice payment method in Germany. It is a local buy now, pay later payment method that allows the buyer to place an order, receive the goods, try them, verify they are in good order, and then pay the invoice within 30 days.',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
'icon' => '',
|
||||
'icon' => '',
|
||||
'itemTitle' => __( 'Pay upon Invoice', 'woocommerce-paypal-payments' ),
|
||||
'itemDescription' => __(
|
||||
'Pay upon Invoice is an invoice payment method in Germany. It is a local buy now, pay later payment method that allows the buyer to place an order, receive the goods, try them, verify they are in good order, and then pay the invoice within 30 days.',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
'fields' => array(
|
||||
'checkoutPageTitle' => array(
|
||||
'type' => 'text',
|
||||
'default' => $this->getPaymentTitle( PayUponInvoiceGateway::ID ) ?? '',
|
||||
'label' => __( 'Checkout page title', 'woocommerce-paypal-payments' ),
|
||||
),
|
||||
'checkoutPageDescription' => array(
|
||||
'type' => 'text',
|
||||
'default' => $this->getPaymentDescription( PayUponInvoiceGateway::ID ) ?? '',
|
||||
'label' => __( 'Checkout page description', 'woocommerce-paypal-payments' ),
|
||||
),
|
||||
),
|
||||
),
|
||||
OXXO::ID => array(
|
||||
'id' => 'oxxo',
|
||||
'title' => __( 'OXXO', 'woocommerce-paypal-payments' ),
|
||||
'description' => __(
|
||||
'id' => OXXO::ID,
|
||||
'title' => __( 'OXXO', 'woocommerce-paypal-payments' ),
|
||||
'description' => __(
|
||||
'OXXO is a Mexican chain of convenience stores. *Get PayPal account permission to use OXXO payment functionality by contacting us at (+52) 800–925–0304',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
'icon' => '',
|
||||
'icon' => '',
|
||||
'itemTitle' => __( 'OXXO', 'woocommerce-paypal-payments' ),
|
||||
'itemDescription' => __(
|
||||
'OXXO is a Mexican chain of convenience stores. *Get PayPal account permission to use OXXO payment functionality by contacting us at (+52) 800–925–0304',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
'fields' => array(
|
||||
'checkoutPageTitle' => array(
|
||||
'type' => 'text',
|
||||
'default' => $this->getPaymentTitle( OXXO::ID ) ?? '',
|
||||
'label' => __( 'Checkout page title', 'woocommerce-paypal-payments' ),
|
||||
),
|
||||
'checkoutPageDescription' => array(
|
||||
'type' => 'text',
|
||||
'default' => $this->getPaymentDescription( OXXO::ID ) ?? '',
|
||||
'label' => __( 'Checkout page description', 'woocommerce-paypal-payments' ),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -277,28 +649,44 @@ class PaymentRestEndpoint extends RestEndpoint {
|
|||
foreach ( $this->gateways() as $key => $value ) {
|
||||
if ( ! isset( $all_gateways[ $key ] ) ) {
|
||||
$gateway_settings[ $key ] = array(
|
||||
'id' => $this->gateways()[ $key ]['id'] ?? '',
|
||||
'title' => $this->gateways()[ $key ]['title'] ?? '',
|
||||
'description' => $this->gateways()[ $key ]['description'] ?? '',
|
||||
'enabled' => false,
|
||||
'icon' => $this->gateways()[ $key ]['icon'] ?? '',
|
||||
'id' => $this->gateways()[ $key ]['id'] ?? '',
|
||||
'title' => $this->gateways()[ $key ]['title'] ?? '',
|
||||
'description' => $this->gateways()[ $key ]['description'] ?? '',
|
||||
'enabled' => false,
|
||||
'icon' => $this->gateways()[ $key ]['icon'] ?? '',
|
||||
'itemTitle' => $this->gateways()[ $key ]['itemTitle'] ?? '',
|
||||
'itemDescription' => $this->gateways()[ $key ]['itemDescription'] ?? '',
|
||||
);
|
||||
|
||||
if ( isset( $this->gateways()[ $key ]['fields'] ) ) {
|
||||
$gateway_settings[ $key ]['fields'] = $this->gateways()[ $key ]['fields'];
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$gateway = $all_gateways[ $key ];
|
||||
|
||||
$gateway_settings[ $key ] = array(
|
||||
'enabled' => 'yes' === $gateway->enabled,
|
||||
'title' => $this->gateways()[ $key ]['title'] ?? $gateway->get_title(),
|
||||
'description' => $this->gateways()[ $key ]['description'] ?? $gateway->get_description(),
|
||||
'method_title' => $gateway->get_method_title(),
|
||||
'id' => $this->gateways()[ $key ]['id'] ?? $key,
|
||||
'icon' => $this->gateways()[ $key ]['icon'] ?? '',
|
||||
'enabled' => 'yes' === $gateway->enabled,
|
||||
'title' => $gateway->get_title(),
|
||||
'description' => $gateway->get_description(),
|
||||
'id' => $this->gateways()[ $key ]['id'] ?? $key,
|
||||
'icon' => $this->gateways()[ $key ]['icon'] ?? '',
|
||||
'itemTitle' => $this->gateways()[ $key ]['itemTitle'] ?? '',
|
||||
'itemDescription' => $this->gateways()[ $key ]['itemDescription'] ?? '',
|
||||
);
|
||||
|
||||
if ( isset( $this->gateways()[ $key ]['fields'] ) ) {
|
||||
$gateway_settings[ $key ]['fields'] = $this->gateways()[ $key ]['fields'];
|
||||
}
|
||||
}
|
||||
|
||||
$gateway_settings['paypalShowLogo'] = $this->settings->get_paypal_show_logo();
|
||||
$gateway_settings['threeDSecure'] = $this->settings->get_three_d_secure();
|
||||
$gateway_settings['fastlaneCardholderName'] = $this->settings->get_fastlane_cardholder_name();
|
||||
$gateway_settings['fastlaneDisplayWatermark'] = $this->settings->get_fastlane_display_watermark();
|
||||
|
||||
return $this->return_success( $gateway_settings );
|
||||
}
|
||||
|
||||
|
@ -322,20 +710,64 @@ class PaymentRestEndpoint extends RestEndpoint {
|
|||
|
||||
$gateway = $all_gateways[ $key ];
|
||||
$new_data = $request_data[ $key ];
|
||||
$gateway->init_form_fields();
|
||||
$settings = $gateway->settings;
|
||||
|
||||
if ( isset( $new_data['enabled'] ) ) {
|
||||
$gateway->update_option( 'enabled', $new_data['enabled'] ? 'yes' : 'no' );
|
||||
}
|
||||
if ( isset( $new_data['title'] ) ) {
|
||||
$gateway->update_option( 'title', sanitize_text_field( $new_data['title'] ) );
|
||||
}
|
||||
if ( isset( $new_data['description'] ) ) {
|
||||
$gateway->update_option( 'description', wp_kses_post( $new_data['description'] ) );
|
||||
$settings['enabled'] = wc_bool_to_string( $new_data['enabled'] );
|
||||
$gateway->enabled = $settings['enabled'];
|
||||
}
|
||||
|
||||
$gateway->process_admin_options();
|
||||
if ( isset( $new_data['title'] ) ) {
|
||||
$settings['title'] = sanitize_text_field( $new_data['title'] );
|
||||
$gateway->title = $settings['title'];
|
||||
}
|
||||
|
||||
if ( isset( $new_data['description'] ) ) {
|
||||
$settings['description'] = wp_kses_post( $new_data['description'] );
|
||||
$gateway->description = $settings['description'];
|
||||
}
|
||||
|
||||
$gateway->settings = $settings;
|
||||
update_option( $gateway->get_option_key(), $settings );
|
||||
}
|
||||
|
||||
$wp_data = $this->sanitize_for_wordpress(
|
||||
$request->get_params(),
|
||||
$this->field_map
|
||||
);
|
||||
|
||||
$this->settings->from_array( $wp_data );
|
||||
$this->settings->save();
|
||||
|
||||
return $this->get_details();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns title for the given gateway.
|
||||
*
|
||||
* @param string $id Gateway ID.
|
||||
* @return string
|
||||
*/
|
||||
private function getPaymentTitle( string $id ): string {
|
||||
if ( ! isset( WC()->payment_gateways()->payment_gateways()[ $id ] ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return WC()->payment_gateways()->payment_gateways()[ $id ]->get_title() ?? '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns title for the given gateway.
|
||||
*
|
||||
* @param string $id Gateway ID.
|
||||
* @return string
|
||||
*/
|
||||
private function getPaymentDescription( string $id ): string {
|
||||
if ( ! isset( WC()->payment_gateways()->payment_gateways()[ $id ] ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return WC()->payment_gateways()->payment_gateways()[ $id ]->get_description() ?? '';
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue