mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-01 07:02:48 +08:00
switch bearer and api hosts depending on onboarding status
This commit is contained in:
parent
d1c4d470d9
commit
0d0ad67508
1 changed files with 31 additions and 2 deletions
|
@ -5,6 +5,9 @@ declare(strict_types=1);
|
|||
namespace Inpsyde\PayPalCommerce\Onboarding;
|
||||
|
||||
use Dhii\Data\Container\ContainerInterface;
|
||||
use Inpsyde\PayPalCommerce\ApiClient\Authentication\Bearer;
|
||||
use Inpsyde\PayPalCommerce\ApiClient\Authentication\ConnectBearer;
|
||||
use Inpsyde\PayPalCommerce\ApiClient\Authentication\PayPalBearer;
|
||||
use Inpsyde\PayPalCommerce\Onboarding\Assets\OnboardingAssets;
|
||||
use Inpsyde\PayPalCommerce\Onboarding\Endpoint\LoginSellerEndpoint;
|
||||
use Inpsyde\PayPalCommerce\Onboarding\Render\OnboardingRenderer;
|
||||
|
@ -20,6 +23,7 @@ use Inpsyde\PayPalCommerce\WcGateway\Processor\AuthorizedPaymentsProcessor;
|
|||
use Inpsyde\PayPalCommerce\WcGateway\Processor\OrderProcessor;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Settings\Settings;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Settings\SettingsFields;
|
||||
use WpOop\TransientCache\CachePoolFactory;
|
||||
|
||||
return [
|
||||
|
||||
|
@ -39,12 +43,37 @@ return [
|
|||
return 'https://api.sandbox.paypal.com';
|
||||
}
|
||||
|
||||
//ToDo: Real connect.woocommerce.com
|
||||
if ($environment->currentEnvironmentIs(Environment::SANDBOX)) {
|
||||
return 'https://api.sandbox.paypal.com';
|
||||
return 'http://connect-woo.wpcust.com';
|
||||
}
|
||||
return 'https://api.sandbox.paypal.com';
|
||||
return 'http://connect-woo.wpcust.com';
|
||||
|
||||
},
|
||||
|
||||
'api.bearer' => static function (ContainerInterface $container): Bearer {
|
||||
|
||||
$state = $container->get('onboarding.state');
|
||||
if ($state->currentState() < State::STATE_ONBOARDED) {
|
||||
return new ConnectBearer();
|
||||
}
|
||||
global $wpdb;
|
||||
$cacheFactory = new CachePoolFactory($wpdb);
|
||||
$pool = $cacheFactory->createCachePool('ppcp-token');
|
||||
$key = $container->get('api.key');
|
||||
$secret = $container->get('api.secret');
|
||||
//ToDo: Remove Test Key and Secret
|
||||
//$key = 'AQB97CzMsd58-It1vxbcDAGvMuXNCXRD9le_XUaMlHB_U7XsU9IiItBwGQOtZv9sEeD6xs2vlIrL4NiD';
|
||||
//$secret = 'EILGMYK_0iiSbja8hT-nCBGl0BvKxEB4riHgyEO7QWDeUzCJ5r42JUEvrI7gpGyw0Qww8AIXxSdCIAny';
|
||||
|
||||
$host = $container->get('api.host');
|
||||
return new PayPalBearer(
|
||||
$pool,
|
||||
$host,
|
||||
$key,
|
||||
$secret
|
||||
);
|
||||
},
|
||||
'onboarding.state' => function(ContainerInterface $container) : State {
|
||||
$environment = $container->get('onboarding.environment');
|
||||
$settings = $container->get('wcgateway.settings');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue