Beispiel #1
0
        public IActionResult Configure()
        {
            //whether user has the authority
            if (!_permissionService.Authorize(StandardPermissionProvider.ManagePaymentMethods))
            {
                return(AccessDeniedView());
            }

            //prepare model
            var model = new ConfigurationModel
            {
                IsConfigured             = IsConfigured(),
                ApplicationId            = _squarePaymentSettings.ApplicationId,
                ApplicationSecret        = _squarePaymentSettings.ApplicationSecret,
                AccessToken              = _squarePaymentSettings.AccessToken,
                AccessTokenRenewalPeriod = _squarePaymentSettings.AccessTokenRenewalPeriod,
                TransactionModeId        = (int)_squarePaymentSettings.TransactionMode,
                TransactionModes         = _squarePaymentSettings.TransactionMode.ToSelectList(),
                LocationId              = _squarePaymentSettings.LocationId,
                AdditionalFee           = _squarePaymentSettings.AdditionalFee,
                AdditionalFeePercentage = _squarePaymentSettings.AdditionalFeePercentage
            };

            //prepare business locations, every payment a merchant processes is associated with one of these locations
            if (!string.IsNullOrEmpty(model.AccessToken))
            {
                model.Locations = _squarePaymentManager.GetActiveLocations()
                                  .Select(location => new SelectListItem {
                    Text = location.BusinessName, Value = location.Id
                }).ToList();
            }

            //add the special item for 'there are no location' with value 0
            if (!model.Locations.Any())
            {
                var noLocationText = _localizationService.GetResource("Plugins.Payments.Square.Fields.Location.NotExist");
                model.Locations.Add(new SelectListItem {
                    Text = noLocationText, Value = "0"
                });
            }

            //get access token renewal period in days
            var task = _scheduleTaskService.GetTaskByType(SquarePaymentDefaults.RenewAccessTokenTask);

            if (task != null)
            {
                model.AccessTokenRenewalPeriod = task.Seconds / 60 / 60 / 24;
            }

            return(View("~/Plugins/Payments.Square/Views/Configure.cshtml", model));
        }
Beispiel #2
0
        public IActionResult Configure()
        {
            //whether user has the authority
            if (!_permissionService.Authorize(StandardPermissionProvider.ManagePaymentMethods))
            {
                return(AccessDeniedView());
            }

            //prepare model
            var model = new ConfigurationModel
            {
                ApplicationId           = _squarePaymentSettings.ApplicationId,
                ApplicationSecret       = _squarePaymentSettings.ApplicationSecret,
                AccessToken             = _squarePaymentSettings.AccessToken,
                UseSandbox              = _squarePaymentSettings.UseSandbox,
                TransactionModeId       = (int)_squarePaymentSettings.TransactionMode,
                TransactionModes        = _squarePaymentSettings.TransactionMode.ToSelectList(),
                LocationId              = _squarePaymentSettings.LocationId,
                AdditionalFee           = _squarePaymentSettings.AdditionalFee,
                AdditionalFeePercentage = _squarePaymentSettings.AdditionalFeePercentage
            };

            //prepare business locations, every payment a merchant processes is associated with one of these locations
            if (!string.IsNullOrEmpty(model.AccessToken))
            {
                model.Locations = _squarePaymentManager.GetActiveLocations().Select(location =>
                {
                    var name = location.BusinessName;
                    if (!location.Name.Equals(location.BusinessName))
                    {
                        name = $"{name} ({location.Name})";
                    }
                    return(new SelectListItem {
                        Text = name, Value = location.Id
                    });
                }).ToList();
            }

            //add the special item for 'there are no location' with value 0
            if (!model.Locations.Any())
            {
                var noLocationText = _localizationService.GetResource("Plugins.Payments.Square.Fields.Location.NotExist");
                model.Locations.Add(new SelectListItem {
                    Text = noLocationText, Value = "0"
                });
            }

            return(View("~/Plugins/Payments.Square/Views/Configure.cshtml", model));
        }
Beispiel #3
0
        public IActionResult Configure()
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManagePaymentMethods))
            {
                return(AccessDeniedView());
            }

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

            //prepare model
            var model = new ConfigurationModel
            {
                ApplicationSecret             = settings.ApplicationSecret,
                UseSandbox                    = settings.UseSandbox,
                Use3ds                        = settings.Use3ds,
                TransactionModeId             = (int)settings.TransactionMode,
                LocationId                    = settings.LocationId,
                AdditionalFee                 = settings.AdditionalFee,
                AdditionalFeePercentage       = settings.AdditionalFeePercentage,
                ActiveStoreScopeConfiguration = storeId
            };

            if (model.UseSandbox)
            {
                model.SandboxApplicationId = settings.ApplicationId;
                model.SandboxAccessToken   = settings.AccessToken;
            }
            else
            {
                model.ApplicationId = settings.ApplicationId;
                model.AccessToken   = settings.AccessToken;
            }

            if (storeId > 0)
            {
                model.UseSandbox_OverrideForStore              = _settingService.SettingExists(settings, x => x.UseSandbox, storeId);
                model.Use3ds_OverrideForStore                  = _settingService.SettingExists(settings, x => x.Use3ds, storeId);
                model.TransactionModeId_OverrideForStore       = _settingService.SettingExists(settings, x => x.TransactionMode, storeId);
                model.LocationId_OverrideForStore              = _settingService.SettingExists(settings, x => x.LocationId, storeId);
                model.AdditionalFee_OverrideForStore           = _settingService.SettingExists(settings, x => x.AdditionalFee, storeId);
                model.AdditionalFeePercentage_OverrideForStore = _settingService.SettingExists(settings, x => x.AdditionalFeePercentage, storeId);
            }

            //prepare business locations, every payment a merchant processes is associated with one of these locations
            if (!string.IsNullOrEmpty(settings.AccessToken))
            {
                model.Locations = _squarePaymentManager.GetActiveLocations(storeId).Select(location =>
                {
                    var name = location.BusinessName;
                    if (!location.Name.Equals(location.BusinessName))
                    {
                        name = $"{name} ({location.Name})";
                    }
                    return(new SelectListItem {
                        Text = name, Value = location.Id
                    });
                }).ToList();
                if (model.Locations.Any())
                {
                    var selectLocationText = _localizationService.GetResource("Plugins.Payments.Square.Fields.Location.Select");
                    model.Locations.Insert(0, new SelectListItem {
                        Text = selectLocationText, Value = "0"
                    });
                }
            }

            //add the special item for 'there are no location' with value 0
            if (!model.Locations.Any())
            {
                var noLocationText = _localizationService.GetResource("Plugins.Payments.Square.Fields.Location.NotExist");
                model.Locations.Add(new SelectListItem {
                    Text = noLocationText, Value = "0"
                });
            }

            //warn admin that the location is a required parameter
            if (string.IsNullOrEmpty(settings.LocationId) || settings.LocationId.Equals("0"))
            {
                _notificationService.WarningNotification(_localizationService.GetResource("Plugins.Payments.Square.Fields.Location.Hint"));
            }

            //migrate to using refresh tokens
            if (!settings.UseSandbox && settings.RefreshToken == Guid.Empty.ToString())
            {
                var migrateMessage = $"Your access token is deprecated.<br /> " +
                                     $"1. In the <a href=\"http://squ.re/nopcommerce1\" target=\"_blank\">Square Developer Portal</a> make sure your application is on Connect API version 2019-03-13 or later.<br /> " +
                                     $"2. On this page click 'Obtain access token' below.<br />";
                _notificationService.ErrorNotification(migrateMessage, encode: false);
            }

            return(View("~/Plugins/Payments.Square/Views/Configure.cshtml", model));
        }