Implementation of Templates/Themes/Plugins Sales on Website
A digital products marketplace — templates, themes, plugins — requires specific infrastructure: secure file delivery, license management, update system, author management.
Digital Product Sales Models
Regular License — for a single project/client. Extended License — for multiple projects or commercial use. Different prices, different usage rights, stored as different SKUs of one product.
File Delivery After Payment
class DigitalProductDeliveryService
{
public function deliver(Purchase $purchase): void
{
$product = $purchase->product;
// Create a secure download link
$downloadToken = $this->createDownloadToken($purchase);
// Email with download button
Mail::to($purchase->customer_email)->send(
new DigitalProductDeliveryMail($purchase, $downloadToken)
);
// Save for access from personal account
$purchase->update(['download_token' => $downloadToken, 'status' => 'delivered']);
}
private function createDownloadToken(Purchase $purchase): string
{
return DB::table('download_tokens')->insertGetId([
'purchase_id' => $purchase->id,
'token' => Str::random(64),
'download_limit'=> 5,
'download_count'=> 0,
'expires_at' => now()->addDays(30),
]);
}
}
Update System
// Check for updates for WordPress plugin
Route::get('/api/plugins/{slug}/update-check', function (Request $request, string $slug) {
$licenseKey = $request->input('license_key');
$currentVersion = $request->input('version');
$product = Product::where('slug', $slug)->firstOrFail();
$license = License::where('key', $licenseKey)->where('product_id', $product->id)->first();
if (!$license || $license->status !== 'active') {
return response()->json(['update_available' => false, 'error' => 'Invalid license']);
}
$latestVersion = $product->latest_version;
if (version_compare($latestVersion, $currentVersion, '>')) {
return response()->json([
'update_available' => true,
'version' => $latestVersion,
'download_url' => route('plugins.download', ['slug' => $slug, 'token' => $license->id]),
'changelog' => $product->latest_changelog,
]);
}
return response()->json(['update_available' => false]);
});
Ratings and Reviews System
// Only buyers can leave reviews
Route::post('/products/{product}/reviews', function (Request $request, Product $product) {
$hasPurchased = Purchase::where([
'customer_id' => auth()->id(),
'product_id' => $product->id,
])->exists();
if (!$hasPurchased) abort(403, 'Only buyers can leave reviews');
Review::create([
'product_id' => $product->id,
'customer_id' => auth()->id(),
'rating' => $request->input('rating'),
'title' => $request->input('title'),
'body' => $request->input('body'),
'version' => $request->input('version'),
]);
$product->updateRatingAverage();
})->middleware('auth');
Author Payouts
class AuthorPayoutService
{
public function calculatePayout(int $authorId, string $period): array
{
$sales = Sale::where('author_id', $authorId)
->wherePeriod($period)
->get();
$gross = $sales->sum('price');
$fee = $gross * 0.30; // 30% platform commission
$payout = $gross - $fee;
return compact('gross', 'fee', 'payout', 'sales');
}
}
Timeline
Digital products marketplace with licenses, updates, and author payouts: 20–28 business days.







