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:
@@ -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',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user