Files
fotospiel-app/app/Http/Controllers/Api/Marketing/GiftVoucherCheckoutController.php

45 lines
1.3 KiB
PHP

<?php
namespace App\Http\Controllers\Api\Marketing;
use App\Http\Controllers\Controller;
use App\Services\GiftVouchers\GiftVoucherCheckoutService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Validation\ValidationException;
class GiftVoucherCheckoutController extends Controller
{
public function __construct(private readonly GiftVoucherCheckoutService $checkout) {}
public function tiers(): JsonResponse
{
return response()->json([
'data' => $this->checkout->tiers(),
]);
}
public function store(Request $request): JsonResponse
{
$data = $this->validate($request, [
'tier_key' => ['required', 'string'],
'purchaser_email' => ['required', 'email:rfc,dns'],
'recipient_email' => ['nullable', 'email:rfc,dns'],
'recipient_name' => ['nullable', 'string', 'max:191'],
'message' => ['nullable', 'string', 'max:500'],
'success_url' => ['nullable', 'url'],
'return_url' => ['nullable', 'url'],
]);
$checkout = $this->checkout->create($data);
if (! $checkout['checkout_url']) {
throw ValidationException::withMessages([
'tier_key' => __('Unable to create Paddle checkout.'),
]);
}
return response()->json($checkout);
}
}