Skip to content

Commit

Permalink
Paypal config class updated
Browse files Browse the repository at this point in the history
Settings option setup
  • Loading branch information
shewa12 committed Oct 18, 2024
1 parent d22c593 commit 737aaa0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
1 change: 1 addition & 0 deletions ecommerce/PaymentGateways/Configs/PaymentUrlsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public function get_field_value( array $config, string $field_name ) {
foreach ( $config['fields'] as $field ) {
if ( $field['name'] === $field_name ) {
$value = $field['value'] ?? '';
break;
}
}
return $value;
Expand Down
28 changes: 22 additions & 6 deletions ecommerce/PaymentGateways/Configs/PaypalConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,12 @@ class PaypalConfig extends Config implements ConfigContract {
public function __construct() {
parent::__construct();

$config = Settings::get_payment_gateway_config( 'paypal' );
$settings = Settings::get_payment_gateway_settings( 'paypal' );

$this->environment = $this->get_field_value( $config, 'environment' );
$this->merchant_email = $this->get_field_value( $config, 'merchant_email' );
$this->client_id = $this->get_field_value( $config, 'client_id' );
$this->client_secret = $this->get_field_value( $config, 'secret_id' );
$this->webhook_id = $this->get_field_value( $config, 'webhook_id' );
$config_keys = array_keys( $this->get_config_keys() );
foreach ( $config_keys as $key ) {
$this->$key = $this->get_field_value( $settings, $key );
}
}

public function getMode(): string {
Expand Down Expand Up @@ -160,4 +159,21 @@ public function is_configured() {
// Return true if all the settings are filled.
return $this->merchant_email && $this->client_id && $this->client_secret;
}

/**
* Get config keys
*
* @since 3.0.0
*
* @return array
*/
private function get_config_keys() {
return array(
'environment',
'merchant_email',
'client_id',
'secret_id',
'webhook_id',
);
}
}
14 changes: 8 additions & 6 deletions ecommerce/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -358,18 +358,20 @@ public static function get_payment_settings() {
*
* @return array
*/
public static function get_payment_gateway_config( $gateway_name ) {
public static function get_payment_gateway_settings( $gateway_name ) {
$settings = self::get_payment_settings();

if ( empty( $gateway_name ) || ! isset( $settings['payment_methods'] ) || ! is_array( $settings['payment_methods'] ) ) {
return array();
}

$data = array_filter(
$settings['payment_methods'],
function ( $method ) use ( $gateway_name ) {
return $method['name'] === $gateway_name;
}
$data = array_values(
array_filter(
$settings['payment_methods'],
function ( $method ) use ( $gateway_name ) {
return $method['name'] === $gateway_name;
}
)
);

return isset( $data[0] ) ? $data[0] : array();
Expand Down

0 comments on commit 737aaa0

Please sign in to comment.