Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paid plugins #3040

Open
wants to merge 17 commits into
base: development
Choose a base branch
from
65 changes: 65 additions & 0 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Http\Controllers;

use App\ApiKey;
use App\Http\Controllers\Common\CronController;
use App\Http\Controllers\Order\RenewController;
use App\Http\Requests\ProductRenewalRequest;
Expand All @@ -16,6 +17,7 @@
use App\Model\Product\Subscription;
use App\User;
use Exception;
use GuzzleHttp\Client;
use Illuminate\Http\Request;

class HomeController extends BaseHomeController
Expand Down Expand Up @@ -616,4 +618,67 @@

return response()->json(['group' => $group]);
}

public function getDetailedBillingInfo(Request $request): \Illuminate\Http\JsonResponse
{
$order = $request->input('order');
// Fetch the order details
$user = Order::where('number', $order)->value('client');

$email = User::where('id', $user)->value('email');

if (! $email) {
return response()->json([]);
}

return response()->json([
'billing_client_email' => $email,
]);
}

public function getDetailsForAClient(Request $request)
{
$client = $request->input('client');

$license = $request->input('license');

$user = User::where('email', $client)->value('id');

$licenses = Order::where('client', $user)
->whereHas('product', function ($query) {
$query->where('product_type', 'plugin');
})
->pluck('serial_key')
->toArray();

$licenses = array_merge([$license], $licenses);

$client = new Client(['verify' => false]);

$licenseUrl = ApiKey::value('license_url');

Check notice on line 658 in app/Http/Controllers/HomeController.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

app/Http/Controllers/HomeController.php#L658

Avoid using static access to class '\App\ApiKey' in method 'getDetailsForAClient'.

$response = $client->get($licenseUrl.'api/pluginLicense', [
'query' => ['license_code' => json_encode($licenses)],
]);

return json_decode($response->getBody()->getContents(), true);
}

public function getProductRelease(Request $request)
{
$product_id = $request->input('product_id');

$version = $request->input('version');

$product_upload = ProductUpload::where('product_id', $product_id)
->where('is_private', 0)
->where('version', $version)
->orderByDesc('version') // Order by version in descending order
->select('version', 'title', 'description', 'dependencies', 'updated_at')
->first(); // Get the first result (latest version)

$product = Product::where('id', $product_id)->select('name', 'description', 'shoping_cart_link', 'product_description')->first();

return ['product' => $product, 'release' => $product_upload];
}
}
21 changes: 21 additions & 0 deletions app/Http/Controllers/License/LicenseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ public function createNewLicene($orderid, $product, $user_id, $licenseExpiry, $u
$productId = $this->searchProductId($sku);
$OauthDetails = $this->oauthAuthorization();
$token = $OauthDetails->access_token;

$addLicense = $this->postCurl($url.'api/admin/license/add', "api_key_secret=$api_key_secret&product_id=$productId&license_code=$serial_key&license_require_domain=1&license_status=1&license_order_number=$orderNo&license_domain=$domain&license_ip=$ip&license_require_domain=$requireDomain&license_limit=6&license_expire_date=$licenseExpiry&license_updates_date=$updatesExpiry&license_support_date=$supportExpiry&license_disable_ip_verification=0&license_limit=1", $token);
} catch (\Exception $ex) {
throw new \Exception('Please configure the valid license details in Apikey settings.');
Expand Down Expand Up @@ -517,6 +518,26 @@ public function licenseRedirect($orderNumber)
return redirect('/orders/'.Order::where('number', $orderNumber)->value('id'));
}

public function syncTheAddonForALicense($product_ids, $license_code, $options = [])
{
$url = $this->url;
$api_key_secret = $this->api_key_secret;

$OauthDetails = $this->oauthAuthorization();
$token = $OauthDetails->access_token;
// Convert arrays to JSON for proper request formatting
$options = json_encode($options);

$postData = http_build_query([
'api_key_secret' => $api_key_secret,
'license_code' => $license_code,
'product_ids' => $product_ids,
'options' => $options,
]);

$this->postCurl($url.'api/admin/license/syncAddonLicense', $postData, $token);
}

public function getInstallationLogsDetails($license_code)
{
$url = $this->url;
Expand Down
42 changes: 42 additions & 0 deletions app/Http/Controllers/Order/BaseOrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

namespace App\Http\Controllers\Order;

use App\Http\Controllers\License\LicenseController;
use App\Http\Controllers\License\LicensePermissionsController;
use App\Model\Common\StatusSetting;
use App\Model\Common\TemplateType;
use App\Model\Configure\ProductPluginGroup;
use App\Model\Order\Order;
use App\Model\Payment\Plan;
use App\Model\Product\Product;
Expand Down Expand Up @@ -121,6 +123,12 @@ public function getIfItemPresent($item, $invoiceid, $user_id, $order_status, $ad
$this->addOrderInvoiceRelation($invoiceid, $order->id);
if ($plan_id != 0) {
$this->addSubscription($order->id, $plan_id, $version, $product, $serial_key, $admin);

$addOnIds = implode(',', $this->product->find($product)->productPluginGroupsAsProduct->pluck('plugin_id')->toArray());

$options = $this->formatConfigurableOptions($product);

(new LicenseController())->syncTheAddonForALicense($addOnIds, $serial_key, $options);
}

if (emailSendingStatus()) {
Expand Down Expand Up @@ -412,4 +420,38 @@ public function downloadUrl($userid, $orderid)

return $url;
}

public function formatConfigurableOptions($productId)
{
// Retrieve the product ID and related plugin IDs in one query
$productIds = ProductPluginGroup::where('product_id', $productId)
->pluck('plugin_id')
->prepend($productId)
->toArray();

// Fetch all products with related configurations in one query
$products = $this->product->with('configOptions.configOptionValues')
->whereIn('id', $productIds)
->get();

// Check if any products were found
if ($products->isEmpty()) {
return [];
}

// Format the configuration options
return $products->flatMap(function ($product) {
return $product->configOptions->flatMap(function ($configOption) use ($product) {
return $configOption->configOptionValues->map(function ($configOptionValue) use ($product, $configOption) {
return [
'product_id' => $product->id,
'option_group' => $configOption->configGroup->config_group_name,
'option_name' => $configOption->config_option_name,
'key' => $configOptionValue->key,
'value' => $configOptionValue->value,
];
});
});
});
}
}
2 changes: 2 additions & 0 deletions app/Http/Controllers/Product/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ public function store(Request $request)
'name' => 'required|unique:products,name',
'type' => 'required',
'description' => 'required',
'product_description' => 'required',
'image' => 'sometimes|mimes:jpeg,png,jpg|max:2048',
'product_sku' => 'required|unique:products,product_sku',
'group' => 'required',
Expand Down Expand Up @@ -439,6 +440,7 @@ public function update($id, Request $request)
'name' => 'required',
'type' => 'required',
'description' => 'required',
'product_description' => 'required',
'image' => 'sometimes|mimes:jpeg,png,jpg|max:2048',
'product_sku' => 'required',
'group' => 'required',
Expand Down
21 changes: 21 additions & 0 deletions app/Model/Configure/ConfigGroup.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

Check notice on line 2 in app/Model/Configure/ConfigGroup.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

app/Model/Configure/ConfigGroup.php#L2

Missing file doc comment
namespace App\Model\Configure;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class ConfigGroup extends Model
{
use HasFactory;

protected $table = 'config_group';

protected $guarded = [];

// Define the relationship with ConfigOption
public function configOptions()
{
return $this->hasMany(ConfigOption::class, 'group_id');
}
}
40 changes: 40 additions & 0 deletions app/Model/Configure/ConfigOption.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

Check notice on line 2 in app/Model/Configure/ConfigOption.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

app/Model/Configure/ConfigOption.php#L2

Missing file doc comment
namespace App\Model\Configure;

use App\Model\Payment\Plan;
use App\Model\Product\Product;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class ConfigOption extends Model

Check notice on line 10 in app/Model/Configure/ConfigOption.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

app/Model/Configure/ConfigOption.php#L10

Missing doc comment for class ConfigOption
{
use HasFactory;

protected $table = 'config_option';

protected $guarded = [];

// Define the relationship with ConfigGroup
public function configGroup()
{
return $this->belongsTo(ConfigGroup::class, 'group_id');
}

// Define the relationship with Plan
public function plan()

Check notice on line 25 in app/Model/Configure/ConfigOption.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

app/Model/Configure/ConfigOption.php#L25

You must use "/**" style comments for a function comment
{
return $this->belongsTo(Plan::class);
}

// Define the relationship with ConfigOptionValue
public function configOptionValues()

Check notice on line 31 in app/Model/Configure/ConfigOption.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

app/Model/Configure/ConfigOption.php#L31

You must use "/**" style comments for a function comment
{
return $this->hasMany(ConfigOptionValue::class, 'option_id');
}

public function product()
{
return $this->belongsTo(Product::class);
}
}
20 changes: 20 additions & 0 deletions app/Model/Configure/ConfigOptionValue.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace App\Model\Configure;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class ConfigOptionValue extends Model

Check notice on line 8 in app/Model/Configure/ConfigOptionValue.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

app/Model/Configure/ConfigOptionValue.php#L8

Missing doc comment for class ConfigOptionValue
{
use HasFactory;

protected $table = 'config_option_values';
protected $guarded = [];

// Define the relationship with ConfigOption
public function configOption()
{
return $this->belongsTo(ConfigOption::class, 'option_id');
}
}
28 changes: 28 additions & 0 deletions app/Model/Configure/PluginCompatibleWithProducts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace App\Model\Configure;

use App\Model\Product\Product;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class PluginCompatibleWithProducts extends Model

Check notice on line 9 in app/Model/Configure/PluginCompatibleWithProducts.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

app/Model/Configure/PluginCompatibleWithProducts.php#L9

Missing doc comment for class PluginCompatibleWithProducts
{
use HasFactory;

protected $table = 'plugin_compatible_with_products';

protected $guarded = [];

// Define the relationship with Product (as product)
public function productComp()

Check notice on line 18 in app/Model/Configure/PluginCompatibleWithProducts.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

app/Model/Configure/PluginCompatibleWithProducts.php#L18

You must use "/**" style comments for a function comment
{
return $this->belongsTo(Product::class, 'product_id');
}

// Define the relationship with Product (as plugin)
public function pluginComp()

Check notice on line 24 in app/Model/Configure/PluginCompatibleWithProducts.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

app/Model/Configure/PluginCompatibleWithProducts.php#L24

You must use "/**" style comments for a function comment
{
return $this->belongsTo(Product::class, 'plugin_id');
}
}
28 changes: 28 additions & 0 deletions app/Model/Configure/ProductPluginGroup.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace App\Model\Configure;

use App\Model\Product\Product;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class ProductPluginGroup extends Model
{
use HasFactory;

protected $table = 'product_plugin_group';

protected $guarded = [];

// Define the relationship with Product (as product)
public function product()

Check notice on line 18 in app/Model/Configure/ProductPluginGroup.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

app/Model/Configure/ProductPluginGroup.php#L18

You must use "/**" style comments for a function comment
{
return $this->belongsTo(Product::class, 'product_id');
}

// Define the relationship with Product (as plugin)
public function plugin()

Check notice on line 24 in app/Model/Configure/ProductPluginGroup.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

app/Model/Configure/ProductPluginGroup.php#L24

You must use "/**" style comments for a function comment
{
return $this->belongsTo(Product::class, 'plugin_id');
}
}
6 changes: 6 additions & 0 deletions app/Model/Payment/Plan.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Model\Payment;

use App\BaseModel;
use App\Model\Configure\ConfigOption;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Spatie\Activitylog\LogOptions;
use Spatie\Activitylog\Traits\LogsActivity;
Expand Down Expand Up @@ -67,4 +68,9 @@ public function getActivitylogOptions(): LogOptions
{
return LogOptions::defaults();
}

public function configOptions()
{
return $this->hasMany(ConfigOption::class);
}
}
Loading