Page 1 of 1

Send data using POST method

Posted: Mon Nov 28, 2011 3:33 am
by sina_saeedi82
Hi. I'm trying to write a wordpress plugin to contacting with a payment gateway. The gateway is an Iranian bank named Mellat.
First of all I have to send a request to their web-service and they respond me. There are 2 things in response, a string named $RefId and a status. If status be 0 it means every thing is ok and now I redirect customer and send $RefId to bank's gateway using POST method. And then they respond me if payment is ok or not.
I cant send $RefId with POST. How can I do this?

Point: I wrote another payment plugin for another bank named Parsian. The procedure is same but in that case I had to send data using GET method that was so easy. I used this piece of code to redirect using GET method:

Code: Select all

$parsURL = "https://www.pec24.com/pecpaymentgateway/?au=" . $authority ;
header("Location: $parsURL");
exit();

Re: Send data using POST method

Posted: Mon Nov 28, 2011 3:43 am
by mikeashfield

Code: Select all

<?php
    $parsURL="https://www.pec24.com/pecpaymentgateway/?au=".$authority.;
    header("'Location: ".$parsURL."'");
    exit();
?>

Re: Send data using POST method

Posted: Mon Nov 28, 2011 4:15 am
by twinedev
Look up cURL, which basically act like a web browsers that is all done via programming, so you can assign POST data to submit to a site.

-Greg

Re: Send data using POST method

Posted: Mon Nov 28, 2011 4:22 am
by sina_saeedi82
mikeashfield wrote:

Code: Select all

<?php
    $parsURL="https://www.pec24.com/pecpaymentgateway/?au=".$authority.;
    header("'Location: ".$parsURL."'");
    exit();
?>
The code I inserted, is for another bank that uses GET method. The code is right and works. Now, for another bank, I need to send my data using POST method. It only accepts POST method. How can I send data with POST method in php?
twinedev wrote:Look up cURL, which basically act like a web browsers that is all done via programming, so you can assign POST data to submit to a site.

-Greg
I'm not familiar with cURL. I have to send s.th like this:

Code: Select all

<form method="POST" action="https://pgw.bpm.bankmellat.ir/pgwchannel/startpay.mellat">
<input type="hidden" name="RefId" value="<?php echo $RefId ?>">
</form>
Could you tell me how can I send it using cURL?

Re: Send data using POST method

Posted: Mon Nov 28, 2011 4:54 am
by mikeashfield
You could also do it with JS too:

Code: Select all

<script language="javascript" version="1.3" type="text/javascript">
function postwith (to,p) {
var myForm = document.createElement("form");
myForm.method="post" ;
myForm.action = to ;
for (var k in p) {
var myInput = document.createElement("input") ;
myInput.setAttribute("name", k) ;
myInput.setAttribute("value", p[k]);
myForm.appendChild(myInput) ;
}
document.body.appendChild(myForm) ;
myForm.submit() ;
document.body.removeChild(myForm) ;
}
</script>
<body onload="postwith('hxtp://urlropost.com',{key:value,key1:value1});">