Dev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideLegal TermsGitHubDev CommunityOptimizely AcademySubmit a ticketLog In
Dev Guide

Extend the PunchOutOrderRequestParser

Describes how to extend the PunchOutOrderRequestParser in Optimizely Configured Commerce.

PunchOut is a mechanism by which the e-procurement application makes it possible for a buyer to access a supplier's website from the buyer's own procurement application.

Optimizely Configured Commerce integrates with PunchOut but may require customization. The following sample code shows how to extend the PunchOutOrderRequestParser to accommodate additional fields.

The following extends the schema by storing the new field's temporary storage using HttpContext as an item collection. Dependency injection will detect the new plug-in and use it automatically.

 using System;
    using System.Linq;
    using System.Xml;
    using InSite.Model.PunchOut;
    using InSite.PunchOut.Interfaces;
    using InSite.PunchOut;
    using System.Web;
    using System.Text.RegularExpressions;
    using InSite.Model;
    namespace Custom.Infrastructure.Plugins
    {
        public class PunchOutOrderRequestParser_Custom : PunchOutOrderRequestParser
            {
                public PunchOutOrderRequestParser_Custom(IXmlHelper xmlHelper,
                IPunchOutOrderRequestLineOutParser lineOutParser,
                IArgumentContract argumentContract)
                : base(xmlHelper, lineOutParser, argumentContract)
                { }
            public override PunchOutOrderRequest CreatePunchOutOrderMessageFromXml(string punchOutOrderMessage, string currentDomain)
            {
                // custom - replaced ScrubSharedSecretFromXml with a custom version of it called ScrubXml.
                // In addition to erasing the SharedSecret element from the incoming xml message, it masks
            // all the pCard information with Xs.
            var xml = XmlHelper.CreateXmlDocument(punchOutOrderMessage);
            var obfuscator = PluginLocator.GetPlugin();
            var orderRequest = new PunchOutOrderRequest
            {
                FromIdentity = XmlHelper.GetInnerTextFromNode(xml, "cXML/Header/From/Credential/Identity"),
                ToIdentity = XmlHelper.GetInnerTextFromNode(xml, "cXML/Header/To/Credential/Identity"),
                SenderIdentity = XmlHelper.GetInnerTextFromNode(xml, "cXML/Header/Sender/Credential/Identity"),
                SecretWord = XmlHelper.GetInnerTextFromNode(xml, "cXML/Header/Sender/Credential/SharedSecret"),
                FromUserAgent = XmlHelper.GetInnerTextFromNode(xml, "cXML/Header/Sender/UserAgent"),
                OrderId = XmlHelper.GetPropertyFromNode(xml, "cXML/Request/OrderRequest/OrderRequestHeader", "orderID"),
                OrderDate = XmlHelper.GetPropertyFromNode(xml, "cXML/Request/OrderRequest/OrderRequestHeader", "orderDate"),
                OrderType = XmlHelper.GetPropertyFromNode(xml, "cXML/Request/OrderRequest/OrderRequestHeader", "orderType"),
                ReleaseRequired = XmlHelper.GetPropertyFromNode(xml, "cXML/Request/OrderRequest/OrderRequestHeader", "releaseRequired"),
                Type = XmlHelper.GetPropertyFromNode(xml, "cXML/Request/OrderRequest/OrderRequestHeader", "type"),
                OrderVersion = XmlHelper.GetPropertyFromNode(xml, "cXML/Request/OrderRequest/OrderRequestHeader", "orderVersion"),
                IsInternalVersion = XmlHelper.GetPropertyFromNode(xml, "cXML/Request/OrderRequest/OrderRequestHeader", "isInternalVersion"),
                AgreementId = XmlHelper.GetPropertyFromNode(xml, "cXML/Request/OrderRequest/OrderRequestHeader", "agreementID"),
                AgreementPayloadId = XmlHelper.GetPropertyFromNode(xml, "cXML/Request/OrderRequest/OrderRequestHeader", "agreementPayloadID"),
                ParentAgreementId = XmlHelper.GetPropertyFromNode(xml, "cXML/Request/OrderRequest/OrderRequestHeader", "parentAgreementID"),
                ParentAgreementPayloadId = XmlHelper.GetPropertyFromNode(xml, "cXML/Request/OrderRequest/OrderRequestHeader", "parentAgreementPayloadID"),
                EffectiveDate = XmlHelper.GetPropertyFromNode(xml, "cXML/Request/OrderRequest/OrderRequestHeader", "effectiveDate"),
                ExpirationDate = XmlHelper.GetPropertyFromNode(xml, "cXML/Request/OrderRequest/OrderRequestHeader", "expirationDate"),
                RequisitionId = XmlHelper.GetPropertyFromNode(xml, "cXML/Request/OrderRequest/OrderRequestHeader", "requisitionID"),
                ShipComplete = XmlHelper.GetPropertyFromNode(xml, "cXML/Request/OrderRequest/OrderRequestHeader", "shipComplete"),
                PunchOutOrderRequestCXml = obfuscator.Obfuscate(punchOutOrderMessage),
                Total = XmlHelper.GetInnerTextFromNode(xml, "cXML/Request/OrderRequest/OrderRequestHeader/Total/Money"),
                TotalCurrency = XmlHelper.GetPropertyFromNode(xml, "cXML/Request/OrderRequest/OrderRequestHeader/Total/Money", "currency"),
                Shipping = XmlHelper.GetInnerTextFromNode(xml, "cXML/Request/OrderRequest/OrderRequestHeader/Shipping/Money"),
                ShippingCurrency = XmlHelper.GetPropertyFromNode(xml, "cXML/Request/OrderRequest/OrderRequestHeader/Shipping/Money", "currency"),
                ShippingDescription = XmlHelper.GetInnerTextFromNode(xml, "cXML/Request/OrderRequest/OrderRequestHeader/Shipping/Description"),
                BillToAddressId = XmlHelper.GetPropertyFromNode(xml, "cXML/Request/OrderRequest/OrderRequestHeader/BillTo/Address", "addressID"),
                BillToCity = XmlHelper.GetInnerTextFromNode(xml, "cXML/Request/OrderRequest/OrderRequestHeader/BillTo/Address/PostalAddress/City"),
                BillToName = XmlHelper.GetInnerTextFromNode(xml, "cXML/Request/OrderRequest/OrderRequestHeader/BillTo/Address/Name"),
                BillToCountry = XmlHelper.GetInnerTextFromNode(xml, "cXML/Request/OrderRequest/OrderRequestHeader/BillTo/Address/PostalAddress/Country"),
                BillToPostalCode = XmlHelper.GetInnerTextFromNode(xml, "cXML/Request/OrderRequest/OrderRequestHeader/BillTo/Address/PostalAddress/PostalCode"),
                BillToState = XmlHelper.GetInnerTextFromNode(xml, "cXML/Request/OrderRequest/OrderRequestHeader/BillTo/Address/PostalAddress/State"),
                BillToIsoCountryCode = XmlHelper.GetPropertyFromNode(xml, "cXML/Request/OrderRequest/OrderRequestHeader/BillTo/Address/PostalAddress/Country", "isoCountryCode"),
                BillToEmail = XmlHelper.GetInnerTextFromNode(xml, "cXML/Request/OrderRequest/OrderRequestHeader/BillTo/Address/Email"),
                BillToTelephoneNumber = XmlHelper.GetInnerTextFromNode(xml, "cXML/Request/OrderRequest/OrderRequestHeader/BillTo/Address/Phone/TelephoneNumber/Number"),
                BillToTelephoneAreaOrCityCode = XmlHelper.GetInnerTextFromNode(xml, "cXML/Request/OrderRequest/OrderRequestHeader/BillTo/Address/Phone/TelephoneNumber/AreaOrCityCode"),
                BillToTelephoneCountryCode = XmlHelper.GetInnerTextFromNode(xml, "cXML/Request/OrderRequest/OrderRequestHeader/BillTo/Address/Phone/TelephoneNumber/CountryCode"),
                BillToTelephoneIsoCountryCode = XmlHelper.GetPropertyFromNode(xml, "cXML/Request/OrderRequest/OrderRequestHeader/BillTo/Address/Phone/TelephoneNumber/CountryCode", "isoCountryCode"),
                ShipToAddressId = XmlHelper.GetPropertyFromNode(xml, "cXML/Request/OrderRequest/OrderRequestHeader/ShipTo/Address", "addressID"),
                ShipToCity = XmlHelper.GetInnerTextFromNode(xml, "cXML/Request/OrderRequest/OrderRequestHeader/ShipTo/Address/PostalAddress/City"),
                ShipToName = XmlHelper.GetInnerTextFromNode(xml, "cXML/Request/OrderRequest/OrderRequestHeader/ShipTo/Address/Name"),
                ShipToCountry = XmlHelper.GetInnerTextFromNode(xml, "cXML/Request/OrderRequest/OrderRequestHeader/ShipTo/Address/PostalAddress/Country"),
                ShipToPostalCode = XmlHelper.GetInnerTextFromNode(xml, "cXML/Request/OrderRequest/OrderRequestHeader/ShipTo/Address/PostalAddress/PostalCode"),
                ShipToState = XmlHelper.GetInnerTextFromNode(xml, "cXML/Request/OrderRequest/OrderRequestHeader/ShipTo/Address/PostalAddress/State"),
                ShipToIsoCountryCode = XmlHelper.GetPropertyFromNode(xml, "cXML/Request/OrderRequest/OrderRequestHeader/ShipTo/Address/PostalAddress/Country", "isoCountryCode"),
                ShipToEmail = XmlHelper.GetInnerTextFromNode(xml, "cXML/Request/OrderRequest/OrderRequestHeader/ShipTo/Address/Email"),
                ShipToTelephoneNumber = XmlHelper.GetInnerTextFromNode(xml, "cXML/Request/OrderRequest/OrderRequestHeader/ShipTo/Address/Phone/TelephoneNumber/Number"),
                ShipToTelephoneAreaOrCityCode = XmlHelper.GetInnerTextFromNode(xml, "cXML/Request/OrderRequest/OrderRequestHeader/ShipTo/Address/Phone/TelephoneNumber/AreaOrCityCode"),
                ShipToTelephoneCountryCode = XmlHelper.GetInnerTextFromNode(xml, "cXML/Request/OrderRequest/OrderRequestHeader/ShipTo/Address/Phone/TelephoneNumber/CountryCode"),
                ShipToTelephoneIsoCountryCode = XmlHelper.GetPropertyFromNode(xml, "cXML/Request/OrderRequest/OrderRequestHeader/ShipTo/Address/Phone/TelephoneNumber/CountryCode", "isoCountryCode"),
                Comments = XmlHelper.GetInnerTextFromNode(xml, "cXML/Request/OrderRequest/OrderRequestHeader/Comments"),
                PaymentCardDate = XmlHelper.GetPropertyFromNode(xml, "cXML/Request/OrderRequest/OrderRequestHeader/Payment/PCard", "expiration"),
                PaymentCardNumber = XmlHelper.GetPropertyFromNode(xml, "cXML/Request/OrderRequest/OrderRequestHeader/Payment/PCard", "number")
            };
                           //custom
            HttpContext.Current.Items["PCardName"] = XmlHelper.GetPropertyFromNode(xml, "cXML/Request/OrderRequest/OrderRequestHeader/Payment/PCard", "name");
            HttpContext.Current.Items["PCard"] = orderRequest.PaymentCardNumber;
            HttpContext.Current.Items["PCardDate"] = orderRequest.PaymentCardDate;
            //end custom
            ParseExtrinsics(orderRequest, xml);
            ParsePo(orderRequest, xml);
            orderRequest = PunchOutOrderRequestLineOutParser.ParseLineOuts(xml, orderRequest);
            orderRequest = ParseDeliverTo(xml, "cXML/Request/OrderRequest/OrderRequestHeader/BillTo/Address/PostalAddress/DeliverTo", orderRequest);
            orderRequest = ParseDeliverTo(xml, "cXML/Request/OrderRequest/OrderRequestHeader/ShipTo/Address/PostalAddress/DeliverTo", orderRequest);
            orderRequest = ParseAddress(xml, "cXML/Request/OrderRequest/OrderRequestHeader/BillTo/Address/PostalAddress/Street", orderRequest);
            orderRequest = ParseAddress(xml, "cXML/Request/OrderRequest/OrderRequestHeader/ShipTo/Address/PostalAddress/Street", orderRequest);
               return orderRequest;
            }
        }
    }

For more information on creating custom plug-ins, see Configuring the Windows Integration Service.