Matt Elhotiby
Matt Elhotiby

Reputation: 44086

PHP redirect with POST

Ok so i am trying to do a redirect with PHP with a PaymentID ...i am not sure how to do this ...here are the instructions and even some example asp.net code to help

Redirect to the Mercury HostedCheckout Page Mercury HostedCheckout URL: Test URL: https://hc.mercurydev.net/Checkout.aspx

Hidden Fields in HTML Form Post to HostedCheckout

Field Name   Description                                                          Required
PaymentID    The unique identifier returned by the InitiatePayment web service.   Yes

And here is the sample code in C# for asp.net

Redirect sample code This is sample code that will redirect the browser to Mercury’s HostedCheckout page. It is server side C# code used in an asp.net click event that creates an html response that will redirect to Mercury.

//Set the necessary variables before building html.
string hostedCheckoutURL = ConfigurationManager.AppSettings["HostedCheckoutURL"]; 
string paymentID = this.txtPaymentID.Text;
//Build an html form post to be sent back to the browser. 
//It will redirect the browser to the Mercury HostedCheckout page. 
Response.Clear(); 
Response.Write("<html><head>"); 
Response.Write("</head><body onload=\"document.frmCheckout.submit()\">"); 
Response.Write("<form name=\"frmCheckout\" method=\"Post\" action=\"" + hostedCheckoutURL + "\" >"); 
Response.Write("<input name=\"PaymentID\" type=\"hidden\" value=\"" + paymentID + "\">"); 
Response.Write("</form>"); 
Response.Write("</body></html>"); 
Response.End();

Basically I need to do the same request in PHP...any ideas

Upvotes: 1

Views: 879

Answers (1)

Dejan Marjanović
Dejan Marjanović

Reputation: 19380

You have to include("config.php"); or such to get $hostedCheckoutURL, but I don't know from where do you get PaymentID.

<?php
//Set the necessary variables before building html.
$hostedCheckoutURL = "https://hc.mercurydev.net/Checkout.aspx"; 
$paymentID = "123456789";
//Build an html form post to be sent back to the browser. 
//It will redirect the browser to the Mercury HostedCheckout page. 
echo("<html><head>"); 
echo("</head><body onload=\"document.frmCheckout.submit()\">"); 
echo("<form name=\"frmCheckout\" method=\"Post\" action=\"".$hostedCheckoutURL."\" >"); 
echo("<input name=\"PaymentID\" type=\"hidden\" value=\"".$paymentID."\">"); 
echo("</form>"); 
echo("</body></html>");
?>

Upvotes: 3

Related Questions