diff --git a/src/Appwrite/Platform/Modules/Payments/Http/Plans/Create.php b/src/Appwrite/Platform/Modules/Payments/Http/Plans/Create.php index f733a924dc..a9d3c73f6c 100644 --- a/src/Appwrite/Platform/Modules/Payments/Http/Plans/Create.php +++ b/src/Appwrite/Platform/Modules/Payments/Http/Plans/Create.php @@ -143,13 +143,19 @@ class Create extends Base return new AppwriteException(ExtendException::RESOURCE_ALREADY_EXISTS); } + $payments = (array) $project->getAttribute('payments', []); + $providerConfigs = (array) ($payments['providers'] ?? []); + if (empty($providerConfigs)) { + $response->setStatusCode(Response::STATUS_CODE_BAD_REQUEST); + $response->json(['message' => 'At least one payment provider must be configured before creating plans']); + return; + } + $created = $dbForProject->createDocument('payments_plans', $document); $queueForEvents->setParam('planId', $planId); // Provision on configured providers - $payments = (array) $project->getAttribute('payments', []); - $providerConfigs = (array) ($payments['providers'] ?? []); $providersMeta = []; foreach ($providerConfigs as $providerId => $providerConfig) { $state = new ProviderState((string) $providerId, (array) $providerConfig, (array) ($providerConfig['state'] ?? [])); diff --git a/src/Appwrite/Platform/Modules/Payments/Http/Subscriptions/Get.php b/src/Appwrite/Platform/Modules/Payments/Http/Subscriptions/Get.php index 2ae130c42d..9d47922889 100644 --- a/src/Appwrite/Platform/Modules/Payments/Http/Subscriptions/Get.php +++ b/src/Appwrite/Platform/Modules/Payments/Http/Subscriptions/Get.php @@ -134,6 +134,17 @@ class Get extends Base } } + if ($actorId !== '') { + $collection = $actorType === 'team' ? 'teams' : 'users'; + $actor = $dbForProject->getDocument($collection, $actorId); + + if ($actor->isEmpty()) { + $response->setStatusCode(Response::STATUS_CODE_NOT_FOUND); + $response->json(['message' => 'Actor not found']); + return; + } + } + $queries = [ Query::equal('actorType', [$actorType]), Query::equal('actorId', [$actorId]), diff --git a/src/Appwrite/Platform/Modules/Payments/Http/Webhooks/Provider/Create.php b/src/Appwrite/Platform/Modules/Payments/Http/Webhooks/Provider/Create.php index 8e9f1693b8..b48b5c1f15 100644 --- a/src/Appwrite/Platform/Modules/Payments/Http/Webhooks/Provider/Create.php +++ b/src/Appwrite/Platform/Modules/Payments/Http/Webhooks/Provider/Create.php @@ -9,6 +9,7 @@ use Appwrite\SDK\Method; use Appwrite\Utopia\Response; use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\UID; +use Utopia\Database\Database; use Utopia\Platform\Action; use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Request; @@ -48,14 +49,32 @@ class Create extends Base ->inject('request') ->inject('registryPayments') ->inject('dbForPlatform') - ->inject('dbForProject') + ->inject('getProjectDB') ->inject('queueForEvents') ->callback($this->action(...)); } - public function action(string $providerId, string $projectId, Response $response, Request $request, Registry $registryPayments, \Utopia\Database\Database $dbForPlatform, \Utopia\Database\Database $dbForProject, Event $queueForEvents) + public function action( + string $providerId, + string $projectId, + Response $response, + Request $request, + Registry $registryPayments, + Database $dbForPlatform, + callable $getProjectDB, + Event $queueForEvents + ) { $project = Authorization::skip(fn () => $dbForPlatform->getDocument('projects', $projectId)); + + if ($project === null || $project->isEmpty()) { + $response->setStatusCode(Response::STATUS_CODE_NOT_FOUND); + $response->json(['message' => 'Project not found']); + return; + } + + $dbForProject = $getProjectDB($project); + // Feature flag: ignore if disabled $paymentsCfg = (array) $project->getAttribute('payments', []); if (isset($paymentsCfg['enabled']) && $paymentsCfg['enabled'] === false) {