// Handling credit cards
    private SetAccountCreditCardTokenRequest Request_SaveNewCreditCardToAccount(AccountCreditCardType creditCardType)
    {
        SetAccountCreditCardTokenRequest request = new SetAccountCreditCardTokenRequest();

        request.CustomerID = Identity.Current.CustomerID;

        request.CreditCardToken = NewCreditCardPaymentToken;
        request.CreditCardAccountType = creditCardType;
        request.ExpirationMonth = Autoship.PropertyBag.CreditCardExpirationDate.Month;
        request.ExpirationYear = Autoship.PropertyBag.CreditCardExpirationDate.Year;

        request.BillingName = Autoship.PropertyBag.CreditCardNameOnCard;
        request.BillingAddress = Autoship.PropertyBag.CreditCardBillingAddress;
        request.BillingCity = Autoship.PropertyBag.CreditCardBillingCity;
        request.BillingState = Autoship.PropertyBag.CreditCardBillingState;
        request.BillingZip = Autoship.PropertyBag.CreditCardBillingZip;
        request.BillingCountry = Autoship.PropertyBag.CreditCardBillingCountry;

        return request;
    }
 public CreditCardOnFile(AccountCreditCardType creditCardType)
 {
     CreditCardType = creditCardType;
 }
    public bool IsCreditCardOnFileValid(AccountCreditCardType creditCardType)
    {
        var creditCardOnFile = CreditCardsOnFile.Where(c => c.CreditCardType == creditCardType).FirstOrDefault();

        if (creditCardOnFile == null) return false;

        TimeSpan expirationDateDifference = creditCardOnFile.ExpirationDate.Subtract(DateTime.Now);

        return (!string.IsNullOrEmpty(creditCardOnFile.CreditCardNumberDisplay)
                && expirationDateDifference.Days > 0
                && !string.IsNullOrEmpty(creditCardOnFile.NameOnCard)
                && !string.IsNullOrEmpty(creditCardOnFile.BillingAddress)
                && !string.IsNullOrEmpty(creditCardOnFile.BillingCity)
                && !string.IsNullOrEmpty(creditCardOnFile.BillingState)
                && !string.IsNullOrEmpty(creditCardOnFile.BillingZip)
                && !string.IsNullOrEmpty(creditCardOnFile.BillingCountry));
    }
    public void RenderCreditCardOnFile(AccountCreditCardType creditCardType)
    {
        if (IsCreditCardOnFileValid(creditCardType))
        {
            StringBuilder html = new StringBuilder();

            var creditCardOnFile = CreditCardsOnFile.Where(c => c.CreditCardType == creditCardType).FirstOrDefault();

            html.Append(@"
                <tr>
                    <td class='options'>
                        <a href=""" + Page.ClientScript.GetPostBackClientHyperlink(this, "UseCard|" + creditCardType.ToString()) + @""" class='btn btn-success Next'>
                            " + string.Format(Resources.Shopping.UseMy_Card, creditCardType.ToString().ToLower()) + @"</a>
                    </td>
                    <td class='description'>
                        <span class='producttitle'>"
                              + Resources.Shopping.CreditDebitEndingIn + " " + creditCardOnFile.CreditCardNumberDisplay.Replace("*", "") + @"</span>
                    </td>
                    <td class='nameoncard'>
                        " + creditCardOnFile.NameOnCard + @"
                    </td>
                    <td class='expirationdate'>
                        " + creditCardOnFile.ExpirationDate.ToString("M/yyyy") + @"
                    </td>
                </tr>
            ");


            HtmlTextWriter writer = new HtmlTextWriter(Response.Output);
            writer.Write(html.ToString());
        }
    }
    public void RenderCreditCardOnFile(AccountCreditCardType creditCardType)
    {
        string displayCardTypeToExigoButton = "";

        if (IsCreditCardOnFileValid(creditCardType))
        {
            StringBuilder html = new StringBuilder();

            var creditCardOnFile = CreditCardsOnFile.Where(c => c.CreditCardType == creditCardType).FirstOrDefault();

            //Check which card type the credit card is and display it on the exigo button.
            if (creditCardType.Equals(AccountCreditCardType.Primary))
            {
                displayCardTypeToExigoButton = Resources.Shopping.UsePrimaryCard;
            }
            else if(creditCardType.Equals(AccountCreditCardType.Secondary))
            {
                displayCardTypeToExigoButton = Resources.Shopping.UseSecondaryCard;
            }

            html.Append(@"
                <tr>
                    <td class='options'>
                        <a href=""" + Page.ClientScript.GetPostBackClientHyperlink(this, "UseCard|" + creditCardType.ToString()) + @""" class='btn btn-success'>"+displayCardTypeToExigoButton+@"</a>
                    </td>
                    <td class='description'>
                        <span class='producttitle'>
                            " + Resources.Shopping.CreditDebitEndingIn + " " + creditCardOnFile.CreditCardNumberDisplay.Replace("*", "") + @"</span>
                    </td>
                    <td class='nameoncard'>
                        " + creditCardOnFile.NameOnCard + @"
                    </td>
                    <td class='expirationdate'>
                        " + creditCardOnFile.ExpirationDate.ToString("M/yyyy") + @"
                    </td>
                </tr>
            ");


            HtmlTextWriter writer = new HtmlTextWriter(Response.Output);
            writer.Write(html.ToString());
        }
    }
    private ChargeCreditCardTokenOnFileRequest Request_ChargeCreditCardOnFile(AccountCreditCardType creditCardType)
    {
        ChargeCreditCardTokenOnFileRequest request = new ChargeCreditCardTokenOnFileRequest();

        request.CreditCardAccountType = creditCardType;

        return request;
    }