init
This commit is contained in:
232 files changed
+25416
No files matched your search
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\MobileApp;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class AppConfigurationController extends Controller
|
||||
{
|
||||
public function show(Request $request): JsonResponse
|
||||
{
|
||||
/** @var MobileApp $mobileApp */
|
||||
$mobileApp = $request->attributes->get('mobileApp');
|
||||
|
||||
return response()->json(['data' => [
|
||||
'name' => $mobileApp->name,
|
||||
'package_name' => $mobileApp->package_name,
|
||||
'maintenance_mode' => $mobileApp->maintenance_mode,
|
||||
'version' => [
|
||||
'latest_name' => $mobileApp->latest_version_name,
|
||||
'latest_code' => $mobileApp->latest_version_code,
|
||||
'minimum_code' => $mobileApp->minimum_version_code,
|
||||
'store_url' => $mobileApp->store_url ?: 'https://cafebazaar.ir/app/'.$mobileApp->package_name,
|
||||
],
|
||||
'support' => [
|
||||
'email' => $mobileApp->support_email,
|
||||
'privacy_url' => $mobileApp->privacy_url,
|
||||
],
|
||||
'configuration' => $mobileApp->configuration ?? [],
|
||||
'feature_flags' => $mobileApp->feature_flags ?? [],
|
||||
'bazaar' => [
|
||||
'package_name' => $mobileApp->package_name,
|
||||
'store_url' => $mobileApp->store_url ?: 'https://cafebazaar.ir/app/'.$mobileApp->package_name,
|
||||
'login_enabled' => filled($mobileApp->bazaar_login_client_id),
|
||||
'billing_enabled' => filled($mobileApp->bazaar_api_secret),
|
||||
'updater_intent' => 'bazaar://details?id='.$mobileApp->package_name,
|
||||
],
|
||||
]]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\BazaarActiveSubscriptionsRequest;
|
||||
use App\Http\Requests\BazaarSubscriptionRequest;
|
||||
use App\Http\Requests\ConsumeBazaarPurchaseRequest;
|
||||
use App\Http\Requests\ValidateBazaarPurchaseRequest;
|
||||
use App\Http\Requests\VerifyBazaarSignatureRequest;
|
||||
use App\Models\BazaarPurchase;
|
||||
use App\Models\BazaarSubscription;
|
||||
use App\Models\MobileApp;
|
||||
use App\Services\CafeBazaar\BazaarPurchaseRecorder;
|
||||
use App\Services\CafeBazaar\BazaarSignatureVerifier;
|
||||
use App\Services\CafeBazaar\BazaarSubscriptionRecorder;
|
||||
use App\Services\CafeBazaar\CafeBazaarClient;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
class BazaarBillingController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly CafeBazaarClient $bazaar,
|
||||
private readonly BazaarPurchaseRecorder $purchases,
|
||||
private readonly BazaarSubscriptionRecorder $subscriptions,
|
||||
private readonly BazaarSignatureVerifier $signatures,
|
||||
) {}
|
||||
|
||||
public function validatePurchase(ValidateBazaarPurchaseRequest $request): JsonResponse
|
||||
{
|
||||
$app = $this->app($request);
|
||||
$response = $this->bazaar->validatePurchase($app, $request->string('product_id')->toString(), $request->string('purchase_token')->toString());
|
||||
$this->purchases->record($app, $request->string('product_id')->toString(), $request->string('purchase_token')->toString(), $response);
|
||||
|
||||
return $response->toJsonResponse();
|
||||
}
|
||||
|
||||
public function verifySignature(VerifyBazaarSignatureRequest $request): JsonResponse
|
||||
{
|
||||
$app = $request->attributes->get('mobileApp');
|
||||
|
||||
if (blank($app->bazaar_billing_public_key)) {
|
||||
return response()->json(['error' => [
|
||||
'code' => 'bazaar_public_key_missing',
|
||||
'message' => 'Configure the Bazaar billing public key in the app panel.',
|
||||
]], 422);
|
||||
}
|
||||
|
||||
return response()->json(['data' => [
|
||||
'valid' => $this->signatures->verify(
|
||||
$app->bazaar_billing_public_key,
|
||||
$request->string('original_json')->toString(),
|
||||
$request->string('signature')->toString(),
|
||||
),
|
||||
]]);
|
||||
}
|
||||
|
||||
public function consumePurchase(ConsumeBazaarPurchaseRequest $request): JsonResponse
|
||||
{
|
||||
$app = $this->app($request);
|
||||
$response = $this->bazaar->consumePurchase($app, $request->string('purchase_token')->toString());
|
||||
|
||||
if ($response->successful()) {
|
||||
BazaarPurchase::query()->whereBelongsTo($app)->where('purchase_token_hash', hash('sha256', $request->string('purchase_token')->toString()))->update(['is_consumed' => true]);
|
||||
}
|
||||
|
||||
return $response->toJsonResponse();
|
||||
}
|
||||
|
||||
public function refundPurchase(ConsumeBazaarPurchaseRequest $request): JsonResponse
|
||||
{
|
||||
$app = $this->app($request);
|
||||
$response = $this->bazaar->refundPurchase($app, $request->string('purchase_token')->toString());
|
||||
|
||||
if ($response->successful()) {
|
||||
BazaarPurchase::query()->whereBelongsTo($app)->where('purchase_token_hash', hash('sha256', $request->string('purchase_token')->toString()))->update(['status' => 'refunded']);
|
||||
BazaarSubscription::query()->whereBelongsTo($app)->where('purchase_token_hash', hash('sha256', $request->string('purchase_token')->toString()))->update(['status' => 'refunded']);
|
||||
}
|
||||
|
||||
return $response->toJsonResponse();
|
||||
}
|
||||
|
||||
public function subscription(BazaarSubscriptionRequest $request): JsonResponse
|
||||
{
|
||||
$app = $this->app($request);
|
||||
$response = $this->bazaar->subscription($app, $request->string('subscription_id')->toString(), $request->string('purchase_token')->toString());
|
||||
$this->subscriptions->record($app, $request->string('subscription_id')->toString(), $request->string('purchase_token')->toString(), $response);
|
||||
|
||||
return $response->toJsonResponse();
|
||||
}
|
||||
|
||||
public function activeSubscriptions(BazaarActiveSubscriptionsRequest $request): JsonResponse
|
||||
{
|
||||
return $this->bazaar
|
||||
->activeSubscriptions($this->app($request), $request->string('purchase_token')->toString())
|
||||
->toJsonResponse();
|
||||
}
|
||||
|
||||
public function cancelSubscription(BazaarSubscriptionRequest $request): JsonResponse
|
||||
{
|
||||
$app = $this->app($request);
|
||||
$response = $this->bazaar->cancelSubscription($app, $request->string('subscription_id')->toString(), $request->string('purchase_token')->toString());
|
||||
|
||||
if ($response->successful()) {
|
||||
BazaarSubscription::query()->whereBelongsTo($app)->where('purchase_token_hash', hash('sha256', $request->string('purchase_token')->toString()))->update(['status' => 'cancelled']);
|
||||
}
|
||||
|
||||
return $response->toJsonResponse();
|
||||
}
|
||||
|
||||
private function app(ValidateBazaarPurchaseRequest|ConsumeBazaarPurchaseRequest|BazaarSubscriptionRequest|BazaarActiveSubscriptionsRequest $request): MobileApp
|
||||
{
|
||||
return $request->attributes->get('mobileApp');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\BazaarLoginExchangeRequest;
|
||||
use App\Http\Requests\BazaarLoginRefreshRequest;
|
||||
use App\Models\MobileApp;
|
||||
use App\Services\CafeBazaar\CafeBazaarClient;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Uri;
|
||||
|
||||
class BazaarLoginController extends Controller
|
||||
{
|
||||
public function __construct(private readonly CafeBazaarClient $bazaar) {}
|
||||
|
||||
public function authorizationUrl(Request $request): JsonResponse
|
||||
{
|
||||
$app = $this->app($request);
|
||||
$state = $request->string('state')->trim()->toString();
|
||||
|
||||
if ($state === '' || mb_strlen($state) > 255) {
|
||||
return response()->json(['error' => ['code' => 'invalid_state', 'message' => 'A state value of at most 255 characters is required.']], 422);
|
||||
}
|
||||
|
||||
$url = Uri::of('https://cafebazaar.ir/user/oauth')->withQuery([
|
||||
'redirect_url' => $app->bazaar_login_redirect_url,
|
||||
'client_id' => $app->bazaar_login_client_id,
|
||||
'state' => $state,
|
||||
]);
|
||||
|
||||
return response()->json(['data' => ['authorization_url' => (string) $url, 'state' => $state]]);
|
||||
}
|
||||
|
||||
public function exchange(BazaarLoginExchangeRequest $request): JsonResponse
|
||||
{
|
||||
return $this->bazaar->exchangeLoginCode($this->app($request), $request->string('code')->toString())->toJsonResponse();
|
||||
}
|
||||
|
||||
public function refresh(BazaarLoginRefreshRequest $request): JsonResponse
|
||||
{
|
||||
return $this->bazaar->refreshLoginToken($this->app($request), $request->string('refresh_token')->toString())->toJsonResponse();
|
||||
}
|
||||
|
||||
public function userInfo(Request $request): JsonResponse
|
||||
{
|
||||
$accessToken = $request->bearerToken();
|
||||
|
||||
if (! $accessToken) {
|
||||
return response()->json(['error' => ['code' => 'missing_bazaar_token', 'message' => 'Send the Bazaar access token as a Bearer token.']], 422);
|
||||
}
|
||||
|
||||
return $this->bazaar->userInfo($this->app($request), $accessToken)->toJsonResponse();
|
||||
}
|
||||
|
||||
private function app(Request $request): MobileApp
|
||||
{
|
||||
return $request->attributes->get('mobileApp');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\CommitBazaarReleaseRequest;
|
||||
use App\Http\Requests\UploadBazaarAabRequest;
|
||||
use App\Http\Requests\UploadBazaarApkRequest;
|
||||
use App\Http\Requests\UploadBazaarBinRequest;
|
||||
use App\Models\MobileApp;
|
||||
use App\Services\CafeBazaar\BazaarReleaseRecorder;
|
||||
use App\Services\CafeBazaar\CafeBazaarClient;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class BazaarReleaseController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly CafeBazaarClient $bazaar,
|
||||
private readonly BazaarReleaseRecorder $releases,
|
||||
) {}
|
||||
|
||||
public function store(Request $request): JsonResponse
|
||||
{
|
||||
$app = $this->app($request);
|
||||
$response = $this->bazaar->createRelease($app);
|
||||
$this->releases->record($app, 'draft', $response);
|
||||
|
||||
return $response->toJsonResponse();
|
||||
}
|
||||
|
||||
public function destroy(Request $request): JsonResponse
|
||||
{
|
||||
$app = $this->app($request);
|
||||
$response = $this->bazaar->deleteRelease($app);
|
||||
$this->releases->record($app, 'deleted', $response);
|
||||
|
||||
return $response->toJsonResponse();
|
||||
}
|
||||
|
||||
public function uploadApk(UploadBazaarApkRequest $request): JsonResponse
|
||||
{
|
||||
$app = $this->app($request);
|
||||
$response = $this->bazaar->uploadApk($app, $request->file('apk'), $request->string('architecture')->toString());
|
||||
$this->releases->record($app, 'artifact_uploaded', $response, ['artifact_type' => 'apk']);
|
||||
|
||||
return $response->toJsonResponse();
|
||||
}
|
||||
|
||||
public function uploadAab(UploadBazaarAabRequest $request): JsonResponse
|
||||
{
|
||||
$app = $this->app($request);
|
||||
$response = $this->bazaar->uploadAab($app, $request->file('aab'));
|
||||
$this->releases->record($app, 'awaiting_bin', $response, ['artifact_type' => 'aab']);
|
||||
|
||||
return $response->toJsonResponse();
|
||||
}
|
||||
|
||||
public function uploadBin(UploadBazaarBinRequest $request): JsonResponse
|
||||
{
|
||||
$app = $this->app($request);
|
||||
$response = $this->bazaar->uploadBin($app, $request->file('bin'));
|
||||
$this->releases->record($app, 'processing_bundle', $response, ['artifact_type' => 'aab']);
|
||||
|
||||
return $response->toJsonResponse();
|
||||
}
|
||||
|
||||
public function bundleStatus(Request $request): JsonResponse
|
||||
{
|
||||
return $this->bazaar->bundleStatus($this->app($request))->toJsonResponse();
|
||||
}
|
||||
|
||||
public function commit(CommitBazaarReleaseRequest $request): JsonResponse
|
||||
{
|
||||
$app = $this->app($request);
|
||||
$response = $this->bazaar->commitRelease($app, $request->validated());
|
||||
$this->releases->record($app, 'committed', $response, [...$request->validated(), 'committed_at' => now()]);
|
||||
|
||||
return $response->toJsonResponse();
|
||||
}
|
||||
|
||||
public function last(Request $request, string $mobileApp, string $state): JsonResponse
|
||||
{
|
||||
abort_unless(in_array($state, ['committed', 'uncommitted', 'published'], true), 404);
|
||||
|
||||
$app = $this->app($request);
|
||||
$response = $this->bazaar->lastRelease($app, $state);
|
||||
$this->releases->record($app, $state, $response, $state === 'published' ? ['published_at' => now()] : []);
|
||||
|
||||
return $response->toJsonResponse();
|
||||
}
|
||||
|
||||
private function app(Request $request): MobileApp
|
||||
{
|
||||
return $request->attributes->get('mobileApp');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\ListBazaarReviewsRequest;
|
||||
use App\Http\Requests\ReplyBazaarReviewRequest;
|
||||
use App\Models\MobileApp;
|
||||
use App\Services\CafeBazaar\BazaarReviewRecorder;
|
||||
use App\Services\CafeBazaar\CafeBazaarClient;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
class BazaarReviewController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly CafeBazaarClient $bazaar,
|
||||
private readonly BazaarReviewRecorder $reviews,
|
||||
) {}
|
||||
|
||||
public function index(ListBazaarReviewsRequest $request): JsonResponse
|
||||
{
|
||||
$app = $this->app($request);
|
||||
$response = $this->bazaar->reviews($app, $request->validated());
|
||||
$this->reviews->recordPage($app, $response);
|
||||
|
||||
return $response->toJsonResponse();
|
||||
}
|
||||
|
||||
public function reply(ReplyBazaarReviewRequest $request, string $mobileApp, int $reviewId): JsonResponse
|
||||
{
|
||||
$app = $this->app($request);
|
||||
$response = $this->bazaar->replyToReview($app, $reviewId, $request->validated());
|
||||
$this->reviews->recordReply($app, $reviewId, $response);
|
||||
|
||||
return $response->toJsonResponse();
|
||||
}
|
||||
|
||||
private function app(ListBazaarReviewsRequest|ReplyBazaarReviewRequest $request): MobileApp
|
||||
{
|
||||
return $request->attributes->get('mobileApp');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
abstract class Controller
|
||||
{
|
||||
//
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Models\MobileApp;
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Arr;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class EnsureBazaarConfigured
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param Closure(Request): (Response) $next
|
||||
*/
|
||||
public function handle(Request $request, Closure $next, string $integration): Response
|
||||
{
|
||||
/** @var MobileApp $mobileApp */
|
||||
$mobileApp = $request->attributes->get('mobileApp');
|
||||
$requiredFields = match ($integration) {
|
||||
'billing', 'publishing' => ['bazaar_api_secret'],
|
||||
'reviews' => ['bazaar_comments_header', 'bazaar_comments_secret'],
|
||||
'login' => ['bazaar_login_client_id', 'bazaar_login_client_secret', 'bazaar_login_redirect_url'],
|
||||
default => [],
|
||||
};
|
||||
|
||||
$missingFields = collect($requiredFields)
|
||||
->filter(fn (string $field): bool => blank(Arr::get($mobileApp->getAttributes(), $field)) && blank($mobileApp->{$field}))
|
||||
->values()
|
||||
->all();
|
||||
|
||||
if ($missingFields !== []) {
|
||||
return response()->json(['error' => [
|
||||
'code' => 'bazaar_not_configured',
|
||||
'message' => "The Bazaar {$integration} integration is not configured for this app.",
|
||||
'missing_fields' => $missingFields,
|
||||
]], 422);
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Models\MobileApp;
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class RequireManagementKey
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param Closure(Request): (Response) $next
|
||||
*/
|
||||
public function handle(Request $request, Closure $next): Response
|
||||
{
|
||||
/** @var MobileApp $mobileApp */
|
||||
$mobileApp = $request->attributes->get('mobileApp');
|
||||
$providedKey = (string) $request->header('X-Management-Key');
|
||||
|
||||
if ($providedKey === '' || ! hash_equals($mobileApp->management_key, $providedKey)) {
|
||||
return response()->json(['error' => ['code' => 'invalid_management_key', 'message' => 'A valid X-Management-Key header is required.']], 403);
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Models\MobileApp;
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class ResolveMobileApp
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param Closure(Request): (Response) $next
|
||||
*/
|
||||
public function handle(Request $request, Closure $next): Response
|
||||
{
|
||||
$mobileApp = MobileApp::query()
|
||||
->where('package_name', $request->route('packageName'))
|
||||
->first();
|
||||
|
||||
if (! $mobileApp) {
|
||||
return response()->json(['error' => ['code' => 'app_not_found', 'message' => 'The requested app does not exist.']], 404);
|
||||
}
|
||||
|
||||
if (! $mobileApp->is_active) {
|
||||
return response()->json(['error' => ['code' => 'app_disabled', 'message' => 'This app API is disabled.']], 403);
|
||||
}
|
||||
|
||||
$providedKey = (string) $request->header('X-App-Key');
|
||||
|
||||
if ($providedKey === '' || ! hash_equals($mobileApp->client_key, $providedKey)) {
|
||||
return response()->json(['error' => ['code' => 'invalid_app_key', 'message' => 'A valid X-App-Key header is required.']], 401);
|
||||
}
|
||||
|
||||
$request->attributes->set('mobileApp', $mobileApp);
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class BazaarActiveSubscriptionsRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'purchase_token' => ['required', 'string', 'max:2048'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class BazaarLoginExchangeRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'code' => ['required', 'string', 'max:4096'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class BazaarLoginRefreshRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'refresh_token' => ['required', 'string', 'max:4096'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class BazaarSubscriptionRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'subscription_id' => ['required', 'string', 'max:255'],
|
||||
'purchase_token' => ['required', 'string', 'max:2048'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class CommitBazaarReleaseRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'changelog_fa' => ['nullable', 'string', 'max:5000'],
|
||||
'changelog_en' => ['nullable', 'string', 'max:5000'],
|
||||
'developer_note' => ['nullable', 'string', 'max:5000'],
|
||||
'staged_rollout_percentage' => ['required', 'integer', 'between:1,100'],
|
||||
'auto_publish' => ['required', 'boolean'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class ConsumeBazaarPurchaseRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'purchase_token' => ['required', 'string', 'max:2048'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class ListBazaarReviewsRequest extends FormRequest
|
||||
{
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
if ($this->has('is_replied')) {
|
||||
$this->merge([
|
||||
'is_replied' => filter_var($this->input('is_replied'), FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'publish_date_after' => ['nullable', 'date'],
|
||||
'publish_date_before' => ['nullable', 'date', 'after_or_equal:publish_date_after'],
|
||||
'rate_min' => ['nullable', 'integer', 'between:1,5'],
|
||||
'rate_max' => ['nullable', 'integer', 'between:1,5'],
|
||||
'app_version_code' => ['nullable', 'integer', 'min:1'],
|
||||
'sdk_version' => ['nullable', 'integer', 'min:1'],
|
||||
'is_replied' => ['nullable', 'boolean'],
|
||||
'cursor' => ['nullable', 'string', 'max:2048'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class ReplyBazaarReviewRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'text' => ['required', 'string', 'max:1000'],
|
||||
'email' => ['nullable', 'email', 'max:255'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class UploadBazaarAabRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'aab' => ['required', 'file', 'mimes:aab,zip', 'max:512000'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class UploadBazaarApkRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'architecture' => ['required', Rule::in(['all', 'armeabi-v7a', 'arm64-v8a'])],
|
||||
'apk' => ['required', 'file', 'mimes:apk,zip', 'max:512000'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class UploadBazaarBinRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'bin' => ['required', 'file', 'mimes:bin', 'max:51200'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class ValidateBazaarPurchaseRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'product_id' => ['required', 'string', 'max:255'],
|
||||
'purchase_token' => ['required', 'string', 'max:2048'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class VerifyBazaarSignatureRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'original_json' => ['required', 'string', 'max:65535'],
|
||||
'signature' => ['required', 'string', 'max:8192'],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user