/// <summary> /// 付款 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Button_Click(object sender, RoutedEventArgs e) { if (this.PaymentEvent != null) { PaymentEvent.Invoke(this); } }
public int CreatePaymentEvent(PaymentEventDto paymentDto, int customerId) { PaymentEvent paymentEvent = new PaymentEvent(); UpdatePaymentEvent(ref paymentEvent, paymentDto); Customer customer = _repository.Load <Customer>(customerId); customer.PaymentEvents.Add(paymentEvent); using (TransactionScope scope = new TransactionScope()) { try { _repository.Save <PaymentEvent>(paymentEvent); _repository.Update <Customer>(customer); _repository.Flush(); scope.Complete(); return(paymentEvent.Id); } catch (Exception ex) { log.Error("Error during Creating new PaymentEvent", ex); return(-1); } } }
public async Task EmitEvent(PaymentEvent @event) { using (IConnection conn = _connectionFactory.CreateConnection()) { using (IModel channel = conn.CreateModel()) { channel.QueueDeclare( queue: PaymentProcessedEventsQueueName, durable: false, exclusive: false, autoDelete: false, arguments: null ); string jsonPayload = JsonConvert.SerializeObject(@event); var body = Encoding.UTF8.GetBytes(jsonPayload); channel.BasicPublish( exchange: "", routingKey: PaymentProcessedEventsQueueName, basicProperties: null, body: body ); } }; }
public async Task SendReceipt(Invoice invoice, PaymentEvent payment, SendInvoiceModel model) { await _emailService.SendReceipt(invoice, payment); invoice.Status = Invoice.StatusCodes.Sent; invoice.Sent = true; invoice.SentAt = DateTime.UtcNow; }
private void IsValid(PaymentEvent paymentEvent) { CheckCustomerExistance(paymentEvent.Customer); if (paymentEvent.Amount <= 0) { throw new InvalidEventException("Payment amount must be positive number!"); } }
public void TestOccuredAtIsDefaulted() { // Arrange var paymentEvent = new PaymentEvent(); // Act // Assert paymentEvent.ShouldNotBeNull(); }
public void AddPayment(Customer customer, double amount) { try { var payment = new PaymentEvent(_dateProvider.Now(), customer, amount); _dataRepository.AddEvent(payment); } catch (Exception e) { throw new DataServiceException(e); } }
private PaymentEvent ProcessPaymentEvent(ReceiptResponseModel response, Dictionary <string, string> dictionary) { var paymentEvent = new PaymentEvent { Transaction_Id = response.Transaction_Id, Auth_Amount = response.Auth_Amount, Decision = response.Decision, Reason_Code = response.Reason_Code, Req_Reference_Number = response.Req_Reference_Number, ReturnedResults = JsonConvert.SerializeObject(dictionary) }; _context.PaymentEvents.Add(paymentEvent); return(paymentEvent); }
public void AddEvent_PaymentEventWithPositiveAmout_AddedToEvents() { _bookCopiesInDataFiller[0].IsLent = true; _repo = new DataRepository(new ConstDataFiller(books: _booksInDataFiller, customers: _customersInDataFiller, bookCopies: _bookCopiesInDataFiller, events: _eventsInDataFiller)); var eve = new PaymentEvent(DateTime.Now, _customersInDataFiller[0], 15); _repo.AddEvent(eve); var actual = _repo.GetAllEvents().Contains(eve); Assert.AreEqual(true, actual); }
public void AddEvent_PaymentEventWithZeroOrNegativeAmout_ExceptionThrown() { _bookCopiesInDataFiller[0].IsLent = true; _repo = new DataRepository(new ConstDataFiller(books: _booksInDataFiller, customers: _customersInDataFiller, bookCopies: _bookCopiesInDataFiller, events: _eventsInDataFiller)); var eve = new PaymentEvent(DateTime.Now, _customersInDataFiller[0], 0); Assert.ThrowsException <InvalidEventException>( () => _repo.AddEvent(eve) ); eve = new PaymentEvent(DateTime.Now, _customersInDataFiller[0], -15); Assert.ThrowsException <InvalidEventException>( () => _repo.AddEvent(eve) ); }
public void UpdatePaymentEvent(ref PaymentEvent paymentEvent, PaymentEventDto paymentDto) { paymentEvent.Description = paymentDto.Description; paymentEvent.Name = paymentDto.Title; paymentEvent.PartnerIban = paymentDto.PartnerIban; paymentEvent.Amount = paymentDto.Amount; paymentEvent.Date = paymentDto.Date; paymentEvent.Regular = paymentDto.Regular; if (paymentDto.PartnerId != -1) { BusinessPartner partner = _repository.Load <BusinessPartner>(paymentDto.PartnerId); paymentEvent.Partner = partner; } if (paymentDto.AccountId != -1) { Account account = _repository.Load <Account>(paymentDto.AccountId); paymentEvent.Account = account; } }
public async Task SendReceipt(Invoice invoice, PaymentEvent payment) { var viewbag = GetViewData(); viewbag["Team"] = invoice.Team; var model = new ReceiptViewModel { Invoice = invoice, Payment = payment, }; // add model data to email var prehtml = await RazorTemplateEngine.RenderAsync("/Views/Receipt.cshtml", model, viewbag); // convert email to real html var mjml = await _mjmlServices.Render(prehtml); // build email using (var message = new MailMessage { From = _fromAddress, Subject = $"Receipt from {invoice.Team.Name}" }) { message.Body = mjml.Html; message.IsBodyHtml = true; message.To.Add(new MailAddress(invoice.CustomerEmail, invoice.CustomerName)); // add cc if the billing email is different if (!string.Equals(invoice.CustomerEmail, payment.BillingEmail, StringComparison.OrdinalIgnoreCase)) { var ccName = $"{payment.BillingFirstName} {payment.BillingLastName}"; message.CC.Add(new MailAddress(payment.BillingEmail, ccName)); } // ship it await _client.SendMailAsync(message); Log.Information("Sent Email"); } }
public async Task SendRefundRequest(Invoice invoice, PaymentEvent payment, string refundReason, User user) { var viewbag = GetViewData(); viewbag["Team"] = invoice.Team; viewbag["Slug"] = invoice.Team.Slug; var model = new RefundRequestViewModel() { Invoice = invoice, Payment = payment, RefundReason = refundReason, User = user, }; // add model data to email var prehtml = await RazorTemplateEngine.RenderAsync("/Views/RefundRequest.cshtml", model, viewbag); // convert email to real html MjmlResponse mjml = await _mjmlServices.Render(prehtml); // build email using (var message = new MailMessage { From = _fromAddress, Subject = $"Refund Request from {invoice.Team.Name}" }) { message.Body = mjml.Html; message.IsBodyHtml = true; message.To.Add(_refundAddress); // ship it await _client.SendMailAsync(message); Log.Information("Sent Email"); } }
private async Task <PaymentEvent> ProcessPaymentEvent(ReceiptResponseModel response, Dictionary <string, string> dictionary) { // create and record event var paymentEvent = new PaymentEvent { Processor = "CyberSource", ProcessorId = response.Transaction_Id, Decision = response.Decision, OccuredAt = response.AuthorizationDateTime, BillingFirstName = response.Req_Bill_To_Forename.SafeTruncate(60), BillingLastName = response.Req_Bill_To_Surname.SafeTruncate(60), BillingEmail = response.Req_Bill_To_Email.SafeTruncate(1500), BillingCompany = response.Req_Bill_To_Company_Name.SafeTruncate(60), BillingPhone = response.Req_Bill_To_Phone.SafeTruncate(100), BillingStreet1 = response.Req_Bill_To_Address_Line1.SafeTruncate(400), BillingStreet2 = response.Req_Bill_To_Address_Line2.SafeTruncate(400), BillingCity = response.Req_Bill_To_Address_City.SafeTruncate(50), BillingState = response.Req_Bill_To_Address_State.SafeTruncate(64), BillingCountry = response.Req_Bill_To_Address_Country.SafeTruncate(2), BillingPostalCode = response.Req_Bill_To_Address_Postal_Code.SafeTruncate(10), CardType = response.Req_Card_Type.SafeTruncate(3), CardNumber = response.Req_Card_Number.SafeTruncate(20), CardExpiry = response.CardExpiration, ReturnedResults = JsonConvert.SerializeObject(dictionary), }; if (decimal.TryParse(response.Auth_Amount, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out decimal amount)) { paymentEvent.Amount = amount; } _dbContext.PaymentEvents.Add(paymentEvent); await _dbContext.SaveChangesAsync(); return(paymentEvent); }
public async Task RefundInvoice(Invoice invoice, PaymentEvent payment, string refundReason, User user) { await _emailService.SendRefundRequest(invoice, payment, refundReason, user); invoice.Status = Invoice.StatusCodes.Refunding; }
public HomeOwner() { Inbox += new PaymentEvent(ReceiveBill); }
public UtilityCo() { Inbox += new PaymentEvent(this.ReceivePayment); }
public void shipPayOrders() { string msg = "You buy products with PayPal"; string msgOne = "You buy products with CreditCard"; PaymentEvent paymentEvent = new PaymentEvent(); UserNotified userNotified = new UserNotified(); paymentEvent.userNotifiedHandler += userNotified.MsgProcessed; var username = new User(); Console.WriteLine(username.Name); for (int i = 0; i < userOrders.Count; i++) { Console.WriteLine($"{i + 1}:Name:{userOrders[i].Product.Name} price:{userOrders[i].Product.Price} quanity:{userOrders[i].Quantity}"); } double totalSum = userOrders.Sum(el => el.TotalPrice); Console.WriteLine("Total:" + totalSum); Console.WriteLine("You can continue to add orders or pay and ship current orders"); Console.WriteLine("To continue adding orders enter add , to continue to paying and shipping orders enter submit"); var userInput = Console.ReadLine(); if (userInput == "submit") { Console.WriteLine("Pay with credit card or paypal by entering credit or pay"); var creditCard = Console.ReadLine(); if (creditCard == "credit") { userNotified.MsgProcessed(msg); } if (creditCard == "pay") { userNotified.MsgProcessed(msgOne); } Console.WriteLine("If you are living in Skopje, Bitola, Ohrid, Stip you can get your products by entering your city name"); var city = Console.ReadLine(); if (city == "Skopje" || city == "Bitola" || city == "Ohrid" || city == "Stip") { Console.WriteLine("Please enter posta or delco to ship your orders"); var ship = Console.ReadLine(); if (ship == "posta") { Console.WriteLine("Your orders are shipped by posta...."); } if (ship == "delco") { Console.WriteLine("Your orders are shipped by delco...."); } Console.WriteLine("See your list of expensive orders above 50.000 or see your cheap orders under 50.000 by entering exp or cheap"); Console.WriteLine("Enter exp or cheap"); var cost = Console.ReadLine(); if (cost == "exp") { double fiveK = 50.000; var totalSumExp = userOrders.Where(x => x.TotalPrice > fiveK); foreach (var item in totalSumExp) { Console.WriteLine(item); } } if (cost == "cheap") { double fiveK = 50.000; var totalSumExp = userOrders.Where(x => x.TotalPrice < fiveK); foreach (var item in totalSumExp) { Console.WriteLine(item); } } } } else { Console.WriteLine("We dont have service for shipping in your city yet or you dont choose right paying method"); } }