Files
wticreatorstudio/Modules/Subscription/Services/AugmentationService.php
T
2024-02-12 22:54:20 -05:00

864 lines
42 KiB
PHP

<?php
namespace Modules\Subscription\Services;
class AugmentationService
{
public function __construct() {
$this->addSubscriptionGeneralSettings();
$this->updateRegistrationForm();
$this->updateWelcomePage();
$this->updateProductDetailsPage();
$this->updateProfileMenu();
$this->updateCategoryPaginatePage();
$this->updateListingPaginatePage();
$this->updateRegisterController();
$this->updateUserModel();
$this->addPlanRelationToProduct();
$this->updateOrderController();
//$this->updateCheckoutController();
$this->updateGuestCheckoutMiddleware();
$this->addSubscriptionSelectFieldToProductCreateForm();
$this->addSubscriptionSelectFieldToProductEditForm();
$this->updateStripePost();
$this->addEmailSettingsToGeneralSettings();
$this->addSubscriptionTraitToUserModel();
$this->updateVericyCsrftoken();
$this->updateKernel();
$this->updateLoginController();
}
public function addSubscriptionGeneralSettings() {
if (isModuleActive('GeneralSetting')) {
$path = module_path('GeneralSetting', 'Http/Controllers/GeneralSettingController.php');
if (file_exists($path)) {
$content = file_get_contents($path);
if (!preg_match("/updateOption\('customer_subscription'/", $content)) {
$matches = null;
preg_match("/if\(\\\$request->has\('pwa_app_name'\)[.\s\S]+?}/", $content, $matches);
if (count($matches) > 0) {
$code = $matches[0];
$snippet = "
if (isModuleActive('Subscription')) {
app(\Modules\Subscription\Http\Controllers\SettingController::class)->updateOption('customer_subscription', \$request->customer_subscription);
}
";
$code .= $snippet;
$content = preg_replace("/if\(\\\$request->has\('pwa_app_name'\)[.\s\S]+?}/", $code, $content);
file_put_contents($path, $content);
}
}
}
$path = module_path('GeneralSetting', 'Resources/views/page_components/general_settings.blade.php');
if (file_exists($path)) {
$content = file_get_contents($path);
if (!preg_match("/@include\('subscription::components\._customer_subscription_control'\)/", $content)) {
$matches = null;
preg_match('/[.\s\S]+pwa_app_name[.\s\S]+?<\/div>[.\s\S]+?<\/div>/', $content, $matches);
if (count($matches) > 0) {
$code = $matches[0];
$snippet = "
@if (isModuleActive('Subscription'))
@include('subscription::components._customer_subscription_control')
@endif
";
$code .= $snippet;
$content = preg_replace('/[.\s\S]+pwa_app_name[.\s\S]+?<\/div>[.\s\S]+?<\/div>/', $code, $content);
file_put_contents($path, $content);
}
}
}
}
}
public function updateRegistrationForm() {
//$theme = app('theme');
//if ($theme) {
//$theme_name = app('theme')->folder_path;
$path = resource_path('views/frontend/amazy/auth/register.blade.php');
if (file_exists($path)) {
$update = false;
$content = file_get_contents($path);
if (!preg_match('/@include\(\'subscription::components\._stripe_form\'\)/', $content)) {
$matches = null;
preg_match('/sign_up_text[.\s\S]+?<\/div>[.\s\S]+?<\/div>/', $content, $matches);
if (count($matches) > 0) {
$code = $matches[0];
$snippet = "
@if (isModuleActive('Subscription') && isModuleActive('PaymentGateway'))
@include('subscription::components._stripe_form')
@endif
";
$code .= $snippet;
$content = preg_replace('/sign_up_text[.\s\S]+?<\/div>[.\s\S]+?<\/div>/', $code, $content);
$update = true;
}
}
if (!preg_match('/@include\(\'subscription::components\._register_button\'\)/', $content)) {
$content_bak = $content;
$matches = null;
preg_match('/@if\(env\(\'NOCAPTCHA_FOR_REG\'\)[.\s\S]+?@endif[.\s\S]+?@endif[.\s\S]+?<\/div>/', $content, $matches);
if (count($matches) > 0) {
$code = $matches[0];
$snippet = "
@endif
";
$code .= $snippet;
$content = preg_replace('/@if\(env\(\'NOCAPTCHA_FOR_REG\'\)[.\s\S]+?@endif[.\s\S]+?@endif[.\s\S]+?<\/div>/', $code, $content);
$has_post_snippet = true;
}
$matches = null;
preg_match('/@if\(env\(\'NOCAPTCHA_FOR_REG\'\)[.\s\S]+?@endif[.\s\S]+?@endif/', $content, $matches);
if (count($matches) > 0) {
$code = $matches[0];
$snippet = "
@if (isModuleActive('Subscription') && isModuleActive('PaymentGateway'))
@include('subscription::components._register_button')
@else
";
$code .= $snippet;
$content = preg_replace('/@if\(env\(\'NOCAPTCHA_FOR_REG\'\)[.\s\S]+?@endif[.\s\S]+?@endif/', $code, $content);
$has_pre_snippet = true;
}
if ($has_pre_snippet && $has_post_snippet) {
$update = true;
}
else {
$content = $content_bak;
}
}
if (!preg_match('/@include\(\'subscription::components\._plan_select_field\'\)/', $content)) {
$matches = null;
preg_match('/[.\s\S]+password_confirmation[.\s\S]+?<\/div>/', $content, $matches);
if (count($matches) > 0) {
$code = $matches[0];
$snippet = "
@if (isModuleActive('Subscription') && isModuleActive('PaymentGateway'))
@include('subscription::components._plan_select_field')
@endif
";
$code .= $snippet;
$content = preg_replace('/[.\s\S]+password_confirmation[.\s\S]+?<\/div>/', $code, $content);
$update = true;
}
}
if (!preg_match('/@include\(\'subscription::components\._form_head\'\)/', $content)) {
$matches = null;
preg_match('/<form action="{{[\s\S]*?route\(\'register\'\)[.\s\S]+?>/', $content, $matches);
if (count($matches) > 0) {
$code = $matches[0];
$snippet = "
@if (isModuleActive('Subscription') && isModuleActive('PaymentGateway'))
@include('subscription::components._form_head')
@else
<form action=\"{{ route('register') }}\" method=\"POST\" name=\"register\" id=\"register_form\" enctype=\"multipart/form-data\">
@endif
";
$code = $snippet;
$content = preg_replace('/<form action="{{[\s\S]*?route\(\'register\'\)[.\s\S]+?>/', $code, $content);
$update = true;
}
}
if (!preg_match('/@include\(\'subscription::components\._phone_field\'\)/', $content)) {
$matches = null;
preg_match("/@if\(isModuleActive\('Otp'\) && otp_configuration\('otp_activation_for_customer'\)[.\s\S]+?@endif/", $content, $matches);
if (count($matches) > 0) {
$code = $matches[0];
$snippet = "
@if (isModuleActive('Subscription'))
@include('subscription::components._phone_field')
@endif
";
$code .= $snippet;
$content = preg_replace("/@if\(isModuleActive\('Otp'\) && otp_configuration\('otp_activation_for_customer'\)[.\s\S]+?@endif/", $code, $content);
$update = true;
}
}
if (!preg_match('/@include\(\'subscription::components\._username_field\'\)/', $content)) {
$matches = null;
preg_match('/<span class="text-danger" >{{ \$errors->first\(\'referral_code\'\) }}<\/span>[.\s\S]+?<\/div>/', $content, $matches);
if (count($matches) > 0) {
$code = $matches[0];
$snippet = "
@if (isModuleActive('Subscription'))
@include('subscription::components._username_field')
@endif
";
$code .= $snippet;
$content = preg_replace('/<span class="text-danger" >{{ \$errors->first\(\'referral_code\'\) }}<\/span>[.\s\S]+?<\/div>/', $code, $content);
$update = true;
}
}
if ($update) {
file_put_contents($path, $content);
}
}
//}
}
public function updateWelcomePage() {
//$theme = app('theme');
//if ($theme) {
//$theme_name = app('theme')->folder_path;
$path = resource_path('views/frontend/amazy/welcome.blade.php');
if (file_exists($path)) {
$update = false;
$content = file_get_contents($path);
if (!preg_match("/WPSES/", $content)) {
$content = preg_replace_callback('|<a class="add_cart add_to_cart[.\s\S]+?<\/a>|', function ($matches) {
return "
{{-- WPSES --}}
@if (isModuleActive('Subscription') && isModuleActive('PaymentGateway') && app(\Modules\Subscription\Http\Controllers\SubscriptionController::class)->isAddToCartAllowed())
".$matches[0]."
@endif";
}, $content);
file_put_contents($path, $content);
}
}
//}
}
public function updateProductDetailsPage() {
//$theme = app('theme');
//if ($theme) {
//$theme_name = app('theme')->folder_path;
$path = resource_path('views/frontend/amazy/pages/product_details.blade.php');
if (file_exists($path)) {
$update = false;
$content = file_get_contents($path);
if (!preg_match("/PDSSB/", $content)) {
$matches = null;
preg_match('/<div class="row mt_30 " id="add_to_cart_div">/', $content, $matches);
if (count($matches) > 0) {
$code = $matches[0];
$snippet = "
{{-- PDSSB --}}
@if (isModuleActive('Subscription') && isModuleActive('PaymentGateway'))
@include('subscription::components._add_to_cart_div')
@else
";
$code = $code.$snippet;
$content = preg_replace('/<div class="row mt_30 " id="add_to_cart_div">/', $code, $content);
//file_put_contents($path, $content);
$update = true;
}
$matches = null;
preg_match('/<div class="row mt_30 " id="add_to_cart_div">[.\s\S]+?@endif/', $content, $matches);
if (count($matches) > 0) {
$code = $matches[0];
$snippet = "
@endif
";
$code = $code.$snippet;
$content = preg_replace('/<div class="row mt_30 " id="add_to_cart_div">[.\s\S]+?@endif/', $code, $content);
//file_put_contents($path, $content);
$update = true;
}
if ($update) {
file_put_contents($path, $content);
}
}
}
//}
}
public function updateProfileMenu() {
//$theme = app('theme');
//if ($theme) {
//$theme_name = app('theme')->folder_path;
$path = resource_path('views/frontend/amazy/pages/profile/partials/_menu.blade.php');
if (file_exists($path)) {
$update = false;
$content = file_get_contents($path);
if (!preg_match("/@include\('subscription::components\._dashboard_menu'\)/", $content)) {
$matches = null;
preg_match('/<li[.\s\S]+?{{url\(\'\/profile\'\)}}[.\s\S]+?<\/li>/', $content, $matches);
if (count($matches) > 0) {
$code = $matches[0];
$snippet = "
@if (isModuleActive('Subscription') && isModuleActive('PaymentGateway'))
@include('subscription::components._dashboard_menu')
@endif
";
$code = $code.$snippet;
$content = preg_replace('/<li[.\s\S]+?{{url\(\'\/profile\'\)}}[.\s\S]+?<\/li>/', $code, $content);
//file_put_contents($path, $content);
$update = true;
}
if ($update) {
file_put_contents($path, $content);
}
}
}
//}
}
public function updateCategoryPaginatePage() {
//$theme = app('theme');
//if ($theme) {
//$theme_name = app('theme')->folder_path;
$path = resource_path('views/frontend/amazy/partials/category_paginate_data.blade.php');
if (file_exists($path)) {
$update = false;
$content = file_get_contents($path);
if (!preg_match("/WCPSES/", $content)) {
$content = preg_replace_callback('|<a class="add_cart add_to_cart addToCartFromThumnail"[.\s\S]+?<\/a>|', function ($matches) {
return "
{{-- WCPSES --}}
@if (isModuleActive('Subscription') && isModuleActive('PaymentGateway') && app(\Modules\Subscription\Http\Controllers\SubscriptionController::class)->isAddToCartAllowed())
".$matches[0]."
@endif";
}, $content);
file_put_contents($path, $content);
}
}
//}
}
public function updateListingPaginatePage() {
//$theme = app('theme');
//if ($theme) {
//$theme_name = app('theme')->folder_path;
$path = resource_path('views/frontend/amazy/partials/listing_paginate_data.blade.php');
if (file_exists($path)) {
$update = false;
$content = file_get_contents($path);
if (!preg_match("/WCPSES/", $content)) {
$content = preg_replace_callback('|<a class="add_cart add_to_cart addToCartFromThumnail"[.\s\S]+?<\/a>|', function ($matches) {
return "
{{-- WCPSES --}}
@if (isModuleActive('Subscription') && isModuleActive('PaymentGateway') && app(\Modules\Subscription\Http\Controllers\SubscriptionController::class)->isAddToCartAllowed())
".$matches[0]."
@endif";
}, $content);
$content = preg_replace_callback('|<a class="add_cart add_to_cart add_to_cart_gift_thumnail"[.\s\S]+?<\/a>|', function ($matches) {
return "
{{-- WCPSES --}}
@if (isModuleActive('Subscription') && isModuleActive('PaymentGateway') && app(\Modules\Subscription\Http\Controllers\SubscriptionController::class)->isAddToCartAllowed())
".$matches[0]."
@endif";
}, $content);
file_put_contents($path, $content);
}
}
//}
}
public function updateRegisterController() {
$path = app_path('Http/Controllers/Auth/RegisterController.php');
if (file_exists($path)) {
$update = false;
$content = file_get_contents($path);
if (!preg_match("/SMRDF/", $content)) {
$matches = null;
preg_match('/\$user = User::create\(\[/', $content, $matches);
if (count($matches) > 0) {
$code = $matches[0];
$snippet = "
// SMRDF
if (isModuleActive('Subscription')) {
\$email = \$data['email'];
\$phone = \$data['phone'];
\$username = \$data['username'];
}
";
$code = $snippet.$code;
$content = preg_replace('/\$user = User::create\(\[/', $code, $content);
//file_put_contents($path, $content);
$update = true;
}
$matches = null;
preg_match('/\'username\' => isset\(\$phone\) \? \$phone : NULL,/', $content, $matches);
if (count($matches) > 0) {
$code = $matches[0];
$snippet = "'username' => isset(\$username) ? \$username : NULL,";
$code = $code.$snippet;
$content = preg_replace('/\'username\' => isset\(\$phone\) \? \$phone : NULL,/', $code, $content);
//file_put_contents($path, $content);
$update = true;
}
if ($update) {
file_put_contents($path, $content);
}
}
if (!preg_match("/SMRDF2/", $content)) {
$matches = null;
preg_match('/\$user = User::create\(\[/', $content, $matches);
if (count($matches) > 0) {
$code = $matches[0];
$snippet = "
// SMRDF2
if (isModuleActive('Subscription')) {
\$zipcode = \$data['zipcode'];
}
";
$code = $snippet.$code;
$content = preg_replace('/\$user = User::create\(\[/', $code, $content);
//file_put_contents($path, $content);
$update = true;
}
$matches = null;
preg_match("/'currency_code' => app\('general_setting'\)->currency_code,/", $content, $matches);
if (count($matches) > 0) {
$code = $matches[0];
$snippet = "
'zipcode' => isset(\$zipcode) ? \$zipcode : null,
";
$code = $code.$snippet;
$content = preg_replace("/'currency_code' => app\('general_setting'\)->currency_code,/", $code, $content);
//file_put_contents($path, $content);
$update = true;
}
if ($update) {
file_put_contents($path, $content);
}
}
}
}
public function updateUserModel() {
$path = app_path('Models/User.php');
if (file_exists($path)) {
$update = false;
$content = file_get_contents($path);
if (!preg_match("/'zipcode'/", $content)) {
$matches = null;
preg_match("/'currency_code'/", $content, $matches);
if (count($matches) > 0) {
$code = $matches[0];
$snippet = "
'currency_code',
'zipcode'
";
$code = $snippet;
$content = preg_replace("/'currency_code'/", $code, $content);
//file_put_contents($path, $content);
$update = true;
}
if ($update) {
file_put_contents($path, $content);
}
}
}
}
public function addPlanRelationToProduct() {
if (isModuleActive('Product')) {
$path = module_path('Product', 'Entities/Product.php');
if (file_exists($path)) {
$content = file_get_contents($path);
if (!preg_match("/plan\(\)/", $content)) {
$matches = null;
preg_match("/public function getTranslateProductSubtitle2Attribute\(\)[.\s\S]+?}/", $content, $matches);
if (count($matches) > 0) {
$code = $matches[0];
$snippet = "
public function plan() {
return \$this->hasOne(\Modules\Subscription\Entities\SubscriptionPlan::class, 'id', 'plan_id');
}
";
$code .= $snippet;
$content = preg_replace("/public function getTranslateProductSubtitle2Attribute\(\)[.\s\S]+?}/", $code, $content);
file_put_contents($path, $content);
}
}
}
}
}
public function updateOrderController() {
$path = app_path('Http/Controllers/Frontend/OrderController.php');
if (file_exists($path)) {
$update = false;
$content = file_get_contents($path);
if (!preg_match("/Session::has\('subscription_payment'\)/", $content)) {
$matches = null;
preg_match("/\\\$order = \\\$this->orderService->orderStore\(\\\$request->except\('_token'\)\);/", $content, $matches);
if (count($matches) > 0) {
$code = $matches[0];
$snippet = "
if (isModuleActive('Subscription') && Session::has('subscription_payment')) {
\$user = auth()->user();
\$plan = session()->get('selected_plan');
\$last_payment_date = session()->get('last_payment_date');
\$customer_subscription = new \Modules\Subscription\Entities\CustomerSubscription();
\$customer_subscription->customer_id = \$user->id;
\$customer_subscription->plan_id = \$plan->id;
\$customer_subscription->status = 'onhold';
\$customer_subscription->is_paid = true;
\$customer_subscription->last_payment_date = \$last_payment_date;
\$customer_subscription->save();
\$transaction = session()->get('user_transaction');
if (\$transaction) {
\$transaction->morphable_id = \$customer_subscription->id;
\$transaction->morphable_type = get_class(\$customer_subscription);
\$transaction->update();
}
\$deliveredProcess = \Modules\OrderManage\Entities\DeliveryProcess::where('name', 'Delivered')->first();
if (\$deliveredProcess) {
\$order->customer_id = \$user->id;
\$order->is_paid = true;
\$order->is_confirmed = true;
\$order->is_completed = true;
\$order->order_status = \$deliveredProcess->id;
\$order->update();
\$packages = \$order->packages;
foreach (\$packages as \$package) {
\$package->is_paid = true;
\$package->delivery_status = \$deliveredProcess->id;
\$package->update();
}
}
}
";
$code .= $snippet;
$content = preg_replace("/\\\$order = \\\$this->orderService->orderStore\(\\\$request->except\('_token'\)\);/", $code, $content);
//file_put_contents($path, $content);
$update = true;
}
if ($update) {
file_put_contents($path, $content);
}
}
}
}
public function updateCheckoutController() {
$path = app_path('Http/Controllers/Frontend/CheckoutController.php');
if (file_exists($path)) {
$update = false;
$content = file_get_contents($path);
if (!preg_match("/Session::has\('subscription_payment'\)/", $content)) {
$matches = null;
preg_match("/\\\$orderController = App::make\(OrderController::class\);/", $content, $matches);
if (count($matches) > 0) {
$code = $matches[0];
$snippet = "
if (isModuleActive('Subscription') && Session::has('subscription_payment')) {
\$user = auth()->user();
\$plan = Session::get('selected_plan');
\$customer_subscription = new \Modules\Subscription\Entities\CustomerSubscription();
\$customer_subscription->customer_id = \$user->id;
\$customer_subscription->plan_id = \$plan->id;
\$customer_subscription->status = 'onhold';
\$customer_subscription->is_paid = true;
\$customer_subscription->save();
}
";
$code = $snippet.$code;
$content = preg_replace("/\\\$orderController = App::make\(OrderController::class\);/", $code, $content);
//file_put_contents($path, $content);
$update = true;
}
if ($update) {
file_put_contents($path, $content);
}
}
}
}
public function updateGuestCheckoutMiddleware() {
$path = app_path('Http/Middleware/GuestCheckout.php');
if (file_exists($path)) {
$update = false;
$content = file_get_contents($path);
if (!preg_match("/Session::has\('subscription_payment'\)/", $content)) {
$matches = null;
preg_match("/app\('general_setting'\)->guest_checkout \|\| auth\(\)->check\(\)/", $content, $matches);
if (count($matches) > 0) {
$code = $matches[0];
$snippet = "app('general_setting')->guest_checkout || auth()->check() || (isModuleActive('Subscription') && Session::has('subscription_payment'))";
$code = $snippet;
$content = preg_replace("/app\('general_setting'\)->guest_checkout \|\| auth\(\)->check\(\)/", $code, $content);
//file_put_contents($path, $content);
$update = true;
}
if ($update) {
file_put_contents($path, $content);
}
}
}
}
public function addSubscriptionSelectFieldToProductCreateForm() {
if (isModuleActive('Product')) {
$path = module_path('Product', 'Resources/views/products/create.blade.php');
if (file_exists($path)) {
$content = file_get_contents($path);
if (!preg_match("/@include\('subscription::components\._product_subscription_select_field'\)/", $content)) {
$matches = null;
preg_match("/@if\(isModuleActive\('GoldPrice'\)\)/", $content, $matches);
if (count($matches) > 0) {
$code = $matches[0];
$snippet = "
@if (isModuleActive('Subscription'))
@include('subscription::components._product_subscription_select_field')
@endif
";
$code = $snippet.$code;
$content = preg_replace("/@if\(isModuleActive\('GoldPrice'\)\)/", $code, $content);
file_put_contents($path, $content);
}
}
}
}
}
public function addSubscriptionSelectFieldToProductEditForm() {
if (isModuleActive('Product')) {
$path = module_path('Product', 'Resources/views/products/edit.blade.php');
if (file_exists($path)) {
$content = file_get_contents($path);
if (!preg_match("/@include\('subscription::components\._product_subscription_select_field'\)/", $content)) {
$matches = null;
preg_match("/@if\(isModuleActive\('GoldPrice'\)\)/", $content, $matches);
if (count($matches) > 0) {
$code = $matches[0];
$snippet = "
@if (isModuleActive('Subscription'))
@include('subscription::components._product_subscription_select_field')
@endif
";
$code = $snippet.$code;
$content = preg_replace("/@if\(isModuleActive\('GoldPrice'\)\)/", $code, $content);
file_put_contents($path, $content);
}
}
}
}
}
public function updateStripePost() {
if (isModuleActive('PaymentGateway')) {
$path = module_path('PaymentGateway', 'Http/Controllers/StripeController.php');
if (file_exists($path)) {
$content = file_get_contents($path);
if (!preg_match("/isModuleActive\\('Subscription'\\) && session\\(\\)->has\\('subscription_payment'\\)/", $content)) {
$update = false;
$matches = null;
preg_match("/\\\$stripe = Stripe\\\\Charge::create[.\s\S]+?\]\);/", $content, $matches);
if (count($matches) > 0) {
$code = $matches[0];
$snippet = "
if (isModuleActive('Subscription') && \Illuminate\Support\Facades\Session::has('subscription_payment')) {
\$stripe = Stripe\Charge::create ([
\"amount\" => round(\$data['amount'] * 100),
\"currency\" => \$currency_code,
\"source\" => \$data['stripeToken'],
\"description\" => \"Payment from \". url('/'),
\"capture\" => false
]);
}
else {
\$stripe = Stripe\Charge::create ([
\"amount\" => round(\$data['amount'] * 100),
\"currency\" => \$currency_code,
\"source\" => \$data['stripeToken'],
\"description\" => \"Payment from \". url('/')
]);
}
";
$code = $snippet;
$content = preg_replace("/\\\$stripe = Stripe\\\\Charge::create[.\s\S]+?\]\);/", $code, $content);
$update = true;
}
$matches = null;
preg_match("/LogActivity::successLog\('Order payment successful\.'\);/", $content, $matches);
if (count($matches) > 0) {
$code = $matches[0];
$snippet = "
if (isModuleActive('Subscription') && session()->has('subscription_payment')) {
\$user = auth()->user();
\$defaultIncomeAccount = \$this->defaultIncomeAccount();
\$seller_subscription = session()->get('selected_plan');
\$transactionRepo = new TransactionRepository(new Transaction);
\$transaction = \$transactionRepo->makeTransaction(\$user->first_name.\" - Subsriction Payment\", \"in\", \"Stripe\", \"subscription_payment\", \$defaultIncomeAccount, \"Subscription Payment\", \$seller_subscription, \$data['amount'], Carbon::now()->format('Y-m-d'), \$seller_subscription->seller->id, null, null);
SubsciptionPaymentInfo::create([
'transaction_id' => \$transaction->id,
'txn_id' => \$return_data,
'seller_id' => \$seller_subscription->seller->id,
'subscription_type' => \$seller_subscription->product->plan->billing_type
]);
session()->put('last_payment_date', Carbon::now()->format('Y-m-d'));
session()->put('user_transaction', \$transaction);
LogActivity::successLog('Subscription payment successful.');
}
";
$code .= $snippet;
$content = preg_replace("/LogActivity::successLog\('Order payment successful\.'\);/", $code, $content);
$update = true;
}
if ($update) {
file_put_contents($path, $content);
}
}
}
}
}
public function updateVericyCsrftoken() {
$path = app_path('Http/Middleware/VerifyCsrfToken.php');
if (file_exists($path)) {
$update = false;
$content = file_get_contents($path);
if (!preg_match("/subscriptions\/webhooks\/stripe/", $content)) {
$matches = null;
preg_match("/\'search\'\,/", $content, $matches);
if (count($matches) > 0) {
$code = $matches[0];
$snippet = "'search',\n\t\t'/subscriptions/webhooks/stripe',";
$code = $snippet;
$content = preg_replace("/\'search\'\,/", $code, $content);
//file_put_contents($path, $content);
$update = true;
}
if ($update) {
file_put_contents($path, $content);
}
}
}
}
public function updateKernel() {
$path = app_path('Console/Kernel.php');
if (file_exists($path)) {
$update = false;
$content = file_get_contents($path);
if (!preg_match("/command\:customerSubscription/", $content)) {
$matches = null;
preg_match("/\\\$schedule\-\>command\(\'command\:sellerSubscription\'\)\-\>daily\(\)\;/", $content, $matches);
if (count($matches) > 0) {
$code = $matches[0];
$snippet = "\$schedule->command('command:sellerSubscription')->daily();\n\t\t\$schedule->command('command:customerSubscription')->daily();";
$code = $snippet;
$content = preg_replace("/\\\$schedule\-\>command\(\'command\:sellerSubscription\'\)\-\>daily\(\)\;/", $code, $content);
//file_put_contents($path, $content);
$update = true;
}
if ($update) {
file_put_contents($path, $content);
}
}
}
}
public static function addEmailSettingsToGeneralSettings() {
if (isModuleActive('GeneralSetting')) {
$path = module_path('GeneralSetting', 'Http/Controllers/GeneralSettingController.php');
$path = module_path('GeneralSetting', 'Resources/views/page_components/general_settings.blade.php');
if (file_exists($path)) {
$update = false;
$content = file_get_contents($path);
if (!preg_match("/@include\('subscription::components\._sales_team_email'\)/", $content)) {
$matches = null;
preg_match('/[.\s\S]+pwa_app_name[.\s\S]+?<\/div>[.\s\S]+?<\/div>[.\s\S]+?onboarding_emails[.\s\S]+?\@endif/', $content, $matches);
if (count($matches) > 0) {
$code = $matches[0];
$snippet = "
@if (isModuleActive('Subscription'))
@include('subscription::components._sales_team_email')
@endif
";
$code .= $snippet;
$content = preg_replace('/[.\s\S]+pwa_app_name[.\s\S]+?<\/div>[.\s\S]+?<\/div>[.\s\S]+?onboarding_emails[.\s\S]+?\@endif/', $code, $content);
$update = true;
}
}
}
if ($update) {
file_put_contents($path, $content);
}
}
}
public function addSubscriptionTraitToUserModel() {
$path = app_path('Models/User.php');
if (file_exists($path)) {
$update = false;
$content = file_get_contents($path);
if (!preg_match("/SubscriptionTrait/", $content)) {
$matches = null;
preg_match('/[.\s\S]+Authenticatable[.\s\S]+?{/', $content, $matches);
if (count($matches) > 0) {
$code = $matches[0];
$snippet = "\n\n\tuse \Modules\Subscription\Traits\SubscriptionTrait;";
$code .= $snippet;
$content = preg_replace("/[.\s\S]+Authenticatable[.\s\S]+?{/", $code, $content);
$update = true;
}
}
if ($update) {
file_put_contents($path, $content);
}
}
}
public function updateLoginController() {
$path = app_path('Http/Controllers/Auth/LoginController.php');
if (file_exists($path)) {
$update = false;
$content = file_get_contents($path);
if (!preg_match('/[.\s\S]+redirectTo\([.\s\S]+?{[.\s\S]+?isModuleActive\(\'WTIJobBoard\'\)/', $content)) {
$matches = null;
preg_match('/[.\s\S]+redirectTo\([.\s\S]+?{[.\s\S]+?\$next_url[.\s\S]+?}/', $content, $matches);
if (count($matches) > 0) {
$code = $matches[0];
$snippet = "\n\t\tif(isModuleActive('WTIJobBoard')){\n\t\t\tif(auth()->user()->role->type == 'superadmin' || auth()->user()->role->type == 'admin'){\n\t\t\t\treturn '/admin-dashboard';\n\t\t\t}\n\t\t\tif(auth()->user()->role->type == 'staff'){\n\t\t\t\treturn route('job_board.creator.index');\n\t\t\t}\n\t\t\tif(isModuleActive('Subscription')){\n\t\t\t\t\$subscription = auth()->user()->subscription_status;\n\t\t\t\tif(\$subscription['approved'] && \$subscription['status'] == 'active') {\n\t\t\t\t\treturn route('job_board.index');\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn route('frontend.my-subscription');\n\t\t}";
$code .= $snippet;
$content = preg_replace('/[.\s\S]+redirectTo\([.\s\S]+?{[.\s\S]+?\$next_url[.\s\S]+?}/', $code, $content);
$update = true;
}
}
if ($update) {
file_put_contents($path, $content);
}
}
}
}