Example #1
0
        public bool AddPackageHistoryNoToken(PackageHistoryDto packageHistoryInfo)
        {
            var packageHistory = new PackageHistory();

            using (var scope = new TransactionScope())
            {
                var franchiseeTenant = _franchiseeTenantRepository.GetById(packageHistoryInfo.FranchiseeTenantId);

                packageHistory.PackageId          = packageHistoryInfo.PackageId;
                packageHistory.OldPackageId       = packageHistoryInfo.OldPackageId;
                packageHistory.StartDate          = packageHistoryInfo.StartDate;
                packageHistory.EndDate            = packageHistoryInfo.EndDate;
                packageHistory.RequestId          = packageHistoryInfo.RequestId;
                packageHistory.FranchiseeTenantId = packageHistoryInfo.FranchiseeTenantId;
                packageHistory.AccountNumber      = franchiseeTenant.AccountNumber;
                packageHistory.IsApply            = packageHistoryInfo.IsApply;
                Add(packageHistory);


                franchiseeTenant.CurrentPackageId       = packageHistory.PackageId;
                franchiseeTenant.RemainingAmount        = packageHistoryInfo.Amount;
                franchiseeTenant.NextBillingDate        = packageHistoryInfo.NextBillingDate;
                franchiseeTenant.PackageNextBillingDate = packageHistoryInfo.PackageNextBillingDate;

                _franchiseeTenantRepository.Update(franchiseeTenant);
                _franchiseeTenantRepository.Commit();
                scope.Complete();
                return(true);
            }
        }
Example #2
0
        public ActionResult Active(string keyCode, int packageId)
        {
            //TODO: Issue Respone all error 403
            Response.Status     = "200 OK";
            Response.StatusCode = 200;
            //TODO: Issue Respone all error 403

            var productKey         = ConfigurationManager.AppSettings["ProductKey"];
            var secretKey          = ConfigurationManager.AppSettings["SecretKey"];
            var url                = ConfigurationManager.AppSettings["Url"];
            var isRecurrence       = ConfigurationManager.AppSettings["IsRecurrence"];
            var recurrenceInterval = ConfigurationManager.AppSettings["RecurrenceInterval"];
            var passPhrase         = ConfigurationManager.AppSettings["PassPhrase"];
            var paymentUrl         = ConfigurationManager.AppSettings["PaymentUrl"];

            if (string.IsNullOrEmpty(productKey) || string.IsNullOrEmpty(secretKey) || string.IsNullOrEmpty(url) ||
                string.IsNullOrEmpty(isRecurrence) || string.IsNullOrEmpty(recurrenceInterval) || string.IsNullOrEmpty(passPhrase))
            {
                throw new Exception("Missing configuration ProductKey or SecretKey or Url or IsRecurrence or RecurrenceInterval or PassPhrase");
            }

            var franchiseeConfiguration = _franchiseeConfigurationService.GetFranchiseeConfiguration();
            var objFranchiseeAndLicense = new FranchisseNameAndLicenseDto
            {
                FranchiseeName = franchiseeConfiguration != null ? franchiseeConfiguration.Name : "",
                LicenseKey     = franchiseeConfiguration != null ? franchiseeConfiguration.LicenseKey : ""
            };
            //TODO: franchiseeTenantPackageInfo.Active == false update franchiseeTenantPackageInfo.Active == true when deploy
            var franchiseeTenantPackageInfo = _webApiUserService.GetPackageCurrentId(objFranchiseeAndLicense);

            if (franchiseeTenantPackageInfo == null || franchiseeTenantPackageInfo.Active == true)
            {
                return(Redirect("/"));
            }

            var registerPaymentDto = new PaymentInfoDto();

            registerPaymentDto.AccountNumber      = franchiseeTenantPackageInfo.AccountNumber;
            registerPaymentDto.RequestId          = _webApiUserService.GetRequestCurrentId(objFranchiseeAndLicense);
            registerPaymentDto.ProductKey         = productKey;
            registerPaymentDto.SecretKey          = secretKey;
            registerPaymentDto.ReturnUrl          = url + "LicenceExtension/PaySuccess";
            registerPaymentDto.CancelUrl          = url + "LicenceExtension?keyCode=" + keyCode;
            registerPaymentDto.IsRecurrence       = int.Parse(isRecurrence);
            registerPaymentDto.RecurrenceInterval = int.Parse(recurrenceInterval);
            //0: new; 1: change package; 2: change paymentInfo
            registerPaymentDto.TransactionType = 1;
            registerPaymentDto.StartDate       = DateTime.UtcNow;

            if (franchiseeTenantPackageInfo.Amount.GetValueOrDefault() > CaculatorHelper.GetPricePackage(packageId))
            {
                var packageInfo    = _webApiUserService.GetPackageCurrentNoToken(objFranchiseeAndLicense);
                var packageHistory = new PackageHistoryDto();
                packageHistory.StartDate = DateTime.UtcNow;
                if (packageId % 2 == 0)
                {
                    packageHistory.EndDate = DateTime.UtcNow.AddMonths(1);
                }
                else
                {
                    packageHistory.EndDate = DateTime.UtcNow.AddMonths(12);
                }

                packageHistory.OldPackageId       = franchiseeTenantPackageInfo.PackageId;
                packageHistory.PackageId          = packageId;
                packageHistory.FranchiseeTenantId = franchiseeTenantPackageInfo.Id;
                packageHistory.RequestId          = 0;
                packageHistory.IsApply            = true;
                packageHistory.Amount             = franchiseeTenantPackageInfo.Amount.GetValueOrDefault() -
                                                    CaculatorHelper.GetPricePackage(packageId);
                packageHistory.NextBillingDate        = packageHistory.EndDate;
                packageHistory.PackageNextBillingDate = packageId;

                var  isSuccessAddPackage       = _webApiUserService.AddPackageHistoryNoToken(packageHistory);
                bool isSuccessUpdateFranchisee = _webApiUserService.UpdateFranchiseeTenantLicenceExtentsion(objFranchiseeAndLicense);
                if (isSuccessUpdateFranchisee && isSuccessAddPackage)
                {
                    return(RedirectToAction("Success", "LicenceExtension"));
                }

                return(RedirectToAction("Error", "LicenceExtension"));
            }

            registerPaymentDto.TrialAmount = CaculatorHelper.GetPricePackage(packageId) -
                                             franchiseeTenantPackageInfo.Amount.GetValueOrDefault();

            registerPaymentDto.Items = new List <RegisterProduct>
            {
                new RegisterProduct {
                    ItemId = 1, ItemName = CaculatorHelper.GetNamePackage(packageId), ItemQuantity = 1, ItemPrice = CaculatorHelper.GetPricePackage(packageId)
                }
            };

            var textdate = DateTime.Now.Year + "/" + DateTime.Now.Month + "/" + DateTime.Now.Day + "/ | " + DateTime.Now.Hour + "/" + DateTime.Now.Minute + "/" + DateTime.Now.Second;

            registerPaymentDto.AdditionInfo = JsonConvert.SerializeObject(new { PackageId = packageId, DateTimeSend = textdate });

            var user = _userService.FirstOrDefault(o => o.UserRoleId == 1);

            if (user != null)
            {
                registerPaymentDto.FirstName  = user.FirstName;
                registerPaymentDto.MiddleName = user.MiddleName;
                registerPaymentDto.LastName   = user.LastName;
            }

            if (franchiseeConfiguration != null)
            {
                registerPaymentDto.Email    = franchiseeConfiguration.PrimaryContactEmail;
                registerPaymentDto.Address1 = franchiseeConfiguration.Address1;
                registerPaymentDto.Address2 = franchiseeConfiguration.Address2;
                registerPaymentDto.Zip      = franchiseeConfiguration.Zip;
                registerPaymentDto.City     = franchiseeConfiguration.City;
                registerPaymentDto.State    = franchiseeConfiguration.State;
            }

            var data         = JsonConvert.SerializeObject(registerPaymentDto);
            var result       = EncryptHelper.Encrypt(data, passPhrase);
            var encodeUrl    = HttpUtility.UrlEncode(result);
            var encodeBase64 = EncryptHelper.Base64Encode(encodeUrl);

            var returnData = new { PaymentUrl = paymentUrl, Data = encodeBase64 };

            return(Json(returnData, JsonRequestBehavior.AllowGet));
        }
Example #3
0
 public IHttpActionResult AddPackageHistoryNoToken(PackageHistoryDto packageHistoryInfo)
 {
     return(Ok(_packageHistoryService.AddPackageHistoryNoToken(packageHistoryInfo)));
 }
Example #4
0
        public ActionResult PaySuccess(string data)
        {
            var passPhrase = ConfigurationManager.AppSettings["PassPhrase"];

            if (string.IsNullOrEmpty(passPhrase))
            {
                throw new Exception("Missing configuration PassPhrase");
            }
            var base64EncodedBytes = Convert.FromBase64String(data);
            var decode             = System.Text.Encoding.UTF8.GetString(base64EncodedBytes);

            decode = HttpUtility.UrlDecode(decode);
            var decrypt = EncryptHelper.Decrypt(decode, passPhrase);
            var model   = JsonConvert.DeserializeObject <PaymentViewModel>(decrypt);


            if (ModelState.IsValid)
            {
                if (!string.IsNullOrEmpty(model.AdditionInfo))
                {
                    // additionInfo is info of packingeId
                    var additionInfo = JsonConvert.DeserializeObject <dynamic>(model.AdditionInfo);
                    if (CaculatorHelper.IsPropertyExist(additionInfo, "PackageId"))
                    {
                        model.PackageId = (int?)additionInfo.PackageId;
                    }
                }
                var franchiseeConfiguration = _franchiseeConfigurationService.GetFranchiseeConfiguration();
                var objFranchiseeAndLicense = new FranchisseNameAndLicenseDto
                {
                    FranchiseeName = franchiseeConfiguration != null ? franchiseeConfiguration.Name : "",
                    LicenseKey     = franchiseeConfiguration != null ? franchiseeConfiguration.LicenseKey : ""
                };

                var packageInfo = _webApiUserService.GetPackageCurrentNoToken(objFranchiseeAndLicense);
                var info        = _webApiUserService.GetInfoFranchiseeNoToken(objFranchiseeAndLicense);
                if (packageInfo != null && info != null)
                {
                    var packageHistory = new PackageHistoryDto();
                    packageHistory.StartDate = DateTime.UtcNow;
                    if (model.PackageId % 2 == 0)
                    {
                        packageHistory.EndDate = DateTime.UtcNow.AddMonths(1);
                    }
                    else
                    {
                        packageHistory.EndDate = DateTime.UtcNow.AddMonths(12);
                    }

                    packageHistory.OldPackageId       = packageInfo.PackageId;
                    packageHistory.PackageId          = model.PackageId != null ? (int)model.PackageId : 0;
                    packageHistory.FranchiseeTenantId = info.Id;
                    packageHistory.RequestId          = model.RequestId != null ? (int)model.RequestId : 0;
                    packageHistory.IsApply            = true;
                    var  isSuccessAddPackage       = _webApiUserService.AddPackageHistoryNoToken(packageHistory);
                    bool isSuccessUpdateFranchisee = _webApiUserService.UpdateFranchiseeTenantLicenceExtentsion(objFranchiseeAndLicense);
                    if (isSuccessUpdateFranchisee && isSuccessAddPackage)
                    {
                        return(RedirectToAction("Success", "LicenceExtension"));
                    }
                }
            }
            return(RedirectToAction("Error", "LicenceExtension"));
        }