public async Task <IActionResult> GetLykkewalletToken()
        {
            var bearerToken = HttpContext.GetBearerTokenFromAuthorizationHeader();

            if (bearerToken == null)
            {
                return(Unauthorized());
            }

            var httpClient = _httpClientFactory.CreateClient();

            var introspectionResponse = await IntrospectToken(httpClient, bearerToken);

            if (!introspectionResponse.IsActive)
            {
                return(Unauthorized());
            }

            var userId = introspectionResponse.Claims.FirstOrDefault(x => x.Type == JwtClaimTypes.Subject)?.Value;

            var authResult = await _clientSessionsClient.Authenticate(userId, "hobbit");

            var clientAccount = await _clientAccountClient.GetByIdAsync(userId);

            return(new JsonResult(new
            {
                token = authResult.SessionToken,
                authResult.AuthId,
                notificationsId = clientAccount.NotificationsId
            }));
        }
        public async Task <CommandHandlingResult> Handle(SaveEthInHistoryCommand command, IEventPublisher eventPublisher)
        {
            var sw = new Stopwatch();

            sw.Start();

            try
            {
                var cashinId      = command.CashinOperationId.ToString("N");
                var clientId      = command.ClientId;
                var hash          = command.TransactionHash;
                var amount        = command.Amount;
                var clientAddress = command.ClientAddress;

                await _cashOperationsRepositoryClient.RegisterAsync(new CashInOutOperation
                {
                    Id             = cashinId,
                    ClientId       = clientId.ToString(),
                    AssetId        = command.AssetId,
                    Amount         = (double)amount,
                    BlockChainHash = hash,
                    DateTime       = DateTime.UtcNow,
                    AddressTo      = clientAddress,
                    State          = TransactionStates.SettledOnchain
                });

                ChaosKitty.Meow();

                var clientAcc = await _clientAccountClient.GetByIdAsync(clientId.ToString());

                var clientEmail = await _personalDataService.GetEmailAsync(clientId.ToString());

                await _srvEmailsFacade.SendNoRefundDepositDoneMail(clientAcc.PartnerId, clientEmail, amount,
                                                                   command.AssetId);

                await _paymentTransactionsRepository.SetStatus(hash, PaymentStatus.NotifyProcessed);

                ChaosKitty.Meow();

                eventPublisher.PublishEvent(new EthCashinSavedInHistoryEvent()
                {
                    TransactionHash = hash
                });

                return(CommandHandlingResult.Ok());
            }
            catch (Exception e)
            {
                _log.Error(nameof(SaveEthInHistoryCommand), e, context: command);
                throw;
            }
            finally
            {
                sw.Stop();
                _log.Info("Command execution time",
                          context: new { TxHandler = new { Handler = nameof(EthereumCoreCommandHandler), Command = nameof(SaveEthInHistoryCommand),
                                                           Time    = sw.ElapsedMilliseconds } });
            }
        }
Esempio n. 3
0
        public async Task <string> GetNotificationId(string clientId)
        {
            var clientAcc = await _clientAccountsClient.GetByIdAsync(clientId);

            if (clientAcc != null)
            {
                return(clientAcc.NotificationsId);
            }

            throw new Exception(string.Format("Can't get notification Id for clientId = {0}", clientId));
        }
Esempio n. 4
0
        public async Task UpdatePersonalInformation(string clientId, string firstName, string lastName)
        {
            string fullname = $"{firstName} {lastName}";

            var changes = new KycPersonalDataChanges
            {
                Changer = RecordChanger.Client,
                Items   = new Dictionary <string, JToken>
                {
                    { nameof(IPersonalData.FirstName), firstName },
                    { nameof(IPersonalData.LastName), lastName },
                    { nameof(IPersonalData.FullName), fullname }
                }
            };

            await _kycProfileService.UpdatePersonalDataAsync(clientId, changes);

            var clientAccount = await _clientAccountClient.GetByIdAsync(clientId);

            await _httpContextAccessor.HttpContext.SignOutAsync(OpenIdConnectConstantsExt.Auth.DefaultScheme);

            var identity = await _userManager.CreateUserIdentityAsync(clientAccount.Id, clientAccount.Email, clientAccount.Email, true);

            await _httpContextAccessor.HttpContext.SignInAsync(OpenIdConnectConstantsExt.Auth.DefaultScheme,
                                                               new ClaimsPrincipal(identity),
                                                               new AuthenticationProperties());
        }
        private async Task Handle(TransactionProcessedEvent evt, ICommandSender sender)
        {
            ChaosKitty.Meow();

            var clientAcc = await _clientAccountClient.GetByIdAsync(evt.ClientId);

            var sendEmailCommand = new SendNoRefundDepositDoneMailCommand
            {
                Email   = clientAcc.Email,
                Amount  = evt.Amount,
                AssetId = evt.Asset.Id
            };

            sender.SendCommand(sendEmailCommand, "email");

            ChaosKitty.Meow();

            var pushSettings = await _clientAccountClient.GetPushNotificationAsync(evt.ClientId);

            if (pushSettings.Enabled)
            {
                var sendNotificationCommand = new SendNotificationCommand
                {
                    NotificationId = clientAcc.NotificationsId,
                    Type           = NotificationType.TransactionConfirmed,
                    Message        = string.Format(TextResources.CashInSuccessText, new decimal(evt.Amount).TruncateDecimalPlaces(evt.Asset.Accuracy), evt.Asset.Id)
                };
                sender.SendCommand(sendNotificationCommand, "notifications");
            }
        }
        public async Task Process(HashEvent ev)
        {
            var tx = await _bitcoinTransactionRepository.FindByTransactionIdAsync(ev.Id);

            if (tx == null)
            {
                return;
            }

            string hash = ev.Hash;

            switch (tx.CommandType)
            {
            case BitCoinCommands.CashOut:
                var cashOutContext = await _transactionService.GetTransactionContext <CashOutContextData>(tx.TransactionId);

                var clientAcc = await _сlientAccountClient.GetByIdAsync(cashOutContext.ClientId);

                var clientEmail = await _personalDataService.GetEmailAsync(cashOutContext.ClientId);

                await _cashOperationsRepositoryClient.UpdateBlockchainHashAsync(cashOutContext.ClientId, cashOutContext.CashOperationId, hash);

                await _srvEmailsFacade.SendNoRefundOCashOutMail(clientAcc.PartnerId, clientEmail, cashOutContext.Amount, cashOutContext.AssetId, hash);

                break;
            }
        }
Esempio n. 7
0
        public async Task <string> Build(string template, string clientId, string assetId)
        {
            var client = await _clientAccountClient.GetByIdAsync(clientId);

            var asset = await _assetsService.TryGetAssetAsync(assetId);

            var assetTitle = asset.DisplayId ?? assetId;

            return(string.Format(template, assetTitle, client.ExternalId));
        }
Esempio n. 8
0
        private async Task <ClientModel> GetClientByIdAsync(string clientId)
        {
            ClientModel client = null;

            try
            {
                client = await _clientAccountClient.GetByIdAsync(clientId);
            }
            catch (Exception)
            {
                _log.WriteInfo(nameof(GetClientByIdAsync), clientId, "Can't get client info");
            }

            return(client);
        }