0

I have following form which I wish to submit to WorldPay. Before submitting though, I would like to save some variables into session using PHP. I don't prefer to use jQuery or Ajax if possible.

Thanks in advance.

<form action="https://secure-test.worldpay.com/wcc/purchase" name="buyform" id="buyform" method="post"> 
  <input type="hidden" name="instId"  value="123456">
  <input type="hidden" name="cartId" value="abc123">
  <input type="hidden" name="currency" value="GBP">
  <input type="hidden" name="hideCurrency">
  <input type="hidden" name="amount"  value="10">
  <input type="hidden" name="desc" value="">
  <input type="hidden" name="testMode" value="100">
  <input type="hidden" name="lang" value="en-GB">
  <input type="hidden" name="noLanguageMenu">
  <input type="hidden" name="hideContact">

  <input type="hidden" name="fixContact">
  <input type="hidden" name="name" value="AUTHORISED">
  <input type="hidden" name="address1" value="4 The Street">
  <input type="hidden" name="address2" value="My Suburb">
  <input type="hidden" name="address3" value="">
  <input type="hidden" name="town" value="my town">
  <input type="hidden" name="region" value="region or county">
  <input type="hidden" name="postcode" value="AB10 5AB">
  <input type="hidden" name="country" value="GB">
  <input type="hidden" name="tel" value="0123456789">
  <input type="hidden" name="email" value="demo@worldpay.com">
</form>
user845480
  • 11
  • 3
  • Set the form action to your own script, store variables there, then redirect further (with the post data) to worldpay. Don't think a browser would 'like' this though.. I would use AJAX. – AmazingDreams Feb 22 '13 at 21:56
  • About redirecting with post data: http://stackoverflow.com/questions/5576619/php-redirect-with-post-data – AmazingDreams Feb 22 '13 at 22:03

1 Answers1

0

Make sure to run session_start() first thing, before any headers have been sent. Then putting a value in the the session is as easy as:

$_SESSION['instId'] = $_POST['instId']

Do that for every form value and it will be saved and accesible to the session array as long as that session is valid.

You'll need to point your form to your own script first for this to work.

After that you can do a request using curl to send the post data on to https://secure-test.worldpay.com/wcc/purchase like so:

//set POST variables
$url = 'https://secure-test.worldpay.com/wcc/purchase';
$fields = array(
    'instId' => urlencode($_POST['instId']),
    ... other fields
);

$postVars = http_build_query($fields);

$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $postVars);

$result = curl_exec($ch);
curl_close($ch);
earl3s
  • 2,393
  • 1
  • 23
  • 24
  • Did that answer the question? Was it more about how to save it to a session first, or how to send this to another location afterward? – earl3s Feb 22 '13 at 21:58
  • His form does not point to his own script, would be difficult – AmazingDreams Feb 22 '13 at 21:59
  • Could you please paste me an example about posting with curl? – user845480 Feb 22 '13 at 22:14
  • I completed the fields above and tried the script however I get following error on WorldPay page: Secure Payment Page Sorry, there was a problem processing your payment: The information sent from the merchant's site is invalid or incomplete. Please send the following information to the merchant: The transaction cannot be processed for one or more of the following reasons: The merchant account is suspended. The order currency selected is not supported. The authorisation mode is incorrect. Test mode is unavailable. The installation is not live. Server ID mm2imscs4p (WPReq-77780) – user845480 Feb 23 '13 at 15:44
  • I don't know anything about WorldPay specifically. Can you talk to tech support there, or find an API page to get the details on how to send them a POST request? – earl3s Feb 26 '13 at 17:55