示例#1
0
        /// <summary>
        /// Executes a task
        /// </summary>
        public void Execute()
        {
            //whether plugin is active
            if (!_paymentService.LoadPaymentMethodBySystemName(SquarePaymentDefaults.SystemName).IsPaymentMethodActive(_paymentSettings))
            {
                return;
            }

            try
            {
                //get the new access token
                var newAccessToken = _squarePaymentManager.RenewAccessToken(new RenewAccessTokenRequest
                {
                    ApplicationId      = _squarePaymentSettings.ApplicationId,
                    ApplicationSecret  = _squarePaymentSettings.ApplicationSecret,
                    ExpiredAccessToken = _squarePaymentSettings.AccessToken
                });
                if (string.IsNullOrEmpty(newAccessToken))
                {
                    throw new NopException("No service response");
                }

                //if access token successfully received, save it for the further usage
                _squarePaymentSettings.AccessToken = newAccessToken;
                _settingService.SaveSetting(_squarePaymentSettings);

                //log information about the successful renew of the access token
                _logger.Information(_localizationService.GetResource("Plugins.Payments.Square.RenewAccessToken.Success"));
            }
            catch (Exception exception)
            {
                //log error on renewing of the access token
                _logger.Error(_localizationService.GetResource("Plugins.Payments.Square.RenewAccessToken.Error"), exception);
            }
        }
示例#2
0
        /// <summary>
        /// Executes a task
        /// </summary>
        public void Execute()
        {
            //whether plugin is active
            if (!_paymentPluginManager.IsPluginActive(SquarePaymentDefaults.SystemName))
            {
                return;
            }

            //do not execute for sandbox environment
            if (_squarePaymentSettings.UseSandbox)
            {
                return;
            }

            try
            {
                var storeId = _storeContext.CurrentStore.Id;

                //get the new access token
                var(newAccessToken, refreshToken) = _squarePaymentManager.RenewAccessToken(storeId);
                if (string.IsNullOrEmpty(newAccessToken) || string.IsNullOrEmpty(refreshToken))
                {
                    throw new NopException("No service response");
                }

                //if access token successfully received, save it for the further usage
                _squarePaymentSettings.AccessToken  = newAccessToken;
                _squarePaymentSettings.RefreshToken = refreshToken;

                _settingService.SaveSetting(_squarePaymentSettings, x => x.AccessToken, storeId, false);
                _settingService.SaveSetting(_squarePaymentSettings, x => x.RefreshToken, storeId, false);

                _settingService.ClearCache();

                //log information about the successful renew of the access token
                _logger.Information(_localizationService.GetResource("Plugins.Payments.Square.RenewAccessToken.Success"));
            }
            catch (Exception exception)
            {
                //log error on renewing of the access token
                _logger.Error(_localizationService.GetResource("Plugins.Payments.Square.RenewAccessToken.Error"), exception);
            }
        }