/// <summary> /// Places a bet /// </summary> async Task <Guid> IGameCommands.PlaceBetAsync([NotNull] GameActionData gameActionData, [NotNull] GameActionContext context, Guid playerId) { var player = await ValidatePlayer(playerId); await ValidateBrand(player.BrandId); var gameProviderId = await ValidateGameProvider(context.GameProviderCode); ValidateTransactionIsUnique(gameActionData.ExternalTransactionId, gameProviderId); using (var scope = CustomTransactionScope.GetTransactionScopeAsync()) { var game = GetGameByExternalGameId(gameActionData.ExternalGameId); var round = _repository.GetOrCreateRound(gameActionData.RoundId, game.Id, player.Id, player.BrandId); await _walletOperations.PlaceBetAsync(playerId, game.Id, round.Data.Id, gameActionData.Amount, gameActionData.ExternalTransactionId); var placeBetGameActionId = round.Place(gameActionData, context); _repository.Rounds.AddOrUpdate(x => x.ExternalRoundId, round.Data); _repository.SaveChanges(); round.Events.ForEach(ev => _eventBus.Publish(ev)); scope.Complete(); return(placeBetGameActionId); } }
/// <summary> /// Registers a Win bet action /// </summary> /// <param name="gameActionData"></param> /// <param name="context"></param> /// <returns></returns> async Task <Guid> IGameCommands.WinBetAsync([NotNull] GameActionData gameActionData, [NotNull] GameActionContext context) { var gameProviderId = await ValidateGameProvider(context.GameProviderCode); ValidateTransactionIsUnique(gameActionData.ExternalTransactionId, gameProviderId); using (var scope = CustomTransactionScope.GetTransactionScopeAsync()) { var round = GetRound(gameActionData); await _walletOperations.WinBetAsync(round.Data.PlayerId, round.Data.GameId, round.Data.Id, gameActionData.Amount, gameActionData.ExternalTransactionId); var winGameActionId = round.Win(gameActionData, context); await _repository.SaveChangesAsync(); round.Events.ForEach(ev => _eventBus.Publish(ev)); scope.Complete(); return(winGameActionId); } }
async Task <Guid> IGameCommands.WinBetAsync([NotNull] GameActionData actionData, [NotNull] GameActionContext context) { var gameProviderId = await ValidateGameProviderAsync(context.GameProviderCode); ValidateTransactionIsUnique(actionData.ExternalTransactionId, gameProviderId); using (var scope = CustomTransactionScope.GetTransactionScopeAsync()) { var round = GetRound(actionData); var walletTransactionId = await _walletOperations.WinBetAsync(round.Data.PlayerId, round.Data.GameId, round.Data.Id, actionData.Amount); var winGameActionId = round.Win( actionData.Amount, actionData.Description, walletTransactionId, actionData.ExternalTransactionId, actionData.ExternalBetId, actionData.TransactionReferenceId, actionData.BatchId); await _repository.SaveChangesAsync(); await _gameEventsProcessor.Process(round.Events, context.PlayerToken, round.Data.BrandCode, actionData, context.GameProviderCode); scope.Complete(); return(winGameActionId); } }
public async Task <IHttpActionResult> GetStatus(Guid playerId) { VerifyPermission(Permissions.View, Modules.PlayerManager); // do not lock using (var scope = CustomTransactionScope.GetTransactionScopeAsync(IsolationLevel.ReadUncommitted)) { var player = await _playerQueries.GetPlayerAsync(playerId); scope.Complete(); return(Ok(player.IsOnline)); } }
/// <summary> /// Cancels a game action /// </summary> /// <param name="gameActionData"></param> /// <param name="context"></param> /// <returns></returns> async Task <Guid> IGameCommands.CancelTransactionAsync([NotNull] GameActionData gameActionData, [NotNull] GameActionContext context) { var gameProviderId = await ValidateGameProvider(context.GameProviderCode); ValidateTransactionIsUnique(gameActionData.ExternalTransactionId, gameProviderId); using (var scope = CustomTransactionScope.GetTransactionScopeAsync()) { var round = GetRound(gameActionData); var gameActionToCancel = round.GetGameActionByReferenceId(gameActionData.TransactionReferenceId); if (gameActionToCancel == null) { throw new GameActionNotFoundException(); } var amount = -gameActionToCancel.Amount; if (gameActionToCancel.Amount != amount) { // TODO: raise an administrative event (amounts don't match when cancelling a transaction) } await _walletOperations.CancelBetAsync(round.Data.PlayerId, round.Data.GameId, round.Data.Id, gameActionData.ExternalTransactionId, gameActionData.TransactionReferenceId); var cancelGameActionId = CancelRound(round, gameActionData, context); _repository.SaveChanges(); round.Events.ForEach(ev => _eventBus.Publish(ev)); scope.Complete(); return(cancelGameActionId); } }
/// <summary> /// Places a bet /// </summary> async Task <Guid> IGameCommands.PlaceBetAsync([NotNull] GameActionData actionData, [NotNull] GameActionContext context, Guid playerId) { var player = await _repository.Players.SingleAsync(x => x.Id == playerId); await ValidateBrand(player.BrandId); var gameProviderId = await ValidateGameProviderAsync(context.GameProviderCode); ValidateTransactionIsUnique(actionData.ExternalTransactionId, gameProviderId); using (var scope = CustomTransactionScope.GetTransactionScopeAsync()) { var game = GetGameByExternalGameId(actionData.ExternalGameId); var round = _repository.GetOrCreateRound(actionData.RoundId, game.Id, player.Id, player.BrandId); var walletTransactionId = await _walletOperations.PlaceBetAsync(player.Id, round.Data.GameId, round.Data.Id, actionData.Amount); var placeBetGameActionId = round.Place( actionData.Amount, actionData.Description, walletTransactionId, actionData.ExternalTransactionId, actionData.ExternalBetId, actionData.TransactionReferenceId); _repository.Rounds.AddOrUpdate(x => x.ExternalRoundId, round.Data); _repository.SaveChanges(); await _gameEventsProcessor.Process(round.Events, context.PlayerToken, round.Data.BrandCode, actionData, context.GameProviderCode); scope.Complete(); return(placeBetGameActionId); } }
public async Task <SubmitOnlineDepositRequestResult> SubmitOnlineDepositRequest(OnlineDepositRequest request) { var validationResult = new OnlineDepositRequestValidator(_repository).Validate(request); if (!validationResult.IsValid) { throw new RegoValidationException(validationResult); } var player = _repository.Players.FirstOrDefault(x => x.Id == request.PlayerId); var paymentGetewaySettings = _paymentGatewaySettingsQueries.GetOnePaymentGatewaySettingsByPlayerId(player.Id); if (paymentGetewaySettings == null) { throw new RegoException("PaymentGatewaySettings not found"); } var method = paymentGetewaySettings.OnlinePaymentMethodName; var channel = paymentGetewaySettings.Channel; var paymentUrl = paymentGetewaySettings.EntryPoint; _validator.ValidatePaymentSetting(request.PlayerId, method, request.Amount, player.CurrencyCode); var number = GenerateOrderId(method, channel); var merchantId = GetDepositMerchantId(); var hashKey = GetDepositHashKey(); var depositParams = new OnlineDepositParams(); depositParams.Method = method; depositParams.Channel = channel; depositParams.Amount = request.Amount; depositParams.MerchantId = merchantId; depositParams.OrderId = number; depositParams.Currency = player.CurrencyCode; depositParams.Language = request.CultureCode; depositParams.ReturnUrl = request.ReturnUrl; depositParams.NotifyUrl = request.NotifyUrl; depositParams.Signature = EncryptHelper.GetMD5HashInHexadecimalFormat(depositParams.SignParams + hashKey); var id = Guid.NewGuid(); var brandId = player.BrandId; var now = _paymentQueries.GetBrandDateTimeOffset(brandId); var onlineDepositEntity = new Entities.OnlineDeposit(id, number, request, depositParams, brandId, now); var submitEvent = onlineDepositEntity.Submit(); using (var scope = CustomTransactionScope.GetTransactionScopeAsync()) { if (!string.IsNullOrWhiteSpace(request.BonusCode) || (request.BonusId.HasValue && request.BonusId != Guid.Empty)) { var bonusRedemptionId = await _bonusApiProxy.ApplyForBonusAsync(new DepositBonusApplication { PlayerId = request.PlayerId, BonusId = request.BonusId, Amount = request.Amount, DepositId = onlineDepositEntity.Data.Id, BonusCode = onlineDepositEntity.Data.BonusCode }); onlineDepositEntity.SetBonusRedemption(bonusRedemptionId); } _repository.OnlineDeposits.Add(onlineDepositEntity.Data); _eventBus.Publish(submitEvent); _repository.SaveChanges(); scope.Complete(); } return(new SubmitOnlineDepositRequestResult { DepositId = id, RedirectUrl = new Uri(paymentUrl), RedirectParams = depositParams }); }
//[Permission(Permissions.Create, Module = Modules.OfflineDepositRequests)] public async Task <OfflineDeposit> Submit(OfflineDepositRequest request) { var validationResult = _offlineDepositQueries.GetValidationResult(request); if (validationResult.IsValid == false) { throw new RegoException(string.Join("/n", validationResult.Errors.Select(failure => failure.ErrorMessage))); } var player = _repository.Players .Include(x => x.Brand) .Single(p => p.Id == request.PlayerId); var bankAccount = _repository.BankAccounts .Include(x => x.Bank) .Single(x => x.Id == request.BankAccountId); _validator.Validate(request.PlayerId, bankAccount.CurrencyCode, request.Amount); _identityValidator.Validate(request.PlayerId, TransactionType.Deposit); var deposit = new Entities.OfflineDeposit(request, bankAccount, player, _actorInfoProvider.Actor.UserName); using (var scope = CustomTransactionScope.GetTransactionScopeAsync()) { var depositEvent = deposit.Submit(); _repository.OfflineDeposits.Add(deposit.Data); if (request.BonusId.HasValue || string.IsNullOrWhiteSpace(request.BonusCode) == false) { var bonusRedemptionId = await _bonusApiProxy.ApplyForBonusAsync(new DepositBonusApplication { PlayerId = player.Id, BonusId = request.BonusId, BonusCode = request.BonusCode, Amount = request.Amount, DepositId = deposit.Data.Id }); deposit.SetBonusRedemption(bonusRedemptionId); } _repository.SaveChanges(); _eventBus.Publish(depositEvent); scope.Complete(); } var messageModel = new OfflineDepositRequestedModel { BankName = bankAccount.Bank.BankName, BankAccountName = bankAccount.AccountName, BankAccountNumber = bankAccount.AccountNumber }; _messageTemplateService.TrySendPlayerMessage( player.Id, MessageType.OfflineDepositRequested, MessageDeliveryMethod.Email, messageModel); _messageTemplateService.TrySendPlayerMessage( player.Id, MessageType.OfflineDepositRequested, MessageDeliveryMethod.Sms, messageModel); var data = Mapper.Map <OfflineDeposit>(deposit.Data); return(data); }
TransactionScope ITransactionScopeProvider.GetTransactionScopeAsync() { return(CustomTransactionScope.GetTransactionScopeAsync()); }