public async Task <IActionResult> Add([FromBody] AddVolatilitySettingsModel model) { IMerchant merchant = await _merchantService.GetAsync(model.MerchantId); if (merchant == null) { return(NotFound(ErrorResponse.Create("Merchant not found"))); } try { await _volatilitySettingsService.AddAsync(new VolatilitySettings { MerchantId = model.MerchantId, ZeroCoverageAssetPairs = model.ZeroCoverageAssetPairs, IsDeltaSpreadFixed = model.IsDeltaSpreadFixed }); return(Created(Url.Action("Get", new { merchantId = model.MerchantId }), null)); } catch (VolatilitySettingsAlreadyExistException e) { _log.Error(e, context: model.ToDetails()); return(BadRequest(ErrorResponse.Create(e.Message))); } }
public async Task <IMerchant> InsertAsync(IMerchant merchant) { var existingEmailIndex = await _emailIndexStorage.GetDataAsync( MerchantEntity.IndexByEmail.GeneratePartitionKey(merchant.Email), MerchantEntity.IndexByEmail.GenerateRowKey()); if (existingEmailIndex != null) { throw new DuplicateMerchantEmailException(merchant.Email); } var entity = MerchantEntity.ById.Create(merchant); try { await _storage.InsertThrowConflict(entity); } catch (DuplicateKeyException) { throw new DuplicateMerchantNameException(merchant.Name); } var index = MerchantEntity.IndexByEmail.Create(entity); await _emailIndexStorage.InsertThrowConflict(index); return(entity); }
public async Task <IActionResult> GetForMerchant(string merchantId, string assetPairId) { IMerchant merchant = await _merchantService.GetAsync(merchantId); if (merchant == null) { return(NotFound(ErrorResponse.Create("Merchant not found"))); } try { IMarkup markup = await _markupService.GetForMerchantAsync(merchantId, assetPairId); if (markup == null) { return(NotFound(ErrorResponse.Create("Markup has not been set"))); } return(Ok(Mapper.Map <MarkupResponse>(markup))); } catch (Exception ex) { await _log.WriteErrorAsync(nameof(MarkupsController), nameof(GetForMerchant), ex); throw; } }
public async Task <IActionResult> CreateAsync([FromBody] CreateMerchantRequest request) { try { var merchant = Mapper.Map <Merchant>(request); IMerchant createdMerchant = await _merchantService.CreateAsync(merchant); return(Ok(Mapper.Map <MerchantModel>(createdMerchant))); } catch (InvalidRowKeyValueException e) { _log.Error(e, $"{e.Variable}: {e.Value}"); return(BadRequest(ErrorResponse.Create(e.Message))); } catch (Exception exception) when(exception is DuplicateMerchantNameException || exception is DuplicateMerchantApiKeyException || exception is DuplicateMerchantEmailException) { _log.Warning(exception.Message, context: request.ToDetails()); return(BadRequest(ErrorResponse.Create(exception.Message))); } }
public async Task <IActionResult> SetForMerchant(string merchantId, string assetPairId, [FromBody] UpdateMarkupRequest request) { IMerchant merchant = await _merchantService.GetAsync(merchantId); if (merchant == null) { return(NotFound(ErrorResponse.Create("Merchant not found"))); } if (!string.IsNullOrEmpty(request.PriceAssetPairId)) { AssetPair priceAssetPair = await _assetsLocalCache.GetAssetPairByIdAsync(request.PriceAssetPairId); if (priceAssetPair == null) { return(NotFound(ErrorResponse.Create("Price asset pair doesn't exist"))); } } try { await _markupService.SetForMerchantAsync(assetPairId, merchantId, request.PriceAssetPairId, request.PriceMethod, request); return(Ok()); } catch (Exception ex) { await _log.WriteErrorAsync(nameof(MarkupsController), nameof(SetForMerchant), ex); throw; } }
public async Task <IActionResult> CreateAsync([FromBody] CreateMerchantRequest request) { if (!ModelState.IsValid) { return(BadRequest(new ErrorResponse().AddErrors(ModelState))); } try { var merchant = Mapper.Map <Merchant>(request); IMerchant createdMerchant = await _merchantService.CreateAsync(merchant); return(Ok(Mapper.Map <MerchantModel>(createdMerchant))); } catch (Exception exception) when(exception is DuplicateMerchantNameException || exception is DuplicateMerchantApiKeyException) { await _log.WriteWarningAsync(nameof(MerchantsController), nameof(CreateAsync), request.ToJson(), exception); return(BadRequest(ErrorResponse.Create(exception.Message))); } catch (Exception exception) { await _log.WriteErrorAsync(nameof(MerchantsController), nameof(CreateAsync), request.ToJson(), exception); throw; } }
public IResult PerformCommand(IMobileObject performer, ICommand command) { foreach (INonPlayerCharacter npc in performer.Room.NonPlayerCharacters) { foreach (IPersonality personality in npc.Personalities) { IMerchant merchantPersonality = personality as IMerchant; if (merchantPersonality != null) { if (command.Parameters.Count > 0) { int item; int.TryParse(command.Parameters[0].ParameterValue, out item); if (item > 0) { return(merchantPersonality.Buy(npc, performer, item)); } else { return(merchantPersonality.List(npc, performer)); } } else { return(merchantPersonality.List(npc, performer)); } } } } return(new Result(false, "There is no merchant here to sell to you.")); }
public async Task <IActionResult> ResolveSettlementAssets(string merchantId) { IMerchant merchant = await _merchantService.GetAsync(merchantId); if (merchant == null) { return(NotFound(ErrorResponse.Create("Couldn't find merchant"))); } try { IReadOnlyList <string> assets = await _assetsAvailabilityService.ResolveSettlementAsync(merchantId); return(Ok(new AvailableAssetsResponseModel { Assets = assets })); } catch (Exception ex) { await _log.WriteErrorAsync(nameof(MerchantsController), nameof(ResolveSettlementAssets), new { merchantId }.ToJson(), ex); throw; } }
public async Task ReplaceAsync(IMerchant merchant) { var entity = new MerchantEntity( MerchantEntity.ById.GeneratePartitionKey(merchant.Name), MerchantEntity.ById.GenerateRowKey(merchant.Name)); Mapper.Map(merchant, entity); entity.ETag = "*"; await _storage.ReplaceAsync(entity); if (!string.IsNullOrEmpty(merchant.Email)) { var existingEmailIndex = await _emailIndexStorage.GetDataAsync( MerchantEntity.IndexByEmail.GeneratePartitionKey(merchant.Email), MerchantEntity.IndexByEmail.GenerateRowKey()); if (existingEmailIndex == null) { var newEmailIndex = MerchantEntity.IndexByEmail.Create(entity); await _emailIndexStorage.InsertThrowConflict(newEmailIndex); } } }
public CieloApi(IEnvironment environment, IMerchant merchant) { this.Environment = environment; this.Merchant = merchant; PreConfigurationTls12(); }
private static void VerifyNpc(INonPlayerCharacter npc) { VerifyMob(npc); string type = "NPC"; VerifyNpcType(npc, type); VerifyNpcLevel(npc, type); foreach (IPersonality personality in npc.Personalities) { IMerchant merchant = personality as IMerchant; if (merchant != null) { foreach (IItem item in merchant.Sellables) { VerifyItem(item); } } IPhase phase = personality as IPhase; if (phase != null) { if (!npc.God) { ThrowConfigException(npc, type, string.Format($"Npc {npc.ShortDescription} needs to have God mode turned on.")); } } } }
public static MerchantEntity Create(IMerchant src) { var entity = new MerchantEntity(GeneratePartitionKey(src.Name), GenerateRowKey(src.Name)); Mapper.Map(src, entity); return(entity); }
public async Task ReplaceAsync(IMerchant merchant) { var entity = new MerchantEntity(GetPartitionKey(merchant.Name), GetRowKey(merchant.Name)); Mapper.Map(merchant, entity); entity.ETag = "*"; await _storage.ReplaceAsync(entity); }
public static string ToContext(this IMerchant merchant) { return(new Dictionary <string, string> { { nameof(merchant.Id), merchant.Id }, { nameof(merchant.Name), merchant.Name }, { nameof(merchant.TimeCacheRates), merchant.TimeCacheRates.ToString(CultureInfo.InvariantCulture) }, { nameof(merchant.LwId), merchant.LwId } }.ToJson()); }
protected virtual RestClient CreateClient(string baseUrl, IMerchant merchant) { var client = new RestClient(baseUrl); client.Proxy = WebRequest.DefaultWebProxy; client.AddDefaultHeader("MerchantId", merchant.Id.ToString()); client.AddDefaultHeader("MerchantKey", merchant.Key); return(client); }
public PaymentsController( IUserService userService, IPriceListService priceListService, ITicketTypeService ticketTypeService, ITransactionService transactionAppService, ITicketService ticketService, IMerchant merchant ) { paymentsService = new PaymentsService( transactionAppService, priceListService, ticketTypeService, ticketService, userService, merchant); }
public async Task <IActionResult> GetAsync(string merchantId) { IMerchant merchant = await _merchantService.GetAsync(merchantId); if (merchant == null) { return(NotFound(ErrorResponse.Create("Couldn't find merchant"))); } var model = Mapper.Map <MerchantModel>(merchant); return(Ok(model)); }
private void ValidateMerchant(OnlinePaymentViewModel viewModel, out IMerchant merchant, out IAccount merchantAccount) { merchant = _merchantService.FindMerchant(viewModel.MerchantId); if (merchant == null) { merchantAccount = null; ModelState.AddModelError(string.Empty, "Invalid merchant"); } else { merchantAccount = merchant.Accounts.FirstOrDefault(x => string.Equals(x.Currency, viewModel.Currency, StringComparison.InvariantCultureIgnoreCase)); if (merchantAccount == null) { ModelState.AddModelError(string.Empty, "Invalid merchant currency"); } } }
public async Task SetPublicKeyAsync(string merchantName, string publicKey) { IMerchant merchant = await _merchantRepository.GetAsync(merchantName); if (merchant == null) { throw new MerchantNotFoundException(merchantName); } merchant.PublicKey = publicKey; await _merchantRepository.ReplaceAsync(merchant); await _log.WriteInfoAsync(nameof(MerchantService), nameof(SetPublicKeyAsync), merchant.ToContext(), "Merchant public key updated"); }
public async Task UpdateAsync(IMerchant merchant) { IMerchant existingMerchant = await _merchantRepository.GetAsync(merchant.Name); if (existingMerchant == null) { throw new MerchantNotFoundException(merchant.Name); } Mapper.Map(merchant, existingMerchant); await _merchantRepository.ReplaceAsync(existingMerchant); await _log.WriteInfoAsync(nameof(MerchantService), nameof(UpdateAsync), merchant.ToContext(), "Merchant updated"); }
public async Task <IMerchant> CreateAsync(IMerchant merchant) { IReadOnlyList <IMerchant> merchants = await _merchantRepository.FindAsync(merchant.ApiKey); if (merchants.Count > 0) { throw new DuplicateMerchantApiKeyException(merchant.ApiKey); } IMerchant createdMerchant = await _merchantRepository.InsertAsync(merchant); await _log.WriteInfoAsync(nameof(MerchantService), nameof(CreateAsync), merchant.ToContext(), "Merchant created"); return(createdMerchant); }
public async Task <IActionResult> ResolvePaymentAssets(string merchantId, [FromQuery] string settlementAssetId) { IMerchant merchant = await _merchantService.GetAsync(merchantId); if (merchant == null) { return(NotFound(ErrorResponse.Create("Couldn't find merchant"))); } string lykkeAssetId = await _lykkeAssetsResolver.GetLykkeId(settlementAssetId); Asset asset = await _assetsLocalCache.GetAssetByIdAsync(lykkeAssetId); if (asset == null) { return(NotFound(ErrorResponse.Create("Couldn't find asset"))); } try { IReadOnlyList <string> assets = await _assetsAvailabilityService.ResolvePaymentAsync(merchantId, settlementAssetId); return(Ok(new AvailableAssetsResponseModel { Assets = assets })); } catch (AssetUnknownException assetEx) { await _log.WriteErrorAsync(nameof(MerchantsController), nameof(ResolvePaymentAssets), new { assetEx.Asset }.ToJson(), assetEx); return(BadRequest(ErrorResponse.Create(assetEx.Message))); } catch (Exception ex) { await _log.WriteErrorAsync(nameof(MerchantsController), nameof(ResolvePaymentAssets), new { merchantId, settlementAssetId }.ToJson(), ex); throw; } }
public PaymentsService( ITransactionService transactionAppService, IPriceListService priceListService, ITicketTypeService ticketTypeService, ITicketService ticketService, IUserService userService, IMerchant merchant ) { this.userService = userService; this.ticketService = ticketService; this.userService = userService; this.transactionAppService = transactionAppService; this.priceListService = priceListService; this.ticketTypeService = ticketTypeService; liqPayClient = new LiqPayClient(merchant.PublicKey, merchant.PrivateKey); }
public async Task UpdateAsync(IMerchant srcMerchant) { srcMerchant.TrimProperties(); IMerchant existingMerchant = await _merchantRepository.GetAsync(srcMerchant.Name); if (existingMerchant == null) { throw new MerchantNotFoundException(srcMerchant.Name); } if (srcMerchant.ApiKey != existingMerchant.ApiKey) { IReadOnlyList <IMerchant> merchants = await _merchantRepository.FindApiKeyAsync(srcMerchant.ApiKey); if (merchants.Any()) { throw new DuplicateMerchantApiKeyException(srcMerchant.ApiKey); } } if (string.IsNullOrEmpty(srcMerchant.Email)) { srcMerchant.Email = existingMerchant.Email; } else { if (!string.IsNullOrEmpty(existingMerchant.Email)) { throw new MerchantEmailUpdateException(existingMerchant.Id); } IMerchant emailMerchant = await _merchantRepository.FindEmailAsync(srcMerchant.Email); if (emailMerchant != null) { throw new DuplicateMerchantEmailException(srcMerchant.Email); } } await _merchantRepository.ReplaceAsync(srcMerchant); _log.Info("Merchant updated", srcMerchant); }
public async Task <IActionResult> GetAsync(string merchantId) { try { IMerchant merchant = await _merchantService.GetAsync(Uri.UnescapeDataString(merchantId)); if (merchant == null) { return(NotFound(ErrorResponse.Create("Merchant not found"))); } return(Ok(Mapper.Map <MerchantModel>(merchant))); } catch (InvalidRowKeyValueException e) { _log.Error(e, $"{e.Variable}: {e.Value}"); return(BadRequest(ErrorResponse.Create(e.Message))); } }
public FuncResult VerifySignature() { IMerchant merchant = GetMerchant(); if (merchant == null) { return(FuncResult.FailResult("无效商户号", 400)); } AsciiSortedDictionary <object> dic = JsonSerializer.Deserializer <AsciiSortedDictionary <object> >(GetRequestOriginalString()); dic.Remove(item => item.Key.Equals("sign", StringComparison.OrdinalIgnoreCase) || item.Value == null || string.IsNullOrEmpty(item.Value.ToString())); StringBuilder builder = new StringBuilder(); dic.Aggregate(builder, (b, kv) => b.Append(kv.Key).Append("=").Append(kv.Value).Append("&")); builder.Remove(builder.Length - 1, 1); bool res = merchant.VerifySignature(builder.ToString(), GetRequestSignature()); return(new FuncResult { Success = res, Message = "签名验证不正确", StatusCode = 2 }); }
public IResult PerformCommand(IMobileObject performer, ICommand command) { foreach (INonPlayerCharacter npc in performer.Room.NonPlayerCharacters) { foreach (IPersonality personality in npc.Personalities) { IMerchant merchantMasterPersonality = personality as IMerchant; if (merchantMasterPersonality != null) { if (command.Parameters.Count > 0) { IItem item = null; foreach (IItem i in performer.Items) { if (i.KeyWords.Contains(command.Parameters[0].ParameterValue, StringComparer.CurrentCultureIgnoreCase)) { item = i; break; } } if (item != null) { return(merchantMasterPersonality.Sell(npc, performer, item)); } else { return(merchantMasterPersonality.Offer(npc, performer)); } } else { return(merchantMasterPersonality.Offer(npc, performer)); } } } } return(new Result(false, "There is no merchant here to sell to.")); }
public async Task <IActionResult> GetAllForMerchant(string merchantId) { IMerchant merchant = await _merchantService.GetAsync(merchantId); if (merchant == null) { return(NotFound(ErrorResponse.Create("Merchant not found"))); } try { IReadOnlyList <IMarkup> markups = await _markupService.GetForMerchantAsync(merchantId); return(Ok(Mapper.Map <IEnumerable <MarkupResponse> >(markups))); } catch (Exception ex) { await _log.WriteErrorAsync(nameof(MarkupsController), nameof(GetAllForMerchant), ex); throw; } }
public async Task <IActionResult> GetAssetsPersonalSettings([FromQuery] string merchantId) { IMerchant merchant = await _merchantService.GetAsync(merchantId); if (merchant == null) { return(NotFound(ErrorResponse.Create("Couldn't find merchant"))); } try { IAssetAvailabilityByMerchant personal = await _assetsAvailabilityService.GetPersonalAsync(merchantId); return(Ok(Mapper.Map <AssetAvailabilityByMerchantResponse>(personal))); } catch (Exception ex) { await _log.WriteErrorAsync(nameof(AssetsController), nameof(GetAssetsPersonalSettings), ex); throw; } }
public async Task <IMerchant> InsertAsync(IMerchant merchant) { var entity = new MerchantEntity(GetPartitionKey(merchant.Name), GetRowKey(merchant.Name)); Mapper.Map(merchant, entity); try { await _storage.InsertAsync(entity); } catch (StorageException ex) { if (ex.Message == ConflictMessage) { throw new DuplicateMerchantNameException(merchant.Name); } throw; } return(entity); }
public MerchantTier(IMerchant merchantsRepository) { this.merchantsRepository = merchantsRepository; }