Jump to content
mohammad2232

simple payment form

Recommended Posts

hello

i have 3 php smple file for local payment company that i tried to make simple form for work with that but really i can't do that!

i just read some php , html , css references in w3schools step by step but i don't know where is problem!?

these are free sample file

functions.php

function send($api, $amount, $redirect, $factorNumber=null) {
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, 'https://pay.ir/payment/send');
	curl_setopt($ch, CURLOPT_POSTFIELDS,"api=$api&amount=$amount&redirect=$redirect&factorNumber=$factorNumber");
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
	$res = curl_exec($ch);
	curl_close($ch);
	return $res;
}

function verify($api, $transId) {
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, 'https://pay.ir/payment/verify');
	curl_setopt($ch, CURLOPT_POSTFIELDS, "api=$api&transId=$transId");
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
	$res = curl_exec($ch);
	curl_close($ch);
	return $res;
}

send.php

include_once("functions.php");
$api = 'test';
$amount = 'Amount';
$redirect = 'Callback';
$factorNumber = 123;
$result = send($api,$amount,$redirect,$factorNumber);
$result = json_decode($result);
if($result->status) {
	$go = "https://pay.ir/payment/gateway/$result->transId";
	header("Location: $go");
} else {
	echo $result->errorMessage;
}

verify.php

include_once("functions.php");
$api = 'test';
$transId = $_POST['transId'];
$result = verify($api,$transId);
$result = json_decode($result);
print_r($result);

and i create index.php

<!DOCTYPE html>
<html>
<body>

<form method="post" action="/send.php">
  Name: <input type="text" name="fname">
  <br>
  <br>
    price: <input type="number" name="Amount">

  <input type="submit">
</form>


</body>
</html>

but this is not work

can anybody help me thanks

Share this post


Link to post
Share on other sites

Saying it doesn't work isn't enough information, what specifically happens?

Share this post


Link to post
Share on other sites
1 hour ago, justsomeguy said:

Saying it doesn't work isn't enough information, what specifically happens?

it should get amount and set it in send.php and send to gateway for pay (that "test" in api work for test it)

but only show this

 

 

00ae.PNG

Edited by mohammad2232

Share this post


Link to post
Share on other sites

Do you have an opening PHP tag in your code?  You need to tell the server where the PHP code to execute is, and you use PHP tags for that.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×