mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-06 03:02:34 +01:00
ba75a44eb8
* Adopt Laravel coding style The Laravel framework adopts the PSR-2 coding style with some additions. Laravel apps *should* adopt this coding style as well. However, Shift allows you to customize the adopted coding style by adding your own [PHP CS Fixer][1] `.php_cs` config to your project. You may use [Shift's .php_cs][2] file as a base. [1]: https://github.com/FriendsOfPHP/PHP-CS-Fixer [2]: https://gist.github.com/laravel-shift/cab527923ed2a109dda047b97d53c200 * Shift bindings PHP 5.5.9+ adds the new static `class` property which provides the fully qualified class name. This is preferred over using class name strings as these references are checked by the parser. * Shift core files * Shift to Throwable * Add laravel/ui dependency * Unindent vendor mail templates * Shift config files * Default config files In an effort to make upgrading the constantly changing config files easier, Shift defaulted them so you can review the commit diff for changes. Moving forward, you should use ENV variables or create a separate config file to allow the core config files to remain automatically upgradeable. * Shift Laravel dependencies * Shift cleanup * Upgrade to Laravel 7 Co-authored-by: Laravel Shift <shift@laravelshift.com>
144 lines
4.8 KiB
PHP
144 lines
4.8 KiB
PHP
<?php
|
|
/**
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
*
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
*
|
|
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
|
*
|
|
* @license https://opensource.org/licenses/AAL
|
|
*/
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Account;
|
|
use App\Utils\CurlUtils;
|
|
use App\Utils\Ninja;
|
|
use Illuminate\Foundation\Bus\DispatchesJobs;
|
|
use Illuminate\Http\Request;
|
|
|
|
class LicenseController extends BaseController
|
|
{
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
/**
|
|
* Claim a white label license.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*
|
|
* @OA\Get(
|
|
* path="/api/v1/claim_license",
|
|
* operationId="getClaimLicense",
|
|
* tags={"claim_license"},
|
|
* summary="Attempts to claim a white label license",
|
|
* description="Attempts to claim a white label license",
|
|
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
|
|
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
|
* @OA\Parameter(
|
|
* name="license_key",
|
|
* in="query",
|
|
* description="The license hash",
|
|
* example="d87sh-s755s-s7d76-sdsd8",
|
|
* required=true,
|
|
* @OA\Schema(
|
|
* type="string",
|
|
* format="string",
|
|
* ),
|
|
* ),
|
|
* @OA\Parameter(
|
|
* name="product_id",
|
|
* in="query",
|
|
* description="The ID of the product purchased.",
|
|
* example="1",
|
|
* required=true,
|
|
* @OA\Schema(
|
|
* type="string",
|
|
* format="string",
|
|
* ),
|
|
* ),
|
|
* @OA\Response(
|
|
* response=200,
|
|
* description="Success!",
|
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
|
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
|
|
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
|
|
* ),
|
|
* @OA\Response(
|
|
* response=422,
|
|
* description="Validation error",
|
|
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
|
|
|
* ),
|
|
* @OA\Response(
|
|
* response="default",
|
|
* description="Unexpected Error",
|
|
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
|
* ),
|
|
* )
|
|
*/
|
|
public function index()
|
|
{
|
|
|
|
/* Catch claim license requests */
|
|
if (config('ninja.environment') == 'selfhost' && request()->has('license_key')) {
|
|
$license_key = request()->input('license_key');
|
|
$product_id = 3;
|
|
|
|
$url = config('ninja.license_url')."/claim_license?license_key={$license_key}&product_id={$product_id}&get_date=true";
|
|
$data = trim(CurlUtils::get($url));
|
|
|
|
if ($data == Account::RESULT_FAILURE) {
|
|
$error = [
|
|
'message' => trans('texts.invalid_white_label_license'),
|
|
'errors' => new \stdClass,
|
|
];
|
|
|
|
return response()->json($error, 400);
|
|
} elseif ($data) {
|
|
$date = date_create($data)->modify('+1 year');
|
|
|
|
if ($date < date_create()) {
|
|
$error = [
|
|
'message' => trans('texts.invalid_white_label_license'),
|
|
'errors' => new \stdClass,
|
|
];
|
|
|
|
return response()->json($error, 400);
|
|
} else {
|
|
$account = auth()->user()->company()->account;
|
|
|
|
$account->plan_term = Account::PLAN_TERM_YEARLY;
|
|
$account->plan_paid = $data;
|
|
$account->plan_expires = $date->format('Y-m-d');
|
|
$account->plan = Account::PLAN_WHITE_LABEL;
|
|
$account->save();
|
|
|
|
$error = [
|
|
'message' => trans('texts.bought_white_label'),
|
|
'errors' => new \stdClass,
|
|
];
|
|
|
|
return response()->json($error, 200);
|
|
}
|
|
} else {
|
|
$error = [
|
|
'message' => trans('texts.white_label_license_error'),
|
|
'errors' => new \stdClass,
|
|
];
|
|
|
|
return response()->json($error, 400);
|
|
}
|
|
}
|
|
|
|
$error = [
|
|
'message' => 'Invalid license, or invalid environment '.config('ninja.environment'),
|
|
'errors' => new \stdClass,
|
|
];
|
|
|
|
return response()->json($error, 400);
|
|
}
|
|
}
|