PluginProbe
PayPlug for WooCommerce (Official) / 3.1.0
PayPlug for WooCommerce (Official) v3.1.0
3.1.0 3.0.0 2.18.0 1.0.17 1.0.18 1.0.19 1.0.20 1.0.21 1.0.22 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.1.0 1.10.0 1.10.1 1.2.1 1.2.10 1.2.11 1.2.2 1.2.3 1.2.4 1.2.5 All 102 releases
← All changes | src/Gateway/PayplugPermissions.php +11 -13 2.18.0 → 3.1.0 View file →
@@ -13,12 +13,12 @@
13 13 use Payplug\PayplugWoocommerce\PayplugWoocommerceHelper;
14 14
15 15 class PayplugPermissions
16 16 {
17 - const OPTION_NAME = 'payplug_permission';
18 - const LIVE_MODE = 'use_live_mode';
19 - const SAVE_CARD = 'can_save_cards';
20 - const USE_ONEY = 'can_use_oney';
17 + public const OPTION_NAME = 'payplug_permission';
18 + public const LIVE_MODE = 'use_live_mode';
19 + public const SAVE_CARD = 'can_save_cards';
20 + public const USE_ONEY = 'can_use_oney';
21 21
22 22 /**
23 23 * The current mode for the gateway.
24 24 *
@@ -41,20 +41,18 @@
41 41 /**
42 42 * PayplugPermissions constructor.
43 43 *
44 44 * @param PayplugGateway $gateway
45 + * @param string|null $bearer_token Already-resolved bearer token for the gateway's
46 + * current mode (see PayplugGateway::init_payplug()).
47 + * Resolved here if not given.
45 48 */
46 - public function __construct(PayplugGateway $gateway)
49 + public function __construct(PayplugGateway $gateway, ?string $bearer_token = null)
47 50 {
48 - $this->gateway_mode = $gateway->get_configuration()->get_option('mode');
49 - $api_key = json_decode($gateway->get_configuration()->get_option('api_key'), true);
51 + $this->gateway_mode = $gateway->get_configuration()->get_option('mode') ? 'live' : 'test';
50 52
51 - // todo: check if we should get the jwt instead api key
52 - if (!isset($api_key['live']) || !isset($api_key['test'])) {
53 - $this->current_key = '';
54 - } else {
55 - $this->current_key = 'live' === $this->gateway_mode ? $api_key['live'] : $api_key['test'];
56 - }
53 + // get_bearer_token() refreshes the JWT if it's close to expiry (OAuth2 accounts).
54 + $this->current_key = $bearer_token ?? (string) $gateway->get_api()->get_bearer_token($this->gateway_mode);
57 55 $this->load_permissions();
58 56 }
59 57
60 58 /**