protected void GiftCertificatesGrid_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            int             GiftCertificateId = AlwaysConvert.ToInt(e.CommandArgument);
            GiftCertificate gc = GiftCertificateDataSource.Load(GiftCertificateId);

            if (gc == null)
            {
                return;
            }
            IGiftCertKeyProvider provider = AbleContext.Container.Resolve <IGiftCertKeyProvider>();

            if (e.CommandName.Equals("Generate"))
            {
                gc.SerialNumber = provider.GenerateGiftCertificateKey();
                gc.AddActivatedTransaction();
                gc.Save();
                GiftCertificatesGrid.DataBind();
            }
            else if (e.CommandName.Equals("Deactivate"))
            {
                gc.SerialNumber = "";
                gc.AddDeactivatedTransaction();
                gc.Save();
                GiftCertificatesGrid.DataBind();
            }
        }
예제 #2
0
        private int SaveGiftCertificate()
        {
            if (Page.IsValid)
            {
                IGiftCertKeyProvider gckProvider = AbleContext.Container.Resolve <IGiftCertKeyProvider>();
                _GiftCertificate.Name = Name.Text;
                decimal newBalance = AlwaysConvert.ToDecimal(Balance.Text);

                if (newBalance != _GiftCertificate.Balance)
                {
                    _GiftCertificate.AddBalanceUpdatedTransaction(_GiftCertificate.Balance, newBalance);
                    _GiftCertificate.Balance = newBalance;
                }

                DateTime newDate = ExpireDate.SelectedEndDate;
                DateTime oldDate = _GiftCertificate.ExpirationDate.HasValue ? _GiftCertificate.ExpirationDate.Value : DateTime.MinValue;
                if (!oldDate.Equals(newDate))
                {
                    _GiftCertificate.AddExpiryUpdatedTransaction(oldDate, newDate);
                    _GiftCertificate.ExpirationDate = ExpireDate.NullableSelectedEndDate;
                }

                if (GenerateSerialNumber.Checked)
                {
                    if (string.IsNullOrEmpty(_GiftCertificate.SerialNumber))
                    {
                        _GiftCertificate.AddActivatedTransaction();
                    }
                    _GiftCertificate.SerialNumber = gckProvider.GenerateGiftCertificateKey();
                }
                _GiftCertificate.Save();
                return(_GiftCertificate.Id);
            }
            return(0);
        }
        protected void GiftCertificatesGrid_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            int             index             = AlwaysConvert.ToInt(e.CommandArgument);
            int             GiftCertificateId = AlwaysConvert.ToInt(GiftCertificatesGrid.DataKeys[index].Value);
            GiftCertificate gc = FindGiftCertificate(GiftCertificateId);

            if (gc == null)
            {
                return;
            }

            IGiftCertKeyProvider       provider = AbleContext.Container.Resolve <IGiftCertKeyProvider>();
            GiftCertificateTransaction trans;

            if (e.CommandName.Equals("Activate"))
            {
                gc.SerialNumber       = provider.GenerateGiftCertificateKey();
                trans                 = new GiftCertificateTransaction();
                trans.GiftCertificate = gc;
                trans.Amount          = gc.Balance;
                trans.Description     = "Gift certificate activated.";
                trans.OrderId         = _Order.Id;
                trans.TransactionDate = LocaleHelper.LocalNow;
                gc.Transactions.Add(trans);
                gc.Save();
                // Trigger Gift Certificate Activated / Validate Event
                StoreEventEngine.GiftCertificateValidated(gc, trans);
                BindGiftCertificatesGrid();
            }
            else if (e.CommandName.Equals("Deactivate"))
            {
                gc.SerialNumber       = "";
                trans                 = new GiftCertificateTransaction();
                trans.GiftCertificate = gc;
                trans.Amount          = gc.Balance;
                trans.Description     = "Gift certificate deactivated.";
                trans.OrderId         = _Order.Id;
                trans.TransactionDate = LocaleHelper.LocalNow;
                gc.Transactions.Add(trans);
                gc.Save();
                BindGiftCertificatesGrid();
            }
        }
예제 #4
0
        /// <summary>
        /// Submits an authorization request
        /// </summary>
        /// <param name="authorizeRequest">The authorization request</param>
        /// <returns>Transaction that represents the result of the authorization request</returns>
        public override Transaction DoAuthorize(AuthorizeTransactionRequest authorizeRequest)
        {
            Transaction transaction = new Transaction();

            transaction.PaymentGatewayId = this.PaymentGatewayId;
            //always use authorize capture.
            transaction.TransactionType = TransactionType.AuthorizeCapture;

            string          serialNumber = authorizeRequest.Payment.AccountData;
            GiftCertificate gc           = GiftCertificateDataSource.LoadForSerialNumber(serialNumber);

            string errorMessage = string.Empty;

            if (gc == null)
            {
                errorMessage = "No gift certificate found with given serial number.";
            }
            else if (gc.IsExpired())
            {
                errorMessage = "Gift certificate is expired.";
            }
            else if (gc.Balance < authorizeRequest.Amount)
            {
                errorMessage = "Gift certificate does not have enough balance to complete this transaction.";
            }
            else
            {
                LSDecimal newAmount = gc.Balance - authorizeRequest.Amount;
                gc.Balance = newAmount;
                GiftCertificateTransaction trans = new GiftCertificateTransaction();
                trans.TransactionDate = LocaleHelper.LocalNow;
                trans.Amount          = authorizeRequest.Amount;
                trans.OrderId         = authorizeRequest.Payment.OrderId;
                trans.Description     = string.Format("An amount of {0:lc} used in purchase. Remaining balance is {1:lc}.", authorizeRequest.Amount, newAmount);
                gc.Transactions.Add(trans);
                gc.Save();
            }

            if (string.IsNullOrEmpty(errorMessage))
            {
                transaction.TransactionStatus = TransactionStatus.Successful;
                transaction.ResponseCode      = "0";
                transaction.ResponseMessage   = "SUCCESS";
                transaction.Amount            = authorizeRequest.Amount;
            }
            else
            {
                transaction.TransactionStatus = TransactionStatus.Failed;
                transaction.ResponseCode      = "1";
                transaction.ResponseMessage   = errorMessage;
                transaction.Amount            = authorizeRequest.Amount;
            }

            return(transaction);
        }
        private int SaveGiftCertificate()
        {
            if (Page.IsValid)
            {
                // VALIDATE IF A PROPER EXPIRE DATE IS SELECTED
                if (ExpireDate.SelectedEndDate != DateTime.MinValue && DateTime.Compare(ExpireDate.SelectedEndDate, LocaleHelper.LocalNow) < 0)
                {
                    CustomValidator dateValidator = new CustomValidator();
                    dateValidator.ControlToValidate = "Name"; // THIS SHOULD BE "ExpireDate" CONTROL, BUT THAT CANNOT BE VALIDATED
                    dateValidator.Text         = "*";
                    dateValidator.ErrorMessage = "Expiration date cannot be in the past.";
                    dateValidator.IsValid      = false;
                    phExpirationValidator.Controls.Add(dateValidator);
                    return(0);
                }
                GiftCertificate _GiftCertificate = new GiftCertificate();
                _GiftCertificate.Name           = Name.Text;
                _GiftCertificate.Store          = AbleContext.Current.Store;
                _GiftCertificate.CreatedBy      = AbleContext.Current.UserId;
                _GiftCertificate.Balance        = AlwaysConvert.ToDecimal(Balance.Text);
                _GiftCertificate.ExpirationDate = ExpireDate.NullableSelectedEndDate;
                _GiftCertificate.CreateDate     = LocaleHelper.LocalNow;
                _GiftCertificate.AddCreatedManuallyTransaction();

                if (Activated.Checked)
                {
                    IGiftCertKeyProvider gckProvider = AbleContext.Container.Resolve <IGiftCertKeyProvider>();
                    _GiftCertificate.SerialNumber = gckProvider.GenerateGiftCertificateKey();
                    _GiftCertificate.AddActivatedTransaction();
                }
                else
                {
                    _GiftCertificate.SerialNumber = "";
                }

                _GiftCertificate.Save();
                return(_GiftCertificate.Id);
            }
            return(0);
        }