Пример #1
0
        public async Task <WithdrawalResponse> GetWithdrawal(GetWithdrawalRequest request)
        {
            var withdrawal = await this.AuthenticatedSendAsync <GetWithdrawalRequest, WithdrawalResponse>(request, request.Request(this._apiKey.Host));

            if (withdrawal.Signature == withdrawal.CalculateSignature(this._signatureService))
            {
                return(withdrawal);
            }

            throw new Exception($"Signature error, response signature: {withdrawal.Signature}, calculated signature: {withdrawal.CalculateSignature(this._signatureService)}");
        }
        public async Task <GetWithdrawalResponse> GetWithdrawalById(GetWithdrawalRequest request)
        {
            request.AddToActivityAsJsonTag("request-data");
            _logger.LogInformation("Receive GetWithdrawal request: {JsonRequest}", JsonConvert.SerializeObject(request));

            try
            {
                await using var context = new DatabaseContext(_dbContextOptionsBuilder.Options);
                var withdrawal = await context.Withdrawals
                                 .Where(e => e.Id == request.Id)
                                 .FirstOrDefaultAsync();

                if (withdrawal == null)
                {
                    return(new GetWithdrawalResponse()
                    {
                        Success = false,
                        ErrorMessage = $"Withdrawal with Id {request.Id} was not found"
                    });
                }

                var response = new GetWithdrawalResponse
                {
                    Success    = true,
                    Withdrawal = new Withdrawal(withdrawal),
                };

                _logger.LogInformation("Return GetWithdrawal response for Id: {id}",
                                       withdrawal.TransactionId);
                return(response);
            }
            catch (Exception exception)
            {
                _logger.LogError(exception,
                                 "Cannot get GetWithdrawal Id: {Id}",
                                 request.Id);
                return(new GetWithdrawalResponse {
                    Success = false, ErrorMessage = exception.Message
                });
            }
        }