/// <summary> /// This method executes immediately after an order has bene submitted for any reward post processing required. /// </summary> public void OrderPostProcessing(IOrder order) { //Update the Customer Extended and set the Redeemed to true for the paticular Reward IList <Product> rewardProducts = GetRewardProducts(order.Products); if (rewardProducts.Count <= 0) { return; } if (CustomerId == 0) { throw new ApplicationException("CustomerId cannot be zero"); } foreach (var rp in rewardProducts) { var discount = (EBRewardDiscount)rp.Discounts[0]; //Update Customer Extended for each var result = Api.UpdateCustomerExtended(new UpdateCustomerExtendedRequest() { CustomerID = CustomerId, CustomerExtendedID = discount.CustomerExtendedDetailId, ExtendedGroupID = (int)CustomerExtendedGroup.EbRewards, //Field1 = discount.PhaseNumber.ToString(CultureInfo.InvariantCulture), Field5 = 1.ToString(CultureInfo.InvariantCulture) //Set Redeemed to True }); } }
/// <summary> /// This method verifies an order is valid to be submitted in regards to the reward. An exception is thrown if the order is invalid. /// </summary> public void VerifyOrderIsValid(IOrder order) { IList <Product> rewardProducts = GetRewardProducts(order.Products); if (rewardProducts.Count <= 0) { return; } if (CustomerId == 0) { throw new ApplicationException("CustomerId cannot be zero"); } // Quantities greater than one cannot be purchased using the reward IEnumerable <Product> productsWithMultipleRewards = rewardProducts.Where(p => p.Discounts.Count(d => d.DiscountType == DiscountType.EBRewards) > 1); if (productsWithMultipleRewards.Count() > 1) { throw new ApplicationException("Extraordinary Beginnings Reward cannot be applied multiple times to the same product."); } //Check for any rewards that have been redeemed or expired foreach (var rp in rewardProducts) { var discount = (EBRewardDiscount)rp.Discounts.First(); if (discount.HasBeenRedeemed || DateTime.Now >= discount.CompletionDate) { throw new ApplicationException(string.Format("Item {0} is not not eligible for Extraordinary Beginnings Reward", rp.ItemCode)); } } }
/// <summary> /// This method executes immediately after an order has bene submitted for any reward post processing required. /// </summary> public virtual void OrderPostProcessing(IOrder order) { IList <Product> rewardProducts = GetRewardProducts(order.Products); if (rewardProducts.Count <= 0) { return; } if (CustomerId == 0) { throw new ApplicationException("CustomerId cannot be zero"); } if (IsRewardPointsAccount) { // Deduct points var createPointTransactionRequest = new CreatePointTransactionRequest { CustomerID = CustomerId, PointAccountID = RewardPointsAccountId.Value, TransactionType = PointTransactionType.Adjustment, Amount = -1 * rewardProducts.Count(), Reference = string.Format("Applied Item Code: {0}", string.Join(", ", rewardProducts.Select(p => p.ItemCode))) }; var response = Api.CreatePointTransaction(createPointTransactionRequest); } AddProductsToPurchasedExtendedGroup(rewardProducts); }
/// <summary> /// This method verifies an order is valid to be submitted in regards to the reward. An exception is thrown if the order is invalid. /// </summary> public void VerifyOrderIsValid(IOrder order) { IList <Product> rewardProducts = GetRewardProducts(order.Products); if (rewardProducts.Count() > 0) { if (CustomerId == 0) { throw new ApplicationException("CustomerId cannot be zero"); } // All products must be eligible for half off IEnumerable <Product> productsNotEligibleHalfOff = rewardProducts.Where(p => !p.HalfOffRewardsCreditsEligible); if (productsNotEligibleHalfOff.Count() > 0) { throw new ApplicationException(string.Format("{0} is not not eligible for half off credit", productsNotEligibleHalfOff.First().Description)); } // Quantities greater than one cannot be purchased using the reward IEnumerable <Product> productsWithMultipleRewards = rewardProducts.Where(p => p.Discounts.Where(d => d.DiscountType == RewardHalfOffDiscountType).Count() > 1); if (productsWithMultipleRewards.Count() > 1) { throw new ApplicationException("Half Off Discount cannot be applied multiple times to the same product."); } if (IsRewardPointsAccount) { // Credits cannot be exceeded (one credit per product purchased with this reward) RewardsAccount rewardsAccount = CalculatePointsAccount(order.Products); if (rewardsAccount.AmountRemaining < 0) { throw new ApplicationException("You've exceeded your rewards balance"); } } // Product could not have been purchased before using this reward var previouslyPurchasedItemCodes = PurchasedItemCodes(); IEnumerable <Product> alreadyPurchasedProducts = order.Products.Where(p => previouslyPurchasedItemCodes.Contains(p.ItemCode)); if (alreadyPurchasedProducts.Count() > 0) { throw new ApplicationException(string.Format("{0} has already been purchased with this reward", alreadyPurchasedProducts.First().Description)); } } }
public void OrderPostProcessing(IOrder order) { var rewardProducts = GetRewardProducts(order.Products); if (rewardProducts.Count <= 0) { return; } if (CustomerId == 0) { throw new ApplicationException("CustomerId cannot be zero"); } if (!IsRewardPointsAccount) { return; } foreach (var rp in rewardProducts) { var discount = (RecruitingRewardDiscount)rp.Discounts[0]; // Deduct reward cash var createPointTransactionRequest = new CreatePointTransactionRequest { CustomerID = CustomerId, PointAccountID = RewardPointsAccountId.Value, TransactionType = PointTransactionType.Adjustment, Amount = -1 * discount.AppliedAmount, Reference = string.Format("Applied Item Code: {0}", string.Join(", ", rp.ItemCode)) }; var response = Api.CreatePointTransaction(createPointTransactionRequest); } AddProductsToPurchasedExtendedGroup(rewardProducts); }
/// <summary> /// This method verifies an order is valid to be submitted in regards to the reward. An exception is thrown if the order is invalid. /// </summary> public void VerifyOrderIsValid(IOrder order) { var rewardProducts = GetRewardProducts(order.Products); if (!rewardProducts.Any()) { return; } if (CustomerId == 0) { throw new ApplicationException("CustomerId cannot be zero."); } // All products must be eligible for half off var productsNotEligible = rewardProducts.Where(p => !p.NewProductsLaunchRewardsCreditsEligible); if (productsNotEligible.Any()) { throw new ApplicationException(string.Format("{0} is not not eligible for 50% Off credit.", productsNotEligible.First().Description)); } // Quantities greater than one cannot be purchased using the reward IEnumerable <Product> productsWithMultipleRewards = rewardProducts.Where(p => p.Discounts.Count(d => d.DiscountType == RewardNewProductsLaunchDiscountType) > 1); IEnumerable <Product> productCredit = rewardProducts.Where(p => p.Discounts.Count(d => d.DiscountType.Equals(DiscountType.ProductCredit)) > 1); if (productsWithMultipleRewards.Count() > 1) { throw new ApplicationException("50% off reward cannot be applied multiple times to the same product."); } if (productCredit.Count() > 1) { throw new ApplicationException("Product Credit cannot be applied multiple times to the same product."); } if (IsRewardPointsAccount) { // Credits cannot be exceeded (one credit per product purchased with this reward) var rewardsAccount = CalculatePointsAccount(order.Products); if (rewardsAccount.AmountRemaining < 0) { throw new ApplicationException("You've exceeded your rewards balance."); } } var creditsRemaining = CreditsRemaining(CustomerId, EligibleReward); var productWithDiscount = GetRewardProducts(order.Products); var creditsAvailable = creditsRemaining - productWithDiscount.Count(); AvailableCredits = creditsAvailable; if (creditsAvailable < 0) { // Not enough credits available throw new ApplicationException("You've exceeded your credit balance."); } // Product could not have been purchased before using this reward var previouslyPurchasedItemCodes = PurchasedItemCodes(); var alreadyPurchasedProducts = rewardProducts.Where(p => previouslyPurchasedItemCodes.Contains(p.ItemCode)); if (alreadyPurchasedProducts.Any()) { throw new ApplicationException(string.Format("{0} has already been purchased with this reward.", alreadyPurchasedProducts.First().Description)); } }