protected void SaveLinkButton_Click(object sender, EventArgs e) { FileUpload file = (FileUpload)ProductFormView.FindControl("FileUploadImage") as FileUpload; if (file.HasFile) { file.SaveAs(Server.MapPath("~/ProductImages/" + file.FileName)); Label saveProduct = (Label)ProductFormView.FindControl("ImageUrlLabel") as Label; saveProduct.Text = "~/ProductImages/" + file.FileName; } }
protected void btnPurchase_Click(object sender, EventArgs e) { var prodPrice = ProductFormView.FindControl("ProductPriceLabel") as Label; var priceItem = prodPrice.Text; var prodName = ProductFormView.FindControl("ProductNameLabel") as Label; string nameItem = prodName.Text; var sizeFc = ProductFormView.FindControl("ProductTypeLabel") as Label; string labelItem = sizeFc.Text; decimal postagePackagingCost = 3.99m; decimal productPrice = decimal.Parse(priceItem); int quantityOfProduct = int.Parse(DDLQuantity.SelectedValue); decimal subTotal = (quantityOfProduct * productPrice); decimal total = subTotal + postagePackagingCost; var config = ConfigManager.Instance.GetProperties(); var accessToken = new OAuthTokenCredential(config).GetAccessToken(); var apiContext = new APIContext(accessToken); var productItem = new Item(); productItem.name = nameItem; productItem.currency = "GBP"; productItem.price = productPrice.ToString(); productItem.sku = "FipPro"; productItem.quantity = quantityOfProduct.ToString(); var transactionDetails = new Details(); transactionDetails.tax = "0"; transactionDetails.shipping = postagePackagingCost.ToString(); transactionDetails.subtotal = subTotal.ToString("0.00"); var transactionAmount = new Amount(); transactionAmount.currency = "GBP"; transactionAmount.total = total.ToString("0.00"); transactionAmount.details = transactionDetails; var transaction = new Transaction(); transaction.description = "Products you have ordered!"; transaction.invoice_number = Guid.NewGuid().ToString(); transaction.amount = transactionAmount; transaction.item_list = new ItemList { items = new List <Item> { productItem } }; var payer = new Payer(); payer.payment_method = "paypal"; var redirectUrls = new RedirectUrls(); redirectUrls.cancel_url = "http://" + HttpContext.Current.Request.Url.Authority + HttpContext.Current.Request.ApplicationPath + "/Default.aspx"; redirectUrls.return_url = "http://" + HttpContext.Current.Request.Url.Authority + HttpContext.Current.Request.ApplicationPath + "/user/CompletePurchase.aspx"; var payment = Payment.Create(apiContext, new Payment { intent = "sale", payer = payer, transactions = new List <Transaction> { transaction }, redirect_urls = redirectUrls }); Session["paymentId"] = payment.id; foreach (var link in payment.links) { if (link.rel.ToLower().Trim().Equals("approval_url")) { Response.Redirect(link.href); } } }
protected void btnBuyNow_Click(object sender, EventArgs e) { DropDownList DDLProductQty = (DropDownList)ProductFormView.FindControl("ProductQtyDropDownList"); Label productPrice = (Label)ProductFormView.FindControl("lblProductPrice"); decimal shippingPackagingCost = 5.00m; int productPrice1; int.TryParse((string)productPrice.Text, out productPrice1); int quantityOfProducts = int.Parse(DDLProductQty.SelectedValue); decimal subTotal = (quantityOfProducts * productPrice1); decimal totalAmount = subTotal + shippingPackagingCost; //Authenticate with PayPal var config = ConfigManager.Instance.GetProperties(); var accessToken = new OAuthTokenCredential(config).GetAccessToken(); //Get APIContext Object var apiContext = new APIContext(accessToken); var productStock = new Item(); productStock.name = "Products"; productStock.currency = "SGD"; productStock.price = productPrice1.ToString(); productStock.sku = "ProductCO5027"; //sku is stock keeping unit e.g. manufacturer code productStock.quantity = quantityOfProducts.ToString(); var transactionDetails = new Details(); transactionDetails.tax = "0"; transactionDetails.shipping = shippingPackagingCost.ToString(); transactionDetails.subtotal = subTotal.ToString("0.00"); var transactionAmount = new Amount(); transactionAmount.currency = "SGD"; transactionAmount.total = totalAmount.ToString("0.00"); transactionAmount.details = transactionDetails; var transaction = new Transaction(); transaction.description = "Your order from Fleur.com.bn."; transaction.invoice_number = Guid.NewGuid().ToString(); // this should ideally be the id of a record storing the order transaction.amount = transactionAmount; transaction.item_list = new ItemList { items = new List <Item> { productStock } }; var payer = new Payer(); payer.payment_method = "paypal"; var redirectUrls = new RedirectUrls(); string strPathAndQuery = HttpContext.Current.Request.Url.PathAndQuery; string strUrl = HttpContext.Current.Request.Url.AbsoluteUri.Replace(strPathAndQuery, "/"); redirectUrls.cancel_url = strUrl + "cancel.aspx"; redirectUrls.return_url = strUrl + "completePurchase.aspx"; var payment = Payment.Create(apiContext, new Payment { intent = "sale", payer = payer, transactions = new List <Transaction> { transaction }, redirect_urls = redirectUrls }); Session["paymentId"] = payment.id; foreach (var link in payment.links) { if (link.rel.ToLower().Trim().Equals("approval_url")) { //found the appropriate link, send the user there Response.Redirect(link.href); } } }