//All Services public void Process_AllServices() { DataTable dtbl = null, dtbl1 = null, dtbl2 = null; DataSet ds = null; var sdata = new SellerData(); dtbl = sdata.GetUserStatus(); if (dtbl.Rows.Count > 0) { foreach (DataRow rw in dtbl.Rows) { bool subscription = false; int UserId = Convert.ToInt32(rw["MppUserID"]); String CustmID = Convert.ToString(rw["stp_custId"]); if (!String.IsNullOrWhiteSpace(CustmID)) { subscription = StripeHelper.UnSubscribe(CustmID); //unsubscribe the users either whose status is 2 or active with no card } if (subscription) { ServicesData.UpdatePlanData(UserId, 0); } } } ds = sdata.GetUserEmails(); dtbl1 = ds.Tables[0]; dtbl2 = ds.Tables[1]; if (dtbl1.Rows.Count > 0) { DataTable tbl = new DataTable(); tbl.Columns.AddRange(new DataColumn[2] { new DataColumn("MppUserId", typeof(Int32)), new DataColumn("Limit", typeof(Int32)) }); //Using Parallel Multi-Threading to send multiple bulk email. Parallel.ForEach(dtbl1.AsEnumerable(), row => { String msg = ""; Int32 Limit = Convert.ToInt32(row["accesslimit"]); Int32 UserID = Convert.ToInt32(row["MppUserID"]); msg = alert.SendNewUserAccessAlert(row["Email"].ToString(), row["FirstName"].ToString(), row["LastName"].ToString()); if (msg == "") { tbl.Rows.Add(); tbl.Rows[tbl.Rows.Count - 1][0] = UserID; switch (Limit) { case 1: Limit = 2; break; case 2: Limit = 3; break; default: Limit = 0; break; } tbl.Rows[tbl.Rows.Count - 1][1] = Limit; } }); if (tbl.Rows.Count > 0) { sdata.UpdateUserAccessLimit(tbl); } } if (dtbl2.Rows.Count > 0) { DataTable tbl1 = new DataTable(); DataTable tbl2 = new DataTable(); tbl1.Columns.AddRange(new DataColumn[2] { new DataColumn("UserID", typeof(Int32)), new DataColumn("Status", typeof(Int32)) }); tbl2.Columns.AddRange(new DataColumn[2] { new DataColumn("UserID", typeof(Int32)), new DataColumn("Status", typeof(Int32)) }); //Using Parallel Multi-Threading to send multiple bulk email. Parallel.ForEach(dtbl2.AsEnumerable(), row => { String msg = ""; Int32 UserID = Convert.ToInt32(row["MppUserID"]); String FirstName = Convert.ToString(row["FirstName"]); String LastName = Convert.ToString(row["LastName"]); String Email = Convert.ToString(row["Email"]); DateTime TrialEndDate = Convert.ToDateTime(row["TrailEndDate"]); msg = alert.SendTrialExpiresAlert(Email, TrialEndDate, FirstName, LastName); if (msg == "") { if (TrialEndDate < DateTime.Now) { tbl2.Rows.Add(); tbl2.Rows[tbl2.Rows.Count - 1][0] = UserID; tbl2.Rows[tbl2.Rows.Count - 1][1] = 1; } else { tbl1.Rows.Add(); tbl1.Rows[tbl1.Rows.Count - 1][0] = UserID; tbl1.Rows[tbl1.Rows.Count - 1][1] = 1; } } }); if (tbl1.Rows.Count > 0) { sdata.UpdateSevenTrialEmailStatus(tbl1); } if (tbl2.Rows.Count > 0) { sdata.UpdateTrialEndEmailStatus(tbl2); } } StripeServices.RenewPlan(); }
public HttpStatusCode WebHook() { try { var paymentAlertStatus = 0; string secret = MppUtility.ReadConfig("MS_WebHookReceiverSecret_Custom"); var postdata = new StreamReader(HttpContext.Request.InputStream).ReadToEnd(); var emailboday = ""; var signature = Request.Headers["Stripe-Signature"]; var stripeEvent = StripeEventUtility.ConstructEvent(postdata, signature, secret); var eventid = stripeEvent.Id; var eventdata = StripeHelper.GetStripeEvent(eventid); var data = JObject.Parse(postdata); var custid = data["data"].First().First["customer"].ToString(); var msg = ""; if (eventdata != null && (eventdata.Type == "invoice.payment_succeeded" || eventdata.Type == "invoice.payment_failed")) { String coupon_id = null; var list = data["data"].First().First["lines"]; var Amount = ((double)list["data"].First["amount"]) / 100; var Amount_off = ((double)data["data"].First().First["amount_due"]) / 100; var Discount = data["data"].First().First["discount"]; var start = (double)list["data"].First["period"]["start"]; var end = (double)list["data"].First["period"]["end"]; var startperiod = MppUtility.UnixTimeStampToDateTime(start); var endperiod = MppUtility.UnixTimeStampToDateTime(end); var discount = Math.Round(Amount - Amount_off, 2, MidpointRounding.AwayFromZero); var customerdata = StripeHelper.GetStripeCustomer(custid); var email = customerdata.Email; var last4 = ""; var carddetails = StripeHelper.GetCard(custid); foreach (var card in carddetails) { last4 = card.Last4; } if (Discount.Count() > 0) { coupon_id = Discount["coupon"]["id"].ToString(); } switch (eventdata.Type) { case "invoice.payment_succeeded": msg = AccountData.UpdatePaymentStatus(custid, Amount, Amount_off, coupon_id, discount, startperiod, endperiod, 1); emailboday = "A payment of $" + Amount_off + " was made using your card on file ending with <b> " + last4 + " </b>"; paymentAlertStatus = 1; break; case "invoice.payment_failed": msg = AccountData.UpdatePaymentStatus(custid, Amount, Amount_off, coupon_id, discount, startperiod, endperiod, 0); upData.UpdatePlanData(custid, 0); StripeHelper.UnSubscribe(custid); emailboday = @"A payment $" + Amount_off + " failed from your card ending with <b> " + last4 + " </b>" + "Please check your card details or add new card."; paymentAlertStatus = 2; break; } if (msg == "" && Amount_off != 0) { var respo = EmailAlert.PaymentAlertMail(email, emailboday); if (respo == "success") { sellerData.UpdatePaymentAlert(paymentAlertStatus, custid); } } } else if (stripeEvent.Type == "charge.failed") { var Amount = ((double)data["data"].First().First["amount"]) / 100; var failure_message = data["data"].First().First["failure_message"].ToString(); // msg = AccountData.UpdatePaymentStatus(custid, Amount, Amount, 0, 0.00, startperiod, endperiod, 0); if (Amount > 1)//Card verification charge { upData.UpdatePlanData(custid, 0); StripeHelper.UnSubscribe(custid); } var last4 = ""; var carddetails = StripeHelper.GetCard(custid); var customerdata = StripeHelper.GetStripeCustomer(custid); var email = customerdata.Email; foreach (var card in carddetails) { last4 = card.Last4; } emailboday = @"A payment $" + Amount + " failed from your card ending with <b> " + last4 + " </b>" + "Please check your card details or add new card.</b>Possible reason:" + failure_message; var respo = EmailAlert.PaymentAlertMail(email, emailboday); if (respo == "success" && Amount > 1) { sellerData.UpdatePaymentAlert(2, custid); } } } catch (Exception ex) { String msg = ex.Message; LogFile.WriteLog(msg); } return(HttpStatusCode.OK); }