Exemple #1
0
        /// <summary>
        /// This will check for an existing AutoBill order for the CustomerID and
        /// return the number of days left on that order's subscription, if any.
        /// The existing AutoBill order will be canceled and the items deleted
        /// from the cart.
        /// This should only be used with AppConfig Recurring.LimitCustomerToOneOrder=TRUE
        /// </summary>
        /// <param name="CustomerID"></param>
        /// <returns>Number of subscription days to migrate from existing order. If not a subscription we return zero.</returns>
        public static int ProcessAutoBillMigrateExisting(int CustomerID)
        {
            // This should only be used with AppConfig Recurring.LimitCustomerToOneOrder=TRUE

            int    MigrateDays = 0;
            int    OriginalRecurringOrderNumber = 0;
            bool   IsSubscription          = false;
            String Status                  = AppLogic.ro_OK;
            String RecurringSubscriptionID = String.Empty;

            using (SqlConnection dbconn = new SqlConnection(DB.GetDBConn()))
            {
                dbconn.Open();
                using (IDataReader rs = DB.GetRS("Select top 1 OriginalRecurringOrderNumber, RecurringInterval from ShoppingCart  with (NOLOCK)  where RecurringSubscriptionID<>'' and CustomerID=" + CustomerID.ToString() + " order by OriginalRecurringOrderNumber desc", dbconn))
                {
                    if (rs.Read())
                    {
                        OriginalRecurringOrderNumber = DB.RSFieldInt(rs, "OriginalRecurringOrderNumber");
                        IsSubscription = (DB.RSFieldInt(rs, "RecurringInterval") > 0);
                    }
                }
            }

            if (OriginalRecurringOrderNumber != 0)
            {
                if (IsSubscription && !AppLogic.AppConfigBool("SubscriptionExtensionOccursFromOrderDate"))
                {
                    // get customer's current subscription expiration and compute days remaining
                    using (SqlConnection dbconn = new SqlConnection(DB.GetDBConn()))
                    {
                        dbconn.Open();
                        using (IDataReader rsCust = DB.GetRS("Select SubscriptionExpiresOn from customer  with (NOLOCK)  where CustomerID=" + CustomerID.ToString(), dbconn))
                        {
                            if (rsCust.Read())
                            {
                                TimeSpan TimeRemaining = DB.RSFieldDateTime(rsCust, "SubscriptionExpiresOn").Subtract(DateTime.Today);
                                // Only carry forward if Expires in future
                                if (TimeRemaining.Days > 0)
                                {
                                    MigrateDays = TimeRemaining.Days;
                                }
                            }
                        }
                    }
                }

                RecurringSubscriptionID = AppLogic.GetRecurringSubscriptionIDFromOrder(OriginalRecurringOrderNumber);

                if (RecurringSubscriptionID.Length != 0)
                {
                    // cancel the existing gateway billing
                    String GW = AppLogic.ActivePaymentGatewayCleaned();
                    if (RecurringSubscriptionID.Length != 0)
                    {
                        if (GW == Gateway.ro_GWPAYFLOWPRO)
                        {
                            GatewayProcessor             pfp = GatewayLoader.GetProcessor(Gateway.ro_GWPAYFLOWPRO);
                            IDictionary <string, string> transactionContext = new Dictionary <string, string>();

                            if (RecurringSubscriptionID.ToUpper().StartsWith("B-"))
                            {
                                transactionContext.Add("TENDER", "P");
                            }

                            Status = pfp.RecurringBillingCancelSubscription(RecurringSubscriptionID, OriginalRecurringOrderNumber, transactionContext);
                        }
                        else
                        {
                            Status = "Invalid Gateway";
                        }
                    }
                }

                // now clean up the original order from the cart
                DB.ExecuteSQL(String.Format("delete from kitcart where OriginalRecurringOrderNumber={0}", OriginalRecurringOrderNumber.ToString()));
                DB.ExecuteSQL(String.Format("delete from ShoppingCart where OriginalRecurringOrderNumber={0}", OriginalRecurringOrderNumber.ToString()));
            }
            else
            {
                Status = "OriginalRecurringOrderNumber Not Found.";
            }

            if (AppLogic.AppConfigBool("AuditLog.Enabled"))
            {
                StringBuilder sbDetails = new StringBuilder("Result=" + Status);
                sbDetails.Append(", RecurringSubscriptionID=" + RecurringSubscriptionID);
                sbDetails.Append(", MigrateDays=" + MigrateDays.ToString());
                AppLogic.AuditLogInsert(0, CustomerID, OriginalRecurringOrderNumber, "ProcessAutoBillMigrateExisting", sbDetails.ToString(), CommonLogic.GetThisPageName(true), "RecurringOrderMgr");
            }
            return(MigrateDays);
        }
Exemple #2
0
        // main routine to cancel any active recurring order (can be subscription autobill or in-cart):
        public String CancelRecurringOrder(int OriginalRecurringOrderNumber)
        {
            String Status = AppLogic.ro_OK;

            if (OriginalRecurringOrderNumber != 0)
            {
                String RecurringSubscriptionID = AppLogic.GetRecurringSubscriptionIDFromOrder(OriginalRecurringOrderNumber);

                if (RecurringSubscriptionID.Length != 0)
                {
                    // a Gateway AutoBill order, so cancel the gateway billing first:
                    String GW = AppLogic.ActivePaymentGatewayCleaned();
                    if (RecurringSubscriptionID.Length != 0)
                    {
                        // dynamically load the gateway processor class via the name
                        GatewayProcessor processor = GatewayLoader.GetProcessor(GW);

                        IDictionary <string, string> transactionContext = new Dictionary <string, string>();

                        if (RecurringSubscriptionID.ToUpper().StartsWith("B-"))
                        {
                            transactionContext.Add("TENDER", "P");
                        }

                        if (processor != null)
                        {
                            Status = processor.RecurringBillingCancelSubscription(RecurringSubscriptionID, OriginalRecurringOrderNumber, transactionContext);
                        }
                        else
                        {
                            if (GW == Gateway.ro_GWPAYFLOWPRO)
                            {
                                GatewayProcessor pfp = GatewayLoader.GetProcessor(Gateway.ro_GWPAYFLOWPRO);

                                Status = pfp.RecurringBillingCancelSubscription(RecurringSubscriptionID, OriginalRecurringOrderNumber, transactionContext);
                            }
                            else
                            {
                                Status = "Invalid Gateway";
                            }
                        }
                    }
                }

                int ProcessCustomerID = Order.GetOrderCustomerID(OriginalRecurringOrderNumber);

                if (Status == AppLogic.ro_OK)
                {
                    // now clean it up in the cart only if it cannot be restarted/reactivated
                    DB.ExecuteSQL(String.Format("delete from kitcart where OriginalRecurringOrderNumber={0}", OriginalRecurringOrderNumber.ToString()));
                    DB.ExecuteSQL(String.Format("delete from ShoppingCart where OriginalRecurringOrderNumber={0}", OriginalRecurringOrderNumber.ToString()));

                    // now notify customer of cancellation:
                    Customer ProcessCustomer = new Customer(ProcessCustomerID, true);

                    try
                    {
                        // send email notification to customer
                        string emailSubject = String.Format("{0} - Recurring Order Canceled", AppLogic.AppConfig("StoreName"));
                        string emailBody    = String.Format("Your recurring order has been canceled. The original order number was: {0}", OriginalRecurringOrderNumber.ToString());
                        AppLogic.SendMail(subject: emailSubject,
                                          body: emailBody + AppLogic.AppConfig("MailFooter"),
                                          useHtml: true,
                                          fromAddress: AppLogic.AppConfig("ReceiptEMailFrom"),
                                          fromName: AppLogic.AppConfig("ReceiptEMailFromName"),
                                          toAddress: ProcessCustomer.EMail,
                                          toName: ProcessCustomer.EMail,
                                          bccAddresses: String.Empty,
                                          server: AppLogic.MailServer());


                        // send email notification to admin
                        if (AppLogic.AppConfig("GotOrderEMailTo").Length != 0 && !AppLogic.AppConfigBool("TurnOffStoreAdminEMailNotifications"))
                        {
                            String SendToList = AppLogic.AppConfig("GotOrderEMailTo").Replace(",", ";");
                            if (SendToList.IndexOf(';') != -1)
                            {
                                foreach (String s in SendToList.Split(';'))
                                {
                                    AppLogic.SendMail(subject: emailSubject,
                                                      body: emailBody + AppLogic.AppConfig("MailFooter"),
                                                      useHtml: true,
                                                      fromAddress: AppLogic.AppConfig("GotOrderEMailFrom"),
                                                      fromName: AppLogic.AppConfig("GotOrderEMailFromName"),
                                                      toAddress: s.Trim(),
                                                      toName: s.Trim(),
                                                      bccAddresses: String.Empty,
                                                      server: AppLogic.MailServer());
                                }
                            }
                            else
                            {
                                AppLogic.SendMail(subject: emailSubject,
                                                  body: emailBody + AppLogic.AppConfig("MailFooter"),
                                                  useHtml: true,
                                                  fromAddress: AppLogic.AppConfig("GotOrderEMailFrom"),
                                                  fromName: AppLogic.AppConfig("GotOrderEMailFromName"),
                                                  toAddress: SendToList,
                                                  toName: SendToList,
                                                  bccAddresses: String.Empty,
                                                  server: AppLogic.MailServer());
                            }
                        }
                    }
                    catch { }
                }

                if (AppLogic.AppConfigBool("AuditLog.Enabled"))
                {
                    StringBuilder sbDetails = new StringBuilder("Result=" + Status);
                    sbDetails.Append(", RecurringSubscriptionID=" + RecurringSubscriptionID);
                    AppLogic.AuditLogInsert(0, ProcessCustomerID, OriginalRecurringOrderNumber, "CancelRecurringOrder", sbDetails.ToString(), CommonLogic.GetThisPageName(true), "RecurringOrderMgr");
                }
            }
            return(Status);
        }