Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Payment gateway - Razorpay #80

Merged
merged 4 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
$order=$_SESSION['Order'];
$amount=$_SESSION['amount'];
$userId= $_SESSION['user_id'];

$rid = $_SESSION['rest_id'];

$oid = mt_rand(10000, 99999);
$_SESSION['orderid'] = str_pad($oid, 5, '0', STR_PAD_LEFT);
Expand Down
2 changes: 1 addition & 1 deletion menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ function convertCartToArray(cart) {
<td id="" class="text-center"><b id="totalPrice"></b></td>
</tbody>
</table>
<div id="addVal"></div><form action="/homemade/menu.php" method="post">
<div id="addVal"></div><form action="/alimento/menu.php" method="post">
<input hidden value="<?php echo $id ?>" name="restaurant_id"/>
<a href="checkout.php"> <button id="checkoutBtn" class="btn btn-primary checkOutBtn" style="display:none">CHECKOUT</button></a>
</form>
Expand Down
26 changes: 24 additions & 2 deletions pay.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,29 @@

<script type="text/javascript">
$(document).ready(function() {

$('.razorpay-payment-button').click();
let options = {
// Razorpay options
key: "<?php echo $data['key']?>", // Your Razorpay Key
amount: "<?php echo $data['amount']?>", // Amount is in currency subunits
currency: "INR",
name: "<?php echo $data['name']?>",
description: "<?php echo $data['description']?>",
image: "<?php echo $data['image']?>",
order_id: "<?php echo $data['order_id']?>",
handler: function (response){
window.location.href = "/alimento/verify.php?razorpay_payment_id=" + response.razorpay_payment_id;
},
prefill: {
name: "<?php echo $data['prefill']['name']?>",
email: "<?php echo $data['prefill']['email']?>",
contact: "<?php echo $data['prefill']['contact']?>"
},
notes: {
shopping_order_id: "<?php echo $_SESSION['orderid'] ?>"
}
};

let razorpay = new Razorpay(options);
razorpay.open();
});
</script>
8 changes: 4 additions & 4 deletions verify.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@
$phone=$_SESSION['Billing_phone'];
$name=$_SESSION['name'];


$sql = "INSERT INTO `orders` ( `order_id`, `r_id`, `user_id`, `amount`, `address`, `phone`, `payment`, `order_status`, `rating`, `name`)
VALUES ('$orderId', '$restId', '$userId', '$amount', '$address', '$phone', '$tranStatus', 'Accecpted', '0', '$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) {
Expand All @@ -63,7 +63,7 @@
}

if ($result) {
header("location: Track_order.php");
header("location: track_order.php");
}
}

Expand Down