geschenkgutscheine implementiert ("Paket verschenken"). Neuer Upload-Provider: Sparkbooth.

This commit is contained in:
Codex Agent
2025-12-07 16:54:58 +01:00
parent 3f3c0f1d35
commit 046e2fe3ec
50 changed files with 2422 additions and 130 deletions

View File

@@ -10,6 +10,7 @@ use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Str;
@@ -97,6 +98,11 @@ class Coupon extends Model
return $this->hasMany(CouponRedemption::class);
}
public function giftVoucher(): HasOne
{
return $this->hasOne(GiftVoucher::class);
}
public function scopeActive($query)
{
return $query->where('status', CouponStatus::ACTIVE)

View File

@@ -25,12 +25,16 @@ class Event extends Model
'name' => 'array',
'description' => 'array',
'photobooth_enabled' => 'boolean',
'photobooth_mode' => 'string',
'photobooth_expires_at' => 'datetime',
'photobooth_metadata' => 'array',
'sparkbooth_expires_at' => 'datetime',
'sparkbooth_last_upload_at' => 'datetime',
];
protected $hidden = [
'photobooth_password_encrypted',
'sparkbooth_password_encrypted',
];
protected static function booted(): void
@@ -196,4 +200,26 @@ class Event extends Model
? Crypt::encryptString($value)
: null;
}
public function getSparkboothPasswordAttribute(): ?string
{
$encrypted = $this->attributes['sparkbooth_password_encrypted'] ?? null;
if (! $encrypted) {
return null;
}
try {
return Crypt::decryptString($encrypted);
} catch (DecryptException) {
return null;
}
}
public function setSparkboothPasswordAttribute(?string $value): void
{
$this->attributes['sparkbooth_password_encrypted'] = $value
? Crypt::encryptString($value)
: null;
}
}

View File

@@ -0,0 +1,95 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Str;
class GiftVoucher extends Model
{
/** @use HasFactory<\Database\Factories\GiftVoucherFactory> */
use HasFactory;
use SoftDeletes;
public const STATUS_ISSUED = 'issued';
public const STATUS_REDEEMED = 'redeemed';
public const STATUS_REFUNDED = 'refunded';
public const STATUS_EXPIRED = 'expired';
protected $fillable = [
'code',
'amount',
'currency',
'status',
'purchaser_email',
'recipient_email',
'recipient_name',
'message',
'paddle_transaction_id',
'paddle_checkout_id',
'paddle_price_id',
'coupon_id',
'expires_at',
'redeemed_at',
'refunded_at',
'metadata',
];
protected $casts = [
'amount' => 'decimal:2',
'expires_at' => 'datetime',
'redeemed_at' => 'datetime',
'refunded_at' => 'datetime',
'metadata' => 'array',
];
protected static function booted(): void
{
static::saving(function (self $voucher): void {
if ($voucher->code) {
$voucher->code = Str::upper($voucher->code);
}
if ($voucher->currency) {
$voucher->currency = Str::upper($voucher->currency);
}
});
}
public function coupon(): BelongsTo
{
return $this->belongsTo(Coupon::class);
}
public function isRedeemed(): bool
{
return $this->status === self::STATUS_REDEEMED;
}
public function isRefunded(): bool
{
return $this->status === self::STATUS_REFUNDED;
}
public function isExpired(): bool
{
return $this->status === self::STATUS_EXPIRED || ($this->expires_at && $this->expires_at->isPast());
}
public function canBeRedeemed(): bool
{
return ! $this->isRedeemed() && ! $this->isRefunded() && ! $this->isExpired();
}
public function canBeRefunded(): bool
{
return ! $this->isRedeemed() && ! $this->isRefunded();
}
}

View File

@@ -21,6 +21,8 @@ class Photo extends Model
public const SOURCE_PHOTOBOOTH = 'photobooth';
public const SOURCE_SPARKBOOTH = 'sparkbooth';
public const SOURCE_UNKNOWN = 'unknown';
protected static ?array $columnCache = null;