mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Use DI for General Settings and store only after verification
This commit is contained in:
parent
268ab3a27a
commit
c13680b7f5
2 changed files with 28 additions and 19 deletions
|
@ -9,6 +9,7 @@ declare( strict_types = 1 );
|
|||
|
||||
namespace WooCommerce\PayPalCommerce\Settings;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Settings\Data\GeneralSettings;
|
||||
use WooCommerce\PayPalCommerce\Settings\Endpoint\ConnectManualRestEndpoint;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\Settings\Endpoint\OnboardingRestEndpoint;
|
||||
|
@ -50,7 +51,8 @@ return array(
|
|||
return new ConnectManualRestEndpoint(
|
||||
$container->get( 'api.paypal-host-production' ),
|
||||
$container->get( 'api.paypal-host-sandbox' ),
|
||||
$container->get( 'woocommerce.logger.woocommerce' )
|
||||
$container->get( 'woocommerce.logger.woocommerce' ),
|
||||
$container->get( 'settings.general' )
|
||||
);
|
||||
},
|
||||
'settings.casual-selling.supported-countries' => static function ( ContainerInterface $container ) : array {
|
||||
|
@ -109,4 +111,7 @@ return array(
|
|||
|
||||
return in_array( $country, $eligible_countries, true );
|
||||
},
|
||||
'settings.general' => static function ( ContainerInterface $container ) : GeneralSettings {
|
||||
return new GeneralSettings();
|
||||
},
|
||||
);
|
||||
|
|
|
@ -56,6 +56,13 @@ class ConnectManualRestEndpoint extends RestEndpoint {
|
|||
*/
|
||||
protected $rest_base = 'connect_manual';
|
||||
|
||||
/**
|
||||
* Settings instance.
|
||||
*
|
||||
* @var GeneralSettings
|
||||
*/
|
||||
private $settings = null;
|
||||
|
||||
/**
|
||||
* Field mapping for request.
|
||||
*
|
||||
|
@ -82,16 +89,19 @@ class ConnectManualRestEndpoint extends RestEndpoint {
|
|||
* @param string $live_host The API host for the live mode.
|
||||
* @param string $sandbox_host The API host for the sandbox mode.
|
||||
* @param LoggerInterface $logger The logger.
|
||||
* @param GeneralSettings $settings Settings instance.
|
||||
*/
|
||||
public function __construct(
|
||||
string $live_host,
|
||||
string $sandbox_host,
|
||||
LoggerInterface $logger
|
||||
LoggerInterface $logger,
|
||||
GeneralSettings $settings
|
||||
) {
|
||||
|
||||
$this->live_host = $live_host;
|
||||
$this->sandbox_host = $sandbox_host;
|
||||
$this->logger = $logger;
|
||||
$this->settings = $settings;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -135,18 +145,6 @@ class ConnectManualRestEndpoint extends RestEndpoint {
|
|||
);
|
||||
}
|
||||
|
||||
$settings = new GeneralSettings();
|
||||
if ( $use_sandbox ) {
|
||||
$settings->set_is_sandbox( true );
|
||||
$settings->set_sandbox_client_id( $client_id );
|
||||
$settings->set_sandbox_client_secret( $client_secret );
|
||||
} else {
|
||||
$settings->set_is_sandbox( false );
|
||||
$settings->set_live_client_id( $client_id );
|
||||
$settings->set_live_client_secret( $client_secret );
|
||||
}
|
||||
$settings->save();
|
||||
|
||||
try {
|
||||
$payee = $this->request_payee( $client_id, $client_secret, $use_sandbox );
|
||||
} catch ( Exception $exception ) {
|
||||
|
@ -160,13 +158,19 @@ class ConnectManualRestEndpoint extends RestEndpoint {
|
|||
}
|
||||
|
||||
if ( $use_sandbox ) {
|
||||
$settings->set_sandbox_merchant_id( $payee->merchant_id );
|
||||
$settings->set_sandbox_merchant_email( $payee->email_address );
|
||||
$this->settings->set_is_sandbox( true );
|
||||
$this->settings->set_sandbox_client_id( $client_id );
|
||||
$this->settings->set_sandbox_client_secret( $client_secret );
|
||||
$this->settings->set_sandbox_merchant_id( $payee->merchant_id );
|
||||
$this->settings->set_sandbox_merchant_email( $payee->email_address );
|
||||
} else {
|
||||
$settings->set_live_merchant_id( $payee->merchant_id );
|
||||
$settings->set_live_merchant_email( $payee->email_address );
|
||||
$this->settings->set_is_sandbox( false );
|
||||
$this->settings->set_live_client_id( $client_id );
|
||||
$this->settings->set_live_client_secret( $client_secret );
|
||||
$this->settings->set_live_merchant_id( $payee->merchant_id );
|
||||
$this->settings->set_live_merchant_email( $payee->email_address );
|
||||
}
|
||||
$settings->save();
|
||||
$this->settings->save();
|
||||
|
||||
$result = array(
|
||||
'merchantId' => $payee->merchant_id,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue