Пример #1
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));
        }
Пример #2
0
 public IResponse PostOperationCashOut(CreateCashoutRequest cashoutRequest, string id, string authorization)
 {
     return(Request.Post($"operations/cashout/{id}")
            .WithBearerToken(authorization)
            .AddJsonBody(cashoutRequest).Build().Execute());
 }