Esempio n. 1
0
        private async Task SendSMSMessageAsync(OrderDBE dbOrderExploded, WebUrlConfigurationBE webUrlConfig)
        {
            // Step 1: calc the order total
            decimal orderTotal = (dbOrderExploded.OrderLineItems != null)
                                            ? dbOrderExploded.OrderLineItems.Sum(oli => oli.ItemUnitPrice)
                                            : 0.0M;

            // Step 2: Build the SMS Msg
            string payAwayURL = $"{webUrlConfig.HPPBaseUrl}/customerorder/{dbOrderExploded.OrderGuid}";

            StringBuilder messageBody = new StringBuilder();

            messageBody.AppendLine($"Hello {dbOrderExploded.CustomerName}");

            // we do not know what culture the server is set for so we are explicit, we want to make it formats currency with a US $
            var specificCulture = System.Globalization.CultureInfo.GetCultureInfo("en-US");
            FormattableString formattableString = $"{dbOrderExploded.Merchant.MerchantName} is sending you this link to a secure payment page to enter your payment info for your Order Number: {dbOrderExploded.OrderId:0000} for: {orderTotal:C}";

            messageBody.AppendLine(formattableString.ToString(specificCulture));
            messageBody.AppendLine($"{payAwayURL}");

            // Step 3: Send the SMS msg
            // convert the phone no to the "normalized format"  +15131234567 that the SMS api accepts
            (bool isValidPhoneNo, string formattedPhoneNo, string normalizedPhoneNo) = Utilities.PhoneNoHelpers.NormalizePhoneNo(dbOrderExploded.PhoneNumber);
            var msgSid = SMSController.SendSMSMessage(String.Empty, formattedPhoneNo, messageBody.ToString());

            // Step 4 Create & Save the SMS event
            var dbOrderEvent = new OrderEventDBE()
            {
                OrderId          = dbOrderExploded.OrderId,
                EventDateTimeUTC = DateTime.UtcNow,
                OrderStatus      = Enums.ORDER_STATUS.SMS_Sent,
                EventDescription = $"SMS sent to [{normalizedPhoneNo}]."
            };

            await _dbContext.InsertOrderEventAsync(dbOrderEvent);

            // Step 5: Update the order status
            dbOrderExploded.Status = Enums.ORDER_STATUS.SMS_Sent;
            await _dbContext.UpdateOrderAsync(dbOrderExploded);
        }
Esempio n. 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MerchantController"/> class.
 /// </summary>
 /// <param name="webUrlConfig">The web URL configuration.</param>
 /// <param name="dbContext">The database context.</param>
 /// <param name="logger">The logger.</param>
 public MerchantController(WebUrlConfigurationBE webUrlConfig, SQLiteDBContext dbContext, ILogger <MerchantController> logger)
 {
     this._webUrlConfig = webUrlConfig;
     this._dbContext    = dbContext;
     this.logger        = logger;
 }