private PayPal.Api.Payment CreatePayment(APIContext apiContext, string redirectUrl) { //create itemlist and add item objects to it var itemList = new ItemList() { items = new List <Item>() }; //Adding Item Details like name, currency, price etc List <Cart> listCarts = (List <Cart>)Session[strCart]; foreach (var cart in listCarts) { itemList.items.Add(new Item() { name = cart.Menu.name, currency = "USD", price = cart.Menu.price.ToString(), quantity = cart.Quantity.ToString() }); } var payer = new Payer() { payment_method = "paypal" }; // Configure Redirect Urls here with RedirectUrls object var redirUrls = new RedirectUrls() { cancel_url = redirectUrl + "&Cancel=true", return_url = redirectUrl }; var subtotal = listCarts.Sum(x => x.Quantity * x.Menu.price); var billServChgs = subtotal * 4 / 100; var billtax = (subtotal + billServChgs) * 8 / 100; var fee = billServChgs + billtax + cost; // Adding Tax, shipping and Subtotal details var details = new Details() { tax = fee.ToString(), shipping = "0", subtotal = subtotal.ToString() }; //Final amount with details var amount = new Amount() { currency = "USD", total = (Convert.ToDouble(details.subtotal) + Convert.ToDouble(details.tax) + Convert.ToDouble(details.shipping)).ToString(), details = details }; TempData["Payment"] = amount.total; var transactionList = new List <Transaction>(); // Adding description about the transaction transactionList.Add(new Transaction() { description = "ABC CAFE", invoice_number = Convert.ToString((new Random()).Next(100000)), //Generate an confirmation No amount = amount, item_list = itemList }); this.payment = new PayPal.Api.Payment() { intent = "sale", payer = payer, transactions = transactionList, redirect_urls = redirUrls }; // Create a payment using a APIContext return(this.payment.Create(apiContext)); }
private Payment CreatePayment(APIContext apiContext, string redirectUrl, string name, string price) { var itemList = new ItemList() { items = new List <Item>() }; itemList.items.Add(new Item() { name = name, currency = "USD", price = price, quantity = "1", sku = "sku" }); var payer = new Payer() { payment_method = "paypal" }; var redirUrls = new RedirectUrls() { cancel_url = redirectUrl, return_url = redirectUrl }; var details = new Details() { tax = "0", shipping = "0", subtotal = itemList.items[0].price }; var amount = new Amount() { currency = "USD", total = (Convert.ToDouble(details.subtotal) + Convert.ToDouble(details.tax) + Convert.ToDouble(details.shipping)).ToString(), details = details }; var trasactionList = new List <Transaction>(); trasactionList.Add(new Transaction() { description = "Room booking", amount = amount, item_list = itemList, invoice_number = Convert.ToString((new Random()).Next(100000)) }); payment = new Payment() { intent = "sale", payer = payer, transactions = trasactionList, redirect_urls = redirUrls }; return(payment.Create(apiContext)); }
public Payment CreatePayment(APIContext apiContext, string redirectUrl, CheckOutDTO dto) { // ADD CART ITEMS var itemList = new ItemList() { items = new List <Item>() }; foreach (var item in dto.CheckOutItems) { itemList.items.Add(new Item() { name = item.Name, currency = "USD", price = item.UnitPrice.ToString(), quantity = item.Quantity.ToString(), sku = item.SKU, description = item.Name }); } // CHECK COUPON if (dto.Coupon.Code != "") { itemList.items.Add(new Item() { name = "Coupon Discount:" + dto.Coupon.ValueDisplay, quantity = "1", sku = dto.Coupon.Code, price = dto.CouponDiscount.ToString(), currency = "USD" }); } // CALCULATE AMOUNTS var details = new Details() { subtotal = dto.SubTotalCostDiscounted.ToString(), shipping = dto.ShippingCost.ToString(), }; var amount = new Amount() { currency = "USD", total = dto.TotalCost.ToString(), // Total must be equal to sum of shipping, tax and subtotal. details = details }; // SET TRANSACTION var transactionList = new List <Transaction>(); transactionList.Add(new Transaction() { description = "Cart Checkout from romazonia.com", invoice_number = dto.InvoiceId, amount = amount, item_list = itemList }); // CREATE PAYER var payer = new Payer() { payment_method = "paypal" }; // CREATE URLS var redirUrls = new RedirectUrls() { cancel_url = redirectUrl, return_url = redirectUrl }; // CREATE PAYMENT Payment payment = new Payment() { intent = "sale", payer = payer, transactions = transactionList, redirect_urls = redirUrls }; // RETURN PAYMENT return(payment.Create(apiContext)); // //var profile = new WebProfile //{ // name = "My web experience profile", // presentation = new Presentation // { // brand_name = "My brand name", // locale_code = "US", // logo_image = "https://www.paypalobjects.com/webstatic/i/ex_ce2/logo/logo_paypal_106x28.png", // return_url_label="Back to romazonia.com" // }, // input_fields = new InputFields // { // address_override=1, // no_shipping =0 // } //}; //var itemList = new ItemList() { items = new List<Item>() }; //foreach (var item in dto.CheckOutItems) //{ // itemList.items.Add(new Item() // { // name = item.Name, // currency = "USD", // price = item.UnitPrice.ToString(), // quantity = item.Quantity.ToString(), // sku = item.SKU, // description = item.Name // }); //} //AddressDTO billingAddress=dto.AvailableAddresses.Where(c=>c.Id==dto.SelectedBillingAddressId).SingleOrDefault(); //Address paypalBillingAddress = new Address() //{ // city = billingAddress.City, // country_code = billingAddress.Country, // line1 = billingAddress.Address1, // phone = billingAddress.Phone, // postal_code = billingAddress.PostCode //}; //AddressDTO shippingAddress = dto.AvailableAddresses.Where(c => c.Id == dto.SelectedShippingAddressId).SingleOrDefault(); //ShippingAddress paypalShippingAddress = new ShippingAddress() //{ // city = shippingAddress.City, // country_code = shippingAddress.Country, // line1 = shippingAddress.Address1, // phone = shippingAddress.Phone, // postal_code = shippingAddress.PostCode //}; ////itemList.shipping_address = paypalShippingAddress; //var payer = new Payer() { payment_method = "paypal" }; //var redirUrls = new RedirectUrls() //{ // cancel_url = redirectUrl, // return_url = redirectUrl //}; //var details = new Details() //{ // subtotal = dto.SubTotalCost.ToString(), // shipping=dto.ShippingCost.ToString(), //}; //var amount = new Amount() //{ // currency = "USD", // total = dto.TotalCost.ToString(), // Total must be equal to sum of shipping, tax and subtotal. // details = details //}; //var transactionList = new List<Transaction>(); //transactionList.Add(new Transaction() //{ // description = "Checkout from romazonia.com", // invoice_number = dto.InvoiceId, // amount = amount, // item_list = itemList //}); //Payment payment = new Payment() //{ // //experience_profile_id = profile.id, // intent = "sale", // payer = payer, // transactions = transactionList, // redirect_urls = redirUrls //}; //return payment.Create(apiContext); }
public static string PurchaseBundle(int BundleAmount) { // sandbox account: [email protected] // sandbox customer [email protected] = p1nkfl0yd //string apiUri = "https://api.sandbox.paypal.com"; //string apiUri = "https://api.paypal.com"; string client_id = "Aena3ntSjQJqG9qreGdIco_Gz8ZvT8ER9mJvqTMGs7yd-101IU7tPym6IpG3HN-MGyKlRYmgWao9CcXN"; string secret = "ECXV2PwPM-olaswL9VJ0xrBPmfhRM-onnC9nnWAFlnC1bSZegrT29sJlJ41jFYjBUIIyDVdn_TDq9YS4"; //stage 1) get an access token StringBuilder sb = new StringBuilder(); Dictionary <string, string> sdkConfig = new Dictionary <string, string>(); sdkConfig.Add("mode", "sandbox"); string accessToken = new OAuthTokenCredential(client_id, secret, sdkConfig).GetAccessToken(); APIContext apiContext = new APIContext(accessToken); apiContext.Config = sdkConfig; Amount bundleAmount = new Amount(); bundleAmount.currency = "GBP"; bundleAmount.total = "55.00"; List <Transaction> transactionList = new List <Transaction>(); Transaction tran = new Transaction(); tran.description = "SMS Bundle"; tran.amount = bundleAmount; transactionList.Add(tran); Payer payr = new Payer(); payr.payment_method = "paypal"; RedirectUrls redirUrls = new RedirectUrls(); redirUrls.cancel_url = "https://devtools-paypal.com/guide/pay_paypal/dotnet?cancel=true"; redirUrls.return_url = "https://devtools-paypal.com/guide/pay_paypal/dotnet?success=true"; Payment pymnt = new Payment(); pymnt.intent = "sale"; pymnt.payer = payr; pymnt.transactions = transactionList; pymnt.redirect_urls = redirUrls; Payment createdPayment = pymnt.Create(apiContext); //debug links // Find items where rel contains "approval_url". sb.Append(createdPayment.links[1].href); return(sb.ToString()); }
public Payment CreatePayment(PaymentViewModel paymentViewModel) { var apiContext = new APIContext(accessToken); //Create a Payment Object Payment payment = new Payment(); Payer payer = new Payer(); List <Transaction> transactions = new List <Transaction>(); Transaction transaction = new Transaction(); Amount amount = new Amount(); Details details = new Details(); ItemList itemList = new ItemList(); List <Item> items = new List <Item>(); Item item = new Item(); RedirectUrls redirectUrls = new RedirectUrls(); ShippingAddress shipping_Address = new ShippingAddress(); //The source of the funds for this payment.Payment method is PayPal Wallet payment or bank direct debit. payer.payment_method = "paypal"; //Total tax details.tax = paymentViewModel.Tax.ToString(); //Shipping charge details.shipping = paymentViewModel.ShippingCharge.ToString(); //Total Amount of products not included tax, shipping charge details.subtotal = paymentViewModel.SubTotal.ToString(); //loop through each item or produce foreach (var item1 in paymentViewModel.items) { item.currency = paymentViewModel.Currency; item.name = item1.Name; item.description = item1.Description; item.price = item1.Price.ToString(); item.quantity = item1.Quantity.ToString(); item.sku = "sku"; items.Add(item); } itemList.items = items; itemList.shipping_address = shipping_Address; shipping_Address.recipient_name = paymentViewModel.shipping_Address.Recipient_Name; shipping_Address.line1 = paymentViewModel.shipping_Address.Line1; shipping_Address.line2 = paymentViewModel.shipping_Address.Line2; shipping_Address.city = paymentViewModel.shipping_Address.City; shipping_Address.postal_code = paymentViewModel.shipping_Address.postal_code; shipping_Address.phone = paymentViewModel.shipping_Address.Phone; shipping_Address.state = paymentViewModel.shipping_Address.State; shipping_Address.country_code = "IN"; amount.currency = paymentViewModel.Currency; amount.total = Convert.ToString(paymentViewModel.SubTotal + paymentViewModel.ShippingCharge + paymentViewModel.Tax); amount.details = details; transaction.amount = amount; transaction.item_list = itemList; transactions.Add(transaction); redirectUrls.return_url = _paypalSettings.Return_url; redirectUrls.cancel_url = _paypalSettings.Cancel_url; payment.intent = "sale"; payment.payer = payer; payment.transactions = transactions; payment.redirect_urls = redirectUrls; var CreatedPayment = Payment.Create(apiContext, payment); return(CreatedPayment); }
private Payment CreatePayment(APIContext apiContext, string redirectUrl, List <string> data) { string SubTotal = data[1], ShippingCharge = data[2], GrandTotal = data[3], _tax = data[4], cartemail = data[5], cartphone = data[6], PhoneType = data[7], AcceptMessage = data[8]; var Items = JsonConvert.DeserializeObject <List <ItemModel> >(data[0]); //similar to credit card create itemlist and add item objects to it var itemList = new ItemList() { items = new List <Item>() }; foreach (var Product in Items) { itemList.items.Add(new Item() { name = Product.Item_Name, currency = "USD", price = Product.Item_Price.ToString(), quantity = Product.ItemCounts.ToString(), sku = Product.Item_code.ToString() }); } var payer = new Payer() { payment_method = "paypal" }; // Configure Redirect Urls here with RedirectUrls object var redirUrls = new RedirectUrls() { cancel_url = redirectUrl + "&OrionOrderId=" + OrderId, return_url = redirectUrl + "&OrionOrderId=" + OrderId }; // similar as we did for credit card, do here and create details object var details = new Details() { tax = _tax, shipping = ShippingCharge, subtotal = SubTotal }; // similar as we did for credit card, do here and create amount object var amount = new Amount() { currency = "USD", total = (Convert.ToDecimal(details.shipping) + Convert.ToDecimal(details.subtotal) + Convert.ToDecimal(details.tax)).ToString(), // Total must be equal to sum of shipping, tax and subtotal. details = details }; var transactionList = new List <Transaction>(); transactionList.Add(new Transaction() { description = "Transaction on " + DateTime.UtcNow.ToString(), invoice_number = OrderId, amount = amount, item_list = itemList }); this.payment = new Payment() { intent = "sale", payer = payer, transactions = transactionList, redirect_urls = redirUrls }; SavePayments(data, ShippingCharge, _tax, amount.total, "Transaction on " + DateTime.UtcNow.ToString(), cartemail, cartphone, PhoneType, AcceptMessage); // Create a payment using a APIContext return(this.payment.Create(apiContext)); }
private Payment CreatePayment(APIContext apiContext, string redirectUrl) { var booking = (Booking)Session["Booking"]; booking = _context.Bookings.Include(b => b.Property).OrderByDescending(s => s.Id).FirstOrDefault(); //create itemlist and add item objects to it var itemList = new ItemList() { items = new List <Item>() }; //Adding Item Details like name, currency, price etc itemList.items.Add(new Item() { name = booking.Property.Name, currency = "USD", price = booking.Price.ToString(), quantity = "1", sku = "sku" }); var payer = new Payer() { payment_method = "paypal" }; // Configure Redirect Urls here with RedirectUrls object var redirUrls = new RedirectUrls() { cancel_url = redirectUrl + "&Cancel=true", return_url = redirectUrl }; // Adding Tax, shipping and Subtotal details var details = new Details() { //tax = "1", //shipping = "1", //subtotal = "1" }; //Final amount with details var amount = new Amount() { currency = "USD", total = booking.Price.ToString(), // Total must be equal to sum of tax, shipping and subtotal. details = details }; var transactionList = new List <Transaction>(); // Adding description about the transaction transactionList.Add(new Transaction() { description = Convert.ToString((new Random()).Next(1000000)), invoice_number = Convert.ToString((new Random()).Next(1000000)), //Generate an Invoice No amount = amount, item_list = itemList }); this.payment = new Payment() { intent = "sale", payer = payer, transactions = transactionList, redirect_urls = redirUrls }; // Create a payment using a APIContext return(this.payment.Create(apiContext)); }
protected void btnPurchase_Click(object sender, EventArgs e) { decimal postagePackagingCost = 3.95m; decimal productPrice = 10.00m; 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 = "Product 1"; productItem.currency = "BND"; productItem.price = productPrice.ToString(); productItem.sku = "PRO1"; 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 = "BND"; transactionAmount.total = total.ToString("0.00"); transactionAmount.details = transactionDetails; var transaction = new Transaction(); transaction.description = "Product 1 description"; 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 + "Cancel.aspx"; redirectUrls.return_url = "http://" + HttpContext.Current.Request.Url.Authority + "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); } } }
private Payment CreatePayment(APIContext apicontext, string redirectURl) { var ItemLIst = new ItemList() { items = new List <Item>() }; if (Session["cart"] != "") { List <Models.Home.Item> cart = (List <Models.Home.Item>)(Session["cart"]); foreach (var item in cart) { ItemLIst.items.Add(new Item() { name = item.Product.ProductName.ToString(), currency = "TK", price = item.Product.Price.ToString(), quantity = item.Product.Quantity.ToString(), sku = "sku" }); } var payer = new Payer() { payment_method = "paypal" }; var redirUrl = new RedirectUrls() { cancel_url = redirectURl + "&Cancel=true", return_url = redirectURl }; var details = new Details() { tax = "1", shipping = "1", subtotal = "1" }; var amount = new Amount() { currency = "USD", total = Session["SesTotal"].ToString(), details = details }; var transactionList = new List <Transaction>(); transactionList.Add(new Transaction() { description = "Transaction Description", invoice_number = "#100000", amount = amount, item_list = ItemLIst }); this.payment = new Payment() { intent = "sale", payer = payer, transactions = transactionList, redirect_urls = redirUrl }; } return(this.payment.Create(apicontext)); }
//Createa payment method using an APIContext private Payment CreatePayment(APIContext apiContext, string redirectUrl) { //create itemlist and add item objects to it var itemList = new ItemList() { items = new List <Item>() }; //Adding Item Details like name, currency, price etc List <ShoppingCart> cart = (List <ShoppingCart>)Session["Cart"]; foreach (var item in cart) { itemList.items.Add(new Item() { name = item.Picture.Title, currency = "CAD", price = item.Picture.Price.ToString(), quantity = item.Quantity.ToString(), sku = "sku" }); } var payer = new Payer() { payment_method = "paypal" }; // Configure Redirect Urls here with RedirectUrls object var redirUrls = new RedirectUrls() { cancel_url = redirectUrl + "&Cancel=true", return_url = redirectUrl }; // Adding Tax, shipping and Subtotal details var details = new Details() { shipping = "0", subtotal = cart.Sum(x => x.Quantity * x.Picture.Price).ToString(), tax = ((cart.Sum(x => x.Quantity * x.Picture.Price) * 0.15)).ToString("#,##0.00"), }; //Final amount with details var amount = new Amount() { currency = "CAD", total = (Convert.ToDouble(details.tax) + Convert.ToDouble(details.shipping) + Convert.ToDouble(details.subtotal)).ToString(), // Total must be equal to sum of tax, shipping and subtotal. details = details }; var transactionList = new List <Transaction>(); // Adding description about the transaction transactionList.Add(new Transaction() { description = "Janet Testing Transaction description", invoice_number = Convert.ToString((new Random()).Next(100000)), //Generate an Invoice No amount = amount, item_list = itemList }); this.payment = new Payment() { intent = "sale", payer = payer, transactions = transactionList, redirect_urls = redirUrls }; // Create a payment using a APIContext return(this.payment.Create(apiContext)); }
private Payment CreatePayment(APIContext apiContext, string redirectUrl) { string boughBit = "Bit"; int numberOfBit = 1; var listItems = new ItemList() { items = new List <Item>() }; var Item = new Item() { name = boughBit, currency = "USD", quantity = numberOfBit.ToString(), sku = "sku", price = (numberOfBit * 100).ToString() }; listItems.items.Add(Item); var payer = new Payer() { payment_method = "paypal" }; var redirUrls = new RedirectUrls() { cancel_url = redirectUrl, return_url = redirectUrl }; var details = new Details() { tax = "1", shipping = "2", subtotal = Item.price, }; var amount = new Amount() { currency = "USD", total = (Convert.ToDouble(details.tax) + Convert.ToDouble(details.shipping) + Convert.ToDouble(details.subtotal)).ToString(), details = details }; var transactionList = new List <Transaction>(); transactionList.Add(new Transaction() { description = "Testing buying bit from EasyMoney", invoice_number = Convert.ToString((new Random()).Next(100000)), amount = amount, item_list = listItems }); payment = new Payment() { intent = "sale", payer = payer, transactions = transactionList, redirect_urls = redirUrls }; return(payment.Create(apiContext)); }
protected void btnPurchase_Click(object sender, EventArgs e) { DropDownList ddlQuantity = (DropDownList)FormView1.FindControl("ddlQuantity"); Label productPrice = (Label)FormView1.FindControl("ProductPriceLabel"); Label prodID = (Label)FormView1.FindControl("ProductIDLabel"); decimal shippingPackagingCost = 3.00m; int productPrice1;// = (int) productPrice; int.TryParse((string)productPrice.Text, out productPrice1); int quantityOfProducts = int.Parse(ddlQuantity.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 = prodID.Text; //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 Adidas Online"; 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); } } }
protected void addcart_Click(object sender, EventArgs e) { db_1624956_kstardbEntities itemDB = new db_1624956_kstardbEntities(); prod_table pd = new prod_table(); //available quantity var itemQty = pd.prod_quantity; int intItemQty = Convert.ToInt32(itemQty); //packing cost decimal packingcost = 1.0m; //item price decimal itemprice = int.Parse(prodpricetxt.Text); //number of item bought int quantityofitem = 1; //total of items without shipping decimal subtotal = (quantityofitem * itemprice); //cost of aftershipping decimal total = subtotal + packingcost; //authenticate paypal var config = ConfigManager.Instance.GetProperties(); var accessToken = new OAuthTokenCredential("AZ7aMW32u6mj1chETLHm0U4JOMSjiaVjBUjVioHzcEDcyyU029CH5aTNyoQV0asR_Bgu9-_8W99tHzDi", "ELsoyteIU8HKLQoN4aZg3Px_aH6ln_4v7aS4nEIA0xWnqYph3nd-CwN_5Ly9VCJNag2j6xoAA6ZS0ri0").GetAccessToken(); //Get APIcontext var apiContext = new APIContext(accessToken); apiContext.Config = config; //items transaction and payment objects var buyitem = new Item(); buyitem.name = item; buyitem.currency = "GBP"; buyitem.price = itemprice.ToString(); buyitem.sku = "DummySKU01"; buyitem.quantity = quantityofitem.ToString(); //subtotal var transactionDets = new Details(); transactionDets.tax = "0"; transactionDets.shipping = packingcost.ToString(); transactionDets.subtotal = subtotal.ToString(); //amount object compromising total amount var transactionAmount = new Amount(); transactionAmount.currency = "GBP"; transactionAmount.total = total.ToString("0.00"); transactionAmount.details = transactionDets; //transaction object var transobj = new Transaction(); transobj.description = "your items"; transobj.invoice_number = Guid.NewGuid().ToString(); transobj.amount = transactionAmount; transobj.item_list = new ItemList { items = new List <Item> { buyitem } }; //buyer object var buyer = new Payer(); buyer.payment_method = "paypal"; //redirect to avoid error 404 var redirection = new RedirectUrls(); redirection.cancel_url = "http://1624968.studentwebserver.co.uk/CO5027/Product.aspx"; redirection.return_url = "http://1624968.studentwebserver.co.uk/CO5027/purchased.aspx"; //payment object var pay = Payment.Create(apiContext, new Payment { intent = "sale", payer = buyer, transactions = new List <Transaction> { transobj }, redirect_urls = redirection } ); //create session Session["paymentId"] = pay.id; //URL to send user to from the links in the payment object foreach (var link in pay.links) { if (link.rel.ToLower().Trim().Equals("approval_url")) { //send user to the appropritate link if link is found Response.Redirect(link.href); } } }
protected void btnBuy_Click(object sender, EventArgs e) { var pricingLabel = FormView1.FindControl("ProductPriceLabel") as Label; //string pricestring = pricingLabel.ToString(); var productPricing = pricingLabel.Text; decimal postagePackagingCost = 3.95m; decimal productPrice = decimal.Parse(productPricing); int quantityProduct = int.Parse(ddlistQuantity.SelectedValue); decimal subTotal = (quantityProduct * productPrice); decimal Total = subTotal + postagePackagingCost; var clientId = "Ad1YjbYnAo1qDCIoTgHV3dNjnLRiHsI5sN1RmWHnTDJYn7KOVBtdjwhFwDzmb4SJGr1LPvXdGXVc7HGu"; var clientSecret = "EJs-D45X7amITcUcgLgpv1-za1NaC6zt9p9k8wCYTeyn1TNReA8bCpufB7LP9zpLV_Y4AqDsq-Eu8nSD"; var sdkConfig = new Dictionary <string, string> { { "mode", "sandbox" }, { "clientId", clientId }, { "clientSecret", clientSecret } }; var accessToken = new OAuthTokenCredential(clientId, clientSecret, sdkConfig).GetAccessToken(); var apiContext = new APIContext(accessToken); apiContext.Config = sdkConfig; var Productitem = new Item(); Productitem.name = "Product1"; Productitem.currency = "SGD"; Productitem.price = productPrice.ToString(); Productitem.sku = "PRO1"; //use getValue to obtain from database Productitem.quantity = quantityProduct.ToString(); var transactionDetails = new Details(); transactionDetails.tax = "0"; transactionDetails.shipping = postagePackagingCost.ToString(); transactionDetails.subtotal = subTotal.ToString("0.00"); var transactionAmount = new Amount(); transactionAmount.currency = "SGD"; transactionAmount.total = Total.ToString("0.00"); transactionAmount.details = transactionDetails; var transaction = new Transaction(); transaction.description = "Your Order Of"; 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 redirect = new RedirectUrls(); redirect.cancel_url = "http://" + HttpContext.Current.Request.Url.Authority + "/Default.aspx"; redirect.return_url = "http://" + HttpContext.Current.Request.Url.Authority + "/CompletePurchase.aspx"; var payment = Payment.Create(apiContext, new Payment { intent = "sale", payer = payer, transactions = new List <Transaction> { transaction }, redirect_urls = redirect }); Session["paymentId"] = payment.id; foreach (var link in payment.links) { if (link.rel.ToLower().Trim().Equals("approval_url")) { Response.Redirect(link.href); } } }
public PaymentHandler(List <PaypalItem> items, int uid) { if (apiContext == null) { GetApiContext(); } userId = uid; var payer = new Payer() { payment_method = "paypal" }; var guid = Convert.ToString((new Random()).Next(100000)); string DomainName = "http://localhost:20629"; //string DomainName = "https://localhost:44394"; var redirUrls = new RedirectUrls() { cancel_url = DomainName + "/Cancel/", return_url = DomainName + "/Wallet/PaymentSucess/" }; // Add Items to List ItemList itemList = new ItemList(); itemList.items = new List <Item>(); double subtotal = 0; double taxamount = 0; foreach (PaypalItem item in items) { List <NameValuePair> nl = new List <NameValuePair>(); NameValuePair sizeadd = new NameValuePair(); sizeadd.name = "Size"; sizeadd.value = item.size; nl.Add(sizeadd); PayPal.Api.Item tmp = new Item { currency = item.currency, price = item.price.ToString(), quantity = "1", sku = item.sku, }; subtotal += (item.price * 1); itemList.items.Add(tmp); } taxamount = 0; var details = new Details() { tax = taxamount.ToString(), shipping = "0", subtotal = subtotal.ToString() }; double total = taxamount + _fixedShipping + subtotal; var amount = new Amount() { currency = _Currency, total = total.ToString(), // Total must be equal to sum of shipping, tax and subtotal. details = details }; var transactionList = new List <Transaction>(); Random rand = new Random(DateTime.Now.Second); String invoice = "INV-" + System.DateTime.Now.Ticks.ToString(); transactionList.Add(new Transaction() { description = "Transaction description.", invoice_number = invoice, amount = amount, item_list = itemList }); PayPal.Api.Payment payment = new PayPal.Api.Payment() { intent = "sale", payer = payer, redirect_urls = redirUrls, transactions = transactionList }; var createdPayment = payment.Create(apiContext); // PopulateOrder(invoice , items, amount); var links = createdPayment.links.GetEnumerator(); while (links.MoveNext()) { var link = links.Current; if (link.rel.ToLower().Trim().Equals("approval_url")) { HttpContext.Current.Response.Redirect(link.href); } } }
public void PAYPAL_CONNECTION() { double num = 0; int PersonasFromSpinner = 0; PersonasFromSpinner = Convert.ToInt32(this.spin.Number); //SETS NUMBER OF PERSONS ON SESSION this.Session["PERSONAS"] = PersonasFromSpinner.ToString(); APIContext aPIContext = new APIContext((new OAuthTokenCredential(ConfigManager.Instance.GetProperties())).GetAccessToken()); Payer payer = new Payer() { payment_method = "paypal" }; //RANDOM SEED Convert.ToString((new Random()).Next(100000)); //SET PAYPAL RETURN URLS RedirectUrls redirectUrl = new RedirectUrls() { cancel_url = "http://wakanalake.com/Booking_Cancel.aspx", return_url = "http://wakanalake.com/Booking_Success.aspx" }; ItemList itemList = new ItemList() { items = new List <Item>() }; if (this.Session["TypeAccommodation"].ToString() == "Yurtas" && (PersonasFromSpinner == 1 || PersonasFromSpinner == 2)) { this.Session["altascosto"] = this.Session["highseason_yurta12"].ToString(); this.Session["bajascosto"] = this.Session["lowseason_yurta12"].ToString(); } if (this.Session["TypeAccommodation"].ToString() == "Yurtas" && (PersonasFromSpinner == 3 || PersonasFromSpinner == 4)) { this.Session["altascosto"] = this.Session["highseason_yurta34"].ToString(); this.Session["bajascosto"] = this.Session["lowseason_yurta34"].ToString(); } if (this.Session["TypeAccommodation"].ToString() == "Yurtas" && PersonasFromSpinner == 5) { this.Session["altascosto"] = Convert.ToDecimal(this.Session["highseason_yurta34"].ToString()) + (Convert.ToDecimal(this.Session["yurta_extrabed"].ToString()) * decimal.One); this.Session["bajascosto"] = Convert.ToDecimal(this.Session["lowseason_yurta34"].ToString()) + (Convert.ToDecimal(this.Session["yurta_extrabed"].ToString()) * decimal.One); } if (this.Session["TypeAccommodation"].ToString() == "Yurtas" && PersonasFromSpinner == 6) { this.Session["altascosto"] = Convert.ToDecimal(this.Session["highseason_yurta34"].ToString()) + (Convert.ToDecimal(this.Session["yurta_extrabed"].ToString()) * new decimal(2)); this.Session["bajascosto"] = Convert.ToDecimal(this.Session["lowseason_yurta34"].ToString()) + (Convert.ToDecimal(this.Session["yurta_extrabed"].ToString()) * new decimal(2)); } if (this.Session["TypeAccommodation"].ToString() == "Tepees" && (PersonasFromSpinner == 1 || PersonasFromSpinner == 2)) { this.Session["altascosto"] = this.Session["highseason_tepee12"].ToString(); this.Session["bajascosto"] = this.Session["lowseason_tepee12"].ToString(); } if (this.Session["TypeAccommodation"].ToString() == "Tepees" && (PersonasFromSpinner == 3 || PersonasFromSpinner == 4)) { this.Session["altascosto"] = this.Session["highseason_tepee34"].ToString(); this.Session["bajascosto"] = this.Session["lowseason_tepee34"].ToString(); } if (this.Session["TypeAccommodation"].ToString() == "Tepees" && PersonasFromSpinner == 5) { this.Session["altascosto"] = Convert.ToDecimal(this.Session["highseason_tepee34"].ToString()) + (Convert.ToDecimal(this.Session["tepee_extrabed"].ToString()) * decimal.One); this.Session["bajascosto"] = Convert.ToDecimal(this.Session["lowseason_tepee34"].ToString()) + (Convert.ToDecimal(this.Session["tepee_extrabed"].ToString()) * decimal.One); } if (this.Session["TypeAccommodation"].ToString() == "Tepees" && PersonasFromSpinner == 6) { this.Session["altascosto"] = Convert.ToDecimal(this.Session["highseason_tepee34"].ToString()) + (Convert.ToDecimal(this.Session["tepee_extrabed"].ToString()) * new decimal(2)); this.Session["bajascosto"] = Convert.ToDecimal(this.Session["lowseason_tepee34"].ToString()) + (Convert.ToDecimal(this.Session["tepee_extrabed"].ToString()) * new decimal(2)); } this.Session["HIGH_SEASON_DAYS"] = this.Session["altas"].ToString(); this.Session["HIGH_SEASON_COST"] = this.Session["altascosto"].ToString(); this.Session["LOW_SEASON_DAYS"] = this.Session["bajas"].ToString(); this.Session["LOW_SEASON_COST"] = this.Session["bajascosto"].ToString(); if (Convert.ToInt32(this.Session["altas"].ToString()) > 0) { itemList.items.Add(new Item() { name = string.Concat(this.Session["TypeAccommodation"].ToString(), " High Season Stay"), currency = "EUR", price = this.Session["altascosto"].ToString(), quantity = this.Session["altas"].ToString() }); num = num + Convert.ToDouble(this.Session["altascosto"].ToString()) * Convert.ToDouble(this.Session["altas"].ToString()); } if (Convert.ToInt32(this.Session["bajas"].ToString()) > 0) { itemList.items.Add(new Item() { name = string.Concat(this.Session["TypeAccommodation"].ToString(), " Low Season Stay"), currency = "EUR", price = this.Session["bajascosto"].ToString(), quantity = this.Session["bajas"].ToString() }); num = num + Convert.ToDouble(this.Session["bajascosto"].ToString()) * Convert.ToDouble(this.Session["bajas"].ToString()); } Details detail = new Details() { tax = "0", shipping = "0", subtotal = num.ToString() }; Amount amount = new Amount() { currency = "EUR", total = num.ToString(), details = detail }; this.Session["TOTAL"] = string.Concat(num.ToString(), " EUR"); List <Transaction> transactions = new List <Transaction>() { new Transaction() { description = "Transaction description.", invoice_number = Common.GetRandomInvoiceNumber(), amount = amount, item_list = itemList } }; List <Links> .Enumerator enumerator = (new Payment() { intent = "sale", payer = payer, redirect_urls = redirectUrl, transactions = transactions }).Create(aPIContext).links.GetEnumerator(); while (enumerator.MoveNext()) { Links current = enumerator.Current; if (!current.rel.ToLower().Trim().Equals("approval_url")) { continue; } base.Response.Redirect(current.href); } }
private Payment CreatePayment(APIContext apiContext, string redirectUrl) { var itemList = new ItemList() { items = new List <Item>() }; //Các giá trị bao gồm danh sách sản phẩm, thông tin đơn hàng //Sẽ được thay đổi bằng hành vi thao tác mua hàng trên website List <_GioHang> lstGiohang = Laygiohang(); if (lstGiohang == null) { return(null); } double _subtotal = 0; foreach (var i in lstGiohang) { var _dongia = Math.Round((i.dongia / 23000), 2); itemList.items.Add(new Item() { //Thông tin đơn hàng name = @i.sanpham, currency = "USD", price = _dongia.ToString(), quantity = @i.soluong.ToString(), sku = null }); _subtotal += _dongia * i.soluong; } //Hình thức thanh toán qua paypal var payer = new Payer() { payment_method = "paypal" }; // Configure Redirect Urls here with RedirectUrls object var redirUrls = new RedirectUrls() { cancel_url = redirectUrl, return_url = redirectUrl }; //các thông tin trong đơn hàng var details = new Details() { tax = "0", shipping = "0", subtotal = _subtotal.ToString() }; //Đơn vị tiền tệ và tổng đơn hàng cần thanh toán var amount = new Amount() { currency = "USD", total = _subtotal.ToString(), // Total must be equal to sum of shipping, tax andsubtotal. details = details }; var transactionList = new List <Transaction>(); //Tất cả thông tin thanh toán cần đưa vào transaction transactionList.Add(new Transaction() { description = "Transaction description.", invoice_number = Guid.NewGuid().ToString(), amount = amount, item_list = itemList }); this.payment = new Payment() { intent = "sale", payer = payer, transactions = transactionList, redirect_urls = redirUrls }; // Create a payment using a APIContext return(this.payment.Create(apiContext)); }
private Payment CreatePayment(APIContext apiContext, string redirectUrl) { var itemList = new ItemList() { items = new List <Item>() }; //List<CartViewModel> cart = (List<CartViewModel>)(Session["cart"]); /*itemList.items.Add(new Item() * { * name = "Item Name comes here", * currency = "USD", * price = "1", * quantity = "1", * sku = "sku" * });*/ //create itemlist and add item objects to it foreach (var item in (List <CartViewModel>)(Session["cart"])) { if (item.product.Sale != null) { var p = (double)item.product.UnitPrice; var v = Convert.ToDouble(item.product.Sale.Amount) / 100; var c1 = (p - (p * v)); totalAmount += (double)(Math.Round((c1) / 83) * item.count); itemList.items.Add(new Item() { name = item.product.Product_name, currency = "USD", price = Math.Round((c1) / 83).ToString(), quantity = item.count.ToString(), sku = "sku" }); } else { totalAmount += (double)(Math.Round((item.product.UnitPrice) / 83) * item.count); itemList.items.Add(new Item() { name = item.product.Product_name, currency = "USD", price = Math.Round((item.product.UnitPrice) / 83).ToString(), quantity = item.count.ToString(), sku = "sku" }); } } //Adding Item Details like name, currency, price etc var payer = new Payer() { payment_method = "paypal" }; // Configure Redirect Urls here with RedirectUrls object var redirUrls = new RedirectUrls() { cancel_url = redirectUrl + "&Cancel=true", return_url = redirectUrl }; // Adding Tax, shipping and Subtotal details var details = new Details() { tax = "1", shipping = "1", subtotal = totalAmount.ToString() }; //Final amount with details var amount = new Amount() { currency = "USD", total = (totalAmount + 2).ToString(), // Total must be equal to sum of tax, shipping and subtotal. details = details }; var transactionList = new List <Transaction>(); // Adding description about the transaction transactionList.Add(new Transaction() { description = "Transaction description", invoice_number = "#" + Convert.ToString((new Random()).Next(100000)), //Generate an Invoice No amount = amount, item_list = itemList }); this.payment = new Payment() { intent = "sale", payer = payer, transactions = transactionList, redirect_urls = redirUrls }; return(this.payment.Create(apiContext)); }
//[HttpPost] //public ActionResult InsertContacts() //{ // string sPostCode = Request.Form["postalCodeRu"].ToString(); // string sContactName = Request.Form["yourNameRu"].ToString(); // string sEmail = Request.Form["emailRu"].ToString(); // //db = new AvonessaDBEntities(); // //var i = db.sp_InsertContactData(contact.PostalCode, contact.ContactName, contact.Email); // Dictionary<string, object> postData = new Dictionary<string, object>(); // //перевод из PHP в C# для Payeer.com:+++++++++++++++++++++++++++ // /* // string sm_shop = "61102332"; // string sm_orderid = "12345"; // //============================= // var m_amount = 1.05; // string sm_amount = m_amount.ToString("f2"); // //============================= // string sm_curr = "USD"; // string senc_description = Base64Encode("Test Description"); // string sm_key = "545747sql"; // String[] arHash = new String[] { // sm_shop, sm_orderid, sm_amount, sm_curr, senc_description, sm_key // }; // string sm_sign = sha256(String.Join(":", arHash)); // postData.Add("m_shop", sm_shop); // postData.Add("m_orderid", sm_orderid); // postData.Add("m_amount", sm_amount); // postData.Add("m_curr", sm_curr); // postData.Add("m_desc", senc_description); // postData.Add("m_sign", sm_sign.ToUpper()); // postData.Add("m_process", "send"); // return this.RedirectAndPost("https://payeer.com/merchant/", postData); // */ // //++++++++++++++++++++++++++++++++++++++++++++++++++ // //return new RedirectAndPostActionResult("ShoppingBag", postData); // //или // //return this.RedirectAndPost("http://TheUrlToPostDataTo", postData); // return this.RedirectAndPost("http://TheUrlToPostDataTo", postData); //} //Для PayPal отправляется Form "SBCFormRu". Не забыть изменить sandbox на live public void MakePayPalTransactionRu() { string sTotal = ""; decimal dTotal = 0; short sQuantity = 0; short i = 0; //выборка сумки из базы ===== db = new AvonessaDBEntities(); int iSB_Id = int.Parse(Request.Cookies["AvonessaShoppingBag"]["sb_Id"].ToString()); var query = from sb in db.sp_GetShoppingBagById(iSB_Id) select sb; List <Item> itms = new List <Item>(); Item item = null; foreach (var sb_data in query.ToList()) { sQuantity = short.Parse(Request.Form["qty_item_ru_" + i.ToString()].ToString()); var iq = db.sp_InsertQuantityToSB(int.Parse(sb_data.P_Id.ToString()), iSB_Id, sQuantity); dTotal += sQuantity * decimal.Parse(sb_data.ProductCost.ToString()); item = new Item(); item.name = sb_data.ProductName; //Русское название item.currency = "USD"; item.price = sb_data.ProductCost.ToString().Replace(",", "."); item.quantity = Request.Form["qty_item_ru_" + i.ToString()].ToString(); item.sku = sb_data.P_Id.ToString(); itms.Add(item); i++; } ItemList itemList = new ItemList(); itemList.items = itms; //заносим адрес поставки в базу:===== var ic = db.sp_InsertContactData(Request.Form["yourNameRu"].ToString(), Request.Form["emailRu"].ToString().Trim(), Request.Form["countryRu"].ToString(), Request.Form["postalCodeRu"].ToString(), Request.Form["cityRu"].ToString(), Request.Form["streetHomeFlatRu"].ToString()); //Country Code======================= LookupService ls = new LookupService(@"E:/web/avoness1/App_Data/GeoIP.dat", LookupService.GEOIP_MEMORY_CACHE); Country c = ls.getCountry(Request.ServerVariables["REMOTE_ADDR"]); string cc = c.getCode(); //=================================== ShippingAddress sa = new ShippingAddress(); sa.country_code = cc; sa.city = Request.Form["cityRu"].ToString(); sa.line1 = Request.Form["streetHomeFlatRu"].ToString(); sa.recipient_name = Request.Form["yourNameRu"].ToString(); sa.postal_code = Request.Form["postalCodeRu"].ToString(); itemList.shipping_address = sa; //var sdkConfig = new Dictionary<string, string> { { "mode", "sandbox" } };// when you're live, change "sandbox" to "live" //string accessToken = new OAuthTokenCredential("ATrx7laOExss5QgsAMYpryJJZfo_Vw3gz0_HzOXMNFJjl4bb5rMrmUpj6nRyzm7uJgi-mebtQ7LhUF8y", // "ECDJMgNsx4rwhkHsATlsnp1DUoy6xZXOdLfLpOPqE6ErAHKkRuDQOctcDgEBgSBz68jmzn5OGtwuMTYN", sdkConfig) // .GetAccessToken(); //мои данные [email protected] /* * var sdkConfig = new Dictionary<string, string> { { "mode", "live" } };// when you're live, change "sandbox" to "live" * string accessToken = new OAuthTokenCredential("AYdL5I1bbxg91dez6GLuMSkQHVqtzocJ7LlgNULyEks_ElPjniV5OTP2Ka4IQotS6NyRjAQA87E6hztU", * "EKUkXPL0ZxM2tdmI-r9iMRiQYCVfQxIP7qh6kS21WI5qJ3gPuMOIt3kYGAH0VMi9Eaid07p1KsHecvtD", sdkConfig) * .GetAccessToken(); */ var sdkConfig = new Dictionary <string, string> { { "mode", "live" } }; // when you're live, change "sandbox" to "live" string accessToken = new OAuthTokenCredential("AbZ5lBaf9HfwR9ixms8A4qunW_4m06hliKjqB8NgLOup_4kP1AemIlzu04FOZoKjg2cu0OJYUt4P-YUt", "EOniNB_yLiy4XCNsTzZoadF9dG7MK5aUYwJo4cJk6v0WY54ZIKkZIiBtJWqA1Jam_1rDuR57sYqKCXts", sdkConfig) .GetAccessToken(); var redirectUrls = new RedirectUrls { cancel_url = "http://www.avonessa.com/ShopBagOrder/ShoppingBag/?sb_id=" + iSB_Id + "&cancel=true", return_url = "http://www.avonessa.com/ShopBagOrder/Success/?sb_id=" + iSB_Id + "&success=true" }; // Specify details of your payment amount. Details _details = new Details(); decimal _dShip = 8.75m; // цена поставки sTotal = dTotal.ToString().Replace(",", "."); _details.shipping = _dShip.ToString().Replace(",", "."); _details.subtotal = sTotal; _details.tax = "0"; dTotal = dTotal + _dShip; sTotal = dTotal.ToString().Replace(",", "."); var amnt = new Amount { currency = "USD", total = sTotal, details = _details }; var createdPayment = new Payment { intent = "sale", payer = new Payer { payment_method = "paypal" }, transactions = new List <Transaction> { new Transaction { description = "Оплата за товар", amount = amnt, item_list = itemList } }, redirect_urls = redirectUrls }.Create(new APIContext(accessToken) { Config = sdkConfig }); var approvalUrl = createdPayment.links.Single(l => l.rel == "approval_url").href; //Переход на страницу PayPal для продолжения оплаты: Response.Redirect(approvalUrl); }
protected void btnPurchase_Click(object sender, EventArgs e) { decimal postagePackagingCost = 3.95m; decimal productPrice = 10.00m; decimal quantityOfProduct = int.Parse(ddlQuantity.SelectedValue); decimal subTotal = (quantityOfProduct * productPrice); decimal total = subTotal + postagePackagingCost; var clientId = "AVt620HYECzDcRrkXXjgo8uOnMpDo0eP9CRyIhy9q7-IlN8eqjyAloSy4hjtAg4EJ8H1AQwLhlFTniji"; var clientSecret = "EFK7hYOvEelCIYmMEqvV2nR1UPDcut9PHNcx8-DeN-P3riMxGDVfqMB2bn0f7lb5mfbW71jR0oNESuhU"; var sdkConfig = new Dictionary <string, string> { { "mode", "sandbox" }, { "clientId", "clientId" }, { "clientSecret", "clientSecret" } }; var accessToken = new OAuthTokenCredential(clientId, clientSecret, sdkConfig).GetAccessToken(); var apiContext = new APIContext(accessToken); apiContext.Config = sdkConfig; var productItem = new Item(); productItem.name = "Product 1"; productItem.currency = "USD"; productItem.price = productPrice.ToString(); productItem.sku = "PRO1"; 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 = "USD"; transactionAmount.total = total.ToString("0.00"); transactionAmount.details = transactionDetails; var transaction = new Transaction(); transaction.description = "Your order of Product"; 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 + "/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); } } }
//Для PayPal отправляется Form "SBCFormEn". Не забыть изменить sandbox на live public void MakePayPalTransactionEn() { string sTotal = ""; decimal dTotal = 0; short sQuantity = 0; short i = 0; //выборка сумки из базы db = new AvonessaDBEntities(); int iSB_Id = int.Parse(Request.Cookies["AvonessaShoppingBag"]["sb_Id"].ToString()); var query = from sb in db.sp_GetShoppingBagById(iSB_Id) select sb; List <Item> itms = new List <Item>(); Item item = null; foreach (var sb_data in query.ToList()) { sQuantity = short.Parse(Request.Form["qty_item_en_" + i.ToString()].ToString()); var iq = db.sp_InsertQuantityToSB(int.Parse(sb_data.P_Id.ToString()), iSB_Id, sQuantity); dTotal += sQuantity * decimal.Parse(sb_data.ProductCost.ToString()); item = new Item(); item.name = sb_data.ProductNameEnglish; //название на английском item.currency = "USD"; item.price = sb_data.ProductCost.ToString().Replace(",", "."); item.quantity = Request.Form["qty_item_en_" + i.ToString()].ToString(); item.sku = sb_data.P_Id.ToString(); itms.Add(item); i++; } ItemList itemList = new ItemList(); itemList.items = itms; ////Country Code======================= //LookupService ls = new LookupService(@"E:/web/avoness1/App_Data/GeoIP.dat", LookupService.GEOIP_MEMORY_CACHE); //Country c = ls.getCountry(Request.ServerVariables["REMOTE_ADDR"]); //string cc = c.getCode(); ////=================================== //ShippingAddress sa = new ShippingAddress(); //sa.country_code = cc; //itemList.shipping_address = sa; //===================================== //var sdkConfig = new Dictionary<string, string> { { "mode", "sandbox" } };// when you're live, change "sandbox" to "live" //string accessToken = new OAuthTokenCredential("ATrx7laOExss5QgsAMYpryJJZfo_Vw3gz0_HzOXMNFJjl4bb5rMrmUpj6nRyzm7uJgi-mebtQ7LhUF8y", // "ECDJMgNsx4rwhkHsATlsnp1DUoy6xZXOdLfLpOPqE6ErAHKkRuDQOctcDgEBgSBz68jmzn5OGtwuMTYN", sdkConfig) // .GetAccessToken(); var sdkConfig = new Dictionary <string, string> { { "mode", "live" } }; // when you're live, change "sandbox" to "live" string accessToken = new OAuthTokenCredential("AbZ5lBaf9HfwR9ixms8A4qunW_4m06hliKjqB8NgLOup_4kP1AemIlzu04FOZoKjg2cu0OJYUt4P-YUt", "EOniNB_yLiy4XCNsTzZoadF9dG7MK5aUYwJo4cJk6v0WY54ZIKkZIiBtJWqA1Jam_1rDuR57sYqKCXts", sdkConfig) .GetAccessToken(); var redirectUrls = new RedirectUrls { cancel_url = "http://www.avonessa.com/ShopBagOrder/ShoppingBag/?sb_id=" + iSB_Id + "&cancel=true", return_url = "http://www.avonessa.com/ShopBagOrder/Success/?sb_id=" + iSB_Id + "&success=true" }; // Specify details of your payment amount. Details _details = new Details(); decimal _dShip = 8.75m; // цена поставки sTotal = dTotal.ToString().Replace(",", "."); _details.shipping = _dShip.ToString().Replace(",", "."); _details.subtotal = sTotal; _details.tax = "0"; dTotal = dTotal + _dShip; sTotal = dTotal.ToString().Replace(",", "."); var amnt = new Amount { currency = "USD", total = sTotal, details = _details }; var createdPayment = new Payment { intent = "sale", payer = new Payer { payment_method = "paypal" }, transactions = new List <Transaction> { new Transaction { description = "Payment for the product", amount = amnt, item_list = itemList } }, redirect_urls = redirectUrls }.Create(new APIContext(accessToken) { Config = sdkConfig }); var approvalUrl = createdPayment.links.Single(l => l.rel == "approval_url").href; //Переход на страницу PayPal для продолжения оплаты: Response.Redirect(approvalUrl); }
// this is new private Payment CreatePayment(APIContext apiContext, string redirectUrl, string DonationAmount) { //similar to credit card create itemlist and add item objects to it var itemList = new ItemList() { items = new List <Item>() }; itemList.items.Add(new Item() { name = "Item Name", currency = "USD", price = DonationAmount, quantity = "1", sku = "sku" }); var payer = new Payer() { payment_method = "paypal" }; // Configure Redirect Urls here with RedirectUrls object var redirUrls = new RedirectUrls() { cancel_url = redirectUrl, return_url = redirectUrl }; // similar as we did for credit card, do here and create details object var details = new Details() { tax = "0", shipping = "0", subtotal = DonationAmount }; // similar as we did for credit card, do here and create amount object var amount = new Amount() { currency = "USD", total = DonationAmount, // Total must be equal to sum of shipping, tax and subtotal. details = details }; var transactionList = new List <Transaction>(); var invoice = Convert.ToString((new Random()).Next(100000)); transactionList.Add(new Transaction() { description = "Transaction description.", invoice_number = invoice, amount = amount, item_list = itemList }); this.payment = new Payment() { intent = "sale", payer = payer, transactions = transactionList, redirect_urls = redirUrls }; // Create a payment using a APIContext return(this.payment.Create(apiContext)); }
////Tùy theo máy //private Payment CreatePayment(APIContext apiContext, string redirectUrl) //{ // var itemList = new ItemList() { items = new List<Item>() }; // var cart = Session[CartSession]; // var listcart = new List<CartItem>(); // listcart = (List<CartItem>)cart; // double tong = 0; // giá trị của tổng hóa đơn // string temp = ""; // chuỗi sau khi đã xử lý hoàn chỉnh // string str1 = "", str2 = ""; // 2 chuỗi con // int dem = 0; // biến tìm ra dấu, // //Các giá trị bao gồm danh sách sản phẩm, thông tin đơn hàng // //Sẽ được thay đổi bằng hành vi thao tác mua hàng trên website // foreach (var item in listcart) // { // temp = (float.Parse(item.Product.Price.ToString()) / 23000).ToString();// chuyển từ VND->USD // temp = Math.Round(Convert.ToDecimal(temp), 2).ToString(); // làm tròn lấy 2 số thập phân sau dấu phẩy // //Tùy máy // //dem = temp.IndexOf(","); // tìm kiếm vị trí dấu phẩy // //str1 = temp.Substring(0, dem);// tách chuỗi phía trước dấu phẩy // //str2 = temp.Substring(dem + 1, temp.Length - str1.Length -1); //tách chuỗi phía sau dấu phẩy // //temp = str1 + "." + str2; // ghép chuỗi // itemList.items.Add(new Item() // { // //Thông tin đơn hàng // name = item.Product.Name + " x " + item.Quantity.ToString(), // currency = "USD", // price = temp, // quantity = item.Quantity.ToString(), // }); // tong += ((double.Parse(temp) * double.Parse(item.Quantity.ToString()))); // tong = double.Parse(Math.Round(Convert.ToDecimal(tong), 2).ToString()); // //Tùy máy // //str1 = tong.ToString().Substring(0, dem);// tách chuỗi phía trước dấu phẩy // //str2 = tong.ToString().Substring(dem + 1, tong.ToString().Length - str1.Length - 1); //tách chuỗi phía sau dấu phẩy // //temp = str1 + "." + str2; // ghép chuỗi // } // //Hình thức thanh toán qua paypal // var payer = new Payer() { payment_method = "paypal" }; // // Configure Redirect Urls here with RedirectUrls object // var redirUrls = new RedirectUrls() // { // cancel_url = redirectUrl, // return_url = redirectUrl // }; // //các thông tin trong đơn hàng // var details = new Details() // { // tax = "0", // shipping = "0", // subtotal = tong.ToString() // tổng // }; // //Đơn vị tiền tệ và tổng đơn hàng cần thanh toán // var amount = new Amount() // { // currency = "USD", // total = tong.ToString(), // Total must be equal to sum of shipping, tax and subtotal. nếu không được mở khóa phần trên sửa tong thành temp // details = details // }; // var transactionList = new List<Transaction>(); // //Tất cả thông tin thanh toán cần đưa vào transaction // transactionList.Add(new Transaction() // { // description = "Thông tin sản phẩm", // invoice_number = Guid.NewGuid().ToString(), // amount = amount, // item_list = itemList // }); // this.payment = new Payment() // { // intent = "sale", // payer = payer, // transactions = transactionList, // redirect_urls = redirUrls // }; // // Create a payment using a APIContext // return this.payment.Create(apiContext); //} //Tùy theo máy private Payment CreatePayment(APIContext apiContext, string redirectUrl) { var itemList = new ItemList() { items = new List <Item>() }; var cart = Session[CartSession]; var listcart = new List <CartItem>(); listcart = (List <CartItem>)cart; double tong = 0; // giá trị của tổng hóa đơn string temp = ""; // chuỗi sau khi đã xử lý hoàn chỉnh string str1 = "", str2 = ""; // 2 chuỗi con int dem = 0; // biến tìm ra dấu, //Các giá trị bao gồm danh sách sản phẩm, thông tin đơn hàng //Sẽ được thay đổi bằng hành vi thao tác mua hàng trên website foreach (var item in listcart) { temp = (float.Parse(item.Product.Price.ToString()) / 23000).ToString(); // chuyển từ VND->USD temp = Math.Round(Convert.ToDecimal(temp), 2).ToString(); // làm tròn lấy 2 số thập phân sau dấu phẩy dem = temp.IndexOf(","); // tìm kiếm vị trí dấu phẩy str1 = temp.Substring(0, dem); // tách chuỗi phía trước dấu phẩy str2 = temp.Substring(dem + 1, temp.Length - str1.Length - 1); //tách chuỗi phía sau dấu phẩy temp = str1 + "." + str2; // ghép chuỗi itemList.items.Add(new Item() { //Thông tin đơn hàng name = item.Product.Name + " x " + item.Quantity.ToString(), currency = "USD", price = temp, quantity = item.Quantity.ToString(), }); tong += ((double.Parse(item.Product.Price.ToString()) * double.Parse(item.Quantity.ToString())) / 23000); tong = double.Parse(Math.Round(Convert.ToDecimal(tong), 2).ToString()); dem = tong.ToString().IndexOf(","); str1 = tong.ToString().Substring(0, dem); // tách chuỗi phía trước dấu phẩy str2 = tong.ToString().Substring(dem + 1, tong.ToString().Length - str1.Length - 1); //tách chuỗi phía sau dấu phẩy temp = str1 + "." + str2; // ghép chuỗi } //Hình thức thanh toán qua paypal var payer = new Payer() { payment_method = "paypal" }; // Configure Redirect Urls here with RedirectUrls object var redirUrls = new RedirectUrls() { cancel_url = redirectUrl, return_url = redirectUrl }; //các thông tin trong đơn hàng var details = new Details() { tax = "0", shipping = "0", subtotal = temp // tổng }; //Đơn vị tiền tệ và tổng đơn hàng cần thanh toán var amount = new Amount() { currency = "USD", total = temp, // Total must be equal to sum of shipping, tax and subtotal. details = details }; var transactionList = new List <Transaction>(); //Tất cả thông tin thanh toán cần đưa vào transaction transactionList.Add(new Transaction() { description = "Thông tin sản phẩm", invoice_number = Guid.NewGuid().ToString(), amount = amount, item_list = itemList }); this.payment = new Payment() { intent = "sale", payer = payer, transactions = transactionList, redirect_urls = redirUrls }; // Create a payment using a APIContext return(this.payment.Create(apiContext)); }
private Payment CreatePayment(APIContext apiContext, string redirectUrl) { //create itemlist and add item objects to it var itemList = new ItemList() { items = new List <Item>() }; //Adding Item Details like name, currency, price etc itemList.items.Add(new Item() { name = "Item Name comes here", currency = "USD", price = "1", quantity = "1", sku = "sku" }); var payer = new Payer() { payment_method = "paypal" }; // Configure Redirect Urls here with RedirectUrls object var redirUrls = new RedirectUrls() { cancel_url = redirectUrl + "&Cancel=true", return_url = redirectUrl }; // Adding Tax, shipping and Subtotal details var details = new Details() { tax = "1", shipping = "1", subtotal = "1" }; //Final amount with details var amount = new Amount() { currency = "USD", total = "3", // Total must be equal to sum of tax, shipping and subtotal. details = details }; var transactionList = new List <Transaction>(); // Adding description about the transaction transactionList.Add(new Transaction() { description = "Transaction description", invoice_number = "your generated invoice number", //Generate an Invoice No amount = amount, item_list = itemList }); this.payment = new Payment() { intent = "sale", payer = payer, transactions = transactionList, redirect_urls = redirUrls }; // Create a payment using a APIContext return(this.payment.Create(apiContext)); }
private PayPal.Api.Payment CreatePayment(APIContext apiContext, string redirectUrl) { float subTotal = 0; float toTal = 0; var itemList = new ItemList() { items = new List <Item>() }; if (Session["Cart"] != null) { Cart cart = Session["Cart"] as Cart; foreach (var i in cart.Items) { Item a = new Item(); a.name = i._shopping_product.BookName.ToString(); a.price = i._shopping_product.BookPrice.ToString(); a.quantity = i._shopping_quantity.ToString(); a.sku = "sku"; a.currency = "USD"; itemList.items.Add(a); subTotal += i._shopping_quantity * i._shopping_product.BookPrice; } var payer = new Payer() { payment_method = "paypal" }; // Configure Redirect Urls here with RedirectUrls object var redirUrls = new RedirectUrls() { cancel_url = redirectUrl, return_url = redirectUrl }; // similar as we did for credit card, do here and create details object var details = new Details() { tax = "1", shipping = "1", subtotal = subTotal.ToString() }; // toTal = (subTotal / 23135) + 2; toTal = subTotal + 2; // similar as we did for credit card, do here and create amount object var amount = new Amount() { currency = "USD", total = toTal.ToString(), // Total must be equal to sum of shipping, tax and subtotal. details = details }; var transactionList = new List <Transaction>(); transactionList.Add(new Transaction() { description = "Vận chuyển về Việt Nam", invoice_number = Guid.NewGuid().ToString(), amount = amount, item_list = itemList }); this.payment = new PayPal.Api.Payment() { intent = "sale", payer = payer, transactions = transactionList, redirect_urls = redirUrls }; } // Create a payment using a APIContext return(this.payment.Create(apiContext)); }
public static Payment CreatePayment(APIContext apiContext, string redirectUrl, List <Cart> productList) { List <CartItem> orderSession = new List <CartItem>(); //similar to credit card create itemlist and add item objects to it var itemList = new ItemList(); List <Item> listOfItems = new List <Item>(); decimal subTotal = 0; foreach (var product in productList) { Item item = new Item(); item.currency = "USD"; item.name = product.Product_Name; item.description = product.Product_Description; item.quantity = product.Quantity.ToString(); item.sku = product.Product_Id.ToString(); item.price = product.UnitPrice.ToString(); listOfItems.Add(item); subTotal += (product.Quantity > 1) ? product.UnitPrice * product.Quantity : product.UnitPrice; CartItem _orderSession = new CartItem(); _orderSession.Cart_Id = product.Cart_Id; _orderSession.User_Id = product.User_Id; _orderSession.Product_Id = product.Product_Id; _orderSession.Quantity = product.Quantity; _orderSession.UnitPrice = (decimal)product.PriceTotal; _cartDataService.AddCartItem(_orderSession); } itemList.items = listOfItems; var payer = new Payer() { payment_method = "paypal" }; // Configure Redirect Urls here with RedirectUrls object var redirUrls = new RedirectUrls() { cancel_url = redirectUrl, return_url = redirectUrl }; // similar as we did for credit card, do here and create details object var details = new Details() { tax = "1", shipping = "1", subtotal = subTotal.ToString() }; // similar as we did for credit card, do here and create amount object var amount = new Amount() { currency = "USD", total = (Convert.ToDecimal(details.subtotal) + Convert.ToDecimal(details.shipping) + Convert.ToDecimal(details.tax)).ToString(), //total.ToString(), // Total must be equal to sum of shipping, tax and subtotal. details = details }; var transactionList = new List <Transaction>(); Random r = new Random(); string invoiceCode = DateTime.Now.ToString("MMddyyyyss") + r.Next(100); transactionList.Add(new Transaction() { description = "Transaction description.", invoice_number = invoiceCode + 1, amount = amount, item_list = itemList, }); payment = new Payment() { intent = "sale", payer = payer, transactions = transactionList, redirect_urls = redirUrls }; // Create a payment using a APIContext return(payment.Create(apiContext)); }
private Payment CreatePayment(APIContext apiContext, string redirectUrl) { var itemList = new ItemList() { items = new List <Item>() }; //Các giá trị bao gồm danh sách sản phẩm, thông tin đơn hàng //Sẽ được thay đổi bằng hành vi thao tác mua hàng trên website itemList.items.Add(new Item() { //Thông tin đơn hàng name = "Item Name", currency = "USD", price = "5", quantity = "1", sku = "sku" }); //Hình thức thanh toán qua paypal var payer = new Payer() { payment_method = "paypal" }; // Configure Redirect Urls here with RedirectUrls object var redirUrls = new RedirectUrls() { cancel_url = redirectUrl, return_url = redirectUrl }; //các thông tin trong đơn hàng var details = new Details() { tax = "1", shipping = "1", subtotal = "5" }; //Đơn vị tiền tệ và tổng đơn hàng cần thanh toán var amount = new Amount() { currency = "USD", total = "7", // Total must be equal to sum of shipping, tax and details = details }; var transactionList = new List <Transaction>(); //Tất cả thông tin thanh toán cần đưa vào transaction transactionList.Add(new Transaction() { description = "Transaction description.", invoice_number = "your invoice number", amount = amount, item_list = itemList }); this.payment = new Payment() { intent = "sale", payer = payer, transactions = transactionList, redirect_urls = redirUrls }; // Create a payment using a APIContext return(this.payment.Create(apiContext)); }
private Payment CreatePayment(APIContext apiContext, string redirectUrl) { var itemList = new ItemList() { items = new List <Item>() }; var model = (CommonConstant.InforPaypal)TempData["InforPaypal"]; TempData["InforOrder"] = model; double subtotalUSD = Math.Round(new OrderBookDAO().chuyenVNDtoUSD(model.Total), 2); itemList.items.Add(new Item() { name = "Item Name", currency = "USD", price = subtotalUSD.ToString(), quantity = "1", sku = "sku" }); var payer = new Payer() { payment_method = "paypal" }; // Configure Redirect Urls here with RedirectUrls object var redirUrls = new RedirectUrls() { cancel_url = redirectUrl, return_url = redirectUrl }; // similar as we did for credit card, do here and create details object var details = new Details() { tax = "1", shipping = "1", subtotal = subtotalUSD.ToString(), }; double total1 = subtotalUSD + 2; var amount = new Amount() { currency = "USD", total = total1.ToString(), // Total must be equal to sum of shipping, tax and subtotal. details = details }; var transactionList = new List <Transaction>(); transactionList.Add(new Transaction() { description = "Transaction description.", invoice_number = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss"), amount = amount, item_list = itemList }); this.payment = new Payment() { intent = "sale", payer = payer, transactions = transactionList, redirect_urls = redirUrls }; return(this.payment.Create(apiContext)); // Create a payment using a APIContext }
/// <summary> /// Create Payment method /// </summary> /// <param name="apiContext"></param> /// <param name="redirectUrl"></param> /// <param name="payAmount"></param> /// <returns></returns> public Payment CreatePayment(APIContext apiContext, string redirectUrl, string payAmount, string Description) { StringBuilder log = new StringBuilder(); string requestParameter = "payAmount = " + payAmount + ", " + "Description = " + Description + ", " + "apiContext = " + apiContext; log.Append("CreatePayment method called with request parameters : " + requestParameter); Payment res = null; // new Payment(); try { //create itemlist and add item objects to it var itemList = new ItemList() { items = new List <Item>() }; //Adding Item Details like name, currency, price etc itemList.items.Add(new Item() { name = "Item Name", currency = "USD", price = payAmount, quantity = "1", sku = "sku" }); log.Append("Created payer for payment"); var payer = new Payer() { payment_method = "paypal" }; log.Append("Redirect URL created"); var redirUrls = new RedirectUrls() { cancel_url = redirectUrl + "&Cancel=true", return_url = redirectUrl }; log.Append("Details created"); var details = new Details() { subtotal = payAmount }; log.Append("Amount created"); var amount = new Amount() { currency = "USD", total = payAmount, details = details }; string InvoiceNumber = "INVOICE_" + Guid.NewGuid().ToString(); log.Append("Generated invoice number and created transaction list"); var transactionList = new List <Transaction>(); transactionList.Add(new Transaction() { description = Description, invoice_number = InvoiceNumber, amount = amount, item_list = itemList }); log.Append("payment created"); this.payment = new Payment() { intent = "sale", payer = payer, transactions = transactionList, redirect_urls = redirUrls }; log.Append("payment create method called"); res = this.payment.Create(apiContext); log.Append("create payment method executed successfully with res " + res); LogManagers.LogManagers.WriteTraceLog(log); } catch (Exception ex) { LogManagers.LogManagers.WriteErrorLog(ex); } finally { LogManagers.LogManagers.WriteTraceLog(log); } return(res); }
public string Purchase(string photoname, string size, string cost) { //Dictionary<string, string> sdkConfig = new Dictionary<string, string>(); //sdkConfig.Add("mode", "sandbox"); //string accessToken = new OAuthTokenCredential("Ae2ZWMxCl_ueuNy87vcg52hTjX9aVWfnvLQSMjDuTn2sj0crrWYIWwPseO_6H4nLpXKcHE9_DjtrmDEC", "EEmZr7iiuNCksXtPh5NjcVcguVGic0TwCW-f7GFmgfmrG8wBUhn_UJj53OxraTkKijC4UYQHv-fzlH7z", sdkConfig).GetAccessToken(); //APIContext apiContext = new APIContext(accessToken); APIContext apiContext = GetAPIContext(); Amount amnt = new Amount(); amnt.currency = "USD"; amnt.total = cost; List<Transaction> transactionList = new List<Transaction>(); Transaction tran = new Transaction(); tran.amount = amnt; tran.description = "Photo"; tran.description = "creating a payment"; tran.item_list = new ItemList(); tran.item_list.items = new List<Item>(); tran.item_list.items.Add(new Item()); Item item = new Item(); tran.item_list.items[0].currency = "USD"; tran.item_list.items[0].description = size; tran.item_list.items[0].name = photoname; string price = cost; tran.item_list.items[0].price = price;// "12"; tran.item_list.items[0].quantity = 1.ToString();// "1"; tran.item_list.items[0].sku = photoname + " " + size; tran.item_list.items[0].tax = "0"; transactionList.Add(tran); Payer payr = new Payer(); payr.payment_method = "paypal"; payr.payer_info = new PayerInfo(); RedirectUrls redirUrls = new RedirectUrls(); redirUrls.cancel_url = Request.Url + ""; string tempurl = "http://" + Request.Url.Authority + "/Home/Confirm"; redirUrls.return_url = tempurl; Payment pymnt = new Payment(); pymnt.intent = "sale"; pymnt.payer = payr; pymnt.transactions = transactionList; pymnt.redirect_urls = redirUrls; Payment createdPayment = pymnt.Create(apiContext); Links approvalURL = new Links(); for (int i = 0; i < createdPayment.links.Count; ++i) { if (createdPayment.links[i].rel == "approval_url") { approvalURL = createdPayment.links[i]; i = createdPayment.links.Count; } } return approvalURL.href; }
public static string ConfirmSale(Quote quote) { Dictionary <string, string> payPalConfig = new Dictionary <string, string>(); payPalConfig.Add("mode", mode.ToString()); string AccessToken = GetPayPalAccessToken(); APIContext AC = new APIContext(AccessToken); AC.Config = payPalConfig; Payee pe = new Payee(); pe.merchant_id = "Q4A2XY37JY7VW"; RedirectUrls ru = new RedirectUrls(); ru.return_url = "https://www.chimaeraconspiracy.com/checkout/approved?Quote=" + quote.QuoteKey; ru.cancel_url = "https://www.chimaeraconspiracy.com/checkout/cancelled"; Payer pyr = new Payer(); pyr.payment_method = "paypal"; decimal subtotal = QuoteService.CalculateSubtotal(quote); if (quote.Discount != null) { subtotal -= DiscountService.CalculateDiscount(quote.Discount, subtotal); } List <Transaction> transactions = new List <Transaction>(); Transaction t = new Transaction(); t.amount = new Amount(); t.amount.currency = "USD"; t.amount.details = new Details(); t.amount.details.subtotal = subtotal.ToString("0.00"); t.amount.details.tax = "0.00"; t.amount.details.shipping = quote.ShippingCharge.Value.ToString("0.00"); t.amount.total = Math.Round(subtotal + quote.ShippingCharge.Value, 2, MidpointRounding.AwayFromZero).ToString("0.00"); t.description = "Chimaera Conspiracy Shop Purchase"; Payment p = new Payment(); p.intent = "sale"; p.payer = pyr; p.redirect_urls = ru; p.transactions = new List <Transaction>() { t }; Payment pResp = p.Create(AC); if (pResp.state.Equals("created", StringComparison.OrdinalIgnoreCase)) { return(pResp.links.Where(x => x.rel.Equals("approval_url", StringComparison.OrdinalIgnoreCase)).Select(y => y.href).FirstOrDefault()); } throw new Exception("Paypal: approval_url missing"); }