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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Angelos

    $_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&n ame=fred";
    $ch = curl_init("http s://select.worldpay .com/wcc/purchase");
    curl_setopt($ch , CURLOPT_HEADER, 0);
    curl_setopt($ch , CURLOPT_POST, 1);
    curl_setopt($ch , CURLOPT_POSTFIE LDS, $urlString);
    curl_setopt($ch , CURLOPT_FOLLOWL OCATION, 1);// allow redirects
    curl_setopt($ch , CURLOPT_RETURNT RANSFER, 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 ?
  • Angelos

    #2
    Re: $_POST values to Worldpay https thru a script and not a form

    Angelos wrote:[color=blue]
    > 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&n ame=fred";
    > $ch = curl_init("http s://select.worldpay .com/wcc/purchase");
    > curl_setopt($ch , CURLOPT_HEADER, 0);
    > curl_setopt($ch , CURLOPT_POST, 1);
    > curl_setopt($ch , CURLOPT_POSTFIE LDS, $urlString);
    > curl_setopt($ch , CURLOPT_FOLLOWL OCATION, 1);// allow redirects
    > curl_setopt($ch , CURLOPT_RETURNT RANSFER, 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 ?[/color]



    you can sort of add a product in the cart here and folow the checkout to
    see what happens.

    Comment

    • NC

      #3
      Re: $_POST values to Worldpay https thru a script and not a form

      Angelos wrote:[color=blue]
      >
      > I used curl like in the example bellow:
      > $urlString = "cartId=56997&n ame=fred";
      > $ch = curl_init("http s://select.worldpay .com/wcc/purchase");
      > curl_setopt($ch , CURLOPT_HEADER, 0);
      > curl_setopt($ch , CURLOPT_POST, 1);
      > curl_setopt($ch , CURLOPT_POSTFIE LDS, $urlString);
      > curl_setopt($ch , CURLOPT_FOLLOWL OCATION, 1);// allow redirects
      > curl_setopt($ch , CURLOPT_RETURNT RANSFER, 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.[/color]

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

      Cheers,
      NC

      Comment

      • Angelos

        #4
        Re: $_POST values to Worldpay https thru a script and not a form

        NC wrote:[color=blue]
        > Angelos wrote:
        >[color=green]
        >>I used curl like in the example bellow:
        >>$urlString = "cartId=56997&n ame=fred";
        >>$ch = curl_init("http s://select.worldpay .com/wcc/purchase");
        >>curl_setopt($ ch, CURLOPT_HEADER, 0);
        >>curl_setopt($ ch, CURLOPT_POST, 1);
        >>curl_setopt($ ch, CURLOPT_POSTFIE LDS, $urlString);
        >>curl_setopt($ ch, CURLOPT_FOLLOWL OCATION, 1);// allow redirects
        >>curl_setopt($ ch, CURLOPT_RETURNT RANSFER, 1);
        >>echo $data = curl_exec($ch);
        >>curl_close($c h);
        >>
        >>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.[/color]
        >
        >
        > Yes, because you are telling it to do it. Get rid of echo, and it
        > won't...
        >
        > Cheers,
        > NC
        >[/color]
        But when I get rid of the echo it still doesn't redirect me to worldpay :s

        Comment

        • Angelos

          #5
          Re: $_POST values to Worldpay https thru a script and not a form

          Angelos wrote:[color=blue]
          > 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&n ame=fred";
          > $ch = curl_init("http s://select.worldpay .com/wcc/purchase");
          > curl_setopt($ch , CURLOPT_HEADER, 0);
          > curl_setopt($ch , CURLOPT_POST, 1);
          > curl_setopt($ch , CURLOPT_POSTFIE LDS, $urlString);
          > curl_setopt($ch , CURLOPT_FOLLOWL OCATION, 1);// allow redirects
          > curl_setopt($ch , CURLOPT_RETURNT RANSFER, 1);
          > echo $data = curl_exec($ch);
          > curl_close($ch) ;[/color]

          $urlString = "action=1&actio n=2";
          $url = "https://select.worldpay .com/wcc/purchase";
          $ch = curl_init();
          curl_setopt($ch , CURLOPT_URL,$ur l);
          curl_setopt($ch , CURLOPT_POST, 1);
          curl_setopt($ch , CURLOPT_HEADER, 0);
          curl_setopt($ch , CURLOPT_POSTFIE LDS,$urlString) ;
          curl_setopt($ch , CURLOPT_FOLLOWL OCATION, 1);// allow redirects
          curl_exec ($ch);
          curl_close ($ch);

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

          :s

          Comment

          • Manuel Lemos

            #6
            Re: $_POST values to Worldpay https thru a script and not a form

            Hello,

            on 04/11/2006 11:16 AM Angelos said the following:[color=blue]
            > 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&n ame=fred";
            > $ch = curl_init("http s://select.worldpay .com/wcc/purchase");
            > curl_setopt($ch , CURLOPT_HEADER, 0);
            > curl_setopt($ch , CURLOPT_POST, 1);
            > curl_setopt($ch , CURLOPT_POSTFIE LDS, $urlString);
            > curl_setopt($ch , CURLOPT_FOLLOWL OCATION, 1);// allow redirects
            > curl_setopt($ch , CURLOPT_RETURNT RANSFER, 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.[/color]

            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:




            --

            Regards,
            Manuel Lemos

            Metastorage - Data object relational mapping layer generator
            ✅「官方网站」mk体育拥有各种免费又安全的资源,因为亚洲当中中国玩家人口基数的众多,mk体育创造了中国网络游戏的神话,全球首推免费在线点播体育直播。


            PHP Classes - Free ready to use OOP components written in PHP
            Free PHP Classes and Objects 2025 Versions with PHP Example Scripts, PHP Tutorials, Download PHP Scripts, PHP articles, Remote PHP Jobs, Hire PHP Developers, PHP Book Reviews, PHP Language OOP Materials

            Comment

            • d

              #7
              Re: $_POST values to Worldpay https thru a script and not a form

              "Angelos" <angelos@redcat media.net> wrote in message
              news:YrydnXTKFJ _jIKbZRVnyvg@bt .com...[color=blue]
              > NC wrote:[color=green]
              >> Angelos wrote:
              >>[color=darkred]
              >>>I used curl like in the example bellow:
              >>>$urlString = "cartId=56997&n ame=fred";
              >>>$ch = curl_init("http s://select.worldpay .com/wcc/purchase");
              >>>curl_setopt( $ch, CURLOPT_HEADER, 0);
              >>>curl_setopt( $ch, CURLOPT_POST, 1);
              >>>curl_setopt( $ch, CURLOPT_POSTFIE LDS, $urlString);
              >>>curl_setopt( $ch, CURLOPT_FOLLOWL OCATION, 1);// allow redirects
              >>>curl_setopt( $ch, CURLOPT_RETURNT RANSFER, 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.[/color]
              >>
              >>
              >> Yes, because you are telling it to do it. Get rid of echo, and it
              >> won't... Cheers, NC
              >>[/color]
              > But when I get rid of the echo it still doesn't redirect me to worldpay :s[/color]

              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


              Comment

              Working...