Skip to content

Commit

Permalink
Merge trunk
Browse files Browse the repository at this point in the history
  • Loading branch information
Dinamiko committed Jan 24, 2025
2 parents c8e7ad9 + 143e089 commit 505babb
Show file tree
Hide file tree
Showing 17 changed files with 851 additions and 361 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct(
string $country
) {
$this->allowed_countries = $allowed_countries;
$this->country = $country;
$this->country = $country;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,25 @@ const FeatureSettingsBlock = ( { title, description, ...props } ) => {
<Button
className={ button.class ? button.class : '' }
key={ button.text }
isBusy={ props.actionProps?.isBusy }
isBusy={ props.actionProps?.isBusy }
variant={ button.type }
onClick={ button.onClick }
>
{ button.text }
</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 (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,35 @@ import { ToggleControl } from '@wordpress/components';
import SettingsBlock from './SettingsBlock';
import PaymentMethodIcon from '../PaymentMethodIcon';
import data from '../../../utils/data';
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
__nextHasNoMarginBottom={ true }
checked={ isSelected }
onChange={ onSelect }
/>
{ hasModal && onTriggerModal && (
{ paymentMethod?.fields && onTriggerModal && (
<div
className="ppcp-r-settings-block__payment-methods__item__settings"
onClick={ onTriggerModal }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const PaymentMethodsBlock = ( {
{ paymentMethods.map( ( paymentMethod ) => (
<PaymentMethodItemBlock
key={ paymentMethod.id }
{ ...paymentMethod }
paymentMethod={ paymentMethod }
isSelected={ paymentMethod.enabled }
onSelect={ ( checked ) =>
handleSelect( paymentMethod, checked )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import PaymentMethodsBlock from '../../ReusableComponents/SettingsBlocks/Payment
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 } =
Expand All @@ -14,6 +15,8 @@ const TabPaymentMethods = () => {
const { paymentMethodsAlternative } =
PaymentHooks.usePaymentMethodsAlternative();

const { setPersistent } = usePaymentMethods();

const { activeModal, setActiveModal } = useActiveModal();

const getActiveMethod = () => {
Expand Down Expand Up @@ -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 );
} }
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,57 @@ 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;
} );

if ( ! method?.id ) {
return null;
}

const methodConfig = getPaymentMethods( method );
const methodConfig = paymentMethods.find( ( i ) => i.id === method.id );
if ( ! methodConfig?.fields ) {
return null;
}
Expand Down

This file was deleted.

Loading

0 comments on commit 505babb

Please sign in to comment.