geschenkgutscheine implementiert ("Paket verschenken"). Neuer Upload-Provider: Sparkbooth.
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
95
app/Models/GiftVoucher.php
Normal file
95
app/Models/GiftVoucher.php
Normal 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();
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user