/// <summary> /// Post /transferFunds API call /// </summary> /// <param name="transferFundsRequest"></param> /// <returns>TransferFundsResponse</returns> /// public TransferFundsResponse TransferFunds(TransferFundsRequest transferFundsRequest) { string jsonRequest = Util.JsonOperation.SerializeRequest(transferFundsRequest); string jsonResponse = _transferFunds.Request(jsonRequest); return(JsonConvert.DeserializeObject <TransferFundsResponse>(jsonResponse)); }
public TransferFundsResult TransferFunds(TransferFundsRequest model) { var receivingAccountId = _dbContext.Accounts .Where(a => a.Member.User.Email == model.ReceiverEmail) .Select(a => a.Id) .SingleOrDefault(); if (receivingAccountId == 0) { return(TransferFundsResult.ReceiverEmailNotFound); } var senderAccountId = _dbContext.Accounts .Where(a => a.Member.User.Id == model.SenderUserId) .Select(a => a.Id) .Single(); var transaction = new Transaction { Amount = model.Amount, Description = model.Description, ReceivingAccountId = receivingAccountId, SendingAccountId = senderAccountId, }; _dbContext.Transactions.Add(transaction); _dbContext.SaveChanges(); return(TransferFundsResult.Successful); }
public async Task Handle_InvokesMockBankWithExpectedValues() { //arrange var createPaymentRequest = _fixture.Create <CreatePaymentRequest>(); var expected = new TransferFundsRequest { Currency = createPaymentRequest.Currency, Amount = createPaymentRequest.Amount, Source = new TransferFundsRequest.PaymentSource { Cvv = createPaymentRequest.Source.Cvv, CardExpiry = createPaymentRequest.Source.CardExpiry, CardNumber = createPaymentRequest.Source.CardNumber, }, Recipient = new TransferFundsRequest.PaymentRecipient { SortCode = createPaymentRequest.Recipient.SortCode, AccountNumber = createPaymentRequest.Recipient.AccountNumber } }; //act await _createPaymentHandler.Handle(createPaymentRequest); //assert _mockBankApiClient.Verify(x => x.TransferFunds(It.Is <TransferFundsRequest>(req => req.Should().BeEquivalentToBool(expected))), Times.Once); }
public async Task <TransferFundsResponse> TransferFunds(TransferFundsRequest request) { try { return(await TransferFundsResponseInternal(request)); } catch (Exception e) { return(TransferFundsResponse.ExceptionResponse(e)); } }
public void TestTransferFundsSuccess() { var amount = new Amount("EUR", 1000); var client = CreateMockTestClientNullRequiredFieldsRequest("Mocks/marketpay/fund/transfer-funds-success.json"); var fund = new Fund(client); var transferFundsRequest = new TransferFundsRequest(amount: amount, destinationAccountCode: "190324759", merchantReference: "merchantReference", sourceAccountCode: "00000", transferCode: "1235"); var transferFundsResponse = fund.TransferFunds(transferFundsRequest); Assert.AreEqual("9915090893984580", transferFundsResponse.PspReference); Assert.AreEqual("MerchantReference", transferFundsResponse.MerchantReference); Assert.AreEqual("Received", transferFundsResponse.ResultCode); }
public IActionResult TransferFunds(TransferFundsRequest model) { model.SenderUserId = _httpContextAccessor.HttpContext.User.GetUserId(); var result = _transactionService.TransferFunds(model); if (result == TransferFundsResult.ReceiverEmailNotFound) { return(NotFound($"No user with email {model.ReceiverEmail} exists.")); } return(Ok()); }
private async Task <TransferFundsResponse> TransferFundsResponseInternal(TransferFundsRequest request) { var response = await _httpClient.PostAsync( "api/payment", new StringContent(JsonConvert.SerializeObject(request), Encoding.UTF8, "application/json")); var responseBody = await response.Content.ReadAsStringAsync(); if (!response.IsSuccessStatusCode) { if (response.StatusCode == (HttpStatusCode)HttpStatusCodeUnprocessableEntity) { return(TransferFundsResponse.Error((int)response.StatusCode, JsonConvert.DeserializeObject <TransferFundsErrorResponse>(responseBody))); } else { return(TransferFundsResponse.UnknownError((int)response.StatusCode)); } } var deserialized = JsonConvert.DeserializeObject <TransferFundsSuccessfulResponse>(responseBody); return(TransferFundsResponse.Successful(deserialized)); }