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

Implement Pricing and Control Panel Integration #150

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 104 additions & 0 deletions app/Filament/Resources/ProductsServiceResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php

namespace App\Filament\Resources;

use App\Filament\Resources\ProductsServiceResource\Pages;
use App\Models\Products_Service;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;

class ProductsServiceResource extends Resource
{
protected static ?string $model = Products_Service::class;

protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';

public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('name')
->required()
->maxLength(255),
Forms\Components\Textarea::make('description')
->maxLength(65535)
->columnSpanFull(),
Forms\Components\TextInput::make('base_price')
->required()
->numeric()
->prefix('$'),
Forms\Components\Select::make('type')
->required()
->options([
'hosting' => 'Hosting',
'domain' => 'Domain',
'addon' => 'Add-on',
]),
Forms\Components\Select::make('pricing_model')
->required()
->options([
'fixed' => 'Fixed',
'tiered' => 'Tiered',
'usage_based' => 'Usage-based',
])
->reactive(),
Forms\Components\KeyValue::make('custom_pricing_data')
->keyLabel('Tier/Usage')
->valueLabel('Price')
->visible(fn (Forms\Get $get) => in_array($get('pricing_model'), ['tiered', 'usage_based']))
->columnSpanFull(),
]);
}

public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('name')
->searchable(),
Tables\Columns\TextColumn::make('type'),
Tables\Columns\TextColumn::make('base_price')
->money('USD')
->sortable(),
Tables\Columns\TextColumn::make('pricing_model'),
Tables\Columns\TextColumn::make('created_at')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('updated_at')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
])
->filters([
//
])
->actions([
Tables\Actions\EditAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}

public static function getRelations(): array
{
return [
//
];
}

public static function getPages(): array
{
return [
'index' => Pages\ListProductsServices::route('/'),
'create' => Pages\CreateProductsService::route('/create'),
'edit' => Pages\EditProductsService::route('/{record}/edit'),
];
}
}
15 changes: 14 additions & 1 deletion app/Models/Products_Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,20 @@ class Products_Service extends Model
protected $fillable = [
'name',
'description',
'price',
'base_price',
'type',
'pricing_model',
'custom_pricing_data',
];

protected $casts = [
'custom_pricing_data' => 'array',
];

public function getPriceAttribute()
{
// This method can be implemented to calculate the price based on the pricing model and custom data
// For now, we'll return the base price
return $this->base_price;
}
}
79 changes: 79 additions & 0 deletions app/Services/ControlPanels/DirectAdminClient.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php

namespace App\Services\ControlPanels;

use GuzzleHttp\Client;

class DirectAdminClient
{
protected $client;
protected $apiUrl;
protected $apiToken;

public function __construct()
{
$this->client = new Client();
$this->apiUrl = config('services.directadmin.api_url');
$this->apiToken = config('services.directadmin.api_token');
}

public function createAccount($username, $domain, $package)
{
// Implement DirectAdmin API call to create account
// This is a placeholder and should be replaced with actual DirectAdmin API implementation
$response = $this->client->post($this->apiUrl . '/accounts', [
'headers' => [
'Authorization' => 'Bearer ' . $this->apiToken,
],
'json' => [
'username' => $username,
'domain' => $domain,
'package' => $package,
],
]);

return $response->getStatusCode() == 201;
}

public function suspendAccount($username)
{
// Implement DirectAdmin API call to suspend account
// This is a placeholder and should be replaced with actual DirectAdmin API implementation
$response = $this->client->post($this->apiUrl . '/accounts/' . $username . '/suspend', [
'headers' => [
'Authorization' => 'Bearer ' . $this->apiToken,
],
]);

return $response->getStatusCode() == 200;
}

public function unsuspendAccount($username)
{
// Implement DirectAdmin API call to unsuspend account
// This is a placeholder and should be replaced with actual DirectAdmin API implementation
$response = $this->client->post($this->apiUrl . '/accounts/' . $username . '/unsuspend', [
'headers' => [
'Authorization' => 'Bearer ' . $this->apiToken,
],
]);

return $response->getStatusCode() == 200;
}

public function changePackage($username, $newPackage)
{
// Implement DirectAdmin API call to change package
// This is a placeholder and should be replaced with actual DirectAdmin API implementation
$response = $this->client->put($this->apiUrl . '/accounts/' . $username . '/package', [
'headers' => [
'Authorization' => 'Bearer ' . $this->apiToken,
],
'json' => [
'package' => $newPackage,
],
]);

return $response->getStatusCode() == 200;
}
}
79 changes: 79 additions & 0 deletions app/Services/ControlPanels/PleskClient.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php

namespace App\Services\ControlPanels;

use GuzzleHttp\Client;

class PleskClient
{
protected $client;
protected $apiUrl;
protected $apiToken;

public function __construct()
{
$this->client = new Client();
$this->apiUrl = config('services.plesk.api_url');
$this->apiToken = config('services.plesk.api_token');
}

public function createAccount($username, $domain, $package)
{
// Implement Plesk API call to create account
// This is a placeholder and should be replaced with actual Plesk API implementation
$response = $this->client->post($this->apiUrl . '/accounts', [
'headers' => [
'Authorization' => 'Bearer ' . $this->apiToken,
],
'json' => [
'username' => $username,
'domain' => $domain,
'package' => $package,
],
]);

return $response->getStatusCode() == 201;
}

public function suspendAccount($username)
{
// Implement Plesk API call to suspend account
// This is a placeholder and should be replaced with actual Plesk API implementation
$response = $this->client->post($this->apiUrl . '/accounts/' . $username . '/suspend', [
'headers' => [
'Authorization' => 'Bearer ' . $this->apiToken,
],
]);

return $response->getStatusCode() == 200;
}

public function unsuspendAccount($username)
{
// Implement Plesk API call to unsuspend account
// This is a placeholder and should be replaced with actual Plesk API implementation
$response = $this->client->post($this->apiUrl . '/accounts/' . $username . '/unsuspend', [
'headers' => [
'Authorization' => 'Bearer ' . $this->apiToken,
],
]);

return $response->getStatusCode() == 200;
}

public function changePackage($username, $newPackage)
{
// Implement Plesk API call to change package
// This is a placeholder and should be replaced with actual Plesk API implementation
$response = $this->client->put($this->apiUrl . '/accounts/' . $username . '/package', [
'headers' => [
'Authorization' => 'Bearer ' . $this->apiToken,
],
'json' => [
'package' => $newPackage,
],
]);

return $response->getStatusCode() == 200;
}
}
Loading
Loading