public static void CheckIfValidPayment(UpdatePaymentRequest payment) { try { if (payment == null) { throw new System.Exception("The payment object given was null."); } if (payment.Id <= 0) { throw new System.Exception("The payment id given was invalid."); } if (payment.Amount != null) { CheckAmountValid((decimal)payment.Amount); } if (payment.Created != null) { CheckDateValid((DateTime)payment.Created); } } catch (System.Exception ex) { throw new System.Exception("The payment object cannot be validated: " + ex.Message, ex); } }
public async Task <ActionResult <Payment> > Capture([FromBody] UpdatePaymentRequest request) { try { var payment = await _paymentService.GetPaymentById(request.PaymentId); if (payment == default) { return(NotFound()); } await _paymentService.CapturePayment(payment, request.TransactionDetails); return(Accepted(payment)); } catch (PaymentGatewayServiceException pgse) { _logger.LogError("Caught bad known error from repo"); return(UnprocessableEntity(pgse.Message)); } catch (InvalidTransactionCaptureException intce) { _logger.LogError($"Problem capturing payment - {intce.Message}"); return(BadRequest(intce.Message)); } }
public async Task UpdatesPaymentReplacingMetadata() { // given var payment = await _resourceFactory.CreatePaymentFor(_mandate); var request = new UpdatePaymentRequest { Id = payment.Id, Metadata = new Dictionary <string, string> { ["Key4"] = "Value4", ["Key5"] = "Value5", ["Key6"] = "Value6", }, }; var subject = new PaymentsClient(_clientConfiguration); // when var result = await subject.UpdateAsync(request); var actual = result.Item; // then Assert.That(actual, Is.Not.Null); Assert.That(actual.Id, Is.EqualTo(payment.Id)); Assert.That(actual.Metadata, Is.EqualTo(request.Metadata)); }
public async Task <bool> UpdatePayment(int id, UpdatePaymentRequest request) { try { var paymentModel = await _paymentRepository.GetPaymentById(id); var reservationModel = await _reservationRepository.GetReservatioById(paymentModel.ReservationId); if (reservationModel.ApprovalStatus) { return(false); } paymentModel.Image = request.Image; paymentModel.Amount = request.Amount; paymentModel.Date = request.Date; paymentModel.IsFullAmount = request.IsFullAmount; _repositoryWrapper.Payment.Updete(paymentModel); await _repositoryWrapper.SaveAsync(); return(true); } catch (Exception ex) { throw ex; } }
public void UpdatePayment([FromBody] UpdatePaymentRequest request) { if (request == null) { throw new ArgumentNullException(nameof(request)); } var paymentDate = new DateTime(request.Year, request.Month, 20); CommandProcessor.Execute( new UpdatePaymentCommand(request.Id, request.PaymentTypeId, request.Amount, paymentDate, request.Description) ); }
public async Task <bool> UpdatePayment(int id, UpdatePaymentRequest updatePaymentRequest) { try { var response = await JongSnamServices.UpdatePaymentWithHttpMessagesAsync(id, updatePaymentRequest, CustomHeaders); return(true); } catch (Exception ex) { return(false); throw ex; } }
public void UpdatePaymentRequestIsNullThrows() { // given var subject = new PaymentsClient(_clientConfiguration); UpdatePaymentRequest request = null; // when AsyncTestDelegate test = () => subject.UpdateAsync(request); // then var ex = Assert.ThrowsAsync <ArgumentNullException>(test); Assert.That(ex.ParamName, Is.EqualTo(nameof(request))); }
/// <summary> /// Maps Input parameters for Update Payments /// </summary> /// <param name="request"></param> /// <returns></returns> public UpdatePayment UpdateRequestMapper(UpdatePaymentRequest request) { UpdatePayment updatePayment = new UpdatePayment(); int formatMoney; if (request.Id.Contains("\"")) { request.Id = Regex.Replace(request.Id, "\"", ""); request.Amount = Regex.Replace(request.Amount, "\"", ""); } formatMoney = (int)(Convert.ToDecimal((request.Amount.Substring(1, request.Amount.Length - 1)).Replace(",", "").Trim()) * 100); updatePayment.Amount = formatMoney; updatePayment.Id = request.Id; return(updatePayment); }
public async Task CallsUpdatePaymentEndpoint() { // given var subject = new PaymentsClient(_clientConfiguration); var request = new UpdatePaymentRequest { Id = "PM12345678" }; // when await subject.UpdateAsync(request); // then _httpTest .ShouldHaveCalled("https://api.gocardless.com/payments") .WithVerb(HttpMethod.Put); }
public void UpdatePaymentRequestIdIsNullOrWhiteSpaceThrows(string id) { // given var subject = new PaymentsClient(_clientConfiguration); var request = new UpdatePaymentRequest { Id = id }; // when AsyncTestDelegate test = () => subject.UpdateAsync(request); // then var ex = Assert.ThrowsAsync <ArgumentException>(test); Assert.That(ex.ParamName, Is.EqualTo(nameof(request.Id))); }
public bool UpdatePayment(UpdatePaymentRequest paymentRequest) { NpgsqlConnection connection = new NpgsqlConnection(_connectionString); connection.Open(); try { var setValues = new List <string>(); if (paymentRequest.Amount != null) { setValues.Add($"\"Amount\"='{paymentRequest.Amount}'"); } if (paymentRequest.Created != null) { setValues.Add($"\"Created\"='{paymentRequest.Created:yyyy-MM-dd}'"); } var command = new NpgsqlCommand("UPDATE public.\"Payment\" " + $"SET {string.Join(", ", setValues)} " + $"WHERE \"Id\" = {paymentRequest.Id}", connection); var rowUpdated = false; var reader = command.ExecuteReader(); while (reader.Read()) { rowUpdated = true; } reader.Close(); return(rowUpdated); } catch (System.Exception exception) { throw new System.Exception($"An Error occured while updating the payment (ID: {paymentRequest.Id})", exception); } finally { connection.Close(); } }
public async Task UpdatesPaymentPreservingMetadata() { // given var payment = await _resourceFactory.CreatePaymentFor(_mandate); var request = new UpdatePaymentRequest { Id = payment.Id }; var subject = new PaymentsClient(_clientConfiguration); // when var result = await subject.UpdateAsync(request); var actual = result.Item; // then Assert.That(actual, Is.Not.Null); Assert.That(actual.Id, Is.EqualTo(payment.Id)); Assert.That(actual.Metadata, Is.EqualTo(payment.Metadata)); }
public async Task <IActionResult> AcceptPayment(Guid id, [FromBody] UpdatePaymentRequest request) { if (request.Status != PaymentStatus.Accepted) { return(BadRequest(new { error = $"Payment status can not be {request.Status}" })); } var payment = await _paymentRepository.Get(id); if (payment == null) { return(NotFound()); } payment.Status = request.Status; await _paymentRepository.Update(payment); Console.WriteLine($"[{DateTime.Now.Hour}:{DateTime.Now.Minute}:{DateTime.Now.Second}.{DateTime.Now.Millisecond}] Vartotojas patvirtino mokėjimą. Mokėjimo ID: {payment.Id}"); try { await _cardIssuerService.ReservePayment(payment); await _cardIssuerService.CapturePayment(payment); } catch (Exception) { payment.Status = PaymentStatus.Created; await _paymentRepository.Update(payment); Console.WriteLine($"[{DateTime.Now.Hour}:{DateTime.Now.Minute}:{DateTime.Now.Second}.{DateTime.Now.Millisecond}] Mokėjimo statusas grąžintas į pradinę padėtį. Mokėjimo ID: {payment.Id}"); return(StatusCode(500)); } return(Ok()); }
public IEnumerable <UpdatePaymentResponse> UpdatePayments([FromBody] UpdatePaymentRequest updatePaymentRequest) { try { var requestValues = mapPayment.UpdateRequestMapper(updatePaymentRequest); //decimal amount = requestValues.Amount; if (requestValues.Amount > 100000) { throw new ArgumentException($"You don't have enough funds to make this payment"); } var updatePayment = _repository.UpdatePayment(requestValues); var updatedPayments = mapPayment.UpdatePaymentResponseMapper(updatePayment); return(updatedPayments); } catch (Exception error) { throw error; } }
public async Task <ApiResponse> Update(int paymentRequestId, UpdatePaymentRequest updatePaymentRequest) { return(await Client.Post <UpdatePaymentRequest, ApiResponse>($"paymentrequest/{paymentRequestId}", updatePaymentRequest)); }
public async Task <ActionResult> UpdatePayment(int id, [FromBody] UpdatePaymentRequest request) { var result = await _paymentManager.UpdatePayment(id, request); return(Ok(result)); }