Ejemplo n.º 1
0
        public async Task <TransferOperationResponse> TransferAsync(TransferOperationRequest requestModel)
        {
            var result = await _walletOperationsService.TransferBalanceAsync(
                _requestContext.UserId,
                requestModel.ReceiverEmail,
                requestModel.Amount);

            switch (result.ErrorCode)
            {
            case TransferErrorCodes.None:
                return(_mapper.Map <TransferOperationResponse>(result));

            case TransferErrorCodes.RecipientWalletMissing:
            case TransferErrorCodes.InvalidRecipientId:
                throw LykkeApiErrorException.BadRequest(ApiErrorCodes.Service.InvalidReceiver);

            case TransferErrorCodes.NotEnoughFunds:
                throw LykkeApiErrorException.BadRequest(ApiErrorCodes.Service.SenderCustomerNotEnoughBalance);

            case TransferErrorCodes.InvalidAmount:
                throw LykkeApiErrorException.BadRequest(ApiErrorCodes.Service.InvalidAmount);

            case TransferErrorCodes.SourceCustomerNotFound:
                throw LykkeApiErrorException.BadRequest(ApiErrorCodes.Service.SenderCustomerNotFound);

            case TransferErrorCodes.TargetCustomerNotFound:
                throw LykkeApiErrorException.BadRequest(ApiErrorCodes.Service.TargetCustomerNotFound);

            case TransferErrorCodes.TransferSourceAndTargetMustBeDifferent:
                throw LykkeApiErrorException.BadRequest(ApiErrorCodes.Service.TransferSourceAndTargetMustBeDifferent);

            case TransferErrorCodes.SourceCustomerWalletBlocked:
                throw LykkeApiErrorException.BadRequest(ApiErrorCodes.Service.TransferSourceCustomerWalletBlocked);

            case TransferErrorCodes.TargetCustomerWalletBlocked:
                throw LykkeApiErrorException.BadRequest(ApiErrorCodes.Service.TransferTargetCustomerWalletBlocked);

            default:
                throw new InvalidOperationException($"Unexpected error during Transfer for {_requestContext.UserId} - {result.ErrorCode}");
            }
        }