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; } }
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); }
/// <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()); } }
//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); }
//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; })); }
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)); }