Advertisement
Daniel3996

checkout.php

Dec 11th, 2023 (edited)
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. <?php
  2.  
  3. require __DIR__."/vendor/autoload.php";
  4.  
  5.  
  6. // Replace 'your_key_id' and 'your_secret_key' with your actual Razorpay key and secret
  7. $razorpay_key_id = 'rzp_//';
  8. $razorpay_secret_key = '//;
  9.  
  10. use \Razorpay\Api\Api;
  11.  
  12. // Create an instance of the Razorpay client
  13. $razorpay = new Api($razorpay_key_id, $razorpay_secret_key);
  14.  
  15.  
  16. // Debugging: Output the content of the $_POST array
  17. var_dump($_POST);
  18.  
  19. // Check if the required keys are present in the $_POST array
  20. if (isset($_POST['razorpay_payment_id']) && isset($_POST['totalAmount']) && isset($_POST['product_id'])) {
  21. $razorpay_payment_id = $_POST['razorpay_payment_id'];
  22. $totalAmount = $_POST['totalAmount'];
  23. $product_id = $_POST['product_id'];
  24.  
  25. // Verify the payment using Razorpay SDK
  26. try {
  27. $attributes = array(
  28. 'razorpay_order_id' => $_POST['razorpay_order_id'],
  29. 'razorpay_payment_id' => $razorpay_payment_id,
  30. 'razorpay_signature' => $_POST['razorpay_signature'],
  31. );
  32.  
  33. $razorpay->utility->verifyPaymentSignature($attributes);
  34.  
  35. // Your further processing logic here
  36.  
  37. $response = array("msg" => "Payment successfully credited", "status" => true);
  38. echo json_encode($response);
  39. } catch (Exception $e) {
  40. // Handle the case when payment verification fails
  41. $response = array("msg" => "Payment verification failed", "status" => false);
  42. echo json_encode($response);
  43. }
  44. } else {
  45. // Handle the case when keys are not present
  46. $response = array("msg" => "Missing required parameters", "status" => false);
  47. echo json_encode($response);
  48. }
  49.  
  50. ?>
  51.  
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement