mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-04 08:47:23 +08:00
Merge pull request #2791 from woocommerce/PCP-3891-Store-Manual-Connection-details-in-DB
Store Manual Connection details in DB (3891)
This commit is contained in:
commit
d85d802169
2 changed files with 38 additions and 11 deletions
|
@ -11,6 +11,7 @@ namespace WooCommerce\PayPalCommerce\Settings;
|
|||
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Helper\Cache;
|
||||
use WooCommerce\PayPalCommerce\Settings\Data\CommonSettings;
|
||||
use WooCommerce\PayPalCommerce\Settings\Data\GeneralSettings;
|
||||
use WooCommerce\PayPalCommerce\Settings\Data\OnboardingProfile;
|
||||
use WooCommerce\PayPalCommerce\Settings\Endpoint\CommonRestEndpoint;
|
||||
use WooCommerce\PayPalCommerce\Settings\Endpoint\ConnectManualRestEndpoint;
|
||||
|
@ -49,6 +50,9 @@ return array(
|
|||
$can_use_card_payments
|
||||
);
|
||||
},
|
||||
'settings.data.general' => static function ( ContainerInterface $container ) : GeneralSettings {
|
||||
return new GeneralSettings();
|
||||
},
|
||||
'settings.data.common' => static function ( ContainerInterface $container ) : CommonSettings {
|
||||
return new CommonSettings();
|
||||
},
|
||||
|
@ -62,7 +66,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.data.general' )
|
||||
);
|
||||
},
|
||||
'settings.rest.login_link' => static function ( ContainerInterface $container ) : LoginLinkRestEndpoint {
|
||||
|
|
|
@ -10,17 +10,16 @@ declare( strict_types = 1 );
|
|||
namespace WooCommerce\PayPalCommerce\Settings\Endpoint;
|
||||
|
||||
use Exception;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use RuntimeException;
|
||||
use stdClass;
|
||||
use RuntimeException;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use WP_REST_Request;
|
||||
use WP_REST_Response;
|
||||
use WP_REST_Server;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Authentication\PayPalBearer;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\Orders;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Helper\InMemoryCache;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException;
|
||||
use WP_REST_Server;
|
||||
use WP_REST_Response;
|
||||
use WP_REST_Request;
|
||||
use WooCommerce\PayPalCommerce\Settings\Data\GeneralSettings;
|
||||
|
||||
/**
|
||||
* REST controller for connection via manual credentials input.
|
||||
|
@ -55,6 +54,13 @@ class ConnectManualRestEndpoint extends RestEndpoint {
|
|||
*/
|
||||
protected $rest_base = 'connect_manual';
|
||||
|
||||
/**
|
||||
* Settings instance.
|
||||
*
|
||||
* @var GeneralSettings
|
||||
*/
|
||||
private $settings = null;
|
||||
|
||||
/**
|
||||
* Field mapping for request.
|
||||
*
|
||||
|
@ -81,16 +87,18 @@ 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,11 +143,25 @@ class ConnectManualRestEndpoint extends RestEndpoint {
|
|||
return $this->return_error( $exception->getMessage() );
|
||||
}
|
||||
|
||||
if ( $use_sandbox ) {
|
||||
$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 {
|
||||
$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 );
|
||||
}
|
||||
$this->settings->save();
|
||||
|
||||
return $this->return_success(
|
||||
array(
|
||||
'merchantId' => $payee->merchant_id,
|
||||
'email' => $payee->email_address,
|
||||
'success' => true,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue