geschenkgutscheine implementiert ("Paket verschenken"). Neuer Upload-Provider: Sparkbooth.
This commit is contained in:
31
database/factories/GiftVoucherFactory.php
Normal file
31
database/factories/GiftVoucherFactory.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\GiftVoucher>
|
||||
*/
|
||||
class GiftVoucherFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'code' => strtoupper('GIFT-'.$this->faker->bothify('##??##??')),
|
||||
'amount' => $this->faker->randomElement([29, 59, 129, 149]),
|
||||
'currency' => 'EUR',
|
||||
'status' => \App\Models\GiftVoucher::STATUS_ISSUED,
|
||||
'purchaser_email' => $this->faker->safeEmail(),
|
||||
'recipient_email' => $this->faker->safeEmail(),
|
||||
'recipient_name' => $this->faker->name(),
|
||||
'message' => $this->faker->sentence(8),
|
||||
'expires_at' => now()->addYears(5),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('gift_vouchers', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('code', 64)->unique();
|
||||
|
||||
$table->decimal('amount', 10, 2);
|
||||
$table->char('currency', 3)->default('EUR');
|
||||
$table->string('status', 32)->default('issued');
|
||||
|
||||
$table->string('purchaser_email')->nullable();
|
||||
$table->string('recipient_email')->nullable();
|
||||
$table->string('recipient_name')->nullable();
|
||||
$table->string('message', 500)->nullable();
|
||||
|
||||
$table->string('paddle_transaction_id')->nullable()->unique();
|
||||
$table->string('paddle_checkout_id')->nullable()->unique();
|
||||
$table->string('paddle_price_id')->nullable();
|
||||
|
||||
$table->foreignIdFor(\App\Models\Coupon::class)->nullable()->constrained()->nullOnDelete();
|
||||
|
||||
$table->timestamp('expires_at')->nullable();
|
||||
$table->timestamp('redeemed_at')->nullable();
|
||||
$table->timestamp('refunded_at')->nullable();
|
||||
|
||||
$table->json('metadata')->nullable();
|
||||
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
|
||||
$table->index(['status', 'expires_at']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('gift_vouchers');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('events', function (Blueprint $table) {
|
||||
$table->string('photobooth_mode', 16)
|
||||
->default('ftp')
|
||||
->after('photobooth_enabled');
|
||||
|
||||
$table->string('sparkbooth_username', 32)
|
||||
->nullable()
|
||||
->after('photobooth_path');
|
||||
$table->text('sparkbooth_password_encrypted')
|
||||
->nullable()
|
||||
->after('sparkbooth_username');
|
||||
$table->timestamp('sparkbooth_expires_at')
|
||||
->nullable()
|
||||
->after('sparkbooth_password_encrypted');
|
||||
$table->string('sparkbooth_status', 32)
|
||||
->default('inactive')
|
||||
->after('sparkbooth_expires_at');
|
||||
$table->timestamp('sparkbooth_last_upload_at')
|
||||
->nullable()
|
||||
->after('sparkbooth_status');
|
||||
$table->unsignedInteger('sparkbooth_uploads_last_24h')
|
||||
->default(0)
|
||||
->after('sparkbooth_last_upload_at');
|
||||
$table->unsignedBigInteger('sparkbooth_uploads_total')
|
||||
->default(0)
|
||||
->after('sparkbooth_uploads_last_24h');
|
||||
|
||||
$table->unique('sparkbooth_username');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('events', function (Blueprint $table) {
|
||||
$table->dropUnique(['sparkbooth_username']);
|
||||
|
||||
$table->dropColumn([
|
||||
'photobooth_mode',
|
||||
'sparkbooth_username',
|
||||
'sparkbooth_password_encrypted',
|
||||
'sparkbooth_expires_at',
|
||||
'sparkbooth_status',
|
||||
'sparkbooth_last_upload_at',
|
||||
'sparkbooth_uploads_last_24h',
|
||||
'sparkbooth_uploads_total',
|
||||
]);
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -16,6 +16,7 @@ class DatabaseSeeder extends Seeder
|
||||
MediaStorageTargetSeeder::class,
|
||||
LegalPagesSeeder::class,
|
||||
PackageSeeder::class,
|
||||
GiftVoucherTierSeeder::class,
|
||||
CouponSeeder::class,
|
||||
PackageAddonSeeder::class,
|
||||
EventTypesSeeder::class,
|
||||
|
||||
70
database/seeders/GiftVoucherTierSeeder.php
Normal file
70
database/seeders/GiftVoucherTierSeeder.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Package;
|
||||
use App\Services\Paddle\PaddleGiftVoucherCatalogService;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class GiftVoucherTierSeeder extends Seeder
|
||||
{
|
||||
public function __construct(private readonly PaddleGiftVoucherCatalogService $catalog) {}
|
||||
|
||||
public function run(): void
|
||||
{
|
||||
if (! config('paddle.api_key')) {
|
||||
$this->command?->warn('Skipping gift voucher Paddle sync: paddle.api_key not configured.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$tiers = $this->buildTiers();
|
||||
|
||||
foreach ($tiers as $tier) {
|
||||
$result = $this->catalog->ensureTier($tier);
|
||||
|
||||
$this->command?->info(sprintf(
|
||||
'%s → product %s, price %s',
|
||||
$tier['key'],
|
||||
$result['product_id'],
|
||||
$result['price_id']
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, array{key:string,label:string,amount:float,currency?:string,paddle_product_id?:string|null,paddle_price_id?:string|null}>
|
||||
*/
|
||||
protected function buildTiers(): array
|
||||
{
|
||||
$packages = Package::query()
|
||||
->where('type', 'endcustomer')
|
||||
->whereNotNull('price')
|
||||
->get(['slug', 'name', 'price', 'currency'])
|
||||
->unique(fn (Package $package) => $package->price.'|'.$package->currency);
|
||||
|
||||
return $packages->map(function (Package $package): array {
|
||||
$amount = (float) $package->price;
|
||||
$currency = $package->currency ?? 'EUR';
|
||||
|
||||
return [
|
||||
'key' => 'gift-'.$package->slug,
|
||||
'label' => 'Gutschein '.$package->name,
|
||||
'amount' => $amount,
|
||||
'currency' => $currency,
|
||||
'paddle_price_id' => $this->lookupPaddlePriceId($package->slug),
|
||||
];
|
||||
})->values()->all();
|
||||
}
|
||||
|
||||
protected function lookupPaddlePriceId(string $slug): ?string
|
||||
{
|
||||
return match ($slug) {
|
||||
'starter' => 'pri_01kbwccfe1mpwh7hh60eygemx6',
|
||||
'standard' => 'pri_01kbwccfvzrf4z2f1r62vns7gh',
|
||||
'pro' => 'pri_01kbwccg8vjc5cwz0kftfvf9wm',
|
||||
'premium' => 'pri_01kbwccgnjzwrjy5xg1yp981p6',
|
||||
default => null,
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user