Updated checkout to wait for backend confirmation before advancing, added a “Processing payment…” state with retry/ refresh fallback, and now use Paddle totals/currency for purchase records + confirmation emails (with new email translations).

This commit is contained in:
Codex Agent
2025-12-22 09:06:48 +01:00
parent 41d29eb7d3
commit 84234bfb8e
36 changed files with 1742 additions and 187 deletions

View File

@@ -34,6 +34,7 @@ class PurchaseConfirmation extends Mailable
'user' => $this->purchase->tenant->user,
'package' => $this->purchase->package,
'packageName' => $this->localizedPackageName(),
'priceFormatted' => $this->formattedTotal(),
],
);
}
@@ -49,4 +50,45 @@ class PurchaseConfirmation extends Mailable
return optional($this->purchase->package)->getNameForLocale($locale) ?? '';
}
private function formattedTotal(): string
{
$totals = $this->purchase->metadata['paddle_totals'] ?? [];
$currency = $totals['currency']
?? $this->purchase->metadata['currency']
?? $this->purchase->package?->currency
?? 'EUR';
$amount = array_key_exists('total', $totals) ? (float) $totals['total'] : (float) $this->purchase->price;
$locale = $this->locale ?? app()->getLocale();
$formatter = class_exists(\NumberFormatter::class)
? new \NumberFormatter($this->mapLocale($locale), \NumberFormatter::CURRENCY)
: null;
if ($formatter) {
$formatted = $formatter->formatCurrency($amount, $currency);
if ($formatted !== false) {
return $formatted;
}
}
$symbol = match ($currency) {
'EUR' => '€',
'USD' => '$',
default => $currency,
};
return number_format($amount, 2, ',', '.').' '.$symbol;
}
private function mapLocale(string $locale): string
{
$normalized = strtolower(str_replace('_', '-', $locale));
return match (true) {
str_starts_with($normalized, 'de') => 'de_DE',
str_starts_with($normalized, 'en') => 'en_US',
default => 'de_DE',
};
}
}