mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-08-31 06:52:50 +08:00
👔 Make eligibility flags read-only
This commit is contained in:
parent
7b596dbea5
commit
3b274d02af
4 changed files with 17 additions and 42 deletions
|
@ -57,8 +57,9 @@ abstract class AbstractDataModel {
|
|||
* Loads the model data from WordPress options.
|
||||
*/
|
||||
public function load() : void {
|
||||
$saved_data = get_option( static::OPTION_KEY, array() );
|
||||
$this->data = array_merge( $this->data, $saved_data );
|
||||
$saved_data = get_option( static::OPTION_KEY, array() );
|
||||
$filtered_data = array_intersect_key( $saved_data, $this->data );
|
||||
$this->data = array_merge( $this->data, $filtered_data );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -91,8 +92,6 @@ abstract class AbstractDataModel {
|
|||
$setter = "set_$key";
|
||||
if ( method_exists( $this, $setter ) ) {
|
||||
$this->$setter( $value );
|
||||
} else {
|
||||
$this->data[ $key ] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,9 +45,9 @@ class OnboardingProfile extends AbstractDataModel {
|
|||
) {
|
||||
parent::__construct();
|
||||
|
||||
$this->set_can_use_casual_selling( $can_use_casual_selling );
|
||||
$this->set_can_use_vaulting( $can_use_vaulting );
|
||||
$this->set_can_use_card_payments( $can_use_card_payments );
|
||||
$this->data['can_use_casual_selling'] = $can_use_casual_selling;
|
||||
$this->data['can_use_vaulting'] = $can_use_vaulting;
|
||||
$this->data['can_use_card_payments'] = $can_use_card_payments;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -62,9 +62,9 @@ class OnboardingProfile extends AbstractDataModel {
|
|||
'use_manual_connection' => false,
|
||||
'client_id' => '',
|
||||
'client_secret' => '',
|
||||
'can_use_casual_selling' => false,
|
||||
'can_use_vaulting' => false,
|
||||
'can_use_card_payments' => false,
|
||||
'can_use_casual_selling' => null,
|
||||
'can_use_vaulting' => null,
|
||||
'can_use_card_payments' => null,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -169,15 +169,6 @@ class OnboardingProfile extends AbstractDataModel {
|
|||
return (bool) $this->data['can_use_casual_selling'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether casual selling can be used.
|
||||
*
|
||||
* @param bool $can_use_casual_selling Whether casual selling can be used.
|
||||
*/
|
||||
public function set_can_use_casual_selling( bool $can_use_casual_selling ) : void {
|
||||
$this->data['can_use_casual_selling'] = $can_use_casual_selling;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether vaulting can be used.
|
||||
*
|
||||
|
@ -187,15 +178,6 @@ class OnboardingProfile extends AbstractDataModel {
|
|||
return (bool) $this->data['can_use_vaulting'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether vaulting can be used.
|
||||
*
|
||||
* @param bool $can_use_vaulting Whether vaulting can be used.
|
||||
*/
|
||||
public function set_can_use_vaulting( bool $can_use_vaulting ) : void {
|
||||
$this->data['can_use_vaulting'] = $can_use_vaulting;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether Credit Card payments can be used.
|
||||
*
|
||||
|
@ -204,13 +186,4 @@ class OnboardingProfile extends AbstractDataModel {
|
|||
public function get_can_use_card_payments() : bool {
|
||||
return (bool) $this->data['can_use_card_payments'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether Credit Card payments can be used.
|
||||
*
|
||||
* @param bool $can_use_card_payments Whether Credit Card payments can be used.
|
||||
*/
|
||||
public function set_can_use_card_payments( bool $can_use_card_payments ) : void {
|
||||
$this->data['can_use_card_payments'] = $can_use_card_payments;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,15 +63,15 @@ class OnboardingRestEndpoint extends RestEndpoint {
|
|||
),
|
||||
'can_use_casual_selling' => array(
|
||||
'js_name' => 'canUseCasualSelling',
|
||||
'sanitize' => 'to_boolean',
|
||||
'sanitize' => 'read_only',
|
||||
),
|
||||
'can_use_vaulting' => array(
|
||||
'js_name' => 'canUseVaulting',
|
||||
'sanitize' => 'to_boolean',
|
||||
'sanitize' => 'read_only',
|
||||
),
|
||||
'can_use_card_payments' => array(
|
||||
'js_name' => 'canUseCardPayments',
|
||||
'sanitize' => 'to_boolean',
|
||||
'sanitize' => 'read_only',
|
||||
),
|
||||
);
|
||||
|
||||
|
|
|
@ -53,7 +53,11 @@ class RestEndpoint extends WC_REST_Controller {
|
|||
$source_key = $details['js_name'] ?? '';
|
||||
$sanitation_cb = $details['sanitize'] ?? null;
|
||||
|
||||
if ( ! $source_key || ! isset( $params[ $source_key ] ) ) {
|
||||
if (
|
||||
! $source_key
|
||||
|| ! isset( $params[ $source_key ] )
|
||||
|| 'read_only' === $sanitation_cb
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -121,5 +125,4 @@ class RestEndpoint extends WC_REST_Controller {
|
|||
protected function to_number( $value ) {
|
||||
return $value !== null ? ( is_numeric( $value ) ? $value + 0 : null ) : null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue