Ejemplo n.º 1
0
        public ActionResult RevokeAccessTokens(ConfigurationModel model)
        {
            try
            {
                //try to revoke all access tokens
                var successfullyRevoked = _squarePaymentManager.RevokeAccessTokens(new RevokeAccessTokenRequest
                {
                    ApplicationId     = _squarePaymentSettings.ApplicationId,
                    ApplicationSecret = _squarePaymentSettings.ApplicationSecret,
                    AccessToken       = _squarePaymentSettings.AccessToken
                });
                if (!successfullyRevoked)
                {
                    throw new NopException("Tokens were not revoked");
                }

                //if access token successfully revoked, delete it from the settings
                _squarePaymentSettings.AccessToken = string.Empty;
                _settingService.SaveSetting(_squarePaymentSettings);

                SuccessNotification(_localizationService.GetResource("Plugins.Payments.Square.RevokeAccessTokens.Success"));
            }
            catch (Exception exception)
            {
                ErrorNotification(_localizationService.GetResource("Plugins.Payments.Square.RevokeAccessTokens.Error"));
                if (!string.IsNullOrEmpty(exception.Message))
                {
                    ErrorNotification(exception.Message);
                }
            }

            return(Configure());
        }
        public IActionResult RevokeAccessTokens(ConfigurationModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManagePaymentMethods))
            {
                return(AccessDeniedView());
            }

            try
            {
                //try to revoke all access tokens
                var successfullyRevoked = _squarePaymentManager.RevokeAccessTokens();
                if (!successfullyRevoked)
                {
                    throw new NopException("Tokens were not revoked");
                }

                //if access token successfully revoked, delete it from the settings
                _squarePaymentSettings.AccessToken = string.Empty;
                _settingService.SaveSetting(_squarePaymentSettings);

                _notificationService.SuccessNotification(_localizationService.GetResource("Plugins.Payments.Square.RevokeAccessTokens.Success"));
            }
            catch (Exception exception)
            {
                var error = _localizationService.GetResource("Plugins.Payments.Square.RevokeAccessTokens.Error");
                if (!string.IsNullOrEmpty(exception.Message))
                {
                    error = $"{error} - {exception.Message}";
                }
                _notificationService.ErrorNotification(exception.Message);
            }

            return(Configure());
        }
Ejemplo n.º 3
0
        public IActionResult RevokeAccessTokens(ConfigurationModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManagePaymentMethods))
            {
                return(AccessDeniedView());
            }

            //load settings for a chosen store scope
            var storeId  = _storeContext.ActiveStoreScopeConfiguration;
            var settings = _settingService.LoadSetting <SquarePaymentSettings>(storeId);

            try
            {
                //try to revoke all access tokens
                var successfullyRevoked = _squarePaymentManager.RevokeAccessTokens(storeId);
                if (!successfullyRevoked)
                {
                    throw new NopException("Tokens were not revoked");
                }

                //if access token successfully revoked, delete it from the settings
                settings.AccessToken = string.Empty;
                _settingService.SaveSetting(settings, x => x.AccessToken, storeId);

                _notificationService.SuccessNotification(_localizationService.GetResource("Plugins.Payments.Square.RevokeAccessTokens.Success"));
            }
            catch (Exception exception)
            {
                var error = _localizationService.GetResource("Plugins.Payments.Square.RevokeAccessTokens.Error");
                if (!string.IsNullOrEmpty(exception.Message))
                {
                    error = $"{error} - {exception.Message}";
                }
                _notificationService.ErrorNotification(exception.Message);
            }

            return(RedirectToAction("Configure"));
        }