if (! function_exists('validate_purchase')) {
function validate_purchase($code, $data)
{
$script_url = str_replace('install/process', '', (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http')."://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]");
$fields = [
'item_id' => '47989504',
'purchase_code' => urlencode($code),
'current_version' => setting('current_version'),
];
$response = false;
if (config('app.dev_mode')) {
$url = 'https://desk.spagreen.net/version-check-including-beta';
} else {
$url = 'https://desk.spagreen.net/version-check';
}
$request = curlRequest($url, $fields);
if (property_exists($request, 'status') && $request->status) {
$response = $request->release_info;
}
if (is_bool($response)) {
$latest_version = isAppMode() ? '100' : '140';
} else {
$latest_version = isAppMode() ? '100' : $response->version;
}
$fields = [
'domain' => urlencode($_SERVER['SERVER_NAME']),
'version' => $latest_version,
'item_id' => isAppMode() ? '47989504' : '47989504',
'url' => urlencode($script_url),
'purchase_code' => urlencode($code),
'is_beta' => config('app.dev_mode') ? 1 : 0,
];
$curl_response = curlRequest('https://desk.spagreen.net/verify-installation-v2', $fields);
if (property_exists($curl_response, true) && $curl_response->true) {
try {
envWrite('DB_HOST', $data['DB_HOST']);
envWrite('DB_DATABASE', $data['DB_DATABASE']);
envWrite('DB_USERNAME', $data['DB_USERNAME']);
envWrite('DB_PASSWORD', $data['DB_PASSWORD']);
} catch (\Exception $e) {
return 'Unable to write env file!';
}
// this is where it requests file
$zip_file = $curl_response->release_zip_link;
if ($zip_file) {
try {
//then puts it in this path
$file_path = base_path('public/install/installer.zip');
file_put_contents($file_path, file_get_contents($zip_file));
} catch (Exception $e) {
return 'Zip file cannot be Imported. Please check your server permission or Contact with Script Author.';
}
} else {
return 'Zip file cannot be Imported. Please check your server permission or Contact with Script Author.';
}
return 'success';
} else {
return $curl_response->message;
}
}
}