Help to set up two simple paypal buttons in asp.net please!

Crikey, this is probably not as hard as it at first looks, but I am too busy on other parts of the project to spend too much time on this so I'm hoping someone has done this before or has a link to help with?

So I only want to generate two fixed-price buttons on one page for my users to choose one of two different products. I want to have the buttons encrypted so people don't see the paypal account email in the generated page code.

I have set up the paypal sandbox account, I have set up the IPN page it returns to and I have the IPN code written. All I want is two simple buttons that go off to the Paypal site, allow payment to be made, then return to a "payment made" page on my website, where I will check the result of the IPN callback.  Should be simple, right?  Well I can't find any sane examples out there at all...

LVL 1
carledAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

the_crazedCommented:
for the buttons, why can't you use the code paypal generates for you?
on this screen...
https://www.paypal.com/uk/cgi-bin/webscr?cmd=_web-tools

as for coming back to a page on your site, you can configure this in "My Account > Profile > Website Payment Preferences - Return URL"
0
carledAuthor Commented:
...because that generates html code, not asp.net code. It creates identically-named input items for the two different buttons as far as I can see and as they're not asp.net compatible code samples, the page just submits to itself rather than the paypal site, even if I set the asp.net form action to the remote paypal site, that's why...!
0
carledAuthor Commented:
...to clarify, the classic asp model allowed for multiple forms which would work with the paypal-generated code, but if I have two hidden fields inside the one allowed form on the  same asp.net page both called "encrypted" even though each one is for a different product, how does the receiving page have the faintest idea which one of the two fields to use when the form is submitted?
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

the_crazedCommented:
oh, sorry, I forgot they use forms.

you need to use the approach in
http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_23027841.html

its a version of something posted on c-sharpcorner
http://www.c-sharpcorner.com/UploadFile/desaijm/ASP.NetPostURL11282005005516AM/ASP.NetPostURL.aspx

basically, you need a remote post class (see code below)
add call to it in the onclick of your two paypal buttons, (also see below).

any questions just ask.
//RemotePost class
	public class RemotePost
	{
		private System.Collections.Specialized.NameValueCollection Inputs = new System.Collections.Specialized.NameValueCollection();
		public string Url = "";
		public string Method = "post";
		public string FormName = "form1";
		public void Add(string name,string value)
		{
			Inputs.Add(name,value);
		}
		public void Post()
		{
			HttpContext.Current.Response.Clear();
			HttpContext.Current.Response.Write(string.Format("<form name='{0}' id='{0}' method='{1}' action='{2}'>", FormName, Method, Url));
			for (int i = 0; i < Inputs.Keys.Count; i++)
			{
				HttpContext.Current.Response.Write(string.Format("<input type='hidden' id='{0}' name='{0}' value='{1}'/>", Inputs.Keys[i], Inputs[Inputs.Keys[i]]));
			}
			HttpContext.Current.Response.Write("</form>");
			HttpContext.Current.Response.Write(string.Format("<script language='javascript'>document.{0}.submit()</script>",FormName));
			HttpContext.Current.Response.End(); 
		}
	}
 
//button onclick
protected void btnPay1_Click(object sender, EventArgs e)
    { 
        RemotePost rp = new RemotePost();
        rp.Url = "https://www.paypal.com/cgi-bin/webscr";
        rp.Add("encrypted", "-----BEGIN PKCS7-----MIIHTwYJKoZIhvcNAQcEoIIHQDCCBzwCAQExggEwMIIBLAIBADCBlDCBjjELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAkNBMRYwFAYDVQQHEw1Nb3VudGFpbiBWaWV3MRQwEgYDVQQKEwtQYXlQYWwgSW5jLjETMBEGA1UECxQKbGl2ZV9jZXJ0czERMA8GA1UEAxQIbGl2ZV9hcGkxHDAaBgkqhkiG9w0BCQEWDXJlQHBheXBhbC5jb20CAQAwDQYJKoZIhvcNAQEBBQAEgYApnYQfhswcg56Ok3IF3w3ZzfmD/F0rwt/SC9j6OJ9bomH1hClJTW9VKVEqNebGeiksIKvaPPrTQqiTqByGUQdDI61l+Ijx5CKyTiP/zI6GwIcHXHHcS/vCQOpCzTMTcYM92RrXQR6FTeQNxMBb5l1niGS+CNHY8G/cXKgACuYV3jELMAkGBSsOAwIaBQAwgcwGCSqGSIb3DQEHATAUBggqhkiG9w0DBwQIacyFbTdhOB2Ag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1vdW50YWluIFZpZXcxFDASBgNVBAoTC1BheVBhbCBJbmMuMRMwEQYDVQQLFApsaXZlX2NlcnRzMREwDwYDVQQDFAhsaXZlX2FwaTEcMBoGCSqGSIb3DQEJARYNcmVAcGF5cGFsLmNvbYIBADAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBBQUAA4GBAIFfOlaagFrl71+jq6OKidbWFSE+Q4FqROvdgIONth+8kSK//Y/4ihuE4Ymvzn5ceE3S/iBSQQMjyvb+s2TWbQYDwcp129OPIbD9epdr4tJOUNiSojw7BHwYRiPh58S1xGlFgHFXwrEBb3dgNbMUa+u4qectsMAXpVHnD9wIyfmHMYIBmjCCAZYCAQEwgZQwgY4xCzAJBgNVBAYTAlVTMQswCQYDVQQIEwJDQTEWMBQGA1UEBxMNTW91bnRhaW4gVmlldzEUMBIGA1UEChMLUGF5UGFsIEluYy4xEzARBgNVBAsUCmxpdmVfY2VydHMxETAPBgNVBAMUCGxpdmVfYXBpMRwwGgYJKoZIhvcNAQkBFg1yZUBwYXlwYWwuY29tAgEAMAkGBSsOAwIaBQCgXTAYBgkqhkiG9w0BCQMxCwYJKoZIhvcNAQcBMBwGCSqGSIb3DQEJBTEPFw0wODAyMTIxNDU1NDdaMCMGCSqGSIb3DQEJBDEWBBRfVDF+ntd+AuFaucovP1wO/WiXUDANBgkqhkiG9w0BAQEFAASBgC08jYzJiDuyykNjNc2I5Ziu+UUJaP5mO/i5sJuEnAzg4SW+6NSBsmSQQsjJtzF/ctFw/6EhQPW66Q0vCF8YXchJd6xJiENOBOxFA6FEPG81tyorlRTXk2e+Bu32+NKBH85o4WECfZw01Q57nVatPJpdwSeTwpu3kzNsKkt1PHZ3-----END PKCS7-----");
 
        rp.Post();
     }
 
protected void btnPay2_Click(object sender, EventArgs e)
    { 
        RemotePost rp = new RemotePost();
        rp.Url = "https://www.paypal.com/cgi-bin/webscr";
        rp.Add("encrypted", "-----BEGIN PKCS7-----MIIHTwYJKoZIhvcNAQcEoIIHQDC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BQCgXTAYBgkqhkiG9w0BCQMxCwYJKoZIhvcNAQcBMBwGCSqGSIb3DQEJBTEPFw0wODAyMTIxNDU1NDdaMCMGCSqGSIb3DQEJBDEWBBRfVDF+ntd+AuFaucovP1wO/WiXUDANBgkqhkiG9w0BAQEFAASBgC08jYzJiDuyykNjNc2I5Ziu+UUJaP5mO/i5sJuEnAzg4SW+6NSBsmSQQsjJtzF/ctFw/6EhQPW66Q0vCF8YXchJd6xJiENOBOxFA6FEPG81tyorlRTXk2e+Bu32+NKBH85o4WECfZw01Q57nVatPJpdwSeTwpu3kzNsKkt1PHZ3-----END PKCS7-----");
 
        rp.Post();
     }

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
the_crazedCommented:
p.s. if you want to set up explicit "Successful Payment URL"'s, use the "More Options" button on the paypal button generation screen.
0
carledAuthor Commented:
Thanks for that. I understand the principle and have applied it to my aspx page. However, when I click on a button, it definitely goes through the code - I've tested it under debug and does the post to "https://www.sandbox.paypal.com/cgi-bin/webscr". Trouble is, it just goes to the sort of front page login there and fills in my test account user name and wants a password. I've tried logging into the test account first then running my page from the same browser tab, but it still goes to the login page...

What am I probably doing wrong here? Where should I check?
0
carledAuthor Commented:
Aha... getting somewhere now... I added 'rp.add("cmd","_s-xclick")' to the code-behind just before adding the encrypted button... now it gets to a proper "confirm purchase" page!
0
the_crazedCommented:
good work! I'd forgotten that "cmd" was a required paypal field
0
carledAuthor Commented:
Thanks a lot!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
E-Commerce

From novice to tech pro — start learning today.