fixed event join token handling in the event admin. created new seeders with new tenants and package purchases. added new playwright test scenarios.

This commit is contained in:
Codex Agent
2025-10-26 14:44:47 +01:00
parent 6290a3a448
commit ecf5a23b28
59 changed files with 3900 additions and 691 deletions

View File

@@ -7,18 +7,16 @@ use App\Models\Package;
use App\Models\PackagePurchase;
use App\Models\Tenant;
use App\Models\TenantPackage;
use Illuminate\Http\Request;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Validation\ValidationException;
use Stripe\Stripe;
use Stripe\PaymentIntent;
use PayPal\PayPalClient;
use PayPal\Environment\SandboxEnvironment;
use PayPal\Environment\LiveEnvironment;
use PayPal\Checkout\Orders\OrdersCreateRequest;
use PayPal\Checkout\Orders\OrdersCaptureRequest;
use PayPal\Checkout\Orders\OrdersCreateRequest;
use PayPal\Environment\LiveEnvironment;
use PayPal\Environment\SandboxEnvironment;
use PayPal\PayPalClient;
class PackageController extends Controller
{
@@ -30,7 +28,16 @@ class PackageController extends Controller
->get();
$packages->each(function ($package) {
$package->features = json_decode($package->features ?? '[]', true);
if (is_string($package->features)) {
$decoded = json_decode($package->features, true);
$package->features = is_array($decoded) ? $decoded : [];
return;
}
if (! is_array($package->features)) {
$package->features = [];
}
});
return response()->json([
@@ -51,7 +58,7 @@ class PackageController extends Controller
$package = Package::findOrFail($request->package_id);
$tenant = $request->attributes->get('tenant');
if (!$tenant) {
if (! $tenant) {
throw ValidationException::withMessages(['tenant' => 'Tenant not found.']);
}
@@ -73,7 +80,7 @@ class PackageController extends Controller
$package = Package::findOrFail($request->package_id);
$tenant = $request->attributes->get('tenant');
if (!$tenant) {
if (! $tenant) {
throw ValidationException::withMessages(['tenant' => 'Tenant not found.']);
}
@@ -105,7 +112,7 @@ class PackageController extends Controller
$package = Package::findOrFail($request->package_id);
$tenant = $request->attributes->get('tenant');
if (!$tenant) {
if (! $tenant) {
throw ValidationException::withMessages(['tenant' => 'Tenant not found.']);
}
@@ -146,7 +153,7 @@ class PackageController extends Controller
$package = Package::findOrFail($request->package_id);
$tenant = $request->attributes->get('tenant');
if (!$tenant) {
if (! $tenant) {
throw ValidationException::withMessages(['tenant' => 'Tenant not found.']);
}
@@ -154,7 +161,7 @@ class PackageController extends Controller
throw ValidationException::withMessages(['package' => 'Not a free package.']);
}
DB::transaction(function () use ($request, $package, $tenant) {
DB::transaction(function () use ($package, $tenant) {
PackagePurchase::create([
'tenant_id' => $tenant->id,
'package_id' => $package->id,
@@ -188,7 +195,7 @@ class PackageController extends Controller
$package = Package::findOrFail($request->package_id);
$tenant = $request->attributes->get('tenant');
if (!$tenant) {
if (! $tenant) {
throw ValidationException::withMessages(['tenant' => 'Tenant not found.']);
}
@@ -202,25 +209,25 @@ class PackageController extends Controller
$client = PayPalClient::client($environment);
$request = new OrdersCreateRequest();
$request = new OrdersCreateRequest;
$request->prefer('return=representation');
$request->body = [
"intent" => "CAPTURE",
"purchase_units" => [[
"amount" => [
"currency_code" => "EUR",
"value" => number_format($package->price, 2, '.', ''),
'intent' => 'CAPTURE',
'purchase_units' => [[
'amount' => [
'currency_code' => 'EUR',
'value' => number_format($package->price, 2, '.', ''),
],
"description" => 'Fotospiel Package: ' . $package->name,
"custom_id" => json_encode([
'description' => 'Fotospiel Package: '.$package->name,
'custom_id' => json_encode([
'tenant_id' => $tenant->id,
'package_id' => $package->id,
'user_id' => $tenant->user_id ?? null,
]),
]],
"application_context" => [
"shipping_preference" => "NO_SHIPPING",
"user_action" => "PAY_NOW",
'application_context' => [
'shipping_preference' => 'NO_SHIPPING',
'user_action' => 'PAY_NOW',
],
];
@@ -232,7 +239,7 @@ class PackageController extends Controller
'orderID' => $order->id,
]);
} catch (\Exception $e) {
Log::error('PayPal order creation error: ' . $e->getMessage());
Log::error('PayPal order creation error: '.$e->getMessage());
throw ValidationException::withMessages(['payment' => 'PayPal-Bestellung fehlgeschlagen.']);
}
}
@@ -263,11 +270,11 @@ class PackageController extends Controller
$capture = $response->result;
if ($capture->status !== 'COMPLETED') {
throw new \Exception('PayPal capture not completed: ' . $capture->status);
throw new \Exception('PayPal capture not completed: '.$capture->status);
}
$customId = $capture->purchaseUnits[0]->customId ?? null;
if (!$customId) {
if (! $customId) {
throw new \Exception('No metadata in PayPal order');
}
@@ -275,7 +282,7 @@ class PackageController extends Controller
$tenant = Tenant::find($metadata['tenant_id']);
$package = Package::find($metadata['package_id']);
if (!$tenant || !$package) {
if (! $tenant || ! $package) {
throw new \Exception('Tenant or package not found');
}
@@ -325,8 +332,9 @@ class PackageController extends Controller
return response()->json(['success' => true, 'message' => 'Payment successful']);
} catch (\Exception $e) {
Log::error('PayPal capture error: ' . $e->getMessage(), ['order_id' => $orderId]);
return response()->json(['success' => false, 'message' => 'Capture failed: ' . $e->getMessage()], 422);
Log::error('PayPal capture error: '.$e->getMessage(), ['order_id' => $orderId]);
return response()->json(['success' => false, 'message' => 'Capture failed: '.$e->getMessage()], 422);
}
}
@@ -380,14 +388,16 @@ class PackageController extends Controller
$type = $request->type;
if ($type === 'reseller_subscription') {
$response = (new StripeController())->createSubscription($request);
$response = (new StripeController)->createSubscription($request);
return $response;
} else {
$response = (new StripeController())->createPaymentIntent($request);
$response = (new StripeController)->createPaymentIntent($request);
return $response;
}
}
// Helper for PayPal client - add this if not exists, or use global
// But since SDK has PayPalClient, assume it's used
}
}