468,549 Members | 2,309 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,549 developers. It's quick & easy.

$_POST values to Worldpay https thru a script and not a form

Hello,

For long time now I am trying to POST some variables from a form to a
script and then that script POST them to another External page or
payment gateway like worldpay.

The reason I want to do that is because I want the user to enter his
details in my website and then post them in Worldpay and continue any
other steps he has to do to pay and then ofcourse using the callback
function right back to the database if the transaction was Succesfull or
not.

I used curl like in the example bellow:
$urlString = "cartId=56997&name=fred";
$ch = curl_init("https://select.worldpay.com/wcc/purchase");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $urlString);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
echo $data = curl_exec($ch);
curl_close($ch);

but thats not working as I expect it to work.
I would excpect to redirect to https://select.worldpay.com/wcc/purchase
and post the values in the $urlString.

My code sort of does that but it includes the worldpay page in my website.
Can you please help me leading me in the right way ?
Apr 11 '06 #1
6 3156
Angelos wrote:
Hello,

For long time now I am trying to POST some variables from a form to a
script and then that script POST them to another External page or
payment gateway like worldpay.

The reason I want to do that is because I want the user to enter his
details in my website and then post them in Worldpay and continue any
other steps he has to do to pay and then ofcourse using the callback
function right back to the database if the transaction was Succesfull or
not.

I used curl like in the example bellow:
$urlString = "cartId=56997&name=fred";
$ch = curl_init("https://select.worldpay.com/wcc/purchase");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $urlString);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
echo $data = curl_exec($ch);
curl_close($ch);

but thats not working as I expect it to work.
I would excpect to redirect to https://select.worldpay.com/wcc/purchase
and post the values in the $urlString.

My code sort of does that but it includes the worldpay page in my website.
Can you please help me leading me in the right way ?


http://www.latevintage.com/content.php?moduleId=2

you can sort of add a product in the cart here and folow the checkout to
see what happens.
Apr 11 '06 #2
NC
Angelos wrote:

I used curl like in the example bellow:
$urlString = "cartId=56997&name=fred";
$ch = curl_init("https://select.worldpay.com/wcc/purchase");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $urlString);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
echo $data = curl_exec($ch);
curl_close($ch);

but thats not working as I expect it to work.
I would excpect to redirect to https://select.worldpay.com/wcc/purchase
and post the values in the $urlString.

My code sort of does that but it includes the worldpay page in my website.


Yes, because you are telling it to do it. Get rid of echo, and it
won't...

Cheers,
NC

Apr 11 '06 #3
NC wrote:
Angelos wrote:
I used curl like in the example bellow:
$urlString = "cartId=56997&name=fred";
$ch = curl_init("https://select.worldpay.com/wcc/purchase");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $urlString);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
echo $data = curl_exec($ch);
curl_close($ch);

but thats not working as I expect it to work.
I would excpect to redirect to https://select.worldpay.com/wcc/purchase
and post the values in the $urlString.

My code sort of does that but it includes the worldpay page in my website.

Yes, because you are telling it to do it. Get rid of echo, and it
won't...

Cheers,
NC

But when I get rid of the echo it still doesn't redirect me to worldpay :s
Apr 11 '06 #4
Angelos wrote:
Hello,

For long time now I am trying to POST some variables from a form to a
script and then that script POST them to another External page or
payment gateway like worldpay.

The reason I want to do that is because I want the user to enter his
details in my website and then post them in Worldpay and continue any
other steps he has to do to pay and then ofcourse using the callback
function right back to the database if the transaction was Succesfull or
not.

I used curl like in the example bellow:
$urlString = "cartId=56997&name=fred";
$ch = curl_init("https://select.worldpay.com/wcc/purchase");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $urlString);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
echo $data = curl_exec($ch);
curl_close($ch);


$urlString = "action=1&action=2";
$url = "https://select.worldpay.com/wcc/purchase";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS,$urlString);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects
curl_exec ($ch);
curl_close ($ch);

THat does exactly the same...
without the echo.

:s

Apr 11 '06 #5
Hello,

on 04/11/2006 11:16 AM Angelos said the following:
For long time now I am trying to POST some variables from a form to a
script and then that script POST them to another External page or
payment gateway like worldpay.

The reason I want to do that is because I want the user to enter his
details in my website and then post them in Worldpay and continue any
other steps he has to do to pay and then ofcourse using the callback
function right back to the database if the transaction was Succesfull or
not.

I used curl like in the example bellow:
$urlString = "cartId=56997&name=fred";
$ch = curl_init("https://select.worldpay.com/wcc/purchase");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $urlString);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
echo $data = curl_exec($ch);
curl_close($ch);

but thats not working as I expect it to work.
I would excpect to redirect to https://select.worldpay.com/wcc/purchase
and post the values in the $urlString.


Don't you need to authenticate somewhere?

Anyway, you may want to try this HTTP client class that supports
redirection and cookie handling. If it does not work for some reason,
you can enable debug output to see exactly the dialog with the server to
figure what is going on:

http://www.phpclasses.org/httpclient
--

Regards,
Manuel Lemos

Metastorage - Data object relational mapping layer generator
http://www.metastorage.net/

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/
Apr 11 '06 #6
d
"Angelos" <an*****@redcatmedia.net> wrote in message
news:Yr********************@bt.com...
NC wrote:
Angelos wrote:
I used curl like in the example bellow:
$urlString = "cartId=56997&name=fred";
$ch = curl_init("https://select.worldpay.com/wcc/purchase");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $urlString);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
echo $data = curl_exec($ch);
curl_close($ch);

but thats not working as I expect it to work.
I would excpect to redirect to https://select.worldpay.com/wcc/purchase
and post the values in the $urlString.

My code sort of does that but it includes the worldpay page in my
website.

Yes, because you are telling it to do it. Get rid of echo, and it
won't... Cheers, NC

But when I get rid of the echo it still doesn't redirect me to worldpay :s


It's redirecting the curl client to the worldpay site, and only if the curl
client has been configured to follow redirects. That's not going to help
anyone :)

Instead of doing it like this, why not have your PHP construct a hidden form
that you submit using javascript to the url in question. That would
redirect the client to worldpay, instead of just the curl client.

hope that helps!

dave
Apr 11 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

13 posts views Thread by Rudolf Horbas | last post: by
7 posts views Thread by Dan | last post: by
1 post views Thread by Antoni | last post: by
1 post views Thread by dave | last post: by
reply views Thread by Anthony | last post: by
2 posts views Thread by Richard Brooks | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.