public SMTPMailService(SMTPMailSettings smtpMailSettings, ProprietorSettings proprietorSettings) { settings = smtpMailSettings; propSettings = proprietorSettings; smtpclient = new SmtpClient(settings.Host, settings.Port) { Credentials = new NetworkCredential(settings.Username, settings.Password), EnableSsl = settings.EnableSSL }; }
public SMTPMailService() { settings = Settings.Get<SMTPMailSettings>(); propSettings = Settings.Get<ProprietorSettings>(); smtpclient = new SmtpClient(settings.Host, settings.Port) { Credentials = new NetworkCredential(settings.Username, settings.Password), EnableSsl = settings.EnableSSL }; }
private async Task ProcessOrder(IDatabase cache, ProprietorSettings defaultAddressSettings, PartnerModels.Infini.Order order) { // Step: Did we read this order before and if we did should we process it? var cachedOrderState = cache.StringGet(order.id.ToString()); if (cachedOrderState.HasValue) { if (!shouldProcess(cachedOrderState.ToString())) { logger.LogDebug($"Skipping order {order.id.ToString()}, it is cached as {cachedOrderState.ToString()}"); return; } } else { // Step: We didn't read this order before. Let's just mark it read before anything happens // We are not using this state now, may be later. cache.StringSet(order.id.ToString(), RemoteJobStage.READ); } var infiniUserId = this.configuration["Infini:userid"]; var serviceCharge = Decimal.Parse(this.configuration["ServiceCharge"]); // Step: Convert the partner order to native taskcat order var taskcatOrder = order.ToClassifiedDeliveryOrder(serviceCharge, defaultAddressSettings, infiniUserId); logger.LogDebug($"Preparing message for order {order.id.ToString()}"); // Step: Throw it to our message bus and update the state to posted. var createJobMessageBody = JsonConvert.SerializeObject(taskcatOrder); var createNewTaskCatJobMessage = new Message(Encoding.UTF8.GetBytes(createJobMessageBody)); try { await this.pushQueueClient.SendAsync(createNewTaskCatJobMessage); cache.StringSet(order.id.ToString(), RemoteJobStage.POSTED); logger.LogInformation($"order {order.id.ToString()} is {RemoteJobStage.POSTED}"); } catch (Exception ex) when(ex is ServiceBusException || ex is InvalidOperationException) { logger.LogError($"Service bus exception encountered, skipping marking the order {RemoteJobStage.POSTED}", ex); } }
public static ClassifiedDeliveryOrder ToClassifiedDeliveryOrder( this Order infiniOrder, Decimal serviceCharge, ProprietorSettings defaultAddressSettings, string userId) { if (infiniOrder == null) { throw new ArgumentNullException(nameof(infiniOrder)); } if (defaultAddressSettings == null) { throw new ArgumentNullException(nameof(defaultAddressSettings)); } if (userId == null) { throw new ArgumentNullException(nameof(userId)); } const string orderPrefix = "IFA"; ClassifiedDeliveryOrder taskcatOrder = new ClassifiedDeliveryOrder( orderPrefix + "-" + infiniOrder.id) { IsAutogenerated = true, ReferenceOrderId = infiniOrder.id.ToString(), Description = GenerateTaskCatJobDescription(infiniOrder), PaymentMethod = CashOnDeliveryPaymentMethod.PaymentMethodKey, OrderCart = new OrderDetails { ServiceCharge = serviceCharge, SubTotal = infiniOrder.total } }; taskcatOrder.OrderCart.TotalToPay = infiniOrder.total + taskcatOrder.OrderCart.ServiceCharge; taskcatOrder.OrderCart.PackageList = new List <ItemDetails>(); taskcatOrder.OrderCart.PackageList.Add(new ItemDetails() { Item = infiniOrder.product, Price = infiniOrder.unit_price, Quantity = infiniOrder.qty }); // Infini doesn't provide a from address for now. We are setting it to a configured default if (infiniOrder.vendor_address == null || !infiniOrder.vendor_address.Any()) { taskcatOrder.From = defaultAddressSettings.Address; taskcatOrder.SellerInfo = new PersonInfo() { Name = defaultAddressSettings.Name, PhoneNumber = defaultAddressSettings.PhoneNumber }; } else { var vendorAddress = infiniOrder.vendor_address.First(); taskcatOrder.From = new DefaultAddress() { AddressLine1 = vendorAddress.address1, AddressLine2 = String.IsNullOrWhiteSpace(vendorAddress.address3) ? vendorAddress.address2 : string.Join(" ", vendorAddress.address2, vendorAddress.address3), }; taskcatOrder.SellerInfo = new PersonInfo() { Name = string.Join(" ", vendorAddress.firstname, vendorAddress.lastname), PhoneNumber = vendorAddress.phone_no }; } taskcatOrder.UserId = userId; taskcatOrder.To = new DefaultAddress( addressLine1: infiniOrder.user_address.address1, addressLine2: string.IsNullOrWhiteSpace(infiniOrder.user_address.address3) ? infiniOrder.user_address.address2 : string.Join(" ", infiniOrder.user_address.address2, infiniOrder.user_address.address3), locality: infiniOrder.user_address.zone, postcode: infiniOrder.user_address.postcode, city: infiniOrder.user_address.city, country: "Bangladesh", // TODO: Infini sends back a country code, either we need to parse it or find a way to make this nice point: null); taskcatOrder.BuyerInfo = new PersonInfo() { Name = string.Join(" ", infiniOrder.user_address.firstname, infiniOrder.user_address.lastname), PhoneNumber = infiniOrder.user_address.phone_no }; taskcatOrder.Variant = DeliveryOrderVariants.EnterpriseDelivery; return(taskcatOrder); }