mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-03 08:37:53 +08:00
make sure client_id and client_secret are properly stored.
This commit is contained in:
parent
de4dc878ef
commit
28863a2b4e
1 changed files with 20 additions and 0 deletions
|
@ -153,6 +153,9 @@ class SettingsListener {
|
|||
$raw_data = ( isset( $_POST['ppcp'] ) ) ? (array) wp_unslash( $_POST['ppcp'] ) : array();
|
||||
// phpcs:enable phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
|
||||
$settings = $this->retrieve_settings_from_raw_data( $raw_data );
|
||||
|
||||
$settings = $this->read_active_credentials_from_settings( $settings );
|
||||
|
||||
if ( ! isset( $_GET[ SectionsRenderer::KEY ] ) || PayPalGateway::ID === $_GET[ SectionsRenderer::KEY ] ) {
|
||||
$settings['enabled'] = isset( $_POST['woocommerce_ppcp-gateway_enabled'] )
|
||||
&& 1 === absint( $_POST['woocommerce_ppcp-gateway_enabled'] );
|
||||
|
@ -171,6 +174,23 @@ class SettingsListener {
|
|||
// phpcs:enable WordPress.Security.NonceVerification.Recommended
|
||||
}
|
||||
|
||||
/**
|
||||
* The actual used client credentials are stored in 'client_secret', 'client_id', 'merchant_id' and 'merchant_email'.
|
||||
* This method populates those fields depending on the sandbox status.
|
||||
*
|
||||
* @param array $settings The settings array.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function read_active_credentials_from_settings( array $settings ) : array {
|
||||
$is_sandbox = isset( $settings['sandbox_on'] ) && $settings['sandbox_on'];
|
||||
$settings['client_id'] = $is_sandbox ? $settings['client_id_sandbox'] : $settings['client_id_production'];
|
||||
$settings['client_secret'] = $is_sandbox ? $settings['client_secret_sandbox'] : $settings['client_secret_production'];
|
||||
$settings['merchant_id'] = $is_sandbox ? $settings['merchant_id_sandbox'] : $settings['merchant_id_production'];
|
||||
$settings['merchant_email'] = $is_sandbox ? $settings['merchant_email_sandbox'] : $settings['merchant_email_production'];
|
||||
return $settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Depending on the settings change, we might need to register or unregister the Webhooks at PayPal.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue