IMMREX7
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
namespace App\Http;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Client;
use Auth;
use Log;
use DB;
class Cashfree {
static function generateOrder($order, $student) {
return [];
$response = self::initiateOrder($order, $student);
$output = array("order_token" => $response["order_token"]);
return response()->json($output, 200);
}
static function generateEaseBuzzOrder($order, $student) {
$keyService = DB::table('pg_keys')->where('purpose',$order->purpose)->where('idSchool',$student->idSchool)->first();
$response = self::initiateEaseBuzzOrder($order, $student);
$easebuzzKey = $keyService->key_value;
$output = array("token" => $response->data, "key" => $easebuzzKey);
Log::info(json_encode($output));
return response()->json($output, 200);
}
static function verifyEasebuzzTransaction($orderInfo){
$student = \App\AdmEntry::where('idStudent', '=', $orderInfo->idStudent)->first();
$params = array();
$keyService = DB::table('pg_keys')->where('purpose',$orderInfo->purpose)->where('idSchool',$student->idSchool)->first();
$params["key"] =$keyService->key_value;
$params["txnid"] = $orderInfo->idOrder;
$params["amount"] = number_format($orderInfo->order_amount,1, '.', '');
$params["email"] = "sppedtrackgps@gmail.com";
$params["phone"] = $student->father_mobile;
$hashStr = $keyService->key_value."|".$params["txnid"]."|".$params["amount"]."|".$params["email"]."|".$params["phone"]."|".$keyService->salt_value;
$hash = hash('sha512', $hashStr);
$params["hash"] = $hash;
$client = new Client;
$response = $client->request('POST', 'https://dashboard.easebuzz.in/transaction/v1/retrieve', [ 'headers' => ['Accept' => 'application/json', 'Content-Type' => 'application/x-www-form-urlencoded'],'form_params' => $params]);
$data =json_decode($response->getBody());
return $data;
}
static function verifyEasebuzzTransactionv2($orderInfo){
$student = \App\AdmEntry::where('idStudent', '=', $orderInfo->idStudent)->first();
$params = array();
$keyService = DB::table('pg_keys')->where('purpose',$orderInfo->purpose)->where('idSchool',$student->idSchool)->first();
$params["key"] =$keyService->key_value;
$params["txnid"] = $orderInfo->idOrder;
$hashStr = $keyService->key_value."|".$params["txnid"]."|".$keyService->salt_value;
$hash = hash('sha512', $hashStr);
$params["hash"] = $hash;
$client = new Client;
$response = $client->request('POST', 'https://dashboard.easebuzz.in/transaction/v2.1/retrieve', [ 'headers' => ['Accept' => 'application/json', 'Content-Type' => 'application/x-www-form-urlencoded'],'form_params' => $params]);
$data =json_decode($response->getBody());
return $data;
}
static function initiateEaseBuzzOrder($order,$student){
$keyService = DB::table('pg_keys')->where('purpose',$order->purpose)->where('idSchool',$student->idSchool)->first();
$easebuzzKey = $keyService->key_value;
$easebuzzSalt = $keyService->salt_value;
$item["id"] = $order->idOrder;
$item["amount"] = number_format($order->order_amount, 1, '.', '');
$item["school_fee"] = "School Fee";
$item["name"] = $student->firstName;
$item["phone"] = $student->father_mobile;
$item["email"] = "sppedtrackgps@gmail.com";
$item["idStudent"] = $student->idStudent;
$item["none"] = "";
$params = array();
$params["key"] = $easebuzzKey;
$params["txnid"] = $item["id"];
$params["amount"] = $item["amount"];
$params["productinfo"] = $item["school_fee"];
$params["firstname"] = $item["name"];
$params["phone"] = $item["phone"];
$params["email"] = $item["email"];
$params["surl"] = "https://online-login.online/easebuzz-success";
$params["furl"] = "https://online-login.online/easebuzz-failure";
$hashStr = $easebuzzKey."|".$item["id"]."|".$item["amount"]."|".$item["school_fee"]."|".$item["name"]."|".$item["email"]."|".$item["idStudent"]."||||||||||".$easebuzzSalt;
$hash = hash('sha512', $hashStr);
$params["hash"] = $hash;
$params["udf1"] = $item["idStudent"];
$params["udf2"] = $item["none"];
$params["udf3"] = $item["none"];
$params["udf4"] = $item["none"];
$params["udf5"] = $item["none"];
$params["udf6"] = $item["none"];
$params["udf7"] = $item["none"];
$params["address1"] = $item["none"];
$params["address2"] = $item["none"];
$params["state"] = $item["none"];
$params["country"] = $item["none"];
$params["zipcode"] = $item["none"];
$params["show_payment_mode"] = $item["none"];
$params["request_flow"] = "SEAMLESS";
$params["sub_merchant_id"] = $item["none"];
$params["payment category"] = $item["none"];
$params["account_no"] = $item["none"];
$client = new Client;
$response = $client->request('POST', 'https://pay.easebuzz.in/payment/initiateLink', [ 'headers' => ['Accept' => 'application/json', 'Content-Type' => 'application/x-www-form-urlencoded'],'form_params' => $params]);
$data =json_decode($response->getBody());
Log::info(json_encode($data));
return $data;
}
static function initiateOrder($order, $student) {
return [];
$curl = curl_init();
$studentid = 'S-'.$student->idStudent.'T';
if(isset($student->father_email) && $student->father_email !="NA")
$email = $student->father_email;
else $email = "sppedtrackgps@gmail.com";
$postData =
array(
'customer_details' => array(
'customer_id' => strval($studentid),
'customer_email' => $email,
'customer_phone' => $student->father_mobile,
),
'order_meta' =>array(
"payment_methods" => ""
),
'order_amount' => $order->order_amount,
'order_currency' => 'INR',
'order_note' => $order->order_note
);
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.cashfree.com/pg/orders",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode($postData),
CURLOPT_HTTPHEADER => [
"Accept: application/json",
"Content-Type: application/json",
"x-api-version: 2022-01-01",
"x-client-id: 1928412d1f5bed99a3fb8e3528148291",
"x-client-secret: 5de10b32c7b12616eaf0576da075c2d173c28ed9"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
header('Content-Type: application/json; charset=utf-8');
echo json_encode(array("error" => 1));
echo "cURL Error #:" . $err;
die();
} else {
$result = json_decode($response, true);
Log::debug($result);
header('Content-Type: application/json; charset=utf-8');
$output = array("order_token" => $result["order_token"]);
$order->order_token = $result["order_token"];
$order->order_id = $result["order_id"];
$order->update();
return $result;
}
}
}
Copyright © 2021 -