/// <summary>
 /// Example rules showing possible ways to handle callbacks
 /// </summary>
 /// <param name="ThisOrder">The Order to perform the calculation</param>
 /// <param name="Address">contains a possible shipping address for an order.
 /// This address should be used to calculate taxes and shipping costs 
 /// for the order.</param>
 /// <param name="MerchantCode">Contains a coupon or gift certificate code
 /// that the customer entered for an order.</param>
 /// <returns></returns>
 public override MerchantCodeResult GetMerchantCodeResult(Order ThisOrder, 
     AnonymousAddress Address, string MerchantCode)
 {
     MerchantCodeResult RetVal = new MerchantCodeResult();
       if (MerchantCode.ToUpper() == SAVE10) {
     RetVal.Amount = 10;
     RetVal.Type = MerchantCodeType.Coupon;
     RetVal.Valid = true;
     RetVal.Message = "You saved $10!";
       }
       else if (MerchantCode.ToUpper() == SAVE20) {
     RetVal.Amount = 20;
     RetVal.Type = MerchantCodeType.Coupon;
     RetVal.Valid = true;
     RetVal.Message = "You saved $20!";
       }
       else if (MerchantCode.ToUpper() == GIFTCERT) {
     RetVal.Amount = 23.46m;
     RetVal.Type = MerchantCodeType.GiftCertificate;
     RetVal.Valid = true;
     RetVal.Message = "Your gift certificate has a balance of $23.46.";
       }
       else {
     RetVal.Message = "Sorry, we didn't recognize code '" + MerchantCode +
       "'.";
       }
       return RetVal;
 }
Exemplo n.º 2
0
 public override decimal GetTaxResult(Order ThisOrder, 
   AnonymousAddress Address, decimal ShippingRate) {
   decimal RetVal = 0;
   if (Address.Region == "HI") {
     decimal Total = 0;
     foreach (OrderLine Line in ThisOrder) {
       Total += Line.UnitPrice * Line.Quantity;
     }
     RetVal = decimal.Round(Total * 0.09m, 2);
   }
   return RetVal;
 }
Exemplo n.º 3
0
 public override ShippingResult GetShippingResult(string ShipMethodName, 
   Order ThisOrder, AnonymousAddress Address) {
   ShippingResult RetVal = new ShippingResult();
   if (ShipMethodName == "UPS Ground" && Address.Region != "HI" && 
     Address.Region != "AL") {
     RetVal.Shippable = true;
     RetVal.ShippingRate = 20;
   }
   if (ShipMethodName == "SuperShip") {
     RetVal.Shippable = true;
     RetVal.ShippingRate = 0;
   }
   return RetVal;
 }
        /// <summary>
        /// Example showing how shipping is calculated for a callback
        /// </summary>
        /// <param name="ShipMethodName">Identifies a shipping method for which
        /// costs need to be calculated.</param>
        /// <param name="ThisOrder">The Order to perform the calculation</param>
        /// <param name="Address">contains a possible shipping address for an order.
        /// This address should be used to calculate taxes and shipping costs 
        /// for the order.</param>
        /// <returns></returns>
        public override ShippingResult GetShippingResult(string ShipMethodName, 
            Order ThisOrder, AnonymousAddress Address)
        {
            ShippingResult RetVal = new ShippingResult();
              if (ShipMethodName == "UPS Ground" && Address.Region != "HI" &&
            Address.Region != "AL") {
            RetVal.Shippable = true;
            RetVal.ShippingRate = 20;
              }
              else if (ShipMethodName == "SuperShip") {
            RetVal.Shippable = true;
            RetVal.ShippingRate = 0;
              }
              else {
            //next we will look at the merchant-private-item-data
            //if the supplier-id is "ABC Candy Company" then you will get free shipping.
            //do not assume the nodes will be in the same order, we will walk the node
            //list looking for a node with the name of "supplier-id"

            //you can just as easily import all the nodes into an XmlDocument and perform
            //XPath statements.

            //You can also create a string dictionary by performing a foreach statement
            //on the nodes and using the node name as the key and the innerText as the
            //value.

            //We are just showing one of many ways to work with an array of XmlNodes.
            //As you can see from the sample code, you may also have children on any
            //of the MerchantPrivateDataNodes.

            string supplierID = "ABC Candy Company".ToUpper();

            foreach (OrderLine Line in ThisOrder) {
              foreach (System.Xml.XmlNode node in Line.MerchantPrivateDataNodes) {
            if (node.Name == "supplier-id") {
              if (supplierID == node.InnerText.ToUpper()) {
                RetVal.Shippable = true;
                RetVal.ShippingRate = 0;
                break;
              }
            }
              }
            }
              }
              return RetVal;
        }
Exemplo n.º 5
0
        public byte[] Process(string CallbackXML)
        {
            _Rules.LogXml(CallbackXML);

            // Deserialize the callback request.
            AutoGen.MerchantCalculationCallback Callback =
              (AutoGen.MerchantCalculationCallback)
              EncodeHelper.Deserialize
              (CallbackXML, typeof(AutoGen.MerchantCalculationCallback));

            _Rules.MerchantPrivateData = Callback.shoppingcart.merchantprivatedata;


            // Create the callback response.
            AutoGen.MerchantCalculationResults RetVal =
              new AutoGen.MerchantCalculationResults();
            // Create the order.
            Order ThisOrder = new Order(Callback);
            // Are there shipping methods?
            string[] ShippingMethods = new string[1] { "" };
            if (Callback.calculate.shipping != null &&
              Callback.calculate.shipping.Length > 0)
            {
                ShippingMethods = new string[Callback.calculate.shipping.Length];
                for (int s = 0; s < ShippingMethods.Length; s++)
                {
                    ShippingMethods[s] = Callback.calculate.shipping[s].name;
                }
            }

            RetVal.results =
              new AutoGen.Result
              [Callback.calculate.addresses.Length * ShippingMethods.Length];
            int ResultIndex = 0;
            for (int s = 0; s < ShippingMethods.Length; s++)
            {
                for (int a = 0; a < Callback.calculate.addresses.Length; a++)
                {
                    AutoGen.Result ThisResult = new AutoGen.Result();
                    ThisResult.addressid = Callback.calculate.addresses[a].id;
                    AnonymousAddress ThisAddress =
                      new AnonymousAddress(Callback.calculate.addresses[a]);
                    // Check shipping, if requested.
                    if (ShippingMethods[s] != "")
                    {
                        ThisResult.shippingname = ShippingMethods[s];
                        ShippingResult SResult =
                          _Rules.GetShippingResult
                          (ShippingMethods[s], ThisOrder, ThisAddress);
                        ThisResult.shippableSpecified = true;
                        ThisResult.shippable = SResult.Shippable;
                        ThisResult.shippingrate = new AutoGen.Money();
                        ThisResult.shippingrate.currency = "USD";
                        ThisResult.shippingrate.Value = SResult.ShippingRate;
                    }
                    // Check tax, if requested.
                    if (Callback.calculate.tax)
                    {
                        ThisResult.totaltax = new AutoGen.Money();
                        ThisResult.totaltax.currency = "USD";
                        ThisResult.totaltax.Value =
                          _Rules.GetTaxResult
                          (ThisOrder, ThisAddress,
                          (ThisResult.shippingrate != null ?
                          ThisResult.shippingrate.Value : 0));
                    }
                    // Check merchant codes.
                    if (Callback.calculate.merchantcodestrings != null)
                    {
                        ThisResult.merchantcoderesults =
                          new AutoGen.ResultMerchantcoderesults();
                        ThisResult.merchantcoderesults.Items =
                          new object[Callback.calculate.merchantcodestrings.Length];
                        ArrayList UsedMerchantCodes = new ArrayList();
                        for (int c = 0; c < Callback.calculate.merchantcodestrings.Length;
                          c++)
                        {
                            MerchantCodeResult MCR;
                            string CurrentMerchantCode =
                              Callback.calculate.merchantcodestrings[c].code;
                            if (UsedMerchantCodes.Contains(CurrentMerchantCode.ToUpper()))
                            {
                                AutoGen.CouponResult CouponResult = new AutoGen.CouponResult();
                                CouponResult.calculatedamount = new AutoGen.Money();
                                CouponResult.calculatedamount.currency = "USD";
                                CouponResult.calculatedamount.Value = 0;
                                CouponResult.code = CurrentMerchantCode;
                                CouponResult.message = "Code already used.";
                                CouponResult.valid = false;
                                ThisResult.merchantcoderesults.Items[c] = CouponResult;
                            }
                            else
                            {
                                MCR =
                                  _Rules.GetMerchantCodeResult
                                  (ThisOrder, ThisAddress, CurrentMerchantCode);
                                if (MCR.Type == MerchantCodeType.GiftCertificate)
                                {
                                    AutoGen.GiftCertificateResult GCResult =
                                      new AutoGen.GiftCertificateResult();
                                    GCResult.calculatedamount = new AutoGen.Money();
                                    GCResult.calculatedamount.currency = "USD";
                                    GCResult.calculatedamount.Value = MCR.Amount;
                                    GCResult.code = CurrentMerchantCode;
                                    GCResult.message = MCR.Message;
                                    GCResult.valid = MCR.Valid;
                                    ThisResult.merchantcoderesults.Items[c] = GCResult;
                                    UsedMerchantCodes.Add(CurrentMerchantCode.ToUpper());
                                }
                                else
                                {
                                    AutoGen.CouponResult CouponResult =
                                      new AutoGen.CouponResult();
                                    CouponResult.calculatedamount = new AutoGen.Money();
                                    CouponResult.calculatedamount.currency = "USD";
                                    CouponResult.calculatedamount.Value = MCR.Amount;
                                    CouponResult.code = CurrentMerchantCode;
                                    CouponResult.message = MCR.Message;
                                    CouponResult.valid = MCR.Valid;
                                    ThisResult.merchantcoderesults.Items[c] = CouponResult;
                                    UsedMerchantCodes.Add(CurrentMerchantCode.ToUpper());
                                }
                            }
                        }
                    }
                    RetVal.results[ResultIndex] = ThisResult;
                    ResultIndex++;
                }
            }

            return EncodeHelper.Serialize(RetVal);
        }
 /// <summary>
 /// The &lt;shipping-rate&gt; tag contains the shipping costs
 /// that have been calculated for an order.
 /// </summary>
 /// <param name="ShipMethodName">Identifies a shipping method for which
 /// costs need to be calculated.</param>
 /// <param name="ThisOrder">The Order to perform the calculation</param>
 /// <param name="Address">contains a possible shipping address for an order.
 /// This address should be used to calculate taxes and shipping costs
 /// for the order.</param>
 /// <returns></returns>
 public virtual ShippingResult GetShippingResult(string ShipMethodName,
                                                 Order ThisOrder, AnonymousAddress Address)
 {
     return(new ShippingResult());
 }
 /// <summary>
 /// The &lt;total-tax&gt; tag contains the total tax amount for an order
 /// </summary>
 /// <param name="ThisOrder">The Order to perform the calculation</param>
 /// <param name="Address">contains a possible shipping address for an order.
 /// This address should be used to calculate taxes and shipping costs
 /// for the order.</param>
 /// <param name="ShippingRate">The cost of shipping the order.</param>
 /// <returns></returns>
 public virtual decimal GetTaxResult(Order ThisOrder,
                                     AnonymousAddress Address, decimal ShippingRate)
 {
     return(0);
 }
 /// <summary>
 /// Return a The &lt;merchant-code-results%gt; tag contains information
 /// about coupons and gift certificates that were calculated into an
 /// order total
 /// </summary>
 /// <param name="ThisOrder">The Order to perform the calculation</param>
 /// <param name="Address">contains a possible shipping address for an order.
 /// This address should be used to calculate taxes and shipping costs
 /// for the order.</param>
 /// <param name="MerchantCode">Contains a coupon or gift certificate code
 /// that the customer entered for an order.</param>
 /// <param name="ShippingRate">The cost of shipping the order.</param>
 /// <returns></returns>
 public virtual MerchantCodeResult GetMerchantCodeResult(Order ThisOrder,
                                                         AnonymousAddress Address, string MerchantCode, decimal ShippingRate)
 {
     return(new MerchantCodeResult());
 }
Exemplo n.º 9
0
 public virtual ShippingResult GetShippingResult(string ShipMethodName,
   Order ThisOrder, AnonymousAddress Address)
 {
     return new ShippingResult();
 }
Exemplo n.º 10
0
 public virtual decimal GetTaxResult(Order ThisOrder,
   AnonymousAddress Address, decimal ShippingRate)
 {
     return 0;
 }
Exemplo n.º 11
0
 public virtual MerchantCodeResult GetMerchantCodeResult(Order ThisOrder,
   AnonymousAddress Address, string MerchantCode)
 {
     return new MerchantCodeResult();
 }