Example #1
0
        public async Task <WithdrawResponse> WithdrawAsync(WithdrawData withdrawData)
        {
            HttpResponseMessage response = null;

            try
            {
                logger.Debug("WithdrawAsync:" + withdrawData.Description);
                string        json        = JsonConvert.SerializeObject(withdrawData, jsonSettings);
                StringContent httpContent = new StringContent(json, Encoding.UTF8, "application/json");
                response = await client.PostAsync(this.zebedeeUrl + "withdrawal-requests", httpContent);

                response.EnsureSuccessStatusCode();
                string responseBody = await response.Content.ReadAsStringAsync();

                //Deserialize
                WithdrawResponse deserializedCharge = JsonConvert.DeserializeObject <WithdrawResponse>(responseBody, jsonSettings);
                return(deserializedCharge);
            }
            catch (Exception e)
            {
                logger.Error(string.Format("WithdrawAsync with Exception : {0}", e));
                logger.Error(response.ToString());
                throw e;
            }
        }
Example #2
0
        public async Task WithdrawAsync(WithdrawData withdrawData, Action <WithdrawResponse> withdrawAction)
        {
            //Deserialize
            WithdrawResponse deserializedCharge = await WithdrawAsync(withdrawData);

            withdrawAction(deserializedCharge);
        }
 /// <summary>
 /// <see cref="IServiceInputValidator"/>
 /// </summary>
 public void Validate(WithdrawData paymentData)
 {
     CheckNotNull(paymentData, "paymentData");
     ValidateAccountNumber(paymentData.AccountNumber);
     ValidateAccessToken(paymentData.AccessToken);
     CheckNotNull(paymentData.OperationTitle, "operation title");
     ValidateAmount(paymentData.Amount);
 }
        public void Withdraw_AmountGreaterThanBalance_ThrowsFaultException_InsufficientFunds()
        {
            var paymentData = new WithdrawData()
            {
                AccountNumber  = _data.ValidSenderAccountNumber,
                AccessToken    = _data.ValidAccessToken,
                Amount         = "20000000000000000",
                OperationTitle = "WOW withdraw"
            };

            _service.Withdraw(paymentData);
        }
        public void Withdraw_ValidData_ReturnsSuccess()
        {
            var paymentData = new WithdrawData()
            {
                AccountNumber  = _data.ValidSenderAccountNumber,
                AccessToken    = _data.ValidAccessToken,
                Amount         = "2",
                OperationTitle = "WOW withdraw"
            };
            var response = _service.Withdraw(paymentData);

            Assert.AreEqual(ResponseStatus.Success, response.ResponseStatus);
        }
Example #6
0
 /// <summary>
 /// Tries to perform withdraw operation, if fails throws Fault Exception
 /// </summary>
 /// <param name="paymentData">data needed to perform withdraw</param>
 /// <returns>response status</returns>
 public PaymentResponse Withdraw(WithdrawData paymentData)
 {
     try
     {
         var account = GetAccount(paymentData.AccessToken, paymentData.AccountNumber);
         _executor.ExecuteAndSave(new Withdraw(account, DecimalParser.Parse(paymentData.Amount), paymentData.OperationTitle), account);
         return(new PaymentResponse(ResponseStatus.Success));
     }
     catch (BankException exception)
     {
         throw new FaultException(exception.ResponseStatus.Message());
     }
 }
Example #7
0
        //Withdraw without Callback
        public async Task <WithdrawResponse> WithDrawAsync(Withdraw withdraw)
        {
            //Satoshi to milli satoshi
            WithdrawData withdrawRequest = new WithdrawData();

            withdrawRequest.Amount      = withdraw.AmountInSatoshi * 1000;
            withdrawRequest.Name        = withdraw.Name;
            withdrawRequest.Description = withdraw.Description;

            WithdrawResponse withdrawResponse = await zbdService.WithdrawAsync(withdrawRequest);

            return(withdrawResponse);
        }
Example #8
0
        //Withdraw with Callback
        public async Task WithDrawAsync(Withdraw withdraw, Action <WithdrawResponse> action)
        {
            //Satoshi to milli satoshi
            WithdrawData withdrawRequest = new WithdrawData();

            withdrawRequest.Amount      = withdraw.AmountInSatoshi * 1000;
            withdrawRequest.Name        = withdraw.Name;
            withdrawRequest.Description = withdraw.Description;


            await zbdService.WithdrawAsync(withdrawRequest, paymentResponse => {
                action(paymentResponse);
            });
        }
        public OperationResult <WithdrawData> MasterWithdraw(long id, decimal amount)
        {
            Logger.Trace("Withraw request. masterId - {0}, amount - {1}", id, amount);
            amount = Math.Abs(amount);
            return(InvokeOperations.InvokeOperation(() =>
            {
                var master = repository.GetMaster(id);
                var amountInInvestRequests = repository.GetInvestSumByMaster(id);
                repository.WithdrawRequest(id, -amount, true);

                var withdrawData = new WithdrawData
                {
                    WalletId = master.wallet_id,
                    AmountAvailable = amountInInvestRequests <= 0
                                                ? 0.0m
                                                : amount < amountInInvestRequests ? amount : amountInInvestRequests
                };

                return withdrawData;
            }));
        }
Example #10
0
        public WithdrawData InvestorWithdraw(long id, decimal amount)
        {
            Logger.Trace("Withraw request. investorId - {0}, amount - {1}", id, amount);
            amount = Math.Abs(amount);
            return(InvokeOperations.InvokeOperation(() =>
            {
                var investor = repository.GetInvestorById(id);
                var amountInInvestRequests = repository.GetInvestSumByInvestor(id);
                repository.WithdrawRequest(id, -amount, false);

                var withdrawData = new WithdrawData
                {
                    WalletId = investor.wallet_id,
                    AmountAvailable = amountInInvestRequests <= 0
                                                ? 0.0m
                                                : amount < amountInInvestRequests ? amount : amountInInvestRequests
                };

                return withdrawData;
            }));
        }
 /// <summary>
 /// <see cref="IBankingService"/>
 /// </summary>
 public PaymentResponse Withdraw(WithdrawData paymentData)
 {
     _inputValidator.Validate(paymentData);
     return(_bank.Withdraw(paymentData));
 }