views:

49

answers:

2

I am having some issue posting data to a specific URL when testing payment transactions on the paypal platform. Although much more technically understood, I chose not to use their API and NVP platform because of the requirement to FIRST create a transaction, then come back and have to create a recurring profile (as opposed to all at once - stupid design in my opinion).

Ultimately, I am trying to take data I have encrypted into a specific variable and post that data to a URL of choice WITHOUT having to treat it as a form where user clicks submit.

My HTML form works - the code is:

<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" target="_blank">';
<input type="hidden" name="cmd" value="_s-xclick"/>';
<input type="hidden" name="encrypted" value="'.$encrypted.'"/>';
<input type="submit" value="Go to checkout" name="submit" class="cartButton" />';
</form>

where $encrypted are my encrypted parameters. While the code works - I do not want to have the user click a link to be sent to the form. Instead, I want the user to click a button which first runs a PHP script to store the data in a temporary database THEN push the required elements (CMD and ENCRYPTED) to the post URL (https://www.sandbox.paypal.com/cgi-bin/webscr).

Any ideas how to accomplish this? Is it possible? I use PHP and mySQL for my site. Using Javascript of any kind is not a solution.

EDIT 1

I have it set up to use cURL as a possible way to POST the data but two things are happening: 1) I am getting no response whatsoever, 2) the consumer actually needs to be redirected to the paypal payment pages with the posted data after the database insert has taken place.

A: 

You could use cURL to post data to the URL.

chigley
@chigley - I should have added my notes; only issue I have with cURL is that I actually need to consumer redirected to the posted URL as well with the posted data
JM4
@JM4 - in which case I can't really think of any suggestions that don't involve JavaScript! It may still be possible with cURL but I don't know enough about it to suggest anything.
chigley
Wrikken
@wrikken - you are incorrect - posting form data and no javascript is quite easily achieved if simple post is all that is required. My issue however is that I need the data posted and the site redirected like a form action="".
JM4
POST's _never_ survive a redirect, it's in the specs. You can let a user do a GET request to a page, but _never_ a POST without using some kind of form. So if Paypal supports a GET url: fine. If they don't: you're out of luck with your requirements. And you are _never_ able te let _my_ browser perform a POST request without me clicking a button if I have javascript disabled. Ever.
Wrikken
inccorect - http://wezfurlong.org/blog/2006/nov/http-post-from-php-without-curl
JM4
@JM4: that is not _my_ browser, that is _your_ server doing the work / POST request, and hence, it will not work, because for the Paypal process to work, _my_ browser has to arrive with the POST values. Read up on your basics, I've heard my last _'you're incorrect'_ for the day from someone who not only doesn't understand the basics (which can happen, we all were once like that), but seems quite unwilling to learn despite turning to others for help. Good luck with that, and have a nice life.
Wrikken
@wrikken - I apologize if coming across as rude or "unwilling" to learn but from my perspective, this is a shining example of what "inexperienced" programmers come across all the time. While the rules you speak of for PayPal may hold true, this was never once mentioned and reading something is "impossible" when it is not in principle. When I test on my local machine - a POST is occurring but I run into an error where the site thinks I need to log into the "sandbox"
JM4
'a POST is occurring' indeed, I emphasizes "_my_" in "_my_ browser" for that reason. If you don't know something the correct response is not _'inccorect'_ (sic), which instantly makes me unwilling to progress any further. Long story short: in response to the POST request (that the browser of the user should perform, not your server), Paypal starts a session, stores values, sets all kind of cookies, which you can't get the users browser to send to paypal.com because cookies aren't shared across domains (in normal security setups for browsers).
Wrikken
I was unaware - thank you for your help
JM4
A: 

Have you considered piping the data through wget?

Tom
@Tom - Not really the solution i am looking for given the Paypal settings
JM4