Fix Paddle coupon payload
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (push) Has been cancelled
tests / ui (push) Has been cancelled

This commit is contained in:
Codex Agent
2026-01-03 15:44:30 +01:00
parent 43b626cbfc
commit 4f1fbcc98b
2 changed files with 113 additions and 4 deletions

View File

@@ -88,19 +88,17 @@ class PaddleDiscountService
protected function buildDiscountPayload(Coupon $coupon): array
{
$payload = [
'name' => $coupon->name,
'code' => $coupon->code,
'type' => $this->mapType($coupon->type),
'amount' => $this->formatAmount($coupon),
'currency_code' => $coupon->currency ?? config('app.currency', 'EUR'),
'currency_code' => Str::upper((string) ($coupon->currency ?? config('app.currency', 'EUR'))),
'enabled_for_checkout' => $coupon->enabled_for_checkout,
'description' => $coupon->description,
'description' => $this->resolveDescription($coupon),
'mode' => $coupon->paddle_mode ?? 'standard',
'usage_limit' => $coupon->usage_limit,
'maximum_recurring_intervals' => null,
'recur' => false,
'restrict_to' => $this->resolveRestrictions($coupon),
'starts_at' => optional($coupon->starts_at)?->toIso8601String(),
'expires_at' => optional($coupon->ends_at)?->toIso8601String(),
];
@@ -146,4 +144,27 @@ class PaddleDiscountService
return $prices->isEmpty() ? null : $prices->all();
}
protected function resolveDescription(Coupon $coupon): string
{
$description = trim((string) ($coupon->description ?? ''));
if ($description !== '') {
return $description;
}
$name = trim((string) ($coupon->name ?? ''));
if ($name !== '') {
return $name;
}
$code = trim((string) ($coupon->code ?? ''));
if ($code !== '') {
return sprintf('Coupon %s', $code);
}
return sprintf('Coupon %d', $coupon->id);
}
}