using PayPal.Api; using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace PayPalCS { public partial class _Default : Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { Dictionary sdkConfig = new Dictionary(); sdkConfig.Add("mode", "sandbox"); Global.accessString = new OAuthTokenCredential("CLIENT ID", "SECRET", sdkConfig).GetAccessToken(); APIContext apiContext = new APIContext(Global.accessString); apiContext.Config = sdkConfig; Amount amnt = new Amount(); amnt.currency = "USD"; amnt.total = txtPrice.Text; List transactionList = new List(); Transaction tran = new Transaction(); tran.description = "creating a payment"; tran.amount = amnt; transactionList.Add(tran); Payer payr = new Payer(); payr.payment_method = "paypal"; RedirectUrls redirUrls = new RedirectUrls(); string baseURL = "http://paypaltest.azurewebsites.net/PayPalCallback.aspx"; redirUrls.cancel_url = baseURL + "?cancel=true"; redirUrls.return_url = baseURL; Payment pymnt = new Payment(); pymnt.intent = "sale"; pymnt.payer = payr; pymnt.transactions = transactionList; pymnt.redirect_urls = redirUrls; Payment createdPayment = pymnt.Create(apiContext); string url = ""; for (int i = 0; i < createdPayment.links.Count; i++) { string t = createdPayment.links[i].rel; if (t.Equals("approval_url")) { url = createdPayment.links[i].href; break; } } // )).links)).Items[1].href Response.Redirect(url); // send the user here to confirm } } }