public async void CanToggleChangellyPaymentMethod() { using (var tester = ServerTester.Create()) { tester.Start(); var user = tester.NewAccount(); user.GrantAccess(); var controller = tester.PayTester.GetController <StoresController>(user.UserId, user.StoreId); var updateModel = new UpdateChangellySettingsViewModel() { ApiSecret = "secret", ApiKey = "key", ApiUrl = "http://gozo.com", ChangellyMerchantId = "aaa", Enabled = true }; Assert.Equal("UpdateStore", Assert.IsType <RedirectToActionResult>( await controller.UpdateChangellySettings(user.StoreId, updateModel, "save")).ActionName); var store = await tester.PayTester.StoreRepository.FindStore(user.StoreId); Assert.True(store.GetStoreBlob().ChangellySettings.Enabled); updateModel.Enabled = false; Assert.Equal("UpdateStore", Assert.IsType <RedirectToActionResult>( await controller.UpdateChangellySettings(user.StoreId, updateModel, "save")).ActionName); store = await tester.PayTester.StoreRepository.FindStore(user.StoreId); Assert.False(store.GetStoreBlob().ChangellySettings.Enabled); } }
public IActionResult UpdateChangellySettings(string storeId) { var store = HttpContext.GetStoreData(); if (store == null) { return(NotFound()); } UpdateChangellySettingsViewModel vm = new UpdateChangellySettingsViewModel(); SetExistingValues(store, vm); return(View(vm)); }
private void SetExistingValues(StoreData store, UpdateChangellySettingsViewModel vm) { var existing = store.GetStoreBlob().ChangellySettings; if (existing == null) { return; } vm.ApiKey = existing.ApiKey; vm.ApiSecret = existing.ApiSecret; vm.ApiUrl = existing.ApiUrl; vm.ChangellyMerchantId = existing.ChangellyMerchantId; vm.Enabled = existing.Enabled; vm.AmountMarkupPercentage = existing.AmountMarkupPercentage; }
public async void CanSetChangellyPaymentMethod() { using (var tester = ServerTester.Create()) { await tester.StartAsync(); var user = tester.NewAccount(); user.GrantAccess(); var controller = tester.PayTester.GetController <StoresController>(user.UserId, user.StoreId); var storeBlob = controller.StoreData.GetStoreBlob(); Assert.Null(storeBlob.ChangellySettings); var updateModel = new UpdateChangellySettingsViewModel() { ApiSecret = "secret", ApiKey = "key", ApiUrl = "http://gozo.com", ChangellyMerchantId = "aaa", }; Assert.Equal("UpdateStore", Assert.IsType <RedirectToActionResult>( await controller.UpdateChangellySettings(user.StoreId, updateModel, "save")).ActionName); var store = await tester.PayTester.StoreRepository.FindStore(user.StoreId); storeBlob = controller.StoreData.GetStoreBlob(); Assert.NotNull(storeBlob.ChangellySettings); Assert.NotNull(storeBlob.ChangellySettings); Assert.IsType <ChangellySettings>(storeBlob.ChangellySettings); Assert.Equal(storeBlob.ChangellySettings.ApiKey, updateModel.ApiKey); Assert.Equal(storeBlob.ChangellySettings.ApiSecret, updateModel.ApiSecret); Assert.Equal(storeBlob.ChangellySettings.ApiUrl, updateModel.ApiUrl); Assert.Equal(storeBlob.ChangellySettings.ChangellyMerchantId, updateModel.ChangellyMerchantId); } }
public async Task <IActionResult> UpdateChangellySettings(string storeId, UpdateChangellySettingsViewModel vm, string command) { var store = HttpContext.GetStoreData(); if (store == null) { return(NotFound()); } if (vm.Enabled) { if (!ModelState.IsValid) { return(View(vm)); } } var changellySettings = new ChangellySettings() { ApiKey = vm.ApiKey, ApiSecret = vm.ApiSecret, ApiUrl = vm.ApiUrl, ChangellyMerchantId = vm.ChangellyMerchantId, Enabled = vm.Enabled, AmountMarkupPercentage = vm.AmountMarkupPercentage }; switch (command) { case "save": var storeBlob = store.GetStoreBlob(); storeBlob.ChangellySettings = changellySettings; store.SetStoreBlob(storeBlob); await _Repo.UpdateStore(store); TempData[WellKnownTempData.SuccessMessage] = "Changelly settings modified"; _changellyClientProvider.InvalidateClient(storeId); return(RedirectToAction(nameof(UpdateStore), new { storeId })); case "test": try { var client = new Changelly(_httpClientFactory.CreateClient(), changellySettings.ApiKey, changellySettings.ApiSecret, changellySettings.ApiUrl); var result = await client.GetCurrenciesFull(); TempData[WellKnownTempData.SuccessMessage] = "Test Successful"; return(View(vm)); } catch (Exception ex) { TempData[WellKnownTempData.ErrorMessage] = ex.Message; return(View(vm)); } default: return(View(vm)); } }