forked from Vimall03/Alimento
-
Notifications
You must be signed in to change notification settings - Fork 0
/
verify.php
90 lines (72 loc) · 2.91 KB
/
verify.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
require('config.php');
session_start();
include 'partials/_dbconnect.php';
require('razorpay-php/Razorpay.php');
use Razorpay\Api\Api;
use Razorpay\Api\Errors\SignatureVerificationError;
$success = true;
$error = "Payment Failed";
if (empty($_POST['razorpay_payment_id']) === false) {
$api = new Api("rzp_test_KvVwa75VGRseJn", "Sw64vDNjVtBESxJq6YJbbPzd");
try {
// Please note that the razorpay order ID must
// come from a trusted source (session here, but
// could be database or something else)
$attributes = array(
'razorpay_order_id' => $_SESSION['razorpay_order_id'],
'razorpay_payment_id' => $_POST['razorpay_payment_id'],
'razorpay_signature' => $_POST['razorpay_signature']
);
$api->utility->verifyPaymentSignature($attributes);
} catch (SignatureVerificationError $e) {
$success = false;
$error = 'Razorpay Error : ' . $e->getMessage();
}
}
if ($success === true) {
$razorpay_order_id = $_SESSION['razorpay_order_id'];
$razorpay_payment_id = $_POST['razorpay_payment_id'];
$razorpay_signature = $_POST['razorpay_signature'];
$tranStatus = 'SUCCESS';
$order = $_SESSION['Order'];
$orderId = $_SESSION['orderid'];
$restId = $_SESSION['rest_id'];
$userId = $_SESSION['user_id'];
$amount = $_SESSION['amount'];
$address = $_SESSION['Billing_address'];
$phone = $_SESSION['Billing_phone'];
$name = $_SESSION['name'];
// Added $order in the query as it is set to 'NOT NULL' and no DEFAULT value is provided. Later it is updated in below forEach loop.
$sql = "INSERT INTO `orders` ( `order_id`, `r_id`, `user_id`, `order`, `amount`, `address`, `phone`, `payment`, `order_status`, `rating`, `name`)
VALUES ('$orderId', '$restId', '$userId', '$order', '$amount', '$address', '$phone', '$tranStatus', 'Accecpted', '0', '$name');";
$result = mysqli_query($conn, $sql);
foreach ($order as $item) {
$sql = "UPDATE `orders` SET `order` = CONCAT(`order`, '$item') WHERE `order_id` = '$orderId';";
$result = mysqli_query($conn, $sql);
}
if ($result) {
header("location: new_track_order.php");
}
}
// $sql = "UPDATE `billing`
// SET
// `Transaction_status` = '$tranStatus',
// `razorpay_signature` =' $razorpay_signature' ,
// `razorpay_payment_id` = '$razorpay_payment_id' ,
// `razorpay_order_id` = '$razorpay_order_id'
// WHERE
// `Order_id` = '{$_SESSION['orderid']}';";
// $result = mysqli_query($conn, $sql);
// if ($result) {
// header("location: thankyou.php");
// }
else {
$html = "<p>Your payment failed</p>
<p>{$error}</p>";
$tranStatus = "FAILED";
$sql = "UPDATE `orders`
SET `Transaction_status` = '$tranStatus'
WHERE `Order_id` = '{$_SESSION['orderid']}';";
$result = mysqli_query($conn, $sql);
}