public async Task <IActionResult> Create([Bind("PaymentDetails,CardOwnerName,CardNumber,ExpirationDate,SecurityCode")] PaymentDetail paymentDetail) { if (ModelState.IsValid) { _context.Add(paymentDetail); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(paymentDetail)); }
public ResponseMessage InsertPayment(Payment payment) { var message = new ResponseMessage(); var value = _dbContext.Add(payment); var insertedCount = Save(); if (insertedCount > 0) { message.SetSuccessMessage("Thank you! Your Payment completed successfully!"); } else { message.SetErrorMessage("Error completing Payment"); } return(message); }
public async Task CreateRequestForCommandAsync <T>(string id) { var exists = await ExistAsync(id); var request = exists ? throw new InvalidOperationException($"Request with {id} already exists") : new ClientRequest { Id = id, Name = typeof(T).Name, Time = DateTime.UtcNow }; _context.Add <ClientRequest>(request); await _context.SaveChangesAsync(); }
public async Task <PaymentDTO> Handle(PostPaymentCommand request, CancellationToken cancellationToken) { var data = new Payment() { Payment_type = request.Data.Attributes.Payment_type, Gross_amount = request.Data.Attributes.Gross_amount, Bank = request.Data.Attributes.Bank, Order_id = request.Data.Attributes.Order_id }; _context.Add(data); await _context.SaveChangesAsync(); var payment = _context.payment.First(x => x.Transaction_status == request.Data.Attributes.Transaction_status); var target = new TargetCommand() { Id = payment.Id }; var command = new PostCommand() { Title = "hello", Message = "this is message body", Type = "email", From = 123456, Targets = new List <TargetCommand>() { target } }; var attributes = new Attribute <PostCommand>() { Attributes = command }; var httpContent = new CommandDTO <PostCommand>() { Data = attributes }; var jsonObject = JsonConvert.SerializeObject(httpContent); //var content = new StringContent(jsonObject, Encoding.UTF8, "application/json"); //await client.PostAsync("http://localhost:5010/notification", content); var factory = new ConnectionFactory() { HostName = "some-rabbit" }; using (var connection = factory.CreateConnection()) using (var notification = connection.CreateModel()) { notification.ExchangeDeclare("userExchange", "fanout"); notification.QueueDeclare( queue: "userQueue", durable: true, exclusive: false, autoDelete: false, arguments: null); notification.QueueBind( queue: "userQueue", exchange: "userExchange", routingKey: string.Empty ); var body = Encoding.UTF8.GetBytes(jsonObject); var properties = notification.CreateBasicProperties(); properties.Persistent = true; notification.BasicPublish( exchange: "", routingKey: "userQueue", basicProperties: null, body: body ); Console.WriteLine("User data has been forwarded"); } return(new PaymentDTO() { Message = "Successfully Added", Success = true }); }
public async Task <IActionResult> Index(PaymentRequest application) { application.OrderId = application.OrderId ?? DateTime.Now.ToString("yyyyMMdd") + Guid.NewGuid().ToString().Replace("-", "").Substring(0, 15); application.Amount = application.Amount.HasValue ? application.Amount.Value : 8000; application.Description = application.Description ?? "电子口岸业务卡工本费"; application.Currency = application.Currency ?? "CNY"; application.AppId = application.AppId ?? "testAppId"; application.CallbackUrl = application.CallbackUrl ?? context.AppClients.AsNoTracking().SingleOrDefault(x => x.AppId == x.AppId)?.DefaultCallbackUrl; Order order = null; if (ModelState["Id"]?.ValidationState == Microsoft.AspNetCore.Mvc.ModelBinding.ModelValidationState.Valid) { order = await context.Orders.SingleOrDefaultAsync(x => x.Id == application.Id); } else if (application.OrderId != null) { order = await context.Orders.SingleOrDefaultAsync(x => x.OrderId == application.OrderId); } if (order == null) { order = new Order() { OrderId = application.OrderId, Amount = application.Amount.Value, Description = application.Description, Currency = application.Currency, Note = application.Note, Status = OrderStatus.Preparing, ApplicantName = application.ApplicantName, CallbackUrl = application.CallbackUrl, AppId = application.AppId, NotifyUrl = application.NotifyUrl }; context.Add(order); await context.SaveChangesAsync(); } else if (order.Status == OrderStatus.Preparing) { application.OrderId = order.OrderId; application.Amount = order.Amount; application.Description = order.Description; application.Currency = order.Currency; application.ApplicantName = order.ApplicantName; } else if (order.Status == OrderStatus.NotPaid) { // 重新下单 if (order.Channel == "wxpay") { order.Status = OrderStatus.Preparing; await context.SaveChangesAsync(); application.OrderId = order.OrderId; application.Amount = order.Amount; application.Description = order.Description; application.Currency = order.Currency; application.ApplicantName = order.ApplicantName; } } else { return(RedirectToAction("Result", new { id = order.Id })); /* * var result = new QueryOrderResult() * { * Result = "FAIL", * Message = "OrderDuplicated", * NonceStr = this.signatureService.GenerateNonceStr() * }; * if (!String.IsNullOrEmpty(application.CallbackUrl) || !String.IsNullOrEmpty(application.AppId)) * { * * if (!String.IsNullOrEmpty(application.AppId)) * { * result.AppId = application.AppId; * result.Signature = this.signatureService.CalculateSignature(result.AsEnumerable(), application.AppId); * } * if (!String.IsNullOrEmpty(application.CallbackUrl)) * { * var redirectUrl = application.CallbackUrl +"?"+ result.AsEnumerable().Aggregate(new StringBuilder(), * (sb, arg) => sb.Append($"&{arg.Key}={arg.Value}"), * sb => sb.ToString().TrimStart('&') * ); * return Redirect(redirectUrl); * } * else * { * var client = await this.context.AppClients.AsNoTracking().SingleOrDefaultAsync(); * if (client != null && !String.IsNullOrEmpty(client.DefaultCallbackUrl)) * { * var redirectUrl = client.DefaultCallbackUrl + "?" + result.AsEnumerable().Aggregate(new StringBuilder(), * (sb, arg) => sb.Append($"&{arg.Key}={arg.Value}"), * sb => sb.ToString().TrimStart('&') * ); * return Redirect(redirectUrl); * } * else * { * return View("Result", new PaymentResult() * { * IsSuccessful = false, * Message = "订单号重复,请重新下单" * }); * } * } * } * else * { * return View("Result", new PaymentResult() * { * IsSuccessful = false, * Message = "订单号重复,请重新下单" * }); * } */ } application.Id = order.Id; return(View(application)); }