コード例 #1
0
        public KycStatusResponse GetClientKycStatus(KycStatusRequest request)
        {
            var existingEntity = _readerKycStatuses.Get(
                KycProfileNoSqlEntity.GeneratePartitionKey(),
                KycProfileNoSqlEntity.GenerateRowKey(request.ClientId));

            if (existingEntity != null)
            {
                return(new KycStatusResponse
                {
                    ClientId = existingEntity.Profile.ClientId,
                    Level = existingEntity.Profile.KycLevel,
                    RequiredDocuments = KycLevelHelper.GetRequiredDocuments(existingEntity.Profile),
                    RequiredVerifications = existingEntity.Profile.RequiredVerifications,
                    DepositStatus = existingEntity.Profile.DepositStatus,
                    TradeStatus = existingEntity.Profile.TradeStatus,
                    WithdrawalStatus = existingEntity.Profile.WithdrawalStatus,
                    VerificationInProgress = !string.IsNullOrEmpty(existingEntity.Profile.ActiveVerificationId)
                });
            }

            var entity = _kycStatusService.GetKycStatusAsync(new KycStatusRequest()
            {
                ClientId = request.ClientId
            }).Result;

            return(entity);
        }
コード例 #2
0
        private async Task <ClientModel> GetClientModel()
        {
            var personalDataTask = _personalDataService.GetAsync(_requestContext.ClientId);
            var cashoutBlockTask = _clientAccountClient.ClientSettings.GetCashOutBlockSettingsAsync(_requestContext.ClientId);
            var backupDoneTask   = _clientAccountClient.ClientSettings.GetBackupSettingsAsync(_requestContext.ClientId);
            var kycStatusTask    = _kycStatusService.GetKycStatusAsync(_requestContext.ClientId);

            await Task.WhenAll(personalDataTask, cashoutBlockTask, backupDoneTask, kycStatusTask);

            var personalData = personalDataTask.Result;

            return(new ClientModel
            {
                Id = new Guid(_requestContext.ClientId),
                TradesBlocked = cashoutBlockTask.Result.TradesBlocked,
                BackupDone = backupDoneTask.Result.BackupDone,
                KycStatus = kycStatusTask.Result.ToString(),
                PersonalData = new PersonalDataModel
                {
                    Country = personalData.Country,
                    CountryFromID = personalData.CountryFromID,
                    CountryFromPOA = personalData.CountryFromPOA
                }
            });
        }
コード例 #3
0
        public async Task <D3KycStatus> GetKycStatusAsync(string irohaUsername)
        {
            ID3User user = await GetUserAsync(irohaUsername);

            KycStatus kycStatus = await _kycStatusService.GetKycStatusAsync(user.ClientId);

            return(kycStatus.GetKycStatus());
        }
コード例 #4
0
        private async Task <ClientModel> GetClientModel()
        {
            var personalData = await _personalDataService.GetAsync(_requestContext.ClientId);

            return(new ClientModel
            {
                Id = new Guid(_requestContext.ClientId),
                TradesBlocked = (await _clientAccountClient.GetCashOutBlockAsync(personalData.Id)).TradesBlocked,
                BackupDone = (await _clientAccountClient.GetBackupAsync(personalData.Id)).BackupDone,
                KycStatus = (await _kycStatusService.GetKycStatusAsync(personalData.Id)).ToString(),
                PersonalData = new PersonalDataModel
                {
                    Country = personalData.Country,
                    CountryFromID = personalData.CountryFromID,
                    CountryFromPOA = personalData.CountryFromPOA
                }
            });
        }
コード例 #5
0
        public async Task <bool> IsKycNeeded(string clientId, string assetId)
        {
            if (string.IsNullOrEmpty(assetId))
            {
                throw new ArgumentException(nameof(assetId));
            }

            var asset = await _assets.GetItemAsync(assetId);

            if (asset == null)
            {
                throw new ArgumentException(nameof(assetId));
            }

            var userKycStatus = await _kycStatusService.GetKycStatusAsync(clientId);

            return(asset.KycNeeded && !userKycStatus.IsKycOkOrReviewDone());
        }
コード例 #6
0
        public async Task <IActionResult> UserInfo()
        {
            IPersonalData personalData;

            try
            {
                personalData = await _personalDataService.GetAsync(_requestContext.ClientId);
            }
            catch (Exception e)
            {
                await _log.WriteErrorAsync(nameof(ClientController), nameof(UserInfo),
                                           $"clientId = {_requestContext.ClientId}", e);

                return(StatusCode((int)HttpStatusCode.InternalServerError));
            }

            return(Ok(new UserInfoResponseModel
            {
                Email = personalData?.Email,
                FirstName = personalData?.FirstName,
                LastName = personalData?.LastName,
                KycStatus = (await _kycStatusService.GetKycStatusAsync(_requestContext.ClientId)).ToApiModel()
            }));
        }
コード例 #7
0
        public async Task <IActionResult> Cashout([FromBody] CreateCashoutRequest cmd, [FromQuery] Guid?id)
        {
            if (string.IsNullOrWhiteSpace(cmd.DestinationAddress) || string.IsNullOrWhiteSpace(cmd.AssetId) || cmd.Volume == 0m)
            {
                throw LykkeApiErrorException.BadRequest(LykkeApiErrorCodes.Service.InvalidInput);
            }

            var asset = await _assetsServiceWithCache.TryGetAssetAsync(cmd.AssetId);

            if (asset == null)
            {
                return(NotFound($"Asset '{cmd.AssetId}' not found."));
            }

            var balance = await _balancesClient.GetClientBalanceByAssetId(new ClientBalanceByAssetIdModel(cmd.AssetId, _requestContext.ClientId));

            var cashoutSettings = await _clientAccountClient.ClientSettings.GetCashOutBlockSettingsAsync(_requestContext.ClientId);

            var kycStatus = await _kycStatusService.GetKycStatusAsync(_requestContext.ClientId);

            if (_baseSettings.EnableTwoFactor)
            {
                try
                {
                    if ((await _confirmationCodesClient.Google2FaIsClientBlacklistedAsync(_requestContext.ClientId)).IsClientBlacklisted)
                    {
                        throw LykkeApiErrorException.Forbidden(LykkeApiErrorCodes.Service.SecondFactorCheckForbiden);
                    }
                }
                catch (ApiException e)
                {
                    if (e.StatusCode == HttpStatusCode.BadRequest)
                    {
                        throw LykkeApiErrorException.Forbidden(LykkeApiErrorCodes.Service.TwoFactorRequired);
                    }
                }
            }

            var operationId = id ?? Guid.NewGuid();

            var cashoutCommand = new CreateCashoutCommand
            {
                OperationId                 = operationId,
                DestinationAddress          = cmd.DestinationAddress,
                DestinationAddressExtension = cmd.DestinationAddressExtension,
                Volume = cmd.Volume,
                Asset  = new AssetCashoutModel
                {
                    Id              = asset.Id,
                    DisplayId       = asset.DisplayId,
                    MultiplierPower = asset.MultiplierPower,
                    AssetAddress    = asset.AssetAddress,
                    Accuracy        = asset.Accuracy,
                    BlockchainIntegrationLayerId = asset.BlockchainIntegrationLayerId,
                    Blockchain           = asset.Blockchain.ToString(),
                    Type                 = asset.Type?.ToString(),
                    IsTradable           = asset.IsTradable,
                    IsTrusted            = asset.IsTrusted,
                    KycNeeded            = asset.KycNeeded,
                    BlockchainWithdrawal = asset.BlockchainWithdrawal,
                    CashoutMinimalAmount = (decimal)asset.CashoutMinimalAmount,
                    LowVolumeAmount      = (decimal?)asset.LowVolumeAmount ?? 0,
                    LykkeEntityId        = asset.LykkeEntityId
                },
                Client = new ClientCashoutModel
                {
                    Id               = new Guid(_requestContext.ClientId),
                    Balance          = balance?.Balance ?? 0,
                    CashOutBlocked   = cashoutSettings.CashOutBlocked,
                    KycStatus        = kycStatus.ToString(),
                    ConfirmationType = "google"
                },
                GlobalSettings = new GlobalSettingsCashoutModel
                {
                    MaxConfirmationAttempts = _baseSettings.MaxTwoFactorConfirmationAttempts,
                    TwoFactorEnabled        = _baseSettings.EnableTwoFactor,
                    CashOutBlocked          = false, // TODO
                    FeeSettings             = new FeeSettingsCashoutModel
                    {
                        TargetClients = new Dictionary <string, string>
                        {
                            { "Cashout", _feeSettings.TargetClientId.Cashout }
                        }
                    }
                }
            };

            _cqrsEngine.SendCommand(cashoutCommand, "apiv2", OperationsBoundedContext.Name);

            return(Created(Url.Action("Get", new { operationId }), operationId));
        }
コード例 #8
0
        public async Task <bool> ValidatePersonalDataUpdateAsync()
        {
            var kycStatus = await _kycStatusService.GetKycStatusAsync(_requestContext.ClientId);

            return(AcceptedKycStatusesForPersonalDataUpdate.Contains(kycStatus));
        }
コード例 #9
0
        public async Task <Guid> CreateWithdrawalAsync(
            string requestId,
            string clientId,
            string walletId,
            string assetId,
            decimal volume,
            string destinationAddress,
            string destinationAddressExtension)
        {
            var uniqueRequestId = $"{walletId}_{requestId}";

            var validationResult =
                await _validationService.ValidateWithdrawalRequestAsync(assetId, volume);

            if (validationResult != null)
            {
                throw HftApiException.Create(validationResult.Code, validationResult.Message).AddField(validationResult.FieldName);
            }

            var operationId = Guid.NewGuid();

            var payload = await _idempotencyService.CreateEntityOrGetPayload(uniqueRequestId, operationId.ToString());

            if (payload != null)
            {
                operationId = Guid.Parse(payload);
            }

            var asset = await _assetsService.GetAssetByIdAsync(assetId);

            if (asset.BlockchainIntegrationType != BlockchainIntegrationType.Sirius)
            {
                throw HftApiException.Create(HftApiErrorCode.ActionForbidden, "Asset unavailable");
            }

            var balances = await _balanceService.GetBalancesAsync(walletId);

            var cashoutSettings = await _clientAccountClient.ClientSettings.GetCashOutBlockSettingsAsync(clientId);

            var kycStatus = await _kycStatusService.GetKycStatusAsync(clientId);

            var cashoutCommand = new CreateCashoutCommand
            {
                OperationId                 = operationId,
                WalletId                    = walletId,
                DestinationAddress          = destinationAddress,
                DestinationAddressExtension = destinationAddressExtension,
                Volume = volume,
                Asset  = new AssetCashoutModel
                {
                    Id              = asset.AssetId,
                    DisplayId       = asset.Symbol,
                    MultiplierPower = asset.MultiplierPower,
                    AssetAddress    = asset.AssetAddress,
                    Accuracy        = asset.Accuracy,
                    BlockchainIntegrationLayerId = asset.BlockchainIntegrationLayerId,
                    Blockchain                = asset.Blockchain.ToString(),
                    Type                      = asset.Type?.ToString(),
                    IsTradable                = asset.IsTradable,
                    IsTrusted                 = asset.IsTrusted,
                    KycNeeded                 = asset.KycNeeded,
                    BlockchainWithdrawal      = asset.BlockchainWithdrawal,
                    CashoutMinimalAmount      = (decimal)asset.CashoutMinimalAmount,
                    LowVolumeAmount           = (decimal?)asset.LowVolumeAmount ?? 0,
                    LykkeEntityId             = asset.LykkeEntityId,
                    SiriusAssetId             = asset.SiriusAssetId,
                    BlockchainIntegrationType = Lykke.Service.Assets.Client.Models.BlockchainIntegrationType.Sirius
                },
                Client = new ClientCashoutModel
                {
                    Id             = new Guid(clientId),
                    Balance        = balances.SingleOrDefault(x => x.AssetId == assetId)?.Available ?? 0,
                    CashOutBlocked = cashoutSettings.CashOutBlocked,
                    KycStatus      = kycStatus.ToString()
                },
                GlobalSettings = new GlobalSettingsCashoutModel
                {
                    MaxConfirmationAttempts = -1,
                    TwoFactorEnabled        = false,
                    CashOutBlocked          = false, // TODO
                    FeeSettings             = new FeeSettingsCashoutModel
                    {
                        TargetClients = new Dictionary <string, string>
                        {
                            { "Cashout", _feeSettings.WithdrawalFeeDestinationClientId }
                        }
                    }
                }
            };

            _cqrsEngine.SendCommand(cashoutCommand, "hft-api", OperationsBoundedContext.Name);

            return(operationId);
        }