Current File : /home/inlingua/public_html/icentex/inlingua_payment/payment/initiatePayment.php
<?php session_start();
include("../dbConnection.php");
use PaymentHandler\APIException;
require_once ("./PaymentHandler.php");
use PaymentHandler\PaymentHandler;

$paymentHandler = new PaymentHandler("resources/config.json");
$queryP="update ingl_payment_gateway set payment_details='".$_REQUEST['payment_details']."' where recNo='".$_SESSION['pid']."'";
$resultP=$conn->query($queryP) or die("Error");

$queryU="select * from  ingl_payment_gateway where recNo='".$_SESSION['pid']."'";
$resultU=$conn->query($queryU);
$numU=$resultU->fetch_assoc();



$amount=$numU['amount_to_pay'];
$orderId=$numU['recNo'];
$customerId =  $numU['Student_id'];
// block:start:session-function



$fname=$numU['Name'];
$lname=$numU['Name'];
$email=$numU['email'];
$mobile=$numU['mobile'];


$url="https://inlinguanewdelhi.in/icentex/inlingua_payment/payment/handlePaymentResponse.php";

$params = json_decode("{\"customer_email\":\"$email\",\n\"customer_phone\":\"$mobile\",\n\"first_name\":\"$fname\",\n\"last_name\":\"$lname\",\n\"amount\":\"$amount\",\n\"order_id\":\"$orderId\",\n\"customer_id\":\"$customerId\",\n\"action\":\"paymentPage\",\n\"return_url\": \"$url\"\n}", true);


try {
    $session = $paymentHandler->orderSession($params);
    // block:end:session-function
    $redirect = $session["payment_links"]["web"];
    header("Location: {$redirect}");
    exit;

} catch (APIException $e ) {
    http_response_code(500);
    $error = json_encode(["message" => $e->getErrorMessage(), "error_code" => $e->getErrorCode(), "http_response_code" => $e->getHttpResponseCode()]);
    echo "<p> Payment server threw a non-2xx error. Error message: {$error} </p>";
    exit;
 } catch (Exception $e) {
    http_response_code(500);
    echo " <p> Unexpected error occurred, Error message:  {$e->getMessage()} </p>";
    exit;
}
?>