mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-04 08:47:23 +08:00
Add support for card icons to Axo Block and move the Change Card Link handling to the store. Also migrate the Change Card Link markup management logic to React
This commit is contained in:
parent
53af77897f
commit
42805c4fb5
17 changed files with 172 additions and 120 deletions
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;
|
Loading…
Add table
Add a link
Reference in a new issue