mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
🔀 Merge branch 'trunk'
This commit is contained in:
commit
69c877fae7
38 changed files with 404 additions and 237 deletions
|
@ -17,10 +17,19 @@ $fast-transition-duration: 0.5s;
|
|||
}
|
||||
|
||||
// 1. AXO Block Radio Label
|
||||
#ppcp-axo-block-radio-label {
|
||||
@include flex-space-between;
|
||||
.wc-block-checkout__payment-method label[for="radio-control-wc-payment-method-options-ppcp-axo-gateway"] {
|
||||
padding-right: .875em;
|
||||
}
|
||||
|
||||
#radio-control-wc-payment-method-options-ppcp-axo-gateway__label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
padding-right: 1em;
|
||||
|
||||
.wc-block-components-payment-method-icons {
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
|
||||
// 2. AXO Block Card
|
||||
|
@ -70,15 +79,16 @@ $fast-transition-duration: 0.5s;
|
|||
}
|
||||
|
||||
&__edit {
|
||||
background-color: transparent;
|
||||
flex-grow: 1;
|
||||
margin-left: auto;
|
||||
text-align: right;
|
||||
border: 0;
|
||||
color: inherit;
|
||||
cursor: pointer;
|
||||
display: block;
|
||||
font-family: inherit;
|
||||
margin: 0 0 0 auto;
|
||||
font-size: 0.875em;
|
||||
font-weight: normal;
|
||||
color: inherit;
|
||||
background-color: transparent;
|
||||
cursor: pointer;
|
||||
|
||||
&:hover {
|
||||
text-decoration: underline;
|
||||
|
|
|
@ -1,15 +1,28 @@
|
|||
import { createElement } from '@wordpress/element';
|
||||
import { useSelect } from '@wordpress/data';
|
||||
import { __ } from '@wordpress/i18n';
|
||||
import { STORE_NAME } from '../../stores/axoStore';
|
||||
|
||||
/**
|
||||
* Renders a button to change the selected card in the checkout process.
|
||||
*
|
||||
* @param {Object} props
|
||||
* @param {Function} props.onChangeButtonClick - Callback function to handle the click event.
|
||||
* @return {JSX.Element} The rendered button as an anchor tag.
|
||||
* @return {JSX.Element|null} The rendered button as an anchor tag, or null if conditions aren't met.
|
||||
*/
|
||||
const CardChangeButton = ( { onChangeButtonClick } ) =>
|
||||
createElement(
|
||||
const CardChangeButton = () => {
|
||||
const { isGuest, cardDetails, cardChangeHandler } = useSelect(
|
||||
( select ) => ( {
|
||||
isGuest: select( STORE_NAME ).getIsGuest(),
|
||||
cardDetails: select( STORE_NAME ).getCardDetails(),
|
||||
cardChangeHandler: select( STORE_NAME ).getCardChangeHandler(),
|
||||
} ),
|
||||
[]
|
||||
);
|
||||
|
||||
if ( isGuest || ! cardDetails || ! cardChangeHandler ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return createElement(
|
||||
'a',
|
||||
{
|
||||
className:
|
||||
|
@ -19,10 +32,11 @@ const CardChangeButton = ( { onChangeButtonClick } ) =>
|
|||
// Prevent default anchor behavior
|
||||
event.preventDefault();
|
||||
// Call the provided click handler
|
||||
onChangeButtonClick();
|
||||
cardChangeHandler();
|
||||
},
|
||||
},
|
||||
__( 'Choose a different card', 'woocommerce-paypal-payments' )
|
||||
);
|
||||
};
|
||||
|
||||
export default CardChangeButton;
|
||||
|
|
|
@ -1,51 +0,0 @@
|
|||
import { createElement, createRoot, useEffect } from '@wordpress/element';
|
||||
import CardChangeButton from './CardChangeButton';
|
||||
|
||||
/**
|
||||
* Manages the insertion and removal of the CardChangeButton in the DOM.
|
||||
*
|
||||
* @param {Object} props
|
||||
* @param {Function} props.onChangeButtonClick - Callback function for when the card change button is clicked.
|
||||
* @return {null} This component doesn't render any visible elements directly.
|
||||
*/
|
||||
const CardChangeButtonManager = ( { onChangeButtonClick } ) => {
|
||||
useEffect( () => {
|
||||
const radioLabelElement = document.getElementById(
|
||||
'ppcp-axo-block-radio-label'
|
||||
);
|
||||
|
||||
if ( radioLabelElement ) {
|
||||
// Check if the change button doesn't already exist
|
||||
if (
|
||||
! radioLabelElement.querySelector(
|
||||
'.wc-block-checkout-axo-block-card__edit'
|
||||
)
|
||||
) {
|
||||
// Create a new container for the button
|
||||
const buttonContainer = document.createElement( 'div' );
|
||||
radioLabelElement.appendChild( buttonContainer );
|
||||
|
||||
// Create a React root and render the CardChangeButton
|
||||
const root = createRoot( buttonContainer );
|
||||
root.render(
|
||||
createElement( CardChangeButton, { onChangeButtonClick } )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Cleanup function to remove the button when the component unmounts
|
||||
return () => {
|
||||
const button = document.querySelector(
|
||||
'.wc-block-checkout-axo-block-card__edit'
|
||||
);
|
||||
if ( button && button.parentNode ) {
|
||||
button.parentNode.remove();
|
||||
}
|
||||
};
|
||||
}, [ onChangeButtonClick ] );
|
||||
|
||||
// This component doesn't render anything directly
|
||||
return null;
|
||||
};
|
||||
|
||||
export default CardChangeButtonManager;
|
|
@ -1,4 +1,2 @@
|
|||
export { default as Card } from './Card';
|
||||
export { default as CardChangeButton } from './CardChangeButton';
|
||||
export { default as CardChangeButtonManager } from './CardChangeButtonManager';
|
||||
export { injectCardChangeButton, removeCardChangeButton } from './utils';
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
import { createElement, createRoot } from '@wordpress/element';
|
||||
import CardChangeButtonManager from './CardChangeButtonManager';
|
||||
|
||||
/**
|
||||
* Injects a card change button into the DOM.
|
||||
*
|
||||
* @param {Function} onChangeButtonClick - Callback function for when the card change button is clicked.
|
||||
*/
|
||||
export const injectCardChangeButton = ( onChangeButtonClick ) => {
|
||||
// Create a container for the button
|
||||
const container = document.createElement( 'div' );
|
||||
document.body.appendChild( container );
|
||||
|
||||
// Render the CardChangeButtonManager in the new container
|
||||
createRoot( container ).render(
|
||||
createElement( CardChangeButtonManager, { onChangeButtonClick } )
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Removes the card change button from the DOM if it exists.
|
||||
*/
|
||||
export const removeCardChangeButton = () => {
|
||||
const button = document.querySelector(
|
||||
'.wc-block-checkout-axo-block-card__edit'
|
||||
);
|
||||
|
||||
// Remove the button's parent node if it exists
|
||||
if ( button && button.parentNode ) {
|
||||
button.parentNode.remove();
|
||||
}
|
||||
};
|
|
@ -0,0 +1,24 @@
|
|||
import CardChangeButton from './../Card/CardChangeButton';
|
||||
|
||||
/**
|
||||
* TitleLabel component for displaying a payment method title with icons and a change card button.
|
||||
*
|
||||
* @param {Object} props - Component props
|
||||
* @param {Object} props.components - Object containing WooCommerce components
|
||||
* @param {Object} props.config - Configuration object for the payment method
|
||||
* @return {JSX.Element} WordPress element
|
||||
*/
|
||||
const TitleLabel = ( { components, config } ) => {
|
||||
const axoConfig = window.wc_ppcp_axo;
|
||||
const { PaymentMethodIcons } = components;
|
||||
|
||||
return (
|
||||
<>
|
||||
<span dangerouslySetInnerHTML={ { __html: config.title } } />
|
||||
<PaymentMethodIcons icons={ axoConfig?.card_icons } />
|
||||
<CardChangeButton />
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default TitleLabel;
|
|
@ -0,0 +1 @@
|
|||
export { default as TitleLabel } from './TitleLabel';
|
|
@ -1,7 +1,6 @@
|
|||
import { log } from '../../../../ppcp-axo/resources/js/Helper/Debug';
|
||||
import { populateWooFields } from '../helpers/fieldHelpers';
|
||||
import { injectShippingChangeButton } from '../components/Shipping';
|
||||
import { injectCardChangeButton } from '../components/Card';
|
||||
import { setIsGuest, setIsEmailLookupCompleted } from '../stores/axoStore';
|
||||
|
||||
/**
|
||||
|
@ -16,7 +15,6 @@ import { setIsGuest, setIsEmailLookupCompleted } from '../stores/axoStore';
|
|||
* @param {Function} setWooShippingAddress - Function to update WooCommerce shipping address.
|
||||
* @param {Function} setWooBillingAddress - Function to update WooCommerce billing address.
|
||||
* @param {Function} onChangeShippingAddressClick - Handler for shipping address change.
|
||||
* @param {Function} onChangeCardButtonClick - Handler for card change.
|
||||
* @return {Function} The email lookup handler function.
|
||||
*/
|
||||
export const createEmailLookupHandler = (
|
||||
|
@ -28,8 +26,7 @@ export const createEmailLookupHandler = (
|
|||
wooBillingAddress,
|
||||
setWooShippingAddress,
|
||||
setWooBillingAddress,
|
||||
onChangeShippingAddressClick,
|
||||
onChangeCardButtonClick
|
||||
onChangeShippingAddressClick
|
||||
) => {
|
||||
return async ( email ) => {
|
||||
try {
|
||||
|
@ -102,9 +99,8 @@ export const createEmailLookupHandler = (
|
|||
setWooBillingAddress
|
||||
);
|
||||
|
||||
// Inject change buttons for shipping and card
|
||||
// Inject the change button for shipping
|
||||
injectShippingChangeButton( onChangeShippingAddressClick );
|
||||
injectCardChangeButton( onChangeCardButtonClick );
|
||||
} else {
|
||||
log( 'Authentication failed or did not succeed', 'warn' );
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ import { useDispatch } from '@wordpress/data';
|
|||
import { log } from '../../../../ppcp-axo/resources/js/Helper/Debug';
|
||||
import { STORE_NAME } from '../stores/axoStore';
|
||||
import { removeShippingChangeButton } from '../components/Shipping';
|
||||
import { removeCardChangeButton } from '../components/Card';
|
||||
import { removeWatermark } from '../components/Watermark';
|
||||
import {
|
||||
removeEmailFunctionality,
|
||||
|
@ -50,7 +49,6 @@ const useAxoCleanup = () => {
|
|||
|
||||
// Remove AXO UI elements
|
||||
removeShippingChangeButton();
|
||||
removeCardChangeButton();
|
||||
removeWatermark();
|
||||
|
||||
// Remove email functionality if it was set up
|
||||
|
|
|
@ -35,6 +35,7 @@ const useAxoSetup = (
|
|||
setIsAxoScriptLoaded,
|
||||
setShippingAddress,
|
||||
setCardDetails,
|
||||
setCardChangeHandler,
|
||||
} = useDispatch( STORE_NAME );
|
||||
|
||||
// Check if PayPal script has loaded
|
||||
|
@ -73,6 +74,7 @@ const useAxoSetup = (
|
|||
if ( paypalLoaded && fastlaneSdk ) {
|
||||
setIsAxoScriptLoaded( true );
|
||||
setIsAxoActive( true );
|
||||
setCardChangeHandler( onChangeCardButtonClick );
|
||||
|
||||
// Create and set up email lookup handler
|
||||
const emailLookupHandler = createEmailLookupHandler(
|
||||
|
@ -84,8 +86,7 @@ const useAxoSetup = (
|
|||
wooBillingAddress,
|
||||
setWooShippingAddress,
|
||||
setWooBillingAddress,
|
||||
onChangeShippingAddressClick,
|
||||
onChangeCardButtonClick
|
||||
onChangeShippingAddressClick
|
||||
);
|
||||
setupEmailFunctionality( emailLookupHandler );
|
||||
}
|
||||
|
|
36
modules/ppcp-axo-block/resources/js/hooks/useCardOptions.js
Normal file
36
modules/ppcp-axo-block/resources/js/hooks/useCardOptions.js
Normal file
|
@ -0,0 +1,36 @@
|
|||
import { useMemo } from '@wordpress/element';
|
||||
|
||||
const DEFAULT_ALLOWED_CARDS = [ 'VISA', 'MASTERCARD', 'AMEX', 'DISCOVER' ];
|
||||
|
||||
/**
|
||||
* Custom hook to determine the allowed card options based on configuration.
|
||||
*
|
||||
* @param {Object} axoConfig - The AXO configuration object.
|
||||
* @return {Array} The final list of allowed card options.
|
||||
*/
|
||||
const useCardOptions = ( axoConfig ) => {
|
||||
const merchantCountry = axoConfig.merchant_country || 'US';
|
||||
|
||||
return useMemo( () => {
|
||||
const allowedCards = new Set(
|
||||
axoConfig.allowed_cards?.[ merchantCountry ] ||
|
||||
DEFAULT_ALLOWED_CARDS
|
||||
);
|
||||
|
||||
// Create a Set of disabled cards, converting each to uppercase
|
||||
const disabledCards = new Set(
|
||||
( axoConfig.disable_cards || [] ).map( ( card ) =>
|
||||
card.toUpperCase()
|
||||
)
|
||||
);
|
||||
|
||||
// Filter out disabled cards from the allowed cards
|
||||
const finalCardOptions = [ ...allowedCards ].filter(
|
||||
( card ) => ! disabledCards.has( card )
|
||||
);
|
||||
|
||||
return finalCardOptions;
|
||||
}, [ axoConfig.allowed_cards, axoConfig.disable_cards, merchantCountry ] );
|
||||
};
|
||||
|
||||
export default useCardOptions;
|
|
@ -3,6 +3,7 @@ import { useSelect } from '@wordpress/data';
|
|||
import Fastlane from '../../../../ppcp-axo/resources/js/Connection/Fastlane';
|
||||
import { log } from '../../../../ppcp-axo/resources/js/Helper/Debug';
|
||||
import { useDeleteEmptyKeys } from './useDeleteEmptyKeys';
|
||||
import useCardOptions from './useCardOptions';
|
||||
import useAllowedLocations from './useAllowedLocations';
|
||||
import { STORE_NAME } from '../stores/axoStore';
|
||||
|
||||
|
@ -27,6 +28,8 @@ const useFastlaneSdk = ( namespace, axoConfig, ppcpConfig ) => {
|
|||
[]
|
||||
);
|
||||
|
||||
const cardOptions = useCardOptions( axoConfig );
|
||||
|
||||
const styleOptions = useMemo( () => {
|
||||
return deleteEmptyKeys( configRef.current.axoConfig.style_options );
|
||||
}, [ deleteEmptyKeys ] );
|
||||
|
@ -51,10 +54,13 @@ const useFastlaneSdk = ( namespace, axoConfig, ppcpConfig ) => {
|
|||
window.localStorage.setItem( 'axoEnv', 'sandbox' );
|
||||
}
|
||||
|
||||
// Connect to Fastlane with locale and style options
|
||||
// Connect to Fastlane with locale, style options, and allowed card brands
|
||||
await fastlane.connect( {
|
||||
locale: configRef.current.ppcpConfig.locale,
|
||||
styles: styleOptions,
|
||||
cardOptions: {
|
||||
allowedBrands: cardOptions,
|
||||
},
|
||||
shippingAddressOptions: {
|
||||
allowedLocations,
|
||||
},
|
||||
|
@ -77,6 +83,7 @@ const useFastlaneSdk = ( namespace, axoConfig, ppcpConfig ) => {
|
|||
styleOptions,
|
||||
isPayPalLoaded,
|
||||
namespace,
|
||||
cardOptions,
|
||||
allowedLocations,
|
||||
] );
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ import usePayPalCommerceGateway from './hooks/usePayPalCommerceGateway';
|
|||
|
||||
// Components
|
||||
import { Payment } from './components/Payment/Payment';
|
||||
import { TitleLabel } from './components/TitleLabel';
|
||||
|
||||
const gatewayHandle = 'ppcp-axo-gateway';
|
||||
const namespace = 'ppcpBlocksPaypalAxo';
|
||||
|
@ -89,12 +90,7 @@ const Axo = ( props ) => {
|
|||
|
||||
registerPaymentMethod( {
|
||||
name: initialConfig.id,
|
||||
label: (
|
||||
<div
|
||||
id="ppcp-axo-block-radio-label"
|
||||
dangerouslySetInnerHTML={ { __html: initialConfig.title } }
|
||||
/>
|
||||
),
|
||||
label: <TitleLabel config={ initialConfig } />,
|
||||
content: <Axo />,
|
||||
edit: createElement( initialConfig.title ),
|
||||
ariaLabel: initialConfig.title,
|
||||
|
|
|
@ -12,6 +12,7 @@ const DEFAULT_STATE = {
|
|||
shippingAddress: null,
|
||||
cardDetails: null,
|
||||
phoneNumber: '',
|
||||
cardChangeHandler: null,
|
||||
};
|
||||
|
||||
// Action creators for updating the store state
|
||||
|
@ -52,6 +53,10 @@ const actions = {
|
|||
type: 'SET_PHONE_NUMBER',
|
||||
payload: phoneNumber,
|
||||
} ),
|
||||
setCardChangeHandler: ( cardChangeHandler ) => ( {
|
||||
type: 'SET_CARD_CHANGE_HANDLER',
|
||||
payload: cardChangeHandler,
|
||||
} ),
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -81,6 +86,8 @@ const reducer = ( state = DEFAULT_STATE, action ) => {
|
|||
return { ...state, cardDetails: action.payload };
|
||||
case 'SET_PHONE_NUMBER':
|
||||
return { ...state, phoneNumber: action.payload };
|
||||
case 'SET_CARD_CHANGE_HANDLER':
|
||||
return { ...state, cardChangeHandler: action.payload };
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
@ -97,6 +104,7 @@ const selectors = {
|
|||
getShippingAddress: ( state ) => state.shippingAddress,
|
||||
getCardDetails: ( state ) => state.cardDetails,
|
||||
getPhoneNumber: ( state ) => state.phoneNumber,
|
||||
getCardChangeHandler: ( state ) => state.cardChangeHandler,
|
||||
};
|
||||
|
||||
// Create and register the Redux store for the AXO block
|
||||
|
@ -163,3 +171,12 @@ export const setCardDetails = ( cardDetails ) => {
|
|||
export const setPhoneNumber = ( phoneNumber ) => {
|
||||
dispatch( STORE_NAME ).setPhoneNumber( phoneNumber );
|
||||
};
|
||||
|
||||
/**
|
||||
* Action dispatcher to update the card change handler in the store.
|
||||
*
|
||||
* @param {Function} cardChangeHandler - The card change handler function.
|
||||
*/
|
||||
export const setCardChangeHandler = ( cardChangeHandler ) => {
|
||||
dispatch( STORE_NAME ).setCardChangeHandler( cardChangeHandler );
|
||||
};
|
||||
|
|
|
@ -38,6 +38,7 @@ return array(
|
|||
$container->get( 'wcgateway.configuration.dcc' ),
|
||||
$container->get( 'onboarding.environment' ),
|
||||
$container->get( 'wcgateway.url' ),
|
||||
$container->get( 'axo.supported-country-card-type-matrix' ),
|
||||
$container->get( 'axo.shipping-wc-enabled-locations' )
|
||||
);
|
||||
},
|
||||
|
|
|
@ -79,6 +79,13 @@ class AxoBlockPaymentMethod extends AbstractPaymentMethodType {
|
|||
*/
|
||||
private $wcgateway_module_url;
|
||||
|
||||
/**
|
||||
* The supported country card type matrix.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $supported_country_card_type_matrix;
|
||||
|
||||
/**
|
||||
* The list of WooCommerce enabled shipping locations.
|
||||
*
|
||||
|
@ -98,6 +105,7 @@ class AxoBlockPaymentMethod extends AbstractPaymentMethodType {
|
|||
* @param DCCGatewayConfiguration $dcc_configuration The DCC gateway settings.
|
||||
* @param Environment $environment The environment object.
|
||||
* @param string $wcgateway_module_url The WcGateway module URL.
|
||||
* @param array $supported_country_card_type_matrix The supported country card type matrix for Axo.
|
||||
* @param array $enabled_shipping_locations The list of WooCommerce enabled shipping locations.
|
||||
*/
|
||||
public function __construct(
|
||||
|
@ -109,18 +117,20 @@ class AxoBlockPaymentMethod extends AbstractPaymentMethodType {
|
|||
DCCGatewayConfiguration $dcc_configuration,
|
||||
Environment $environment,
|
||||
string $wcgateway_module_url,
|
||||
array $supported_country_card_type_matrix,
|
||||
array $enabled_shipping_locations
|
||||
) {
|
||||
$this->name = AxoGateway::ID;
|
||||
$this->module_url = $module_url;
|
||||
$this->version = $version;
|
||||
$this->gateway = $gateway;
|
||||
$this->smart_button = $smart_button;
|
||||
$this->settings = $settings;
|
||||
$this->dcc_configuration = $dcc_configuration;
|
||||
$this->environment = $environment;
|
||||
$this->wcgateway_module_url = $wcgateway_module_url;
|
||||
$this->enabled_shipping_locations = $enabled_shipping_locations;
|
||||
$this->name = AxoGateway::ID;
|
||||
$this->module_url = $module_url;
|
||||
$this->version = $version;
|
||||
$this->gateway = $gateway;
|
||||
$this->smart_button = $smart_button;
|
||||
$this->settings = $settings;
|
||||
$this->dcc_configuration = $dcc_configuration;
|
||||
$this->environment = $environment;
|
||||
$this->wcgateway_module_url = $wcgateway_module_url;
|
||||
$this->supported_country_card_type_matrix = $supported_country_card_type_matrix;
|
||||
$this->enabled_shipping_locations = $enabled_shipping_locations;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -216,6 +226,8 @@ class AxoBlockPaymentMethod extends AbstractPaymentMethodType {
|
|||
: null, // Set to null if WC()->cart is null or get_total doesn't exist.
|
||||
),
|
||||
),
|
||||
'allowed_cards' => $this->supported_country_card_type_matrix,
|
||||
'disable_cards' => $this->settings->has( 'disable_cards' ) ? (array) $this->settings->get( 'disable_cards' ) : array(),
|
||||
'enabled_shipping_locations' => $this->enabled_shipping_locations,
|
||||
'style_options' => array(
|
||||
'root' => array(
|
||||
|
@ -253,6 +265,8 @@ class AxoBlockPaymentMethod extends AbstractPaymentMethodType {
|
|||
),
|
||||
'logging_enabled' => $this->settings->has( 'logging_enabled' ) ? $this->settings->get( 'logging_enabled' ) : '',
|
||||
'wp_debug' => defined( 'WP_DEBUG' ) && WP_DEBUG,
|
||||
'card_icons' => $this->settings->has( 'card_icons' ) ? (array) $this->settings->get( 'card_icons' ) : array(),
|
||||
'merchant_country' => WC()->countries->get_base_country(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -85,6 +85,8 @@ class AxoManager {
|
|||
},
|
||||
};
|
||||
|
||||
this.cardOptions = this.getCardOptions();
|
||||
|
||||
this.enabledShippingLocations =
|
||||
this.axoConfig.enabled_shipping_locations;
|
||||
|
||||
|
@ -664,6 +666,9 @@ class AxoManager {
|
|||
await this.fastlane.connect( {
|
||||
locale: this.locale,
|
||||
styles: this.styles,
|
||||
cardOptions: {
|
||||
allowedBrands: this.cardOptions,
|
||||
},
|
||||
shippingAddressOptions: {
|
||||
allowedLocations: this.enabledShippingLocations,
|
||||
},
|
||||
|
@ -1251,6 +1256,31 @@ class AxoManager {
|
|||
return this.axoConfig?.widgets?.email === 'use_widget';
|
||||
}
|
||||
|
||||
getCardOptions() {
|
||||
const DEFAULT_ALLOWED_CARDS = [
|
||||
'VISA',
|
||||
'MASTERCARD',
|
||||
'AMEX',
|
||||
'DISCOVER',
|
||||
];
|
||||
const merchantCountry = this.axoConfig.merchant_country || 'US';
|
||||
|
||||
const allowedCards = new Set(
|
||||
this.axoConfig.allowed_cards?.[ merchantCountry ] ||
|
||||
DEFAULT_ALLOWED_CARDS
|
||||
);
|
||||
|
||||
const disabledCards = new Set(
|
||||
( this.axoConfig.disable_cards || [] ).map( ( card ) =>
|
||||
card.toUpperCase()
|
||||
)
|
||||
);
|
||||
|
||||
return [ ...allowedCards ].filter(
|
||||
( card ) => ! disabledCards.has( card )
|
||||
);
|
||||
}
|
||||
|
||||
deleteKeysWithEmptyString = ( obj ) => {
|
||||
for ( const key of Object.keys( obj ) ) {
|
||||
if ( obj[ key ] === '' ) {
|
||||
|
|
|
@ -68,6 +68,7 @@ return array(
|
|||
$container->get( 'api.shop.currency.getter' ),
|
||||
$container->get( 'woocommerce.logger.woocommerce' ),
|
||||
$container->get( 'wcgateway.url' ),
|
||||
$container->get( 'axo.supported-country-card-type-matrix' ),
|
||||
$container->get( 'axo.shipping-wc-enabled-locations' )
|
||||
);
|
||||
},
|
||||
|
@ -111,7 +112,31 @@ return array(
|
|||
)
|
||||
);
|
||||
},
|
||||
|
||||
/**
|
||||
* The matrix which countries and card type combinations can be used for AXO.
|
||||
*/
|
||||
'axo.supported-country-card-type-matrix' => static function ( ContainerInterface $container ) : array {
|
||||
/**
|
||||
* Returns which countries and card type combinations can be used for AXO.
|
||||
*/
|
||||
return apply_filters(
|
||||
'woocommerce_paypal_payments_axo_supported_country_card_type_matrix',
|
||||
array(
|
||||
'US' => array(
|
||||
'VISA',
|
||||
'MASTERCARD',
|
||||
'AMEX',
|
||||
'DISCOVER',
|
||||
),
|
||||
'CA' => array(
|
||||
'VISA',
|
||||
'MASTERCARD',
|
||||
'AMEX',
|
||||
'DISCOVER',
|
||||
),
|
||||
)
|
||||
);
|
||||
},
|
||||
'axo.settings-conflict-notice' => static function ( ContainerInterface $container ) : string {
|
||||
$settings_notice_generator = $container->get( 'axo.helpers.settings-notice-generator' );
|
||||
assert( $settings_notice_generator instanceof SettingsNoticeGenerator );
|
||||
|
|
|
@ -29,28 +29,28 @@ class AxoManager {
|
|||
*
|
||||
* @var string
|
||||
*/
|
||||
private $module_url;
|
||||
private string $module_url;
|
||||
|
||||
/**
|
||||
* The assets version.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $version;
|
||||
private string $version;
|
||||
|
||||
/**
|
||||
* The settings.
|
||||
*
|
||||
* @var Settings
|
||||
*/
|
||||
private $settings;
|
||||
private Settings $settings;
|
||||
|
||||
/**
|
||||
* The environment object.
|
||||
*
|
||||
* @var Environment
|
||||
*/
|
||||
private $environment;
|
||||
private Environment $environment;
|
||||
|
||||
/**
|
||||
* The Settings status helper.
|
||||
|
@ -71,22 +71,27 @@ class AxoManager {
|
|||
*
|
||||
* @var LoggerInterface
|
||||
*/
|
||||
private $logger;
|
||||
private LoggerInterface $logger;
|
||||
|
||||
/**
|
||||
* Session handler.
|
||||
*
|
||||
* @var SessionHandler
|
||||
*/
|
||||
private $session_handler;
|
||||
private SessionHandler $session_handler;
|
||||
|
||||
/**
|
||||
* The WcGateway module URL.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $wcgateway_module_url;
|
||||
|
||||
private string $wcgateway_module_url;
|
||||
/**
|
||||
* The supported country card type matrix.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private array $supported_country_card_type_matrix;
|
||||
/**
|
||||
* The list of WooCommerce enabled shipping locations.
|
||||
*
|
||||
|
@ -106,6 +111,7 @@ class AxoManager {
|
|||
* @param CurrencyGetter $currency The getter of the 3-letter currency code of the shop.
|
||||
* @param LoggerInterface $logger The logger.
|
||||
* @param string $wcgateway_module_url The WcGateway module URL.
|
||||
* @param array $supported_country_card_type_matrix The supported country card type matrix for Axo.
|
||||
* @param array $enabled_shipping_locations The list of WooCommerce enabled shipping locations.
|
||||
*/
|
||||
public function __construct(
|
||||
|
@ -118,19 +124,21 @@ class AxoManager {
|
|||
CurrencyGetter $currency,
|
||||
LoggerInterface $logger,
|
||||
string $wcgateway_module_url,
|
||||
array $supported_country_card_type_matrix,
|
||||
array $enabled_shipping_locations
|
||||
) {
|
||||
|
||||
$this->module_url = $module_url;
|
||||
$this->version = $version;
|
||||
$this->session_handler = $session_handler;
|
||||
$this->settings = $settings;
|
||||
$this->environment = $environment;
|
||||
$this->settings_status = $settings_status;
|
||||
$this->currency = $currency;
|
||||
$this->logger = $logger;
|
||||
$this->wcgateway_module_url = $wcgateway_module_url;
|
||||
$this->enabled_shipping_locations = $enabled_shipping_locations;
|
||||
$this->module_url = $module_url;
|
||||
$this->version = $version;
|
||||
$this->session_handler = $session_handler;
|
||||
$this->settings = $settings;
|
||||
$this->environment = $environment;
|
||||
$this->settings_status = $settings_status;
|
||||
$this->currency = $currency;
|
||||
$this->logger = $logger;
|
||||
$this->wcgateway_module_url = $wcgateway_module_url;
|
||||
$this->supported_country_card_type_matrix = $supported_country_card_type_matrix;
|
||||
$this->enabled_shipping_locations = $enabled_shipping_locations;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -193,6 +201,8 @@ class AxoManager {
|
|||
'value' => WC()->cart->get_total( 'numeric' ),
|
||||
),
|
||||
),
|
||||
'allowed_cards' => $this->supported_country_card_type_matrix,
|
||||
'disable_cards' => $this->settings->has( 'disable_cards' ) ? (array) $this->settings->get( 'disable_cards' ) : array(),
|
||||
'enabled_shipping_locations' => $this->enabled_shipping_locations,
|
||||
'style_options' => array(
|
||||
'root' => array(
|
||||
|
@ -231,6 +241,7 @@ class AxoManager {
|
|||
'logging_enabled' => $this->settings->has( 'logging_enabled' ) ? $this->settings->get( 'logging_enabled' ) : '',
|
||||
'wp_debug' => defined( 'WP_DEBUG' ) && WP_DEBUG,
|
||||
'billing_email_button_text' => __( 'Continue', 'woocommerce-paypal-payments' ),
|
||||
'merchant_country' => WC()->countries->get_base_country(),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -377,11 +377,15 @@ class AxoModule implements ServiceModule, ExtendingModule, ExecutableModule {
|
|||
$dcc_configuration = $c->get( 'wcgateway.configuration.dcc' );
|
||||
assert( $dcc_configuration instanceof DCCGatewayConfiguration );
|
||||
|
||||
$subscription_helper = $c->get( 'wc-subscriptions.helper' );
|
||||
assert( $subscription_helper instanceof SubscriptionHelper );
|
||||
|
||||
return ! is_user_logged_in()
|
||||
&& CartCheckoutDetector::has_classic_checkout()
|
||||
&& $dcc_configuration->use_fastlane()
|
||||
&& ! $this->is_excluded_endpoint()
|
||||
&& is_checkout();
|
||||
&& is_checkout()
|
||||
&& ! $subscription_helper->cart_contains_subscription();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -3,7 +3,10 @@ import { useEffect, useState } from '@wordpress/element';
|
|||
import {
|
||||
PayPalScriptProvider,
|
||||
PayPalCardFieldsProvider,
|
||||
PayPalCardFieldsForm,
|
||||
PayPalNameField,
|
||||
PayPalNumberField,
|
||||
PayPalExpiryField,
|
||||
PayPalCVVField,
|
||||
} from '@paypal/react-paypal-js';
|
||||
|
||||
import { CheckoutHandler } from './checkout-handler';
|
||||
|
@ -14,6 +17,7 @@ import {
|
|||
onApproveSavePayment,
|
||||
} from '../card-fields-config';
|
||||
import { cartHasSubscriptionProducts } from '../Helper/Subscription';
|
||||
import { __ } from '@wordpress/i18n';
|
||||
|
||||
export function CardFields( {
|
||||
config,
|
||||
|
@ -92,7 +96,16 @@ export function CardFields( {
|
|||
console.error( err );
|
||||
} }
|
||||
>
|
||||
<PayPalCardFieldsForm />
|
||||
<PayPalNameField placeholder={ __( 'Cardholder Name (optional)', 'woocommerce-paypal-payments' ) }/>
|
||||
<PayPalNumberField placeholder={ __( 'Card number', 'woocommerce-paypal-payments' ) }/>
|
||||
<div style={ { display: "flex", width: "100%" } }>
|
||||
<div style={ { width: "100%" } }>
|
||||
<PayPalExpiryField placeholder={ __( 'MM / YY', 'woocommerce-paypal-payments' ) }/>
|
||||
</div>
|
||||
<div style={ { width: "100%" } }>
|
||||
<PayPalCVVField placeholder={ __( 'CVV', 'woocommerce-paypal-payments' ) }/>
|
||||
</div>
|
||||
</div>
|
||||
<CheckoutHandler
|
||||
getCardFieldsForm={ getCardFieldsForm }
|
||||
getSavePayment={ getSavePayment }
|
||||
|
|
|
@ -1,30 +1,50 @@
|
|||
import {registerPaymentMethod} from '@woocommerce/blocks-registry';
|
||||
import {CardFields} from './Components/card-fields';
|
||||
import { registerPaymentMethod } from '@woocommerce/blocks-registry';
|
||||
import { CardFields } from './Components/card-fields';
|
||||
|
||||
const config = wc.wcSettings.getSetting('ppcp-credit-card-gateway_data');
|
||||
const config = wc.wcSettings.getSetting( 'ppcp-credit-card-gateway_data' );
|
||||
const isUserLoggedIn = config?.scriptData?.is_user_logged_in;
|
||||
const axoConfig = wc.wcSettings.getSetting( 'ppcp-axo-gateway_data' );
|
||||
const axoEnabled = axoConfig !== false;
|
||||
|
||||
const Label = ({components, config}) => {
|
||||
const {PaymentMethodIcons} = components;
|
||||
return <>
|
||||
<span dangerouslySetInnerHTML={{__html: config.title}}/>
|
||||
<PaymentMethodIcons
|
||||
icons={ config.card_icons }
|
||||
align="right"
|
||||
/>
|
||||
</>
|
||||
}
|
||||
const Label = ( { components } ) => {
|
||||
const { PaymentMethodIcons } = components;
|
||||
return (
|
||||
<>
|
||||
<span dangerouslySetInnerHTML={ { __html: config?.title } } />
|
||||
<PaymentMethodIcons icons={ config?.card_icons } align="right" />
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
registerPaymentMethod({
|
||||
name: config.id,
|
||||
label: <Label config={config}/>,
|
||||
content: <CardFields config={config}/>,
|
||||
edit: <CardFields config={config}/>,
|
||||
ariaLabel: config.title,
|
||||
canMakePayment: () => {
|
||||
return true;
|
||||
},
|
||||
supports: {
|
||||
showSavedCards: true,
|
||||
features: config.supports,
|
||||
},
|
||||
});
|
||||
registerPaymentMethod( {
|
||||
name: config?.id,
|
||||
label: <Label />,
|
||||
content: <CardFields config={ config } />,
|
||||
edit: <CardFields config={ config } />,
|
||||
ariaLabel: config?.title,
|
||||
canMakePayment: ( cartData ) => {
|
||||
const cartItems = cartData?.cart?.cartItems || [];
|
||||
|
||||
// Check if any item in the cart is a subscription
|
||||
const hasSubscription = cartItems.some(
|
||||
( item ) =>
|
||||
item?.type === 'subscription' ||
|
||||
item?.type === 'variable-subscription' ||
|
||||
cartData?.paymentRequirements?.includes( 'subscriptions' )
|
||||
);
|
||||
|
||||
// Show payment method if:
|
||||
// 1. Axo is disabled, OR
|
||||
// 2. User is logged in, OR
|
||||
// 3. Axo is enabled AND cart has subscriptions
|
||||
return !! (
|
||||
! axoEnabled ||
|
||||
isUserLoggedIn ||
|
||||
( axoEnabled && hasSubscription )
|
||||
);
|
||||
},
|
||||
supports: {
|
||||
showSavedCards: true,
|
||||
features: config?.supports,
|
||||
},
|
||||
} );
|
||||
|
|
|
@ -802,9 +802,24 @@ if ( block_enabled ) {
|
|||
);
|
||||
}
|
||||
|
||||
const PaypalLabel = ( { components, config } ) => {
|
||||
const { PaymentMethodIcons } = components;
|
||||
|
||||
return (
|
||||
<>
|
||||
<span
|
||||
dangerouslySetInnerHTML={ {
|
||||
__html: config.title,
|
||||
} }
|
||||
/>
|
||||
<PaymentMethodIcons icons={ config.icon } align="right" />
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
registerPaymentMethod( {
|
||||
name: config.id,
|
||||
label: <div dangerouslySetInnerHTML={ { __html: config.title } } />,
|
||||
label: <PaypalLabel config={ config } />,
|
||||
content: descriptionElement,
|
||||
edit: descriptionElement,
|
||||
placeOrderButtonLabel: config.placeOrderButtonText,
|
||||
|
|
|
@ -110,6 +110,7 @@ class AdvancedCardPaymentMethod extends AbstractPaymentMethodType {
|
|||
*/
|
||||
public function get_payment_method_data() {
|
||||
$script_data = $this->smart_button_instance()->script_data();
|
||||
$script_data = array_merge( $script_data, array( 'is_user_logged_in' => is_user_logged_in() ) );
|
||||
|
||||
return array(
|
||||
'id' => $this->name,
|
||||
|
|
|
@ -18,6 +18,7 @@ use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ModuleClassNameI
|
|||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ServiceModule;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||
use WooCommerce\PayPalCommerce\WcSubscriptions\Helper\SubscriptionHelper;
|
||||
|
||||
/**
|
||||
* Class BlocksModule
|
||||
|
@ -73,10 +74,7 @@ class BlocksModule implements ServiceModule, ExtendingModule, ExecutableModule {
|
|||
$settings = $c->get( 'wcgateway.settings' );
|
||||
assert( $settings instanceof Settings );
|
||||
|
||||
// Include ACDC in the Block Checkout only in case Axo doesn't exist or is not available or the user is logged in.
|
||||
if ( ( $settings->has( 'axo_enabled' ) && ! $settings->get( 'axo_enabled' ) ) || is_user_logged_in() ) {
|
||||
$payment_method_registry->register( $c->get( 'blocks.advanced-card-method' ) );
|
||||
}
|
||||
$payment_method_registry->register( $c->get( 'blocks.advanced-card-method' ) );
|
||||
}
|
||||
);
|
||||
|
||||
|
|
|
@ -262,6 +262,13 @@ class PayPalPaymentMethod extends AbstractPaymentMethodType {
|
|||
return array(
|
||||
'id' => $this->gateway->id,
|
||||
'title' => $this->gateway->title,
|
||||
'icon' => array(
|
||||
array(
|
||||
'id' => 'paypal',
|
||||
'alt' => 'PayPal',
|
||||
'src' => $this->gateway->icon,
|
||||
),
|
||||
),
|
||||
'description' => $this->gateway->description,
|
||||
'smartButtonsEnabled' => $smart_buttons_enabled,
|
||||
'placeOrderEnabled' => $place_order_enabled,
|
||||
|
|
|
@ -11,6 +11,7 @@ namespace WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods;
|
|||
|
||||
use WC_Order;
|
||||
use Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\State;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ExecutableModule;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ExtendingModule;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ModuleClassNameIdTrait;
|
||||
|
@ -46,7 +47,7 @@ class LocalAlternativePaymentMethodsModule implements ServiceModule, ExtendingMo
|
|||
$settings = $c->get( 'wcgateway.settings' );
|
||||
assert( $settings instanceof Settings );
|
||||
|
||||
if ( ! $settings->has( 'allow_local_apm_gateways' ) || $settings->get( 'allow_local_apm_gateways' ) !== true ) {
|
||||
if ( ! self::should_add_local_apm_gateways( $settings ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -58,6 +59,11 @@ class LocalAlternativePaymentMethodsModule implements ServiceModule, ExtendingMo
|
|||
* @psalm-suppress MissingClosureParamType
|
||||
*/
|
||||
function ( $methods ) use ( $c ) {
|
||||
$onboarding_state = $c->get( 'onboarding.state' );
|
||||
if ( $onboarding_state->current_state() === State::STATE_START ) {
|
||||
return $methods;
|
||||
}
|
||||
|
||||
if ( ! is_array( $methods ) ) {
|
||||
return $methods;
|
||||
}
|
||||
|
@ -185,18 +191,6 @@ class LocalAlternativePaymentMethodsModule implements ServiceModule, ExtendingMo
|
|||
2
|
||||
);
|
||||
|
||||
add_filter(
|
||||
'woocommerce_paypal_payments_allowed_refund_payment_methods',
|
||||
function( array $payment_methods ) use ( $c ): array {
|
||||
$local_payment_methods = $c->get( 'ppcp-local-apms.payment-methods' );
|
||||
foreach ( $local_payment_methods as $payment_method ) {
|
||||
$payment_methods[] = $payment_method['id'];
|
||||
}
|
||||
|
||||
return $payment_methods;
|
||||
}
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -216,4 +210,17 @@ class LocalAlternativePaymentMethodsModule implements ServiceModule, ExtendingMo
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the local APMs should be added to the available payment gateways.
|
||||
*
|
||||
* @param Settings $settings PayPal gateway settings.
|
||||
* @return bool
|
||||
*/
|
||||
private function should_add_local_apm_gateways( Settings $settings ): bool {
|
||||
return $settings->has( 'enabled' )
|
||||
&& $settings->get( 'enabled' ) === true
|
||||
&& $settings->has( 'allow_local_apm_gateways' )
|
||||
&& $settings->get( 'allow_local_apm_gateways' ) === true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
body:has(.ppcp-r-container--onboarding) {
|
||||
background-color: #fff !important;
|
||||
|
||||
.notice, .nav-tab-wrapper.woo-nav-tab-wrapper, .woocommerce-layout, .wrap.woocommerce form > h2 {
|
||||
.notice, .nav-tab-wrapper.woo-nav-tab-wrapper, .woocommerce-layout, .wrap.woocommerce form > h2, #screen-meta-links {
|
||||
display: none !important;
|
||||
}
|
||||
}
|
||||
|
|
0
modules/ppcp-wc-gateway/assets/images/paypal.png
Executable file → Normal file
0
modules/ppcp-wc-gateway/assets/images/paypal.png
Executable file → Normal file
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 28 KiB |
3
modules/ppcp-wc-gateway/assets/images/paypal.svg
Normal file
3
modules/ppcp-wc-gateway/assets/images/paypal.svg
Normal file
|
@ -0,0 +1,3 @@
|
|||
<svg width="42" height="14" viewBox="0 0 42 14" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M0 -9.53674e-07V10.4722H2.43059V6.91664H3.58333C4.83339 6.91664 5.70838 6.54164 6.31948 5.91668C6.94444 5.27779 7.31944 4.41671 7.31944 3.45842C7.31944 2.50005 6.94444 1.63894 6.31948 1.00006C5.70838 0.37503 4.83339 -9.53674e-07 3.58333 -9.53674e-07H0ZM24.125 -9.53674e-07V10.4722H26.5556V6.91664H27.7083C28.9583 6.91664 29.8333 6.54164 30.4445 5.91668C31.0694 5.27779 31.4444 4.41671 31.4444 3.45842C31.4444 2.50005 31.0694 1.63894 30.4445 1.00006C29.8333 0.37503 28.9583 -9.53674e-07 27.7083 -9.53674e-07H24.125ZM39.6667 -9.53674e-07V10.4722H42V-9.53674e-07H39.6667ZM2.43059 2.1528H3.23613C3.88895 2.1528 4.20834 2.30553 4.44445 2.52778C4.68056 2.75003 4.81944 3.08336 4.81944 3.45842C4.81944 3.83341 4.68056 4.16668 4.44445 4.38885C4.20834 4.6111 3.88895 4.76384 3.23613 4.76384H2.43059V2.1528ZM26.5556 2.1528H27.3611C28.0139 2.1528 28.3333 2.30553 28.5694 2.52778C28.8055 2.75003 28.9444 3.08336 28.9444 3.45842C28.9444 3.83341 28.8055 4.16668 28.5694 4.38885C28.3333 4.6111 28.0139 4.76384 27.3611 4.76384H26.5556V2.1528ZM10.4722 3.30553C8.4861 3.30553 6.9583 4.93053 6.9583 7C6.9583 9.0694 8.4861 10.6945 10.4722 10.6945C11.2639 10.6945 11.9722 10.3889 12.4999 9.87498V10.4722H14.625V3.52784H12.4999V4.12502C11.9722 3.61116 11.2639 3.30553 10.4722 3.30553ZM34.5972 3.30553C32.6111 3.30553 31.0834 4.93053 31.0834 7C31.0834 9.0694 32.6111 10.6945 34.5972 10.6945C35.3889 10.6945 36.0973 10.3889 36.625 9.87498V10.4722H38.7499V3.52784H36.625V4.12502C36.0973 3.61116 35.3889 3.30553 34.5972 3.30553ZM15.1249 3.52784L18.3334 9.19443L15.9166 14H18.3888L23.625 3.52784H21.1528L19.5694 6.83337H19.5555L17.7639 3.52784H15.1249ZM10.8611 5.4167C11.7222 5.4167 12.3611 6.08335 12.3611 7C12.3611 7.91665 11.7222 8.5833 10.8611 8.5833C10 8.5833 9.3611 7.91665 9.3611 7C9.3611 6.08335 10 5.4167 10.8611 5.4167ZM34.9861 5.4167C35.8472 5.4167 36.4861 6.08335 36.4861 7C36.4861 7.91665 35.8472 8.5833 34.9861 8.5833C34.125 8.5833 33.4861 7.91665 33.4861 7C33.4861 6.08335 34.125 5.4167 34.9861 5.4167Z" fill="black"/>
|
||||
</svg>
|
After Width: | Height: | Size: 2.1 KiB |
3
modules/ppcp-wc-gateway/assets/images/ratepay.svg
Normal file
3
modules/ppcp-wc-gateway/assets/images/ratepay.svg
Normal file
File diff suppressed because one or more lines are too long
After Width: | Height: | Size: 7.5 KiB |
|
@ -121,6 +121,7 @@ return array(
|
|||
$container->get( 'api.endpoint.payment-tokens' ),
|
||||
$container->get( 'vaulting.vault-v3-enabled' ),
|
||||
$container->get( 'vaulting.wc-payment-tokens' ),
|
||||
$container->get( 'wcgateway.url' ),
|
||||
$container->get( 'wcgateway.settings.admin-settings-enabled' )
|
||||
);
|
||||
},
|
||||
|
@ -628,17 +629,10 @@ return array(
|
|||
$container->get( 'api.endpoint.order' ),
|
||||
$container->get( 'api.endpoint.payments' ),
|
||||
$container->get( 'wcgateway.helper.refund-fees-updater' ),
|
||||
$container->get( 'wcgateway.allowed_refund_payment_methods' ),
|
||||
$container->get( 'api.prefix' ),
|
||||
$container->get( 'woocommerce.logger.woocommerce' )
|
||||
);
|
||||
},
|
||||
'wcgateway.allowed_refund_payment_methods' => static function ( ContainerInterface $container ): array {
|
||||
return apply_filters(
|
||||
'woocommerce_paypal_payments_allowed_refund_payment_methods',
|
||||
array( PayPalGateway::ID, CreditCardGateway::ID, CardButtonGateway::ID, PayUponInvoiceGateway::ID )
|
||||
);
|
||||
},
|
||||
'wcgateway.processor.authorized-payments' => static function ( ContainerInterface $container ): AuthorizedPaymentsProcessor {
|
||||
$order_endpoint = $container->get( 'api.endpoint.order' );
|
||||
$payments_endpoint = $container->get( 'api.endpoint.payments' );
|
||||
|
@ -1494,7 +1488,8 @@ return array(
|
|||
$container->get( 'wcgateway.pay-upon-invoice-helper' ),
|
||||
$container->get( 'wcgateway.checkout-helper' ),
|
||||
$container->get( 'onboarding.state' ),
|
||||
$container->get( 'wcgateway.processor.refunds' )
|
||||
$container->get( 'wcgateway.processor.refunds' ),
|
||||
$container->get( 'wcgateway.url' )
|
||||
);
|
||||
},
|
||||
'wcgateway.fraudnet-source-website-id' => static function ( ContainerInterface $container ): FraudNetSourceWebsiteId {
|
||||
|
@ -2059,8 +2054,7 @@ return array(
|
|||
$container->get( 'wcgateway.url' ),
|
||||
$container->get( 'ppcp.asset-version' ),
|
||||
$container->get( 'api.endpoint.order' ),
|
||||
$container->get( 'wcgateway.processor.refunds' ),
|
||||
$container->get( 'wcgateway.allowed_refund_payment_methods' )
|
||||
$container->get( 'wcgateway.processor.refunds' )
|
||||
);
|
||||
},
|
||||
'wcgateway.void-button.endpoint' => function( ContainerInterface $container ) : VoidOrderEndpoint {
|
||||
|
|
|
@ -51,13 +51,6 @@ class VoidButtonAssets {
|
|||
*/
|
||||
private $refund_processor;
|
||||
|
||||
/**
|
||||
* The methods that can be refunded.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $allowed_refund_payment_methods;
|
||||
|
||||
/**
|
||||
* VoidButtonAssets constructor.
|
||||
*
|
||||
|
@ -65,20 +58,17 @@ class VoidButtonAssets {
|
|||
* @param string $version The assets version.
|
||||
* @param OrderEndpoint $order_endpoint The order endpoint.
|
||||
* @param RefundProcessor $refund_processor The Refund Processor.
|
||||
* @param array $allowed_refund_payment_methods The methods that can be refunded.
|
||||
*/
|
||||
public function __construct(
|
||||
string $module_url,
|
||||
string $version,
|
||||
OrderEndpoint $order_endpoint,
|
||||
RefundProcessor $refund_processor,
|
||||
array $allowed_refund_payment_methods
|
||||
RefundProcessor $refund_processor
|
||||
) {
|
||||
$this->module_url = $module_url;
|
||||
$this->version = $version;
|
||||
$this->order_endpoint = $order_endpoint;
|
||||
$this->refund_processor = $refund_processor;
|
||||
$this->allowed_refund_payment_methods = $allowed_refund_payment_methods;
|
||||
$this->module_url = $module_url;
|
||||
$this->version = $version;
|
||||
$this->order_endpoint = $order_endpoint;
|
||||
$this->refund_processor = $refund_processor;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -103,7 +93,8 @@ class VoidButtonAssets {
|
|||
return false;
|
||||
}
|
||||
|
||||
if ( ! in_array( $theorder->get_payment_method(), $this->allowed_refund_payment_methods, true ) ) {
|
||||
$payment_gateways = WC()->payment_gateways()->payment_gateways();
|
||||
if ( ! isset( $payment_gateways[ $theorder->get_payment_method() ] ) || ! $payment_gateways[ $theorder->get_payment_method() ]->supports( 'refunds' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -202,6 +202,13 @@ class PayPalGateway extends \WC_Payment_Gateway {
|
|||
*/
|
||||
private $wc_payment_tokens;
|
||||
|
||||
/**
|
||||
* The module URL
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $module_url;
|
||||
|
||||
/**
|
||||
* Whether settings module is enabled.
|
||||
*
|
||||
|
@ -232,6 +239,7 @@ class PayPalGateway extends \WC_Payment_Gateway {
|
|||
* @param PaymentTokensEndpoint $payment_tokens_endpoint Payment tokens endpoint.
|
||||
* @param bool $vault_v3_enabled Whether Vault v3 module is enabled.
|
||||
* @param WooCommercePaymentTokens $wc_payment_tokens WooCommerce payment tokens.
|
||||
* @param string $module_url The module URL.
|
||||
* @param bool $admin_settings_enabled Whether settings module is enabled.
|
||||
*/
|
||||
public function __construct(
|
||||
|
@ -255,6 +263,7 @@ class PayPalGateway extends \WC_Payment_Gateway {
|
|||
PaymentTokensEndpoint $payment_tokens_endpoint,
|
||||
bool $vault_v3_enabled,
|
||||
WooCommercePaymentTokens $wc_payment_tokens,
|
||||
string $module_url,
|
||||
bool $admin_settings_enabled
|
||||
) {
|
||||
$this->id = self::ID;
|
||||
|
@ -279,6 +288,8 @@ class PayPalGateway extends \WC_Payment_Gateway {
|
|||
$this->payment_tokens_endpoint = $payment_tokens_endpoint;
|
||||
$this->vault_v3_enabled = $vault_v3_enabled;
|
||||
$this->wc_payment_tokens = $wc_payment_tokens;
|
||||
$this->module_url = $module_url;
|
||||
$this->icon = apply_filters( 'woocommerce_paypal_payments_paypal_gateway_icon', esc_url( $this->module_url ) . 'assets/images/paypal.svg' );
|
||||
$this->admin_settings_enabled = $admin_settings_enabled;
|
||||
|
||||
$default_support = array(
|
||||
|
|
|
@ -103,6 +103,13 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
|
|||
*/
|
||||
protected $refund_processor;
|
||||
|
||||
/**
|
||||
* The module URL
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $module_url;
|
||||
|
||||
/**
|
||||
* PayUponInvoiceGateway constructor.
|
||||
*
|
||||
|
@ -116,6 +123,7 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
|
|||
* @param CheckoutHelper $checkout_helper The checkout helper.
|
||||
* @param State $state The onboarding state.
|
||||
* @param RefundProcessor $refund_processor The refund processor.
|
||||
* @param string $module_url The module URL.
|
||||
*/
|
||||
public function __construct(
|
||||
PayUponInvoiceOrderEndpoint $order_endpoint,
|
||||
|
@ -127,7 +135,8 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
|
|||
PayUponInvoiceHelper $pui_helper,
|
||||
CheckoutHelper $checkout_helper,
|
||||
State $state,
|
||||
RefundProcessor $refund_processor
|
||||
RefundProcessor $refund_processor,
|
||||
string $module_url
|
||||
) {
|
||||
$this->id = self::ID;
|
||||
|
||||
|
@ -157,6 +166,8 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
|
|||
$this->transaction_url_provider = $transaction_url_provider;
|
||||
$this->pui_helper = $pui_helper;
|
||||
$this->checkout_helper = $checkout_helper;
|
||||
$this->module_url = $module_url;
|
||||
$this->icon = apply_filters( 'woocommerce_paypal_payments_pay_upon_invoice_gateway_icon', esc_url( $this->module_url ) . 'assets/images/ratepay.svg' );
|
||||
|
||||
$this->state = $state;
|
||||
if ( $state->current_state() === State::STATE_ONBOARDED ) {
|
||||
|
|
|
@ -72,20 +72,12 @@ class RefundProcessor {
|
|||
*/
|
||||
private $refund_fees_updater;
|
||||
|
||||
/**
|
||||
* The methods that can be refunded.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $allowed_refund_payment_methods;
|
||||
|
||||
/**
|
||||
* RefundProcessor constructor.
|
||||
*
|
||||
* @param OrderEndpoint $order_endpoint The order endpoint.
|
||||
* @param PaymentsEndpoint $payments_endpoint The payments endpoint.
|
||||
* @param RefundFeesUpdater $refund_fees_updater The refund fees updater.
|
||||
* @param array $allowed_refund_payment_methods The methods that can be refunded.
|
||||
* @param string $prefix The prefix.
|
||||
* @param LoggerInterface $logger The logger.
|
||||
*/
|
||||
|
@ -93,17 +85,15 @@ class RefundProcessor {
|
|||
OrderEndpoint $order_endpoint,
|
||||
PaymentsEndpoint $payments_endpoint,
|
||||
RefundFeesUpdater $refund_fees_updater,
|
||||
array $allowed_refund_payment_methods,
|
||||
string $prefix,
|
||||
LoggerInterface $logger
|
||||
) {
|
||||
|
||||
$this->order_endpoint = $order_endpoint;
|
||||
$this->payments_endpoint = $payments_endpoint;
|
||||
$this->refund_fees_updater = $refund_fees_updater;
|
||||
$this->allowed_refund_payment_methods = $allowed_refund_payment_methods;
|
||||
$this->prefix = $prefix;
|
||||
$this->logger = $logger;
|
||||
$this->order_endpoint = $order_endpoint;
|
||||
$this->payments_endpoint = $payments_endpoint;
|
||||
$this->refund_fees_updater = $refund_fees_updater;
|
||||
$this->prefix = $prefix;
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -119,7 +109,8 @@ class RefundProcessor {
|
|||
*/
|
||||
public function process( WC_Order $wc_order, float $amount = null, string $reason = '' ) : bool {
|
||||
try {
|
||||
if ( ! in_array( $wc_order->get_payment_method(), $this->allowed_refund_payment_methods, true ) ) {
|
||||
$payment_gateways = WC()->payment_gateways()->payment_gateways();
|
||||
if ( ! isset( $payment_gateways[ $wc_order->get_payment_method() ] ) || ! $payment_gateways[ $wc_order->get_payment_method() ]->supports( 'refunds' ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -64,7 +64,8 @@ class PayUponInvoiceGatewayTest extends TestCase
|
|||
$this->pui_helper,
|
||||
$this->checkout_helper,
|
||||
$this->state,
|
||||
$this->refund_processor
|
||||
$this->refund_processor,
|
||||
''
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -124,6 +124,7 @@ class WcGatewayTest extends TestCase
|
|||
$this->paymentTokensEndpoint,
|
||||
$this->vaultV3Enabled,
|
||||
$this->wcPaymentTokens,
|
||||
'',
|
||||
false
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue