mivita/app/Models/PaymentTransaction.php
Kevin 6f21845607 Stripe-Integration (S0–S3): Einmalzahlungen über Stripe Checkout + Notfall-Go-Live
Wegen PAYONE-Ausfall vorgezogen live geschaltet: alle Einmalzahlungen
(Shop + Salescenter) laufen über Stripe Hosted Checkout, Abos sind bis
Phase S4 eingefroren.

- Provider-Abstraktion: PaymentProvider-Enum, PaymentGatewayInterface,
  PaymentProviderManager (Settings-Schalter, provider-treu je Bestand),
  PayoneGateway als unveränderter Adapter
- StripePaymentService: Checkout Session (eine Gesamtposition, Metadata,
  success/cancel-Redirects), StripeClientWrapper (lazy, Dark Launch),
  StripeCustomerService, StripeTransactionRecorder (client_secret-Redaction)
- Webhook /stripe/webhook: Signaturprüfung, Idempotenz über
  stripe_webhook_events (Crash-Retry-Reprocessing), txaction-Prioritäten,
  Betrags-Guard, lockForUpdate-Paid-Pfad, genau eine Bestätigungsmail
- Zahlungsmethoden-Anzeige aus charge.succeeded (carddata inkl. Wallet,
  auftragsunabhängiges Backfill aus dem Event-Store)
- Checkout: Wartungsmodus mit Admin-Bypass, Abo-Freeze-Hinweis,
  Stripe-Option (Online-Zahlung) statt Zahlartenwahl, Vorkasse ausblendbar
- Abo-Freeze-Guards: Cron user:make_abo_order, Retry, Kartenupdate
- Admin-Settings-Karte Zahlungen (Provider, Wartung, Freeze, Vorkasse)
- Hotfix: 500 bei Vorkasse ohne Clearing-Daten in admin/sales/_detail
  und checkout-final (PAYONE-Ausfall)
- Doku dev/2026-07-08-stripe/ (Plan S0–S8, Konzept, IST-Analyse)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-08 15:56:41 +00:00

123 lines
4.8 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Carbon;
/**
* App\Models\PaymentTransaction
*
* @property int $id
* @property int $shopping_payment_id
* @property string $request
* @property int|null $txid
* @property int|null $userid
* @property string|null $status
* @property string|null $key
* @property string|null $txaction
* @property array|null $transmitted_data
* @property int|null $errorcode
* @property string|null $errormessage
* @property string|null $customermessage
* @property Carbon|null $created_at
* @property Carbon|null $updated_at
* @property-read ShoppingPayment $shopping_payment
*
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PaymentTransaction newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PaymentTransaction newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PaymentTransaction query()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PaymentTransaction whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PaymentTransaction whereCustomermessage($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PaymentTransaction whereErrorcode($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PaymentTransaction whereErrormessage($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PaymentTransaction whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PaymentTransaction whereKey($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PaymentTransaction whereRequest($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PaymentTransaction whereShoppingPaymentId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PaymentTransaction whereStatus($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PaymentTransaction whereTransmittedData($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PaymentTransaction whereTxaction($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PaymentTransaction whereTxid($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PaymentTransaction whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PaymentTransaction whereUserid($value)
*
* @property string|null $mode
*
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PaymentTransaction whereMode($value)
*
* @mixin \Eloquent
*/
class PaymentTransaction extends Model
{
protected $table = 'payment_transactions';
protected $casts = [
'transmitted_data' => 'array',
];
protected $fillable = [
'shopping_payment_id',
'provider',
'request',
'txid',
'userid',
'status',
'key',
'txaction',
'transmitted_data',
'errorcode',
'errormessage',
'customermessage',
'mode',
];
public function shopping_payment()
{
return $this->belongsTo('App\Models\ShoppingPayment', 'shopping_payment_id');
}
/**
* Returns a human-readable description for known PAYONE error codes.
*
* @return array<int, string>
*/
public static function payoneErrorDescriptions(): array
{
return [
2 => 'Allgemeiner Fehler',
4 => 'Karte gesperrt',
5 => 'Zahlung abgelehnt',
12 => 'Ungültige Kartennummer',
14 => 'Ungültige Kartendaten',
33 => 'Karte abgelaufen',
34 => 'Karte gesperrt/gestohlen',
55 => 'Falsche PIN',
56 => 'Kunde hat abgebrochen',
58 => 'Transaktion nicht erlaubt',
62 => 'Karte für internationale Transaktionen nicht zugelassen',
104 => 'Karte für Online-Zahlungen nicht erlaubt',
105 => 'Karte ungültig',
120 => 'Falsche Prüfziffer (CVV)',
130 => 'Limit überschritten',
131 => 'Währung nicht unterstützt',
135 => 'Bank antwortet nicht',
136 => 'Bank nicht gefunden',
137 => 'Betrag stimmt nicht überein',
900 => '3D-Secure Authentifizierung fehlgeschlagen',
902 => 'Bank hat abgelehnt',
970 => 'Keine Antwort (Timeout)',
4218 => 'Karte unter Betrugsverdacht',
4219 => 'Transaktion von Kartenaussteller abgelehnt',
];
}
public function getErrorDescriptionAttribute(): ?string
{
if (! $this->errorcode) {
return null;
}
return self::payoneErrorDescriptions()[(int) $this->errorcode] ?? null;
}
}