Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require __DIR__."/vendor/autoload.php";
- // Replace 'your_key_id' and 'your_secret_key' with your actual Razorpay key and secret
- $razorpay_key_id = 'rzp_//';
- $razorpay_secret_key = '//;
- use \Razorpay\Api\Api;
- // Create an instance of the Razorpay client
- $razorpay = new Api($razorpay_key_id, $razorpay_secret_key);
- // Debugging: Output the content of the $_POST array
- var_dump($_POST);
- // Check if the required keys are present in the $_POST array
- if (isset($_POST['razorpay_payment_id']) && isset($_POST['totalAmount']) && isset($_POST['product_id'])) {
- $razorpay_payment_id = $_POST['razorpay_payment_id'];
- $totalAmount = $_POST['totalAmount'];
- $product_id = $_POST['product_id'];
- // Verify the payment using Razorpay SDK
- try {
- $attributes = array(
- 'razorpay_order_id' => $_POST['razorpay_order_id'],
- 'razorpay_payment_id' => $razorpay_payment_id,
- 'razorpay_signature' => $_POST['razorpay_signature'],
- );
- $razorpay->utility->verifyPaymentSignature($attributes);
- // Your further processing logic here
- $response = array("msg" => "Payment successfully credited", "status" => true);
- echo json_encode($response);
- } catch (Exception $e) {
- // Handle the case when payment verification fails
- $response = array("msg" => "Payment verification failed", "status" => false);
- echo json_encode($response);
- }
- } else {
- // Handle the case when keys are not present
- $response = array("msg" => "Missing required parameters", "status" => false);
- echo json_encode($response);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement