void CheckingOut(object sender, CheckingOutEventArgs e)
 {
     //MAKE SURE WE HAVE VALIDATED THIS FORM
     Page.Validate("OPC");
     //IF ANYTHING WAS INVALID CANCEL CHECKOUT
     if (!Page.IsValid)
     {
         e.Cancel = true;
     }
     //MAKE SURE THE SHIPPING MESSAGE IS SET
     if (!e.Cancel)
     {
         int shipmentIndex = 0;
         foreach (RepeaterItem item in ShipmentList.Items)
         {
             BasketShipment shipment    = _Basket.Shipments[shipmentIndex];
             TextBox        shipMessage = (TextBox)item.FindControl("ShipMessage");
             if (shipMessage != null)
             {
                 shipment.ShipMessage = StringHelper.Truncate(shipMessage.Text, 200);
                 shipment.Save();
             }
             shipmentIndex++;
         }
     }
 }
 private void CheckingOutHandler(object sender, CheckingOutEventArgs e)
 {
     CouponCodeRequired.Enabled = false;
     if (CheckingOut != null)
     {
         CheckingOut(sender, e);
     }
     CouponCodeRequired.Enabled = true;
 }
Exemple #3
0
        protected void CreditCardButton_Click(object sender, EventArgs e)
        {
            if (Page.IsValid && CustomValidation())
            {
                //CREATE THE PAYMENT OBJECT
                Payment payment = GetPayment();
                //PROCESS CHECKING OUT EVENT
                bool checkOut = true;
                if (CheckingOut != null)
                {
                    CheckingOutEventArgs c = new CheckingOutEventArgs(payment);
                    CheckingOut(this, c);
                    checkOut = !c.Cancel;
                }
                if (checkOut)
                {
                    //PROCESS A CHECKOUT
                    ICheckoutService checkoutService  = AbleContext.Resolve <ICheckoutService>();
                    CheckoutRequest  checkoutRequest  = new CheckoutRequest(_Basket, payment);
                    CheckoutResponse checkoutResponse = checkoutService.ExecuteCheckout(checkoutRequest, false);
                    if (checkoutResponse.Success)
                    {
                        if (CheckedOut != null)
                        {
                            CheckedOut(this, new CheckedOutEventArgs(checkoutResponse));
                        }
                        Response.Redirect(AbleCommerce.Code.NavigationHelper.GetReceiptUrl(checkoutResponse.Order.OrderNumber));
                    }
                    else
                    {
                        IList <string> warningMessages = checkoutResponse.WarningMessages;
                        if (warningMessages.Count == 0)
                        {
                            warningMessages.Add("The order could not be submitted at this time.  Please try again later or contact us for assistance.");
                        }
                        if (CheckedOut != null)
                        {
                            CheckedOut(this, new CheckedOutEventArgs(checkoutResponse));
                        }
                    }
                }
            }
            else
            {
                CreditCardButton.Text = "Pay With Card";
            }

            // IF NOT SUCCESSFULL / ENABLE THE CHECKOUT BUTTON
            CreditCardButton.Enabled = true;
            FormIsSubmitted.Value    = "0";
        }
Exemple #4
0
        private void PostCheckoutPayment(object sender, CheckingOutEventArgs e)
        {
            // VALIDATE THE PAYMENT
            if (e.Payment.Amount > 0 && e.Payment.Amount <= Order.GetCustomerBalance())
            {
                bool result = PayOrder(e.Payment);
                if (result)
                {
                    Response.Redirect(AbleCommerce.Code.NavigationHelper.GetStoreUrl(this.Page, "Mobile/Members/MyOrder.aspx?OrderNumber=" + this.Order.OrderNumber));
                }
            }

            // CANCEL PENDING CHECKOUT
            e.Cancel = true;
        }
Exemple #5
0
 protected void CheckButton_Click(object sender, EventArgs e)
 {
     if (Page.IsValid)
     {
         //CREATE THE PAYMENT OBJECT
         Payment payment = GetPayment();
         //PROCESS CHECKING OUT EVENT
         bool checkOut = true;
         if (CheckingOut != null)
         {
             CheckingOutEventArgs c = new CheckingOutEventArgs(payment);
             CheckingOut(this, c);
             checkOut = !c.Cancel;
         }
         if (checkOut)
         {
             //PROCESS THE CHECKOUT
             ICheckoutService checkoutService  = AbleContext.Resolve <ICheckoutService>();
             CheckoutRequest  checkoutRequest  = new CheckoutRequest(_Basket, payment);
             CheckoutResponse checkoutResponse = checkoutService.ExecuteCheckout(checkoutRequest, false);
             if (checkoutResponse.Success)
             {
                 if (CheckedOut != null)
                 {
                     CheckedOut(this, new CheckedOutEventArgs(checkoutResponse));
                 }
                 Response.Redirect(AbleCommerce.Code.NavigationHelper.GetReceiptUrl(checkoutResponse.Order.OrderNumber));
             }
             else
             {
                 IList <string> warningMessages = checkoutResponse.WarningMessages;
                 if (warningMessages.Count == 0)
                 {
                     warningMessages.Add("The order could not be submitted at this time.  Please try again later or contact us for assistance.");
                 }
                 if (CheckedOut != null)
                 {
                     CheckedOut(this, new CheckedOutEventArgs(checkoutResponse));
                 }
             }
         }
     }
     else
     {
         CheckButton.Text = string.Format("Pay by {0}", _PaymentMethod.Name);
     }
 }
        protected void PhoneCallButton_Click(object sender, EventArgs e)
        {
            // CREATE THE PAYMENT OBJECT
            Payment payment = GetPayment();

            payment.ReferenceNumber = AbleContext.Current.User.PrimaryAddress.Phone;

            // PROCESS CHECKING OUT EVENT
            bool checkOut = true;

            if (CheckingOut != null)
            {
                CheckingOutEventArgs c = new CheckingOutEventArgs(payment);
                CheckingOut(this, c);
                checkOut = !c.Cancel;
            }
            if (checkOut)
            {
                // CONTINUE TO PROCESS THE CHECKOUT
                Basket           basket           = AbleContext.Current.User.Basket;
                ICheckoutService checkoutService  = AbleContext.Resolve <ICheckoutService>();
                CheckoutRequest  checkoutRequest  = new CheckoutRequest(basket, payment);
                CheckoutResponse checkoutResponse = checkoutService.ExecuteCheckout(checkoutRequest);
                if (checkoutResponse.Success)
                {
                    if (CheckedOut != null)
                    {
                        CheckedOut(this, new CheckedOutEventArgs(checkoutResponse));
                    }
                    Response.Redirect(AbleCommerce.Code.NavigationHelper.GetReceiptUrl(checkoutResponse.Order.OrderNumber));
                }
                else
                {
                    IList <string> warningMessages = checkoutResponse.WarningMessages;
                    if (warningMessages.Count == 0)
                    {
                        warningMessages.Add("The order could not be submitted at this time.  Please try again later or contact us for assistance.");
                    }
                    if (CheckedOut != null)
                    {
                        CheckedOut(this, new CheckedOutEventArgs(checkoutResponse));
                    }
                }
            }
        }
Exemple #7
0
        protected void CompleteButton_Click(object sender, EventArgs e)
        {
            bool checkOut = true;

            if (CheckingOut != null)
            {
                CheckingOutEventArgs c = new CheckingOutEventArgs();
                CheckingOut(this, c);
                checkOut = !c.Cancel;
            }
            if (checkOut)
            {
                Basket basket = AbleContext.Current.User.Basket;
                //PROCESS THE CHECKOUT
                ICheckoutService checkoutService  = AbleContext.Resolve <ICheckoutService>();
                CheckoutRequest  checkoutRequest  = new CheckoutRequest(basket);
                CheckoutResponse checkoutResponse = checkoutService.ExecuteCheckout(checkoutRequest);
                if (checkoutResponse.Success)
                {
                    if (CheckedOut != null)
                    {
                        CheckedOut(this, new CheckedOutEventArgs(checkoutResponse));
                    }
                    Response.Redirect(AbleCommerce.Code.NavigationHelper.GetReceiptUrl(checkoutResponse.Order.OrderNumber));
                }
                else
                {
                    IList <string> warningMessages = checkoutResponse.WarningMessages;
                    if (warningMessages.Count == 0)
                    {
                        warningMessages.Add("The order could not be submitted at this time.  Please try again later or contact us for assistance.");
                    }
                    if (CheckedOut != null)
                    {
                        CheckedOut(this, new CheckedOutEventArgs(checkoutResponse));
                    }
                }
            }
        }
Exemple #8
0
 protected void GiftCertificateButton_Click(object sender, EventArgs e)
 {
     if (Page.IsValid)
     {
         bool checkOut = true;
         if (CheckingOut != null)
         {
             // CREATE THE PAYMENT OBJECT
             Payment payment        = GetPayment();
             CheckingOutEventArgs c = new CheckingOutEventArgs(payment);
             CheckingOut(this, c);
             checkOut = !c.Cancel;
         }
         if (checkOut)
         {
             Basket basket = AbleContext.Current.User.Basket;
             GiftCertificateNumber.Text = StringHelper.StripHtml(GiftCertificateNumber.Text);
             GiftCertificate gc = GiftCertificateDataSource.LoadForSerialNumber(GiftCertificateNumber.Text);
             if (gc == null)
             {
                 GiftCertPaymentErrors.Text = "This is not a valid gift certificate : " + GiftCertificateNumber.Text;
             }
             else if (gc.Balance <= 0)
             {
                 GiftCertPaymentErrors.Text = "There is no balance left for this gift certificate : " + GiftCertificateNumber.Text;
             }
             else if (gc.IsExpired())
             {
                 GiftCertPaymentErrors.Text = "This gift certificate is expired : " + GiftCertificateNumber.Text;
             }
             else if (AlreadyInUse(basket, gc))
             {
                 GiftCertPaymentErrors.Text = "This gift certificate is already applied to your basket : " + GiftCertificateNumber.Text;
             }
             else
             {
                 // process this gift certificate
                 decimal    basketTotal = basket.Items.TotalPrice();
                 BasketItem bitem       = new BasketItem();
                 bitem.Basket        = basket;
                 bitem.OrderItemType = OrderItemType.GiftCertificatePayment;
                 bitem.Price         = -(gc.Balance > basketTotal ? basketTotal : gc.Balance);
                 bitem.Quantity      = 1;
                 bitem.Name          = gc.Name;
                 bitem.Sku           = gc.SerialNumber;
                 basket.Items.Add(bitem);
                 basket.Save();
                 decimal remBalance = basket.Items.TotalPrice();
                 if (remBalance > 0)
                 {
                     GiftCertPaymentErrors.Text = string.Format("A payment of {0} will be made using gift certificate {1}. It will leave a balance of {2} for this order. Please make additional payments.", gc.Balance.LSCurrencyFormat("lc"), GiftCertificateNumber.Text, remBalance.LSCurrencyFormat("lc"));
                 }
                 else
                 {
                     //payment done. process checkout
                     ICheckoutService checkoutService  = AbleContext.Resolve <ICheckoutService>();
                     CheckoutRequest  checkoutRequest  = new CheckoutRequest(basket);
                     CheckoutResponse checkoutResponse = checkoutService.ExecuteCheckout(checkoutRequest);
                     if (checkoutResponse.Success)
                     {
                         if (CheckedOut != null)
                         {
                             CheckedOut(this, new CheckedOutEventArgs(checkoutResponse));
                         }
                         Response.Redirect(AbleCommerce.Code.NavigationHelper.GetReceiptUrl(checkoutResponse.Order.OrderNumber));
                     }
                     else
                     {
                         IList <string> warningMessages = checkoutResponse.WarningMessages;
                         if (warningMessages.Count == 0)
                         {
                             warningMessages.Add("The order could not be submitted at this time.  Please try again later or contact us for assistance.");
                         }
                         if (CheckedOut != null)
                         {
                             CheckedOut(this, new CheckedOutEventArgs(checkoutResponse));
                         }
                     }
                 }
             }
             if (!string.IsNullOrEmpty(GiftCertPaymentErrors.Text))
             {
                 GiftCertErrorsPanel.Visible = true;
             }
         }
     }
 }
Exemple #9
0
        protected void CheckingOut(object sender, CheckingOutEventArgs e)
        {
            Page.Validate();
            if (!Page.IsValid)
            {
                e.Cancel = true;
                return;
            }

            if (Page.IsValid)
            {
                if (!string.IsNullOrEmpty(Comments.Text))
                {
                    foreach (BasketShipment shipment in _basket.Shipments)
                    {
                        shipment.ShipMessage = StringHelper.StripHtml(Comments.Text);
                        shipment.Save();
                    }
                }
            }

            //Make sure basket hasn't changed during checkout
            if (_CurrentBasketHash != _SavedBasketHash)
            {
                e.Cancel = true;
                CheckoutMessagePanel.Visible = true;
                CheckoutMessage.Text         = "Your order has not been completed and payment was not processed.<br /><br />Your cart appears to have been modified during checkout.  Please verify the contents of your order and resubmit your payment.";
                RecalculateBasket(true);

                return;
            }

            //Make sure that a valid billing address is set
            User user = AbleContext.Current.User;

            if (user.PrimaryAddress == null || !user.PrimaryAddress.IsValid)
            {
                e.Cancel = true;

                CheckoutMessagePanel.Visible = true;
                CheckoutMessage.Text         = "Your order has not been completed and payment was not processed.<br /><br />The billing address is invalid.  Please correct the address and resubmit your payment.";

                return;
            }

            if (AbleContext.Current.User.IsAnonymous)
            {
                // ANONYMOUS USER SELECTING GUEST CHECKOUT, CREATE TEMPORARY ACCOUNT
                User   oldUser     = AbleContext.Current.User;
                string newUserName = "******" + Guid.NewGuid().ToString("N") + "@domain.xyz";
                string newEmail    = StringHelper.StripHtml(oldUser.PrimaryAddress.Email);
                string newPassword = Guid.NewGuid().ToString("N");
                MembershipCreateStatus createStatus;
                User newUser = UserDataSource.CreateUser(newUserName, newEmail, newPassword, string.Empty, string.Empty, true, 0, out createStatus);

                // IF THE CREATE FAILS, IGNORE AND CONTINUE CREATING THE ORDER
                if (createStatus == MembershipCreateStatus.Success)
                {
                    // CHANGE THE NAME AND EMAIL TO SOMETHING MORE FRIENDLY THAN GUID
                    newUser.UserName = "******" + newUser.Id.ToString() + "@domain.xyz";
                    newUser.Save();
                    CommerceBuilder.Users.User.Migrate(oldUser, newUser, true, true, true);
                    AbleContext.Current.User = newUser;
                    FormsAuthentication.SetAuthCookie(newUser.UserName, false);
                }
            }
        }
        protected void CompleteButton_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                bool checkOut = true;
                if (CheckingOut != null)
                {
                    CheckingOutEventArgs c = new CheckingOutEventArgs();
                    CheckingOut(this, c);
                    checkOut = !c.Cancel;
                }
                if (checkOut)
                {
                    Basket basket = AbleContext.Current.User.Basket;
                    //PROCESS THE CHECKOUT
                    ICheckoutService checkoutService  = AbleContext.Resolve <ICheckoutService>();
                    CheckoutRequest  checkoutRequest  = new CheckoutRequest(basket);
                    CheckoutResponse checkoutResponse = checkoutService.ExecuteCheckout(checkoutRequest);
                    if (checkoutResponse.Success)
                    {
                        GatewayPaymentProfile profile = null;
                        this.Visible = true;

                        if (ProfilesPH.Visible)
                        {
                            profile = GatewayPaymentProfileDataSource.Load(AlwaysConvert.ToInt(ProfilesList.SelectedValue));
                        }

                        if (CardPH.Visible)
                        {
                            AccountDataDictionary cardDetails = new AccountDataDictionary();
                            cardDetails["AccountName"]     = CardName.Text.Trim();
                            cardDetails["AccountNumber"]   = CardNumber.Text.Trim();
                            cardDetails["ExpirationMonth"] = ExpirationMonth.SelectedItem.Value;
                            cardDetails["ExpirationYear"]  = ExpirationYear.SelectedItem.Value;
                            cardDetails["SecurityCode"]    = SecurityCode.Text.Trim();
                            profile = CreateProfile(cardDetails);
                        }

                        if (profile != null)
                        {
                            IList <Subscription> subscriptions = SubscriptionDataSource.LoadForOrder(checkoutResponse.Order.Id);
                            foreach (Subscription subscription in subscriptions)
                            {
                                if (subscription.PaymentFrequency.HasValue && subscription.PaymentFrequencyUnit.HasValue)
                                {
                                    subscription.PaymentProfile        = profile;
                                    subscription.PaymentProcessingType = PaymentProcessingType.ArbProfileManaged;
                                    subscription.Save();
                                }
                            }
                        }

                        if (CheckedOut != null)
                        {
                            CheckedOut(this, new CheckedOutEventArgs(checkoutResponse));
                        }
                        Response.Redirect(AbleCommerce.Code.NavigationHelper.GetReceiptUrl(checkoutResponse.Order.OrderNumber));
                    }
                    else
                    {
                        IList <string> warningMessages = checkoutResponse.WarningMessages;
                        if (warningMessages.Count == 0)
                        {
                            warningMessages.Add("The order could not be submitted at this time.  Please try again later or contact us for assistance.");
                        }
                        if (CheckedOut != null)
                        {
                            CheckedOut(this, new CheckedOutEventArgs(checkoutResponse));
                        }
                    }
                }
            }
        }
        protected void CreditCardButton_Click(object sender, EventArgs e)
        {
            if (Page.IsValid && CustomValidation())
            {
                // CREATE THE PAYMENT OBJECT
                Payment payment = GetPayment();

                // PROCESS CHECKING OUT EVENT
                bool checkOut = true;
                if (CheckingOut != null)
                {
                    CheckingOutEventArgs c = new CheckingOutEventArgs(payment);
                    CheckingOut(this, c);
                    checkOut = !c.Cancel;
                }

                if (checkOut)
                {
                    // CONTINUE TO PROCESS THE CHECKOUT
                    Basket           basket           = AbleContext.Current.User.Basket;
                    ICheckoutService checkoutService  = AbleContext.Resolve <ICheckoutService>();
                    CheckoutRequest  checkoutRequest  = new CheckoutRequest(basket, payment);
                    CheckoutResponse checkoutResponse = checkoutService.ExecuteCheckout(checkoutRequest);
                    if (checkoutResponse.Success)
                    {
                        GatewayPaymentProfile profile = null;
                        if (trSaveCard.Visible && SaveCard.Checked)
                        {
                            AccountDataDictionary cardDetails = new AccountDataDictionary();
                            cardDetails["AccountName"]     = CardName.Text.Trim();
                            cardDetails["AccountNumber"]   = CardNumber.Text.Trim();
                            cardDetails["ExpirationMonth"] = ExpirationMonth.SelectedItem.Value;
                            cardDetails["ExpirationYear"]  = ExpirationYear.SelectedItem.Value;
                            cardDetails["SecurityCode"]    = SecurityCode.Text.Trim();
                            profile = CreateProfile(cardDetails);
                        }

                        if (AbleContext.Current.Store.Settings.ROCreateNewOrdersEnabled && OrderHelper.HasRecurringSubscriptions(checkoutResponse.Order))
                        {
                            IList <Subscription> subscriptions = SubscriptionDataSource.LoadForOrder(checkoutResponse.Order.Id);
                            foreach (Subscription subscription in subscriptions)
                            {
                                OrderItem oi = subscription.OrderItem;
                                if (oi != null && oi.Price == 0 && OrderHelper.HasRecurringSubscriptions(oi) && subscription.PaymentProfile == null)
                                {
                                    if (profile == null)
                                    {
                                        if (ProfilesPH.Visible)
                                        {
                                            profile = GatewayPaymentProfileDataSource.Load(AlwaysConvert.ToInt(ProfilesList.SelectedValue));
                                        }

                                        if (CardPH.Visible)
                                        {
                                            AccountDataDictionary cardDetails = new AccountDataDictionary();
                                            cardDetails["AccountName"]     = CardName.Text.Trim();
                                            cardDetails["AccountNumber"]   = CardNumber.Text.Trim();
                                            cardDetails["ExpirationMonth"] = ExpirationMonth.SelectedItem.Value;
                                            cardDetails["ExpirationYear"]  = ExpirationYear.SelectedItem.Value;
                                            cardDetails["SecurityCode"]    = SecurityCode.Text.Trim();
                                            profile = CreateProfile(cardDetails);
                                        }
                                    }

                                    subscription.PaymentProfile        = profile;
                                    subscription.PaymentProcessingType = PaymentProcessingType.ArbProfileManaged;
                                    subscription.Save();
                                }
                            }
                        }

                        if (profile != null && payment.PaymentProfile == null)
                        {
                            payment.PaymentProfile = profile;
                            payment.Save();
                        }

                        if (CheckedOut != null)
                        {
                            CheckedOut(this, new CheckedOutEventArgs(checkoutResponse));
                        }
                        Response.Redirect(AbleCommerce.Code.NavigationHelper.GetReceiptUrl(checkoutResponse.Order.OrderNumber));
                    }
                    else
                    {
                        IList <string> warningMessages = checkoutResponse.WarningMessages;
                        if (warningMessages.Count == 0)
                        {
                            warningMessages.Add("The order could not be submitted at this time.  Please try again later or contact us for assistance.");
                        }
                        if (CheckedOut != null)
                        {
                            CheckedOut(this, new CheckedOutEventArgs(checkoutResponse));
                        }
                    }
                }
            }
        }
Exemple #12
0
        protected void CreditCardButton_Click(object sender, EventArgs e)
        {
            if (Page.IsValid && CustomValidation())
            {
                // CREATE THE PAYMENT OBJECT
                Payment payment = GetPayment();

                // PROCESS CHECKING OUT EVENT
                bool checkOut = true;
                if (CheckingOut != null)
                {
                    CheckingOutEventArgs c = new CheckingOutEventArgs(payment);
                    CheckingOut(this, c);
                    checkOut = !c.Cancel;
                }

                if (checkOut)
                {
                    // CONTINUE TO PROCESS THE CHECKOUT
                    Basket           basket           = AbleContext.Current.User.Basket;
                    ICheckoutService checkoutService  = AbleContext.Resolve <ICheckoutService>();
                    CheckoutRequest  checkoutRequest  = new CheckoutRequest(basket, payment);
                    CheckoutResponse checkoutResponse = checkoutService.ExecuteCheckout(checkoutRequest);
                    if (checkoutResponse.Success)
                    {
                        if (trSaveCard.Visible && SaveCard.Checked)
                        {
                            AccountDataDictionary cardDetails = new AccountDataDictionary();
                            cardDetails["AccountName"]     = CardName.Text.Trim();
                            cardDetails["AccountNumber"]   = CardNumber.Text.Trim();
                            cardDetails["ExpirationMonth"] = ExpirationMonth.SelectedItem.Value;
                            cardDetails["ExpirationYear"]  = ExpirationYear.SelectedItem.Value;
                            cardDetails["SecurityCode"]    = SecurityCode.Text.Trim();
                            PaymentMethod         method  = PaymentMethodDataSource.Load(AlwaysConvert.ToInt(CardType.SelectedValue));
                            PaymentGateway        gateway = method.PaymentGateway;
                            PaymentInstrumentData instr   = PaymentInstrumentData.CreateInstance(cardDetails, method.PaymentInstrumentType, null);
                            if (gateway != null)
                            {
                                var    provider          = gateway.GetInstance();
                                string customerProfileId = string.Empty;
                                var    profileResult     = _user.PaymentProfiles.Where(p => p.GatewayIdentifier == gateway.ClassId)
                                                           .GroupBy(p => p.CustomerProfileId)
                                                           .Take(1)
                                                           .Select(g => new { CustomerProfileId = g.Key })
                                                           .SingleOrDefault();

                                if (profileResult != null && !string.IsNullOrEmpty(profileResult.CustomerProfileId))
                                {
                                    customerProfileId = profileResult.CustomerProfileId;
                                }

                                if (string.IsNullOrEmpty(customerProfileId))
                                {
                                    try
                                    {
                                        var rsp = provider.DoCreateCustomerProfile(new CommerceBuilder.Payments.Providers.CreateCustomerProfileRequest(_user));
                                        if (rsp.Successful)
                                        {
                                            customerProfileId = rsp.CustomerProfileId;
                                        }
                                        else if (rsp.ResponseCode == "E00039")
                                        {
                                            var match = Regex.Match(rsp.ResponseMessage, @"\d+", RegexOptions.CultureInvariant);
                                            if (match.Success)
                                            {
                                                customerProfileId = match.Value;
                                            }
                                            else
                                            {
                                                Logger.Error(rsp.ResponseMessage);
                                            }
                                        }
                                        else
                                        {
                                            Logger.Error(rsp.ResponseMessage);
                                        }
                                    }
                                    catch (Exception exp)
                                    {
                                        Logger.Error(exp.Message);
                                    }
                                }

                                try
                                {
                                    var rsp = provider.DoCreatePaymentProfile(new CommerceBuilder.Payments.Providers.CreatePaymentProfileRequest(_user, instr, customerProfileId)
                                    {
                                        ValidateProfile = true
                                    });
                                    if (rsp.Successful)
                                    {
                                        GatewayPaymentProfile gwprofile = new GatewayPaymentProfile();
                                        gwprofile.NameOnCard        = CardName.Text.Trim();;
                                        gwprofile.Expiry            = Misc.GetStartOfDate(new DateTime(AlwaysConvert.ToInt(ExpirationYear.SelectedItem.Value), AlwaysConvert.ToInt(ExpirationMonth.SelectedItem.Value), 1));
                                        gwprofile.CustomerProfileId = customerProfileId;
                                        gwprofile.PaymentProfileId  = rsp.PaymentProfileId;
                                        gwprofile.ReferenceNumber   = StringHelper.MakeReferenceNumber(cardDetails["AccountNumber"]);
                                        gwprofile.User              = _user;
                                        gwprofile.InstrumentType    = instr.InstrumentType;
                                        gwprofile.PaymentMethodName = method.Name;
                                        gwprofile.GatewayIdentifier = gateway.ClassId;
                                        gwprofile.Save();
                                        CardName.Text   = string.Empty;
                                        CardNumber.Text = string.Empty;
                                        ExpirationMonth.SelectedIndex = 0;
                                        ExpirationYear.SelectedIndex  = 0;
                                    }
                                }
                                catch (Exception exp)
                                {
                                    Logger.Error(exp.Message);
                                }
                            }
                        }

                        if (CheckedOut != null)
                        {
                            CheckedOut(this, new CheckedOutEventArgs(checkoutResponse));
                        }
                        Response.Redirect(AbleCommerce.Code.NavigationHelper.GetReceiptUrl(checkoutResponse.Order.OrderNumber));
                    }
                    else
                    {
                        IList <string> warningMessages = checkoutResponse.WarningMessages;
                        if (warningMessages.Count == 0)
                        {
                            warningMessages.Add("The order could not be submitted at this time.  Please try again later or contact us for assistance.");
                        }
                        if (CheckedOut != null)
                        {
                            CheckedOut(this, new CheckedOutEventArgs(checkoutResponse));
                        }
                    }
                }
            }
        }
        protected void MailButton_Click(object sender, EventArgs e)
        {
            // CREATE THE PAYMENT OBJECT
            Payment payment = GetPayment();

            // PROCESS CHECKING OUT EVENT
            bool checkOut = true;

            if (CheckingOut != null)
            {
                CheckingOutEventArgs c = new CheckingOutEventArgs(payment);
                CheckingOut(this, c);
                checkOut = !c.Cancel;
            }
            if (checkOut)
            {
                // CONTINUE TO PROCESS THE CHECKOUT
                Basket basket = AbleContext.Current.User.Basket;


                //Remove code?
                //ICheckoutService checkoutService = AbleContext.Resolve<ICheckoutService>();
                //CheckoutRequest checkoutRequest = new CheckoutRequest(basket, payment);
                //CheckoutResponse checkoutResponse = checkoutService.ExecuteCheckout(checkoutRequest);

                //CUSTOM: PROCESS THE CHECKOUT
                CheckoutRequest  checkoutRequest  = new CheckoutRequest(null);
                CheckoutResponse checkoutResponse = basket.Checkout(checkoutRequest);
                if (checkoutResponse.Success)
                {
                    Order order = new Order();

                    order = OrderDataSource.Load(checkoutResponse.OrderId);

                    Address address = AbleContext.Current.User.PrimaryAddress;

                    // Add the contact details to the saved order.
                    order.BillToEmail     = address.Email;
                    order.BillToFirstName = address.FirstName;
                    order.BillToLastName  = address.LastName;
                    order.BillToPhone     = address.Phone;
                    order.BillToCompany   = address.Company;
                    order.Save();

                    // Save the Comment entered on the Quote Form to the CustomFields table.
                    CustomField comment = new CustomField();
                    comment.FieldName    = "QuoteRequestComment";
                    comment.FieldValue   = Comments.Text;
                    comment.TableName    = "Orders";
                    comment.ForeignKeyId = order.Id;
                    comment.Store.Id     = order.StoreId;
                    comment.Save();

                    // The list of files that have been uploaded
                    List <FileAttachment> files = Session["UPLOADED_BASKET"] as List <FileAttachment>;

                    //CrmHelper.SaveEnquiry(order, StringHelper.StripHtml(Comments.Text), files, AbleContext.Current.Store);

                    if (checkoutResponse.Success)
                    {
                        if (CheckedOut != null)
                        {
                            CheckedOut(this, new CheckedOutEventArgs(checkoutResponse));
                        }
                        Response.Redirect(AbleCommerce.Code.NavigationHelper.GetReceiptUrl(checkoutResponse.Order.OrderNumber));
                    }
                    else
                    {
                        IList <string> warningMessages = checkoutResponse.WarningMessages;
                        if (warningMessages.Count == 0)
                        {
                            warningMessages.Add("The order could not be submitted at this time.  Please try again later or contact us for assistance.");
                        }
                        if (CheckedOut != null)
                        {
                            CheckedOut(this, new CheckedOutEventArgs(checkoutResponse));
                        }
                    }
                }
            }
        }