-
Notifications
You must be signed in to change notification settings - Fork 3
/
Request.php
41 lines (34 loc) · 1.21 KB
/
Request.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
$data = array("merchant_id" => "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"amount" => 1000,
"callback_url" => "http://www.yoursite.com/verify.php",
"description" => "خرید تست",
"metadata" => [ "email" => "info@email.com","mobile"=>"09121234567"],
);
$jsonData = json_encode($data);
$ch = curl_init('https://api.zarinpal.com/pg/v4/payment/request.json');
curl_setopt($ch, CURLOPT_USERAGENT, 'ZarinPal Rest Api v1');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($jsonData)
));
$result = curl_exec($ch);
$err = curl_error($ch);
$result = json_decode($result, true, JSON_PRETTY_PRINT);
curl_close($ch);
if ($err) {
echo "cURL Error #:" . $err;
} else {
if (empty($result['errors'])) {
if ($result['data']['code'] == 100) {
header('Location: https://www.zarinpal.com/pg/StartPay/' . $result['data']["authority"]);
}
} else {
echo'Error Code: ' . $result['errors']['code'];
echo'message: ' . $result['errors']['message'];
}
}
?>