mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
Merge branch 'trunk' into PCP-3136-enable-shipping-callback-for-wc-subscriptions
This commit is contained in:
commit
1de6039d5b
9 changed files with 185 additions and 41 deletions
|
@ -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
|
@ -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);
|
||||||
|
|
|
@ -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,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -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,17 +23,34 @@ 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();
|
||||||
|
|
||||||
// Trigger click event on saveChangesButton after a short delay
|
|
||||||
setTimeout(() => {
|
|
||||||
saveChangesButton.click(); // Trigger click event on saveChangesButton
|
saveChangesButton.click(); // Trigger click event on saveChangesButton
|
||||||
isSaving = false; // Reset flag when saving is complete
|
isSaving = false; // Reset flag when saving is complete
|
||||||
}, 1000); // Adjust the delay as needed
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Fetch the configuration settings
|
||||||
|
fetch(PcpPayLaterConfigurator.ajax.get_config.endpoint, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
action: 'ppc-get-message-config',
|
||||||
|
nonce: PcpPayLaterConfigurator.ajax.get_config.nonce
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
.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({
|
merchantConfigurators.Messaging({
|
||||||
config: PcpPayLaterConfigurator.config,
|
config: config,
|
||||||
merchantClientId: PcpPayLaterConfigurator.merchantClientId,
|
merchantClientId: PcpPayLaterConfigurator.merchantClientId,
|
||||||
partnerClientId: PcpPayLaterConfigurator.partnerClientId,
|
partnerClientId: PcpPayLaterConfigurator.partnerClientId,
|
||||||
partnerName: 'WooCommerce',
|
partnerName: 'WooCommerce',
|
||||||
|
@ -58,5 +74,12 @@ document.addEventListener( 'DOMContentLoaded', () => {
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
console.error('Failed to fetch configuration:', data);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
} );
|
.catch(error => {
|
||||||
|
console.error('Error fetching configuration:', error);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
|
@ -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' )
|
||||||
|
);
|
||||||
|
},
|
||||||
);
|
);
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
@ -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' ),
|
||||||
|
|
|
@ -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 =
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue