Merge branch 'trunk' into PCP-3136-enable-shipping-callback-for-wc-subscriptions

This commit is contained in:
Narek Zakarian 2024-05-22 15:58:35 +04:00
commit 1de6039d5b
No known key found for this signature in database
GPG key ID: 07AFD7E7A9C164A7
9 changed files with 185 additions and 41 deletions

View file

@ -7,6 +7,8 @@
* Fix - Notice on newly created block cart checkout #2211 * Fix - Notice on newly created block cart checkout #2211
* Fix - Apple Pay button in the editor #2177 * Fix - Apple Pay button in the editor #2177
* Fix - Allow shipping callback and skipping confirmation page from any express button #2236 * Fix - Allow shipping callback and skipping confirmation page from any express button #2236
* Fix - Pay Later messaging configurator sometimes displays old settings after saving #2249
* Fix - Update the apple-developer-merchantid-domain-association validation strings for Apple Pay #2251
* Enhancement - Use admin theme color #1602 * Enhancement - Use admin theme color #1602
= 2.7.0 - 2024-04-30 = = 2.7.0 - 2024-04-30 =

File diff suppressed because one or more lines are too long

View file

@ -94,10 +94,7 @@ class Renderer {
return { return {
style, style,
...contextConfig, ...contextConfig,
onClick: (data, actions) => { onClick: this.onSmartButtonClick,
venmoButtonClicked = data.fundingSource === 'venmo'
this.onSmartButtonClick
},
onInit: (data, actions) => { onInit: (data, actions) => {
if (this.onSmartButtonsInit) { if (this.onSmartButtonsInit) {
this.onSmartButtonsInit(data, actions); this.onSmartButtonsInit(data, actions);

View file

@ -1361,7 +1361,7 @@ document.querySelector("#payment").before(document.querySelector(".ppcp-messages
'integration-date' => PAYPAL_INTEGRATION_DATE, 'integration-date' => PAYPAL_INTEGRATION_DATE,
'components' => implode( ',', $this->components() ), 'components' => implode( ',', $this->components() ),
'vault' => ( $this->can_save_vault_token() || $this->subscription_helper->need_subscription_intent( $subscription_mode ) ) ? 'true' : 'false', 'vault' => ( $this->can_save_vault_token() || $this->subscription_helper->need_subscription_intent( $subscription_mode ) ) ? 'true' : 'false',
'commit' => 'false', 'commit' => in_array( $context, $this->pay_now_contexts, true ) ? 'true' : 'false',
'intent' => $intent, 'intent' => $intent,
); );

View file

@ -1,4 +1,4 @@
document.addEventListener( 'DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => {
const form = document.querySelector('#mainform'); const form = document.querySelector('#mainform');
const table = form.querySelector('.form-table'); const table = form.querySelector('.form-table');
const headingRow = table.querySelector('#field-pay_later_messaging_heading'); const headingRow = table.querySelector('#field-pay_later_messaging_heading');
@ -14,7 +14,6 @@ document.addEventListener( 'DOMContentLoaded', () => {
// Insert the new row after the headingRow // Insert the new row after the headingRow
headingRow.parentNode.insertBefore(newRow, headingRow.nextSibling); headingRow.parentNode.insertBefore(newRow, headingRow.nextSibling);
let isSaving = false; // Flag variable to track whether saving is in progress let isSaving = false; // Flag variable to track whether saving is in progress
saveChangesButton.addEventListener('click', () => { saveChangesButton.addEventListener('click', () => {
@ -24,39 +23,63 @@ document.addEventListener( 'DOMContentLoaded', () => {
// Trigger the click event on the publish button // Trigger the click event on the publish button
form.querySelector('.' + publishButtonClassName).click(); form.querySelector('.' + publishButtonClassName).click();
saveChangesButton.click(); // Trigger click event on saveChangesButton
// Trigger click event on saveChangesButton after a short delay isSaving = false; // Reset flag when saving is complete
setTimeout(() => {
saveChangesButton.click(); // Trigger click event on saveChangesButton
isSaving = false; // Reset flag when saving is complete
}, 1000); // Adjust the delay as needed
} }
}); });
merchantConfigurators.Messaging({ // Fetch the configuration settings
config: PcpPayLaterConfigurator.config, fetch(PcpPayLaterConfigurator.ajax.get_config.endpoint, {
merchantClientId: PcpPayLaterConfigurator.merchantClientId, method: 'POST',
partnerClientId: PcpPayLaterConfigurator.partnerClientId, headers: {
partnerName: 'WooCommerce', 'Content-Type': 'application/json'
bnCode: 'Woo_PPCP',
placements: ['cart', 'checkout', 'product', 'shop', 'home', 'custom_placement'],
styleOverrides: {
button: publishButtonClassName,
header: PcpPayLaterConfigurator.headerClassName,
subheader: PcpPayLaterConfigurator.subheaderClassName
}, },
onSave: data => { body: JSON.stringify({
fetch(PcpPayLaterConfigurator.ajax.save_config.endpoint, { action: 'ppc-get-message-config',
method: 'POST', nonce: PcpPayLaterConfigurator.ajax.get_config.nonce
headers: { }),
'Content-Type': 'application/json'
},
credentials: 'same-origin',
body: JSON.stringify({
nonce: PcpPayLaterConfigurator.ajax.save_config.nonce,
config: data,
}),
});
}
}) })
} ); .then(response => {
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
return response.json();
})
.then(data => {
if (data.success) {
const config = data.data;
merchantConfigurators.Messaging({
config: config,
merchantClientId: PcpPayLaterConfigurator.merchantClientId,
partnerClientId: PcpPayLaterConfigurator.partnerClientId,
partnerName: 'WooCommerce',
bnCode: 'Woo_PPCP',
placements: ['cart', 'checkout', 'product', 'shop', 'home', 'custom_placement'],
styleOverrides: {
button: publishButtonClassName,
header: PcpPayLaterConfigurator.headerClassName,
subheader: PcpPayLaterConfigurator.subheaderClassName
},
onSave: data => {
fetch(PcpPayLaterConfigurator.ajax.save_config.endpoint, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
credentials: 'same-origin',
body: JSON.stringify({
nonce: PcpPayLaterConfigurator.ajax.save_config.nonce,
config: data,
}),
});
}
});
} else {
console.error('Failed to fetch configuration:', data);
}
})
.catch(error => {
console.error('Error fetching configuration:', error);
});
});

View file

@ -10,6 +10,7 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\PayLaterConfigurator; namespace WooCommerce\PayPalCommerce\PayLaterConfigurator;
use WooCommerce\PayPalCommerce\PayLaterConfigurator\Endpoint\SaveConfig; use WooCommerce\PayPalCommerce\PayLaterConfigurator\Endpoint\SaveConfig;
use WooCommerce\PayPalCommerce\PayLaterConfigurator\Endpoint\GetConfig;
use WooCommerce\PayPalCommerce\PayLaterConfigurator\Factory\ConfigFactory; use WooCommerce\PayPalCommerce\PayLaterConfigurator\Factory\ConfigFactory;
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface; use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
@ -35,4 +36,10 @@ return array(
$container->get( 'woocommerce.logger.woocommerce' ) $container->get( 'woocommerce.logger.woocommerce' )
); );
}, },
'paylater-configurator.endpoint.get-config' => static function ( ContainerInterface $container ): GetConfig {
return new GetConfig(
$container->get( 'wcgateway.settings' ),
$container->get( 'woocommerce.logger.woocommerce' )
);
},
); );

View file

@ -0,0 +1,99 @@
<?php
/**
* The endpoint for getting the Pay Later messaging config for the configurator.
*
* @package WooCommerce\PayPalCommerce\PayLaterConfigurator\Endpoint
*/
declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\PayLaterConfigurator\Endpoint;
use Psr\Log\LoggerInterface;
use Throwable;
use WooCommerce\PayPalCommerce\PayLaterConfigurator\Factory\ConfigFactory;
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
/**
* Class GetConfig.
*/
class GetConfig {
const ENDPOINT = 'ppc-get-message-config';
/**
* The settings.
*
* @var Settings
*/
protected $settings;
/**
* The logger.
*
* @var LoggerInterface
*/
private $logger;
/**
* GetConfig constructor.
*
* @param Settings $settings The settings.
* @param LoggerInterface $logger The logger.
*/
public function __construct( Settings $settings, LoggerInterface $logger ) {
$this->settings = $settings;
$this->logger = $logger;
}
/**
* Returns the nonce.
*/
public static function nonce(): string {
return self::ENDPOINT;
}
/**
* Handles the request.
*/
public function handle_request(): bool {
if ( ! current_user_can( 'manage_woocommerce' ) ) {
$this->logger->error( 'User does not have permission: manage_woocommerce' );
wp_send_json_error( 'Not admin.', 403 );
return false;
}
try {
$input = file_get_contents( 'php://input' );
if ( false === $input ) {
$this->logger->error( 'Failed to get input data.' );
wp_send_json_error( 'Failed to get input data.', 400 );
return false;
}
$data = json_decode( $input, true );
if ( json_last_error() !== JSON_ERROR_NONE ) {
$this->logger->error( 'Failed to decode JSON: ' . json_last_error_msg() );
wp_send_json_error( 'Failed to decode JSON.', 400 );
return false;
}
if ( ! isset( $data['nonce'] ) || ! wp_verify_nonce( $data['nonce'], self::ENDPOINT ) ) {
$this->logger->error( 'Invalid nonce' );
wp_send_json_error( 'Invalid nonce.', 403 );
return false;
}
$config_factory = new ConfigFactory();
$config = $config_factory->from_settings( $this->settings );
wp_send_json_success( $config );
return true;
} catch ( Throwable $error ) {
$this->logger->error( "GetConfig execution failed. {$error->getMessage()} {$error->getFile()}:{$error->getLine()}" );
wp_send_json_error( 'An error occurred while fetching the configuration.' );
return false;
}
}
}

View file

@ -10,6 +10,7 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\PayLaterConfigurator; namespace WooCommerce\PayPalCommerce\PayLaterConfigurator;
use WooCommerce\PayPalCommerce\Button\Helper\MessagesApply; use WooCommerce\PayPalCommerce\Button\Helper\MessagesApply;
use WooCommerce\PayPalCommerce\PayLaterConfigurator\Endpoint\GetConfig;
use WooCommerce\PayPalCommerce\PayLaterConfigurator\Endpoint\SaveConfig; use WooCommerce\PayPalCommerce\PayLaterConfigurator\Endpoint\SaveConfig;
use WooCommerce\PayPalCommerce\PayLaterConfigurator\Factory\ConfigFactory; use WooCommerce\PayPalCommerce\PayLaterConfigurator\Factory\ConfigFactory;
use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\ServiceProvider; use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\ServiceProvider;
@ -27,7 +28,7 @@ class PayLaterConfiguratorModule implements ModuleInterface {
*/ */
public static function is_enabled(): bool { public static function is_enabled(): bool {
return apply_filters( return apply_filters(
// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
'woocommerce.feature-flags.woocommerce_paypal_payments.paylater_configurator_enabled', 'woocommerce.feature-flags.woocommerce_paypal_payments.paylater_configurator_enabled',
getenv( 'PCP_PAYLATER_CONFIGURATOR' ) !== '0' getenv( 'PCP_PAYLATER_CONFIGURATOR' ) !== '0'
); );
@ -68,6 +69,15 @@ class PayLaterConfiguratorModule implements ModuleInterface {
} }
); );
add_action(
'wc_ajax_' . GetConfig::ENDPOINT,
static function () use ( $c ) {
$endpoint = $c->get( 'paylater-configurator.endpoint.get-config' );
assert( $endpoint instanceof GetConfig );
$endpoint->handle_request();
}
);
$current_page_id = $c->get( 'wcgateway.current-ppcp-settings-page-id' ); $current_page_id = $c->get( 'wcgateway.current-ppcp-settings-page-id' );
if ( $current_page_id !== Settings::PAY_LATER_TAB_ID ) { if ( $current_page_id !== Settings::PAY_LATER_TAB_ID ) {
@ -112,6 +122,10 @@ class PayLaterConfiguratorModule implements ModuleInterface {
'endpoint' => \WC_AJAX::get_endpoint( SaveConfig::ENDPOINT ), 'endpoint' => \WC_AJAX::get_endpoint( SaveConfig::ENDPOINT ),
'nonce' => wp_create_nonce( SaveConfig::nonce() ), 'nonce' => wp_create_nonce( SaveConfig::nonce() ),
), ),
'get_config' => array(
'endpoint' => \WC_AJAX::get_endpoint( GetConfig::ENDPOINT ),
'nonce' => wp_create_nonce( GetConfig::nonce() ),
),
), ),
'config' => $config_factory->from_settings( $settings ), 'config' => $config_factory->from_settings( $settings ),
'merchantClientId' => $settings->get( 'client_id' ), 'merchantClientId' => $settings->get( 'client_id' ),

View file

@ -186,6 +186,8 @@ If you encounter issues with the PayPal buttons not appearing after an update, p
* Fix - Notice on newly created block cart checkout #2211 * Fix - Notice on newly created block cart checkout #2211
* Fix - Apple Pay button in the editor #2177 * Fix - Apple Pay button in the editor #2177
* Fix - Allow shipping callback and skipping confirmation page from any express button #2236 * Fix - Allow shipping callback and skipping confirmation page from any express button #2236
* Fix - Pay Later messaging configurator sometimes displays old settings after saving #2249
* Fix - Update the apple-developer-merchantid-domain-association validation strings for Apple Pay #2251
* Enhancement - Use admin theme color #1602 * Enhancement - Use admin theme color #1602
= 2.7.0 - 2024-04-30 = = 2.7.0 - 2024-04-30 =