protected void SubscriptionsGrid_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Subscription subscription            = e.Item.DataItem as Subscription;
                Label        DeliveryFrequencyLabel  = e.Item.FindControl("DeliveryFrequencyLabel") as Label;
                Label        AutoDeliveryDescription = e.Item.FindControl("AutoDeliveryDescription") as Label;
                if (subscription.PaymentFrequency.HasValue && subscription.PaymentFrequencyUnit.HasValue)
                {
                    PaymentFrequencyUnit unit = subscription.PaymentFrequencyUnit.Value;
                    DeliveryFrequencyLabel = e.Item.FindControl("DeliveryFrequencyLabel") as Label;
                    if (DeliveryFrequencyLabel != null)
                    {
                        DeliveryFrequencyLabel.Text = string.Format("{0} {1}{2}", subscription.PaymentFrequency, unit, subscription.PaymentFrequency > 1 ? "s" : string.Empty);
                    }

                    AutoDeliveryDescription = e.Item.FindControl("AutoDeliveryDescription") as Label;
                    if (AutoDeliveryDescription != null && subscription.SubscriptionPlan.IsRecurring)
                    {
                        AutoDeliveryDescription.Text = string.Format("(Recurring payment amount: {0})", subscription.RecurringChargeEx.LSCurrencyFormat("ulc"));
                    }
                }
                else
                {
                    if (DeliveryFrequencyLabel != null)
                    {
                        DeliveryFrequencyLabel.Text = "N/A";
                    }
                    if (AutoDeliveryDescription != null)
                    {
                        AutoDeliveryDescription.Text = string.Empty;
                    }
                }
            }
        }
 protected void BindAutoDelieveryOptions(Product product)
 {
     if (product.SubscriptionPlan != null)
     {
         string[]             vals = product.SubscriptionPlan.OptionalPaymentFrequencies.Split(',');
         PaymentFrequencyUnit unit = product.SubscriptionPlan.PaymentFrequencyUnit;
         AutoDeliveryInterval.Items.Clear();
         if (vals != null && vals.Length > 0)
         {
             foreach (string val in vals)
             {
                 var item = AlwaysConvert.ToInt(val);
                 if (item > 0)
                 {
                     string text = string.Format("{0} {1}{2}", item, unit, item > 1 ? "s" : string.Empty);
                     AutoDeliveryInterval.Items.Add(new ListItem(text, item.ToString()));
                 }
             }
         }
     }
 }
        protected void SubscriptionGrid_OnRowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                // POPULATE VALUES FOR DELIVERY FREQUENCY
                DropDownList         AutoDeliveryInterval = e.Row.FindControl("AutoDeliveryInterval") as DropDownList;
                LinkButton           saveButton           = e.Row.FindControl("SaveButton") as LinkButton;
                Subscription         subscription         = e.Row.DataItem as Subscription;
                Product              product = subscription.Product;
                PaymentFrequencyUnit unit    = product.SubscriptionPlan.PaymentFrequencyUnit;
                if (!string.IsNullOrEmpty(product.SubscriptionPlan.OptionalPaymentFrequencies))
                {
                    string[] frequencyValues = product.SubscriptionPlan.OptionalPaymentFrequencies.Split(',');
                    if (AutoDeliveryInterval != null && subscription != null)
                    {
                        AutoDeliveryInterval.Items.Clear();
                        AutoDeliveryInterval.Items.Add(new ListItem());
                        if (frequencyValues != null && frequencyValues.Length > 0)
                        {
                            foreach (string val in frequencyValues)
                            {
                                var frequencyValue = AlwaysConvert.ToInt(val);
                                if (frequencyValue > 0)
                                {
                                    string text = string.Format("{0} {1}{2}", frequencyValue, unit, frequencyValue > 1 ? "s" : string.Empty);
                                    AutoDeliveryInterval.Items.Add(new ListItem(text, frequencyValue.ToString()));
                                }
                            }
                        }

                        ListItem item = AutoDeliveryInterval.Items.FindByValue(subscription.PaymentFrequency.ToString());
                        if (item != null)
                        {
                            item.Selected = true;
                        }
                    }

                    if (saveButton != null)
                    {
                        saveButton.Visible = true;
                    }
                }
                else
                {
                    Label NoFrequency = e.Row.FindControl("NoFrequency") as Label;
                    if (NoFrequency != null)
                    {
                        if (subscription.PaymentFrequency.HasValue && subscription.PaymentFrequencyUnit.HasValue)
                        {
                            NoFrequency.Text = string.Format("{0} {1}{2}", subscription.PaymentFrequency, subscription.PaymentFrequencyUnit, subscription.PaymentFrequency > 1 ? "s" : string.Empty);
                        }
                        NoFrequency.Visible = true;
                    }
                    if (AutoDeliveryInterval != null)
                    {
                        AutoDeliveryInterval.Visible = false;
                    }
                    if (saveButton != null)
                    {
                        saveButton.Visible = false;
                    }
                }

                Label DeliveryFrequencyLabel  = e.Row.FindControl("DeliveryFrequencyLabel") as Label;
                Label AutoDeliveryDescription = e.Row.FindControl("AutoDeliveryDescription") as Label;
                if (subscription.PaymentFrequency.HasValue && subscription.PaymentFrequencyUnit.HasValue)
                {
                    unit = subscription.PaymentFrequencyUnit.Value;
                    DeliveryFrequencyLabel = e.Row.FindControl("DeliveryFrequencyLabel") as Label;
                    if (DeliveryFrequencyLabel != null)
                    {
                        DeliveryFrequencyLabel.Text = string.Format("{0} {1}{2}", subscription.PaymentFrequency, unit, subscription.PaymentFrequency > 1 ? "s" : string.Empty);
                    }

                    AutoDeliveryDescription = e.Row.FindControl("AutoDeliveryDescription") as Label;
                    if (AutoDeliveryDescription != null && subscription.SubscriptionPlan.IsRecurring)
                    {
                        AutoDeliveryDescription.Text = string.Format("Recurring payment amount {0}", subscription.RecurringChargeEx.LSCurrencyFormat("ulc"));
                    }
                }
                else
                {
                    if (DeliveryFrequencyLabel != null)
                    {
                        DeliveryFrequencyLabel.Text = "N/A";
                    }
                    if (AutoDeliveryDescription != null)
                    {
                        AutoDeliveryDescription.Text = string.Empty;
                    }
                }

                if (Page.IsPostBack && SubscriptionGrid.EditIndex >= 0 && e.Row.RowIndex == SubscriptionGrid.EditIndex)
                {
                    AddEditableInformation(e);
                }
            }
        }
        private static string GetPaymentPeriod(PaymentFrequencyUnit paymentFrequencyUnit, int paymentFrequency, int numberOfPayments = 0)
        {
            // DETERMINE THE TEXTUAL REPRESENTATION OF THE PAYMENT INTERVAL (WEEKLY, MONTHLY, ETC.)
            switch (paymentFrequencyUnit)
            {
            case PaymentFrequencyUnit.Day:
                if (numberOfPayments == 1)
                {
                    return(paymentFrequency.ToString() + " days");
                }
                if (paymentFrequency == 1)
                {
                    return(paymentFrequency + " day");
                }
                if (paymentFrequency == 7)
                {
                    return("weekly");
                }
                if (paymentFrequency == 14)
                {
                    return("every two weeks");
                }
                if (paymentFrequency == 28)
                {
                    return("every four weeks");
                }
                return("every " + paymentFrequency + " days");

            case PaymentFrequencyUnit.Month:
                if (numberOfPayments == 1)
                {
                    return(paymentFrequency.ToString() + " months");
                }
                if (paymentFrequency == 1)
                {
                    return(paymentFrequency + " month");
                }
                if (paymentFrequency == 1)
                {
                    return("monthly");
                }
                if (paymentFrequency == 3)
                {
                    return("quarterly");
                }
                if (paymentFrequency == 6)
                {
                    return("twice per year");
                }
                if (paymentFrequency == 12)
                {
                    return("yearly");
                }
                return("every " + paymentFrequency + " months");

            default:
                if (numberOfPayments == 1)
                {
                    return(paymentFrequency.ToString() + " years");
                }
                if (paymentFrequency == 1)
                {
                    return(paymentFrequencyUnit.ToString().ToLowerInvariant() + "ly");
                }
                return("every " + paymentFrequency + paymentFrequencyUnit.ToString().ToLowerInvariant() + "s");
            }
        }
示例#5
0
        public static PaymentIntentRequest CreateDirectDebit(string transactionReference, string description, double amount, string currency, DateTime directDebitStartDate, PaymentFrequencyUnit directDebitFrequencyUnit, int directDebitFrequencyInterval, string customerEmail, string customerUniqueReference, CustomerAddress customerAddress, string confirmationPageUrl, string failurePageUrl, string callbackUrl, string additionalData, DateTime?directDebitTrialDateEnd = null)
        {
            var pi = new PaymentIntentRequest();

            pi.PaymentIntentType            = PaymentIntentType.DirectDebit;
            pi.Amount                       = amount;
            pi.Currency                     = currency;
            pi.TransactionReference         = transactionReference;
            pi.Description                  = description;
            pi.DirectDebitStartDate         = directDebitStartDate;
            pi.DirectDebitFrequencyUnit     = directDebitFrequencyUnit;
            pi.DirectDebitFrequencyInterval = directDebitFrequencyInterval;
            pi.CustomerEmail                = customerEmail;
            pi.CustomerUniqueReference      = customerUniqueReference;
            pi.CustomerAddress              = customerAddress;
            pi.ConfirmationPageUrl          = confirmationPageUrl;
            pi.FailurePageUrl               = failurePageUrl;
            pi.CallbackUrl                  = callbackUrl;
            pi.AdditionalData               = additionalData;
            pi.DirectDebitTrialDateEnd      = directDebitTrialDateEnd;
            return(pi);
        }
示例#6
0
        protected void InitFormValues()
        {
            SubscriptionName.Text     = _Subscription.Name;
            SubscriptionQuantity.Text = _Subscription.Quantity.ToString();
            BindSubscriptionGroup();
            Order order = _Subscription.OrderItem.Order;

            OrderNumber.Text        = order.OrderNumber.ToString();
            OrderNumber.NavigateUrl = string.Format(OrderNumber.NavigateUrl, order.OrderNumber);
            OrderDate.Text          = string.Format("{0:d}", _Subscription.OrderDate);
            User user = _Subscription.User;

            UserName.Text        = user.UserName;
            UserName.NavigateUrl = string.Format(UserName.NavigateUrl, user.Id);

            // DECIDE SUBSCRIPTION TYPE, RECURRING SUBSCRIPTIONS HAVE VALUE FOR PaymentFrequency AND PaymentFrequencyUnit FIELDS.
            SubscriptionType.Text = (!_Subscription.PaymentFrequency.HasValue || !_Subscription.PaymentFrequencyUnit.HasValue) ? "One Time" : "Recurring";
            Active.Checked        = _Subscription.IsActive;

            /**
             * FOR RECURRING SUBSCRIPTIONS TRY TO GENERATE OPTIONAL PAYMENT FREQUENCY OPTIONS FROM ASSOCIATED SUBSCRIPTION PLAN,
             * OPTIONAL FREQUENCIES ALLOW CUSTOMERS TO SELECT THE RECURRING INTERVALS DURING PLAN PURCHASE.
             **/
            if (_Subscription.PaymentFrequency.HasValue && _Subscription.PaymentFrequencyUnit.HasValue)
            {
                // RELATED SUBSCRIPTION PLAN HAVE OPTIONAL FREQUENCIES, ALLOW MERCHANT TO CHANGE OPTIONAL FREQUENCY SELECTION MADE BY CUSTOMER
                if (!string.IsNullOrEmpty(_Product.SubscriptionPlan.OptionalPaymentFrequencies))
                {
                    PaymentFrequencyUnit unit            = _Subscription.PaymentFrequencyUnit.Value;
                    string[]             frequencyValues = _Product.SubscriptionPlan.OptionalPaymentFrequencies.Split(',');
                    Frequency.Items.Clear();
                    if (frequencyValues != null && frequencyValues.Length > 0)
                    {
                        foreach (string val in frequencyValues)
                        {
                            var frequencyValue = AlwaysConvert.ToInt(val);
                            if (frequencyValue > 0)
                            {
                                // BUILD OPTIONAL FREQUENCY ITEMS FOR EXAMPLE 2 DAYS, 3 MONTH ETC
                                string text = string.Format("{0} {1}{2}", frequencyValue, unit, frequencyValue > 1 ? "s" : string.Empty);
                                Frequency.Items.Add(new ListItem(text, frequencyValue.ToString()));
                            }
                        }
                    }

                    FixedFrequency.Visible = false;
                    Frequency.Visible      = true;
                }
                else
                {
                    // FIXED FREQUENCY IS MERCHANT DEFIEND RECURRING INTERVAL FOR SUBSCRIPTION PLAN. IT CAN'T BE CHANGED AFTER PLAN PURCHASE.
                    FixedFrequency.Text    = string.Format("{0} {1}{2}", _Subscription.PaymentFrequency, _Subscription.PaymentFrequencyUnit, _Subscription.PaymentFrequency > 1 ? "s" : string.Empty);
                    FixedFrequency.Visible = true;
                    Frequency.Visible      = false;
                }
            }
            else
            {
                trFrequency.Visible = false;
            }

            // PROCESSING STATUS TELLS US ABOUT THE RESULT OF BACKEND RECURRING ORDER MAINTINANCE SERVICES ACTIONS FOR THIS SUBSCRIPTION
            ProcessingStatusLabel.Text = _Subscription.ProcessingStatus.ToString();

            // ANY MESSAGE SENT BY SYSTEM RELATED TO PROCESSINGSTATUS FOR EXAMPLE COULD BE ERROR DETAILS IF STATUS IS ERROR
            string statusMsg = string.IsNullOrEmpty(_Subscription.ProcessingStatusMessage)? "" : _Subscription.ProcessingStatusMessage;

            ProcessingMessage.Text = _Subscription.ProcessingStatus == ProcessingStatus.OK ? "OK" : statusMsg;
            ClearStatusBtn.Visible = _Subscription.ProcessingStatus != ProcessingStatus.OK;

            // FOR RECURRING SUBSCRIPTION THIS IS DATE WHEN LAST ORDER WAS CREATED FOR SUBSCRIPTION.
            UpdateLastOrderDateForDisplay();


            // FOR RECURRING SUBSCRIPTION THIS IS DATE WHEN NEXT ORDER WILL BE CREATED FOR SUBSCRIPTION.
            DateTime nextOrderDate = _Subscription.NextOrderDateForDisplay;

            if (_Subscription.ExpirationDate > DateTime.MinValue && _Subscription.ExpirationDate.Value.Year != DateTime.MaxValue.Year)
            {
                Expiration.Text = string.Format("{0:d}", _Subscription.ExpirationDate);
            }
            else
            {
                Expiration.Text = "N/A";
            }
            if (_Subscription.IsActive && nextOrderDate != DateTime.MinValue)
            {
                NextOrderDate.Text = string.Format("{0:d}", nextOrderDate);
            }
            else
            {
                NextOrderDate.Text = "N/A";
            }

            ListItem frequencyItem = Frequency.Items.FindByValue(_Subscription.PaymentFrequency.ToString());

            if (frequencyItem != null)
            {
                frequencyItem.Selected = true;
            }
            BasePrice.Text   = _Subscription.BasePrice.LSCurrencyFormat("ulc");
            BaseTaxCode.Text = _Subscription.BaseTaxCode != null ? _Subscription.BaseTaxCode.Name : "N/A";
            if (_Subscription.RecurringChargeEx > 0)
            {
                RecurringCharge.Text = _Subscription.RecurringChargeEx.LSCurrencyFormat("ulc");
            }
            else
            {
                RecurringCharge.Text = string.Empty;
            }
            RecurringChargeMode.Text = _Subscription.RecurringChargeMode.ToString();
            RecurringTaxCode.Text    = _Subscription.RecurringTaxCodeEx != null ? _Subscription.RecurringTaxCodeEx.Name : "N/A";
            if (_Subscription.NumberOfPayments > 0)
            {
                NumberOfPayments.Text = _Subscription.NumberOfPayments.ToString();
            }
            else
            {
                NumberOfPayments.Text = string.Empty;
            }
            BillingAddressLink.NavigateUrl = string.Format(BillingAddressLink.NavigateUrl, user.Id, _SubscriptionId);
            BillingAddressLiteral.Text     = _Subscription.FormatBillAddress(true);
            bool isShippable = _Subscription.OrderItem.Shippable != CommerceBuilder.Shipping.Shippable.No;

            ShippingAddressLiteral.Text = isShippable ? _Subscription.FormatShipAddress(true) : "N/A";
            PaymentInfo.Text            = _Subscription.PaymentProfile == null ? "N/A" : _Subscription.PaymentProfile.NameAndTypeWithReference;
            ShippingAddress1.Visible    = isShippable;
        }