public async Task <JsonResult> GetPromocodeStats(string promoCode)
        {
            var key    = System.Configuration.ConfigurationManager.AppSettings["promocodeKey"];
            var secret = System.Configuration.ConfigurationManager.AppSettings["promocodeSecret"];

            var promocodeManager = new PromotionCodeManager(key, secret);

            var stats = await promocodeManager.GetMultiCodeStats(promoCode);


            if (stats != null)
            {
                var data = new { status      = stats.status, availableRedeems = stats.availableRedeems,
                                 redeemCount = stats.redeemCount };

                return(Json(data, JsonRequestBehavior.AllowGet));
            }
            else
            {
                var data = new
                {
                    status           = "ERROR",
                    availableRedeems = 0,
                    redeemCount      = 0
                };

                return(Json(data, JsonRequestBehavior.AllowGet));
            }
        }
        public async Task <JsonResult> RedeemPromocode(string promoCode)
        {
            var key    = System.Configuration.ConfigurationManager.AppSettings["promocodeKey"];
            var secret = System.Configuration.ConfigurationManager.AppSettings["promocodeSecret"];

            var promocodeManager = new PromotionCodeManager(key, secret);

            var isValid = await promocodeManager.ValidatePromoCode(promoCode);


            if (isValid)
            {
                var redeemed = await promocodeManager.RedeemPromoCode(promoCode);

                if (redeemed)
                {
                    var data = new { Redeemed = true, isValid = true };

                    return(Json(data, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    var data = new { Redeemed = false, isValid = true };
                    return(Json(data, JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                var data = new { Redeemed = false, isValid = false };
                return(Json(data, JsonRequestBehavior.AllowGet));
            }
        }
Beispiel #3
0
    protected void btnPromoCode_OnClick(object sender, EventArgs e)
    {
        PromotionCodeManager promoManager = new PromotionCodeManager();

        // Add a check at confirm order screen over this promo value field
        //      check would be to not allow user add same code again at check-out screen
        // On check-out screen, show deducted amount in order total.

        string promoCode      = txtPromo.Text;
        double promoCodeValue = 0.0d;

        BusinessEntities.PreOrderPromo sessionPreOrderPromo = SessionPreOrderPromo;
        if (sessionPreOrderPromo == null)
        {
            sessionPreOrderPromo = new BusinessEntities.PreOrderPromo();
        }

        DateTime       currentDate = DateTime.Now;
        PromotionCodes code        = promoManager.GetPromotionCodeByCode(sessionPreOrderPromo.PreOrderPromoCode = promoCode);

        if (code != null)
        {
            if (currentDate > code.EndDate || currentDate < code.StartDate)
            {
                ShowMessage(Resources.ErrorMessages.PromoOutOfDate, MessageType.Error);
            }
            else if (code.CodeUsageCounter != null && code.CodeUsageCounter == 0)    //  in db it's incrementing
            {
                ShowMessage(Resources.ErrorMessages.PromoCounterZero, MessageType.Error);
            }
            else
            {
                sessionPreOrderPromo.PreOrderPromoValue = code.PromotionValue - code.PromoValueUsed;
                sessionPreOrderPromo.PreOrderPromoCode  = code.PromotionCode;
                txtPromo.Text        = "";
                SessionPreOrderPromo = sessionPreOrderPromo;
            }
        }



        if (sessionPreOrderPromo.PreOrderPromoValue > 0)
        {
            ShowMessage(string.Format(Resources.InfoMessages.PromoCodeAdded, promoCode), MessageType.Success);
        }
        else
        {
            ShowMessage(Resources.ErrorMessages.PromoNotAdded, MessageType.Error);
        }
    }
        private async void btnRedeem_Click(object sender, RoutedEventArgs e)
        {
            PromotionCodeManager man = new PromotionCodeManager("[YOURAPIKEY]",
                                                                "[YOURAPISECRET]");
            var valid = await man.RedeemPromoCode(this.txtPromocode.Text);

            tbStatus.Text = "";
            if (valid)
            {
                tbStatus.Text = "Promocode successfully redeemed :)";
            }
            else
            {
                tbStatus.Text = "Sorry promocode is not available anymore :(";
            }
        }
        private async void btnValidate_Click(object sender, RoutedEventArgs e)
        {
            PromotionCodeManager man = new PromotionCodeManager("[YOURAPIKEY]",
                                                                "[YOURAPISECRET]");
            var valid = await man.ValidatePromoCode(this.txtPromocode.Text);

            tbStatus.Text = "";
            if (valid)
            {
                tbStatus.Text = "Promocode successfully validated :)";
            }
            else
            {
                tbStatus.Text = "Promocode is invalid";
            }
        }
        private async void Button_Click_2(object sender, RoutedEventArgs e)
        {
            PromotionCodeManager man = new PromotionCodeManager("[YOURAPIKEY]",
                                                                "[YOURAPISECRET]");
            var stats = await man.GetMultiCodeStats(this.txtPromocode.Text);

            tbStatus.Text = "";

            if (stats != null)
            {
                tbStatus.Text = string.Format("STATUS: {0}, REDEEM-COUNT: {1}, AVAILABLE-REDEEMS: {2}",
                                              stats.status, stats.redeemCount, stats.availableRedeems);
            }
            else
            {
                tbStatus.Text = "Sorry promocode is not available anymore, or could not be found, or it is no multi-code. :(";
            }
        }
        private async void btnRedeemCode_Copy_Click(object sender, RoutedEventArgs e)
        {
            var apiKey    = "[YOURAPIKEY]";
            var apiSecret = "[YOURAPISECRET]";

            var promocodeManager = new PromotionCodeManager(apiKey, apiSecret);

            var isValid = await promocodeManager.RedeemPromoCode(this.tbPromoCode.Text);

            if (isValid)
            {
                lbResult.Text = "CODE REDEEMED";
            }
            else
            {
                lbResult.Text = "CODE NOT REDEEMED";
            }
        }
        private async void btnRedeemCode_Copy_Click2(object sender, RoutedEventArgs e)
        {
            var apiKey           = "[YOURAPIKEY]";
            var apiSecret        = "[YOURAPISECRET]";
            var promocodeManager = new PromotionCodeManager(apiKey, apiSecret);

            var stats = await promocodeManager.GetMultiCodeStats(this.tbPromoCode.Text);

            this.lbResult.Text = "";

            if (stats != null)
            {
                this.lbResult.Text = string.Format("STATUS: {0}, REDEEM-COUNT: {1}, AVAILABLE-REDEEMS: {2}",
                                                   stats.status, stats.redeemCount, stats.availableRedeems);
            }
            else
            {
                this.lbResult.Text = "Sorry promocode is not available anymore, or could not be found, or it is no multi-code. :(";
            }
        }
    protected void SubmitButton_OnClick(object sender, EventArgs e)
    {
        ////name = Utility.RsaDecrypt(EncrName.Value);
        ////expiry = Convert.ToDateTime(Utility.RsaDecrypt(EncrCardExpiry.Value));
        ////creditCardNumber = Utility.RsaDecrypt(EncrCreditCard.Value);
        ////cvvNumber = Utility.RsaDecrypt(EncrCvv.Value);
        ////recepientEmail = Utility.RsaDecrypt(ReceiverEmail.Value);
        ////ccAddress = Utility.RsaDecrypt(UserEmail.Value);
        ////amount = Convert.ToDouble(Utility.RsaDecrypt(Amount.Value));

        try
        {
            string cipheredText = EncryptedFormData.Value;

            string decipheredString = Utility.RsaDecrypt(cipheredText);

            string[] decipheredAllFields = decipheredString.Split('|');

            name             = decipheredAllFields[0];
            creditCardNumber = decipheredAllFields[1];
            expiryMonth      = Convert.ToByte(decipheredAllFields[2]);
            expiryYear       = Convert.ToByte(decipheredAllFields[3]);
            cvvNumber        = decipheredAllFields[4];
            ccAddress        = decipheredAllFields[5];
            recepientEmail   = decipheredAllFields[6];
            amount           = Convert.ToDouble(decipheredAllFields[7]);

            billingAddress = Utility.RsaDecrypt(EncryptedBillingAddress.Value);
        }
        catch (Exception)
        {
            //MessageBar1.ShowMessage(Resources.ErrorMessages.InputFieldsInvalid, MessageType.Error);
            return;
        }



        Result transactionResut = Result.None;

        if (amount > 0)
        {
            transactionResut = ProcessTransaction(creditCardNumber, name, amount, expiryMonth.ToString() + expiryYear.ToString(), cvvNumber, billingAddress);
        }
        else
        {
            ShowMessage("Amount is too less, can't make transaction", MessageType.Error);
            return;
        }

        if (transactionResut == Result.Success)
        {
            // Add Promotion code to DB with expiry
            PromotionCodes promoCode = new PromotionCodes();
            promoCode.CodeUsageCounter = 0;
            promoCode.EndDate          = null;
            promoCode.StartDate        = null;
            promoCode.PromotionCode    = Utility.RandomString(5);
            promoCode.PromotionName    = "E-Gift by " + name;
            promoCode.PromotionValue   = amount;
            promoCode.TypeOfPromotion  = PromotionType.EGiftCard;

            PromotionCodeManager promoCodeManager = new PromotionCodeManager();
            int result = promoCodeManager.AddPromotionCode(promoCode);
            if (result > 0)
            {
                string subject     = Resources.EmailSubjects.EGift;
                string body        = string.Format(Resources.EmailMessages.EGiftIntimation, amount, name, promoCode);
                string senderEmail = ConfigurationManager.AppSettings["DonotReplyEmail"];
                Utility.SendEmail(senderEmail, recepientEmail, ccAddress, ConfigurationManager.AppSettings["OrderReceiveEmail"], subject, body, false);
                ShowMessage(Resources.ErrorMessages.EGiftSuccess, MessageType.Success);
                //ClearFields();
            }
            else
            {
                ShowMessage(Resources.ErrorMessages.EGiftFailure, MessageType.Warning);
            }
        }
        else
        {
            ShowMessage(Resources.ErrorMessages.CreditCardTransactionError, MessageType.Error);
        }
    }
Beispiel #10
0
    public static object AddPromotionCode(String promotionCode, Double lineTip, Double deliveryCharges)
    {
        #region Variables

        string json = @"{{'SubTotal':{0},'Tax': {1}, 'OrderTotal': {2}, 'InvalidCode': {3} }}";

        Double deduction = 0, NewTotal = 0, Tax = 0;
        PromotionCodeManager promoManager  = new PromotionCodeManager();
        BranchManager        branchManager = new BranchManager();
        JavaScriptSerializer serializer    = new JavaScriptSerializer();

        #endregion

        PromotionCodes code                = promoManager.GetPromotionCodeByCode(promotionCode);
        Branches       branch              = branchManager.GetBranchById(BranchId);
        if (code != null)
        {
            DateTime currentDate = DateTime.Now;

            NewTotal = SessionUserOrder.OrderTotal;
            Tax      = ((NewTotal + deliveryCharges) * Convert.ToDouble(branch.TaxPercentage)) / 100;

            double preOrderPromoValue = 0.0d;

            if (SessionPreOrderPromo != null)
            {
                preOrderPromoValue = SessionPreOrderPromo.PreOrderPromoValue;

                if (SessionPreOrderPromo.PreOrderPromoCode.ToLower().Equals(promotionCode.ToLower()))
                {
                    json = string.Format(json, SessionUserOrder.OrderTotal, Tax,
                                         (SessionUserOrder.OrderTotal + deliveryCharges + Tax + lineTip),
                                         Resources.ErrorMessages.PromoCodeInUse);
                }

                return(serializer.Deserialize <Dictionary <string, string> >(json));
            }

            if (currentDate > code.EndDate || currentDate < code.StartDate)
            {
                json = string.Format(json, SessionUserOrder.OrderTotal, Tax, (SessionUserOrder.OrderTotal + deliveryCharges + Tax + lineTip), Resources.ErrorMessages.PromoOutOfDate);

                return(serializer.Deserialize <Dictionary <string, string> >(json));
            }

            if (code.TypeOfPromotion == PromotionType.EGiftCard && code.CodeUsageCounter != null && code.CodeUsageCounter == 0)    //  in db it's incrementing
            {
                json = string.Format(json, SessionUserOrder.OrderTotal, Tax, (SessionUserOrder.OrderTotal + Tax + lineTip), Resources.ErrorMessages.PromoCounterZero);

                return(serializer.Deserialize <Dictionary <string, string> >(json));
            }

            if (code.TypeOfPromotion == PromotionType.Money)
            {
                deduction = code.PromotionValue;
            }
            else if (code.TypeOfPromotion == PromotionType.EGiftCard)
            {
                if ((code.PromotionValue - code.PromoValueUsed) > 0)
                {
                    if (SessionUserOrder.OrderTotal < (code.PromotionValue - code.PromoValueUsed))
                    {
                        code.PromoValueUsed += deduction = SessionUserOrder.OrderTotal;
                    }
                    else
                    {
                        code.PromoValueUsed += deduction = (code.PromotionValue - code.PromoValueUsed);
                    }
                }
                else
                {       // promo value used completely
                    json = string.Format(json, NewTotal, Tax, (NewTotal + deliveryCharges + Tax + lineTip), Resources.ErrorMessages.PromoCodeBalanceEnded);
                    return(serializer.Deserialize <Dictionary <string, string> >(json));
                }
            }
            else
            {
                deduction = (SessionUserOrder.OrderTotal * code.PromotionValue) / 100;
            }

            NewTotal = SessionUserOrder.OrderTotal;
            NewTotal = NewTotal <= 0 ? 0 : NewTotal;
            Tax      = ((NewTotal + deliveryCharges) * Convert.ToDouble(branch.TaxPercentage)) / 100;

            json = string.Format(json, NewTotal, Tax, (NewTotal + deliveryCharges + Tax + lineTip) - deduction, 0);

            var dict = serializer.Deserialize <Dictionary <string, string> >(json);

            return(dict);
        }
        else
        {
            SessionPreOrderPromo = null;
            Tax  = (SessionUserOrder.OrderTotal + deliveryCharges) * (Convert.ToDouble(branch.TaxPercentage)) / 100;
            json = string.Format(json, SessionUserOrder.OrderTotal, Tax, SessionUserOrder.OrderTotal + deliveryCharges + Tax + lineTip, Resources.ErrorMessages.PromoCodeInvalid);


            var dict = serializer.Deserialize <Dictionary <string, string> >(json);
            return(dict);
        }
    }