name.($note !== null && $note !== '' ? ': '.$note : ''); $transaction = $this->wallet->credit($user, $credits, CreditTransactionType::Grant, $description); $this->activityLog->record( ActivityType::AdminGrant, sprintf( '%s hat %s (%s) %d Credits gutgeschrieben — ohne Zahlung.%s', $grantedBy->name, $user->name, $user->email, $credits, $note !== null && $note !== '' ? ' Grund: '.$note : '', ), user: $user, subject: $transaction, meta: ['credits' => $credits, 'granted_by' => $grantedBy->id, 'note' => $note], ); return $transaction; } /** * Schreibt dem User freie Pressemitteilungen gut: bezahlte Einzel-PM-Käufe * zu 0 € ({@see SinglePurchase::scopeGrantingSubmission()}), die das * Submit-Gate erfüllen und beim Veröffentlichen regulär eingelöst werden. */ public function grantFreePressReleases(User $user, int $count, User $grantedBy, ?string $note = null): void { if ($count < 1) { throw new \InvalidArgumentException('Anzahl muss positiv sein.'); } DB::transaction(function () use ($user, $count): void { for ($i = 0; $i < $count; $i++) { $user->singlePurchases()->create([ 'type' => SinglePurchaseType::SinglePm, 'status' => SinglePurchaseStatus::Paid, 'price_cents' => 0, 'currency' => config('billing.default_currency'), 'paid_at' => now(), ]); } }); $this->activityLog->record( ActivityType::AdminGrant, sprintf( '%s hat %s (%s) %d freie Pressemitteilung(en) gutgeschrieben — ohne Zahlung.%s', $grantedBy->name, $user->name, $user->email, $count, $note !== null && $note !== '' ? ' Grund: '.$note : '', ), user: $user, meta: ['free_press_releases' => $count, 'granted_by' => $grantedBy->id, 'note' => $note], ); } }