diff --git a/.psalm/wcs.php b/.psalm/wcs.php index 1698c98c0..07c3c044c 100644 --- a/.psalm/wcs.php +++ b/.psalm/wcs.php @@ -2120,3 +2120,40 @@ class WC_Product_Subscription_Variation extends WC_Product_Variation {} * */ class WC_Product_Variable_Subscription extends WC_Product_Variable {} + +class WCS_Manual_Renewal_Manager { + + /** + * Initalise the class and attach callbacks. + */ + public static function init() { + } + + /** + * Adds the manual renewal settings. + * + * @since 4.0.0 + * @param $settings The full subscription settings array. + * @return $settings. + */ + public static function add_settings( $settings ) { + } + + /** + * Checks if manual renewals are required - automatic renewals are disabled. + * + * @since 4.0.0 + * @return bool Weather manual renewal is required. + */ + public static function is_manual_renewal_required() { + } + + /** + * Checks if manual renewals are enabled. + * + * @since 4.0.0 + * @return bool Weather manual renewal is enabled. + */ + public static function is_manual_renewal_enabled() { + } +} diff --git a/modules/ppcp-api-client/src/Endpoint/BillingSubscriptions.php b/modules/ppcp-api-client/src/Endpoint/BillingSubscriptions.php index 8a46506b6..281afe0ec 100644 --- a/modules/ppcp-api-client/src/Endpoint/BillingSubscriptions.php +++ b/modules/ppcp-api-client/src/Endpoint/BillingSubscriptions.php @@ -67,7 +67,7 @@ class BillingSubscriptions { */ public function suspend( string $id ):void { $data = array( - 'reason' => 'Suspended by customer', + 'reason' => sprintf( 'Suspended by %s.', is_admin() ? 'merchant' : 'customer' ), ); $bearer = $this->bearer->bearer(); @@ -107,7 +107,7 @@ class BillingSubscriptions { */ public function activate( string $id ): void { $data = array( - 'reason' => 'Reactivated by customer', + 'reason' => sprintf( 'Reactivated by %s.', is_admin() ? 'merchant' : 'customer' ), ); $bearer = $this->bearer->bearer(); @@ -148,7 +148,7 @@ class BillingSubscriptions { */ public function cancel( string $id ): void { $data = array( - 'reason' => 'Cancelled by customer', + 'reason' => sprintf( 'Cancelled by %s.', is_admin() ? 'merchant' : 'customer' ), ); $bearer = $this->bearer->bearer(); diff --git a/modules/ppcp-applepay/src/Assets/BlocksPaymentMethod.php b/modules/ppcp-applepay/src/Assets/BlocksPaymentMethod.php index 2266f4c73..79a9efe9e 100644 --- a/modules/ppcp-applepay/src/Assets/BlocksPaymentMethod.php +++ b/modules/ppcp-applepay/src/Assets/BlocksPaymentMethod.php @@ -113,7 +113,7 @@ class BlocksPaymentMethod extends AbstractPaymentMethodType { 'id' => $this->name, 'title' => $paypal_data['title'], // TODO : see if we should use another. 'description' => $paypal_data['description'], // TODO : see if we should use another. - 'enabled' => $paypal_data['enabled'], // This button is enabled when PayPal buttons are. + 'enabled' => $paypal_data['smartButtonsEnabled'], // This button is enabled when PayPal buttons are. 'scriptData' => $script_data, ); } diff --git a/modules/ppcp-blocks/resources/js/Components/card-fields.js b/modules/ppcp-blocks/resources/js/Components/card-fields.js index 2726bc12e..05d41b315 100644 --- a/modules/ppcp-blocks/resources/js/Components/card-fields.js +++ b/modules/ppcp-blocks/resources/js/Components/card-fields.js @@ -19,11 +19,9 @@ export function CardFields( { config, eventRegistration, emitResponse, - components, } ) { const { onPaymentSetup } = eventRegistration; const { responseTypes } = emitResponse; - const { PaymentMethodIcons } = components; const [ cardFieldsForm, setCardFieldsForm ] = useState(); const getCardFieldsForm = ( cardFieldsForm ) => { @@ -95,10 +93,6 @@ export function CardFields( { } } > - { - let timeoutId = null; - return ( ...args ) => { - window.clearTimeout( timeoutId ); - timeoutId = window.setTimeout( () => { - callback.apply( null, args ); - }, delayMs ); + const state = { + timeoutId: null, + args: null, }; + + /** + * Cancels any pending debounced execution. + */ + const cancel = () => { + if ( state.timeoutId ) { + window.clearTimeout( state.timeoutId ); + } + + state.timeoutId = null; + state.args = null; + }; + + /** + * Immediately executes the debounced function if there's a pending execution. + * @return {void} + */ + const flush = () => { + // If there's nothing pending, return early. + if ( ! state.timeoutId ) { + return; + } + + callback.apply( null, state.args || [] ); + cancel(); + }; + + const debouncedFunc = ( ...args ) => { + cancel(); + state.args = args; + state.timeoutId = window.setTimeout( flush, delayMs ); + }; + + // Attach utility methods + debouncedFunc.cancel = cancel; + debouncedFunc.flush = flush; + + return debouncedFunc; }; diff --git a/modules/ppcp-blocks/resources/js/advanced-card-checkout-block.js b/modules/ppcp-blocks/resources/js/advanced-card-checkout-block.js index cdce4fd87..24c53c5a5 100644 --- a/modules/ppcp-blocks/resources/js/advanced-card-checkout-block.js +++ b/modules/ppcp-blocks/resources/js/advanced-card-checkout-block.js @@ -1,19 +1,30 @@ -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'); -registerPaymentMethod( { - name: config.id, - label:
, - content: , - edit: , - ariaLabel: config.title, - canMakePayment: () => { - return true; - }, - supports: { - showSavedCards: true, - features: config.supports, - }, -} ); +const Label = ({components, config}) => { + const {PaymentMethodIcons} = components; + return <> + + + +} + +registerPaymentMethod({ + name: config.id, + label: