private async Task UpdateOrDeleteLink(CartLink cartLink, bool increment, CancellationToken cancellationToken, bool captureContext = false) { if (cartLink is null) { throw new ArgumentNullException(nameof(cartLink)); } if (increment) { cartLink.Total++; } else { cartLink.Total--; } if (cancellationToken.IsCancellationRequested) { cancellationToken.ThrowIfCancellationRequested(); } if (cartLink.Total == 0) { await _linksEntitiesRepository.DeleteAsync(cartLink, cancellationToken, captureContext).ConfigureAwait(captureContext); await _cartEntitiesRepository.UpdateTimeStampAsync(cartLink.CartId, DateTimeOffset.UtcNow, cancellationToken, captureContext).ConfigureAwait(captureContext); return; } await _linksEntitiesRepository.UpdateAsync(cartLink, cancellationToken, captureContext).ConfigureAwait(captureContext); await _cartEntitiesRepository.UpdateTimeStampAsync(cartLink.CartId, DateTimeOffset.UtcNow, cancellationToken, captureContext).ConfigureAwait(captureContext); }
public void Page_Load() { Predicate <CartLink> match = null; Literal child = new Literal(); StringBuilder builder = new StringBuilder(); string str = string.Empty; string title = string.Empty; PaymentService primaryPaymentService = CommerceContext.Current.PrimaryPaymentService; if (base.CurrentSueetieProduct.ProductTypeID == 5) { foreach (CartLink link in (from p in CommerceCommon.GetCartLinkList(base.CurrentSueetieProduct.ProductID) where p.LicenseTypeID > 11 select p).ToList <CartLink>()) { title = link.PackageTypeDescription + " " + link.LicenseTypeDescription + " Product Key"; str = string.Format(primaryPaymentService.PurchaseUrl, new object[] { primaryPaymentService.AccountName, link.CartLinkID, title, link.Price.ToString("##0.00"), primaryPaymentService.ReturnUrl, primaryPaymentService.ShoppingUrl }); if (this.IsSideBarLink) { builder.Append("<li><a href=\"" + str + "\">" + link.LicenseTypeDescription + " Product Key</a></li>"); } else { builder.Append("<li><a href=\"" + str + "\">Add " + link.LicenseTypeDescription + " Product Key To Your Shopping Cart</a></li>"); } } } else if (base.CurrentSueetieProduct.PurchaseTypeID == 1) { if (match == null) { match = p => p.ProductID == base.CurrentSueetieProduct.ProductID; } CartLink link2 = CommerceCommon.GetCartLinkList(base.CurrentSueetieProduct.ProductID).Find(match); title = base.CurrentSueetieProduct.Title; str = string.Format(primaryPaymentService.PurchaseUrl, new object[] { primaryPaymentService.AccountName, link2.CartLinkID, title, link2.Price.ToString("##0.00"), primaryPaymentService.ReturnUrl, primaryPaymentService.ShoppingUrl }); if (this.IsSideBarLink) { builder.Append("<li><a href=\"" + str + "\">" + SueetieLocalizer.GetMarketplaceString("cartlink_commercial_sidebar") + "</a></li>"); } else { builder.Append("<li><a href=\"" + str + "\">" + string.Format(SueetieLocalizer.GetMarketplaceString("cartlink_commercial_bottom"), base.CurrentSueetieProduct.Title) + "</a></li>"); } } child.Text = builder.ToString(); if (child.Text.Trim().Length > 0) { this.Controls.Add(child); } }
protected override async Task DoProcessAsync(ModifyCartItemsRequest argument, CancellationToken cancellationToken, bool captureContext = false) { try { CartLink link = (await _linksEntitiesRepository .ReadAsync(cancellationToken, captureContext) .ConfigureAwait(captureContext)) .FirstOrDefault(x => x.CartId == argument.CartId && x.ProductId == argument.ProductId); switch (argument.CartItemOperation) { case CartItemOperation.Increment when link is null: { await CreateNewLink(argument, cancellationToken, captureContext).ConfigureAwait(captureContext); } break; case CartItemOperation.Increment: { await UpdateOrDeleteLink(link, true, cancellationToken, captureContext) .ConfigureAwait(captureContext); } break; case CartItemOperation.Decrement when link is null: { LogService.Error?.Write($"Cart with id '{argument.CartId}' doesn't contains product with id '{argument.ProductId}, exiting...'"); } break; case CartItemOperation.Decrement: { await UpdateOrDeleteLink(link, false, cancellationToken, captureContext) .ConfigureAwait(captureContext); } break; default: throw new ArgumentOutOfRangeException(); } } catch (Exception exception) { LogService.Error?.Write(exception.Message); } }
private async Task CreateNewLink(ModifyCartItemsRequest argument, CancellationToken cancellationToken, bool captureContext = false) { CartLink cartLink = new CartLink { CartId = argument.CartId, ProductId = argument.ProductId, Total = argument.Total }; if (cancellationToken.IsCancellationRequested) { cancellationToken.ThrowIfCancellationRequested(); } await _linksEntitiesRepository.CreateAsync(cartLink, cancellationToken, captureContext).ConfigureAwait(captureContext); await _cartEntitiesRepository.UpdateTimeStampAsync(cartLink.CartId, DateTimeOffset.UtcNow, cancellationToken, captureContext).ConfigureAwait(captureContext); }
protected void btnProductKey_OnClick(object sender, EventArgs e) { SueetiePackageType spt = (SueetiePackageType)Enum.ToObject(typeof(SueetiePackageType), int.Parse(this.rblPackageTypes.SelectedValue)); SueetieLicenseType type2 = (SueetieLicenseType)Enum.ToObject(typeof(SueetieLicenseType), int.Parse(this.rblLicenseTypes.SelectedValue)); CartLink cartLink = CommerceCommon.GetCartLink((int)spt, (int)type2); base.CurrentSueetieProduct = Products.GetSueetieProduct(cartLink.ProductID); ProductPurchase productPurchase = new ProductPurchase { UserID = this.ProductKeySueetieUser.UserID, CartLinkID = cartLink.CartLinkID, ProductID = cartLink.ProductID, PurchaseKey = CommerceCommon.GeneratePurchaseKey(), ActionID = base.CurrentSueetieProduct.ActionType() }; int num = Purchases.RecordPurchase(productPurchase); ProductPackage productPackage = CommerceCommon.GetProductPackage(cartLink.ProductID); Licenses.CreateProductLicense(new ProductLicense { PackageTypeID = productPackage.PackageTypeID, LicenseTypeID = cartLink.LicenseTypeID, Version = productPackage.Version, UserID = this.ProductKeySueetieUser.UserID, CartLinkID = cartLink.CartLinkID, PurchaseID = num, License = LicensingCommon.CreateLicenseKey(type2, spt) }); this.txtKey.Text = LicensingCommon.CreateLicenseKey(type2, spt); }
protected void Page_Load(object sender, EventArgs e) { if (!this.Page.IsPostBack) { this.lblPurchaseTitle.Text = SueetieLocalizer.GetMarketplaceString("productpurchase_title_success"); this.pnlLicenses.Visible = false; this.transactionXID = base.Request.QueryString["tx"]; PaymentService primaryPaymentService = CommerceContext.Current.PrimaryPaymentService; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(primaryPaymentService.TransactionUrl); request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; byte[] bytes = base.Request.BinaryRead(HttpContext.Current.Request.ContentLength); string str = Encoding.ASCII.GetString(bytes) + string.Format("&cmd=_notify-synch&tx={0}&at={1}", this.transactionXID, primaryPaymentService.IdentityToken); request.ContentLength = str.Length; StreamWriter writer = new StreamWriter(request.GetRequestStream(), Encoding.ASCII); writer.Write(str); writer.Close(); StreamReader reader = new StreamReader(request.GetResponse().GetResponseStream()); string input = reader.ReadToEnd(); reader.Close(); this.lblTransactionXID.Text = this.transactionXID; List <string> list = (from s in Regex.Split(input, "\n", RegexOptions.ExplicitCapture) where !string.IsNullOrEmpty(s) select s).ToList <string>(); if (list[0] == "SUCCESS") { List <ProductPurchase> list2 = new List <ProductPurchase>(); List <ProductLicense> list3 = new List <ProductLicense>(); this.PaymentProperties = this.CreateDictionary((from t in list where t.Contains("=") select t).ToList <string>()); int num = this.GetNum("num_cart_items"); int num2 = 0; int cartLinkID = -1; int num4 = -1; this.transactionXID = this.GetString("txn_id"); for (int i = 1; i <= num; i++) { num2 = this.GetNum("quantity".AddItemNum(i)); cartLinkID = this.GetNum("item_number".AddItemNum(i)); CartLink cartLink = CommerceCommon.GetCartLink(cartLinkID); for (int j = 0; j < num2; j++) { base.CurrentSueetieProduct = Products.GetSueetieProduct(cartLink.ProductID); ProductPurchase item = new ProductPurchase { TransactionXID = this.transactionXID, UserID = base.CurrentSueetieUserID, CartLinkID = cartLinkID, ProductID = cartLink.ProductID, PurchaseKey = CommerceCommon.GeneratePurchaseKey(), ActionID = base.CurrentSueetieProduct.ActionType() }; list2.Add(item); num4 = Purchases.RecordPurchase(item); if (base.CurrentSueetieProduct.ProductTypeID == 5) { ProductPackage productPackage = CommerceCommon.GetProductPackage(cartLink.ProductID); SueetiePackageType spt = (SueetiePackageType)System.Enum.ToObject(typeof(SueetiePackageType), productPackage.PackageTypeID); ProductLicense license = new ProductLicense { PackageTypeID = productPackage.PackageTypeID, LicenseTypeID = cartLink.LicenseTypeID, Version = productPackage.Version, UserID = base.CurrentSueetieUserID, CartLinkID = cartLinkID, PurchaseID = num4, License = Guid.NewGuid().ToString().ToUpper() }; SueetieLicenseType type2 = (SueetieLicenseType)System.Enum.ToObject(typeof(SueetieLicenseType), cartLink.LicenseTypeID); license.License = LicensingCommon.CreateLicenseKey(type2, spt); list3.Add(license); Licenses.CreateProductLicense(license); } } } this.rptPurchases.DataSource = Purchases.GetPurchasesByTransaction(this.transactionXID); this.rptPurchases.DataBind(); if (list3.Count > 0) { this.rptLicenses.DataSource = Licenses.GetLicensesByTransaction(this.transactionXID); this.rptLicenses.DataBind(); this.pnlLicenses.Visible = true; } } else { this.lblPurchaseTitle.Text = SueetieLocalizer.GetMarketplaceString("productpurchase_title_failure"); this.pnlLicenses.Visible = false; this.pnlPurchases.Visible = false; this.pnlTransactionCode.Visible = false; this.pnlSuccess.Visible = false; this.pnlFailure.Visible = true; MailMessage message = new MailMessage { From = new MailAddress(SiteSettings.Instance.FromEmail, SiteSettings.Instance.FromName) }; MailAddress address = new MailAddress(SiteSettings.Instance.ContactEmail, SiteSettings.Instance.SiteName + SueetieLocalizer.GetMarketplaceString("purchase_failure_email_admin")); message.To.Add(address); message.Subject = SueetieLocalizer.GetMarketplaceString("purchase_failure_email_subject"); string str4 = SueetieLocalizer.GetMarketplaceString("purchase_failure_email_firstline") + Environment.NewLine + Environment.NewLine; object obj2 = str4 + base.CurrentSueetieUser.UserName.ToString() + " (" + base.CurrentSueetieUser.DisplayName + ")"; string str3 = string.Concat(new object[] { obj2, Environment.NewLine, DateTime.Now.ToLongDateString(), ' ', DateTime.Now.ToLongTimeString() }) + Environment.NewLine + Environment.NewLine; message.Body = str3; if (SueetieConfiguration.Get().Core.SendEmails) { EmailHelper.AsyncSendEmail(message); } } } }
public void NavigateCartPage() { CartLink.Click(); }