Esempio n. 1
0
    protected LongRunningTaskStatusInfo processOrder(IConciergeAPIService api)
    {
        var processedOrderPacket = api.PreProcessOrder(targetOrder).ResultValue;

        cleanOrder = processedOrderPacket.FinalizedOrder.ConvertTo <msOrder>();

        //Reset the total because a donation can be any amount - the product price returned from preprocessing is just the "suggested donation"
        cleanOrder.LineItems[0].Total = targetOrder.Total;

        // now, let's set the total - in case the product has added additional stuff like shipping/taxes
        cleanOrder.Total = cleanOrder.LineItems.Sum(x => x.Total);

        cleanOrder.PaymentMethod            = OrderPaymentMethod.CreditCard;
        cleanOrder.CreditCardNumber         = targetCreditCard.CardNumber;
        cleanOrder.CreditCardExpirationDate = targetCreditCard.CardExpirationDate;
        cleanOrder.CCVCode = targetCreditCard.CCVCode;


        cleanOrder.BillingAddress = acBillingAddress.Address;
        // cleanOrder.BillingEmailAddress = tbEmailAddress.Text;


        var info = api.ProcessOrder(cleanOrder, null).ResultValue;

        // let's wait
        return(OrderUtilities.WaitForOrderToComplete(api, info));
    }
Esempio n. 2
0
    protected void btnPlaceOrder_Click(object sender, EventArgs e)
    {
        const string ContentSuffix = "_Contents";

        if (!IsValid)
        {
            return;
        }

        lock (threadLock)
        {
            if (targetOrder == null)
            {
                Refresh();
                return;
            }

            targetOrder.Notes = tbNotesComments.Text;

            // add cross sell
            var csi = MultiStepWizards.PlaceAnOrder.CrossSellItems;
            if (csi != null && csi.Count > 0)
            {
                targetOrder.LineItems.AddRange(csi.FindAll(x => x.Quantity != 0)); // add any cross sell items
            }
            using (var api = GetServiceAPIProxy())
            {
                var msPayload = new List <MemberSuiteObject>();
                // Go over line items and generate payoads for all attachments realted fields.
                foreach (var lineItem in targetOrder.LineItems)
                {
                    // We're looking for _Content only. _Content has to be of MemberSuiteFile type.
                    var attachments = lineItem.Fields.Where(f => f.Key.EndsWith(ContentSuffix) && IsNonEmptyMemberSuiteFile(f.Value))
                                      .Select(c =>
                    {
                        var msf = (MemberSuiteFile)c.Value;
                        // Generate ID
                        var fileId = api.GenerateIdentifer("File").ResultValue;
                        // Create ms object...
                        var mso                     = new MemberSuiteObject();
                        mso.ClassType               = "File";
                        mso.Fields["ID"]            = fileId;
                        mso.Fields["FileContents"]  = msf.FileContents;
                        mso.Fields["Name"]          = msf.FileName;
                        mso.Fields["ContentLength"] = msf.FileContents.Length;

                        return(new { Key = c.Key.Replace(ContentSuffix, string.Empty), FileId = fileId, File = mso });
                    });

                    if (attachments.Count() > 0)
                    {
                        foreach (var a in attachments)
                        {
                            // JES product fullfillment logic expects an xml file to save.. Copy relevant values into MemberSuiteFile & serializer it to send to JES (MS-6424)
                            //
                            var ms = new MemberSuiteFile();
                            ms.FileName     = a.File.SafeGetValue <string>("Name");
                            ms.FileContents = a.File.SafeGetValue <byte[]>("FileContents");
                            ms.FileType     = a.File.SafeGetValue <string>("FileType"); //we don't currently have this


                            var xml = MemberSuite.SDK.Utilities.Xml.Serialize(ms);


                            lineItem.Options.Add(new NameValueStringPair {
                                Name = a.Key, Value = xml
                            });
                            // Add according ms file to payload.
                            msPayload.Add(a.File);
                        }
                    }
                }

                OrderPayload payload = MultiStepWizards.PlaceAnOrder.Payload;

                if (msPayload.Count() > 0)
                {
                    if (payload == null)
                    {
                        payload = new OrderPayload();
                    }

                    if (payload.ObjectsToSave == null)
                    {
                        payload.ObjectsToSave = new List <MemberSuiteObject>();
                    }

                    payload.ObjectsToSave.AddRange(msPayload);
                }

                if (targetOrder.Date == DateTime.MinValue)
                {
                    targetOrder.Date = DateTime.Now;
                }

                var processedOrderPacket = api.PreProcessOrder(targetOrder).ResultValue;
                cleanOrder       = processedOrderPacket.FinalizedOrder.ConvertTo <msOrder>();
                cleanOrder.Total = processedOrderPacket.Total;

                //if (string.IsNullOrWhiteSpace(cleanOrder.BillingEmailAddress))
                //    cleanOrder.BillingEmailAddress = CurrentUser.EmailAddress;

                if (MultiStepWizards.RegisterForEvent.IsSessionSwap)
                {
                    var swapResult = api.SwapSessions(
                        MultiStepWizards.RegisterForEvent.SwapRegistrationID,
                        MultiStepWizards.RegisterForEvent.SessionsToCancel,
                        cleanOrder);

                    if (!swapResult.Success)
                    {
                        QueueBannerError(swapResult.FirstErrorMessage);
                    }
                    else
                    {
                        QueueBannerMessage("Session updates complete.");
                    }

                    MultiStepWizards.RegisterForEvent.Clear();
                    GoTo(MultiStepWizards.PlaceAnOrder.OrderCompleteUrl ?? "OrderComplete.aspx");
                }

                var processInfo = api.ProcessOrder(cleanOrder, payload).ResultValue;


                // let's wait for the order
                var processStatus = OrderUtilities.WaitForOrderToComplete(api, processInfo);

                if (processStatus.Status == LongRunningTaskStatus.Failed)
                {
                    throw new ConciergeClientException(
                              MemberSuite.SDK.Concierge.ConciergeErrorCode.IllegalOperation,
                              processStatus.AdditionalInfo);
                }

                string url = MultiStepWizards.PlaceAnOrder.OrderCompleteUrl ?? "OrderComplete.aspx";
                if (url.Contains("?"))
                {
                    url += "&";
                }
                else
                {
                    url += "?";
                }


                targetOrder = null;

                // clear the cart
                if (isTransient)
                {
                    // clear out the items
                    if (MultiStepWizards.PlaceAnOrder.TransientShoppingCart != null)
                    {
                        MultiStepWizards.PlaceAnOrder.TransientShoppingCart.LineItems.Clear();
                    }

                    MultiStepWizards.PlaceAnOrder.TransientShoppingCart = null;
                }
                else
                {
                    MultiStepWizards.PlaceAnOrder.ShoppingCart       = null;
                    MultiStepWizards.PlaceAnOrder.RecentlyAddedItems = null;
                }

                MultiStepWizards.PlaceAnOrder.CrossSellItems = null;



                MultiStepWizards.PlaceAnOrder.EditOrderLineItem                    = null; // clear this out
                MultiStepWizards.PlaceAnOrder.EditOrderLineItemProductName         = null; // clear this out
                MultiStepWizards.PlaceAnOrder.EditOrderLineItemProductDemographics = null; // clear this out
                MultiStepWizards.PlaceAnOrder.OrderConfirmationPacket              = null;

                if (processStatus.Status == LongRunningTaskStatus.Running)
                {
                    // MS-5204. Don't create job posting here. If JES is down then, job posting will be created
                    // during order processing. Otherwise we'll endup with duplicate job postings.
                    // hack - let's save the job posting
                    //if (MultiStepWizards.PostAJob.JobPosting != null)
                    //    SaveObject(MultiStepWizards.PostAJob.JobPosting);

                    MultiStepWizards.PostAJob.JobPosting = null;

                    GoTo("OrderQueued.aspx");
                }

                var order = LoadObjectFromAPI <msOrder>(processStatus.WorkflowID);
                QueueBannerMessage(string.Format("Order #{0} was processed successfully.",
                                                 order.SafeGetValue <long>(
                                                     msLocallyIdentifiableAssociationDomainObject.FIELDS.LocalID)));

                url += "orderID=" + order.ID;

                if (!url.Contains("contextID="))
                {
                    url += "&contextID=" + order.ID;
                }

                GoTo(url);
            }
        }
    }