To add a simple PayPal button to your website you could use some code like this:
// Variables
string business = "youremail@example.com";
string item_name = "Screwdriver set";
string item_number = "1054b";
decimal amount = 10.99m;
// Build the PayPal url
StringBuilder sb = new StringBuilder();
sb.Append("cmd=_xclick");
sb.Append("&business=" + HttpUtility.UrlEncode(business));
sb.Append("&no_shipping=1");
sb.Append("¤cy_code=GBP");
sb.Append("&lc=GB");
sb.Append("&bn=PP-BuyNowBF");
sb.Append("&item_name=" + HttpUtility.UrlEncode(item_name));
sb.Append("&item_number=" + HttpUtility.UrlEncode(item_number));
sb.Append("&amount=" + HttpUtility.UrlEncode(amount.ToString()));
// Redirect to PayPal to make secure payment
Response.Redirect(@"https://www.paypal.com/cgi-bin/webscr?" + sb.ToString());
Depending on the country you are using PayPal in you may have to change the lc and currency_code lines.
Put this in a button click event on your page, customise the variables as required and you're all set!
// Variables
string business = "youremail@example.com";
string item_name = "Screwdriver set";
string item_number = "1054b";
decimal amount = 10.99m;
// Build the PayPal url
StringBuilder sb = new StringBuilder();
sb.Append("cmd=_xclick");
sb.Append("&business=" + HttpUtility.UrlEncode(business));
sb.Append("&no_shipping=1");
sb.Append("¤cy_code=GBP");
sb.Append("&lc=GB");
sb.Append("&bn=PP-BuyNowBF");
sb.Append("&item_name=" + HttpUtility.UrlEncode(item_name));
sb.Append("&item_number=" + HttpUtility.UrlEncode(item_number));
sb.Append("&amount=" + HttpUtility.UrlEncode(amount.ToString()));
// Redirect to PayPal to make secure payment
Response.Redirect(@"https://www.paypal.com/cgi-bin/webscr?" + sb.ToString());
Depending on the country you are using PayPal in you may have to change the lc and currency_code lines.
Put this in a button click event on your page, customise the variables as required and you're all set!
this code for one item only but for multiple items? what i do?
ReplyDeleteYou just have to use it in loop.
ReplyDeleteIt is just a demo. You have to make changes according to your requirement.
ReplyDelete