diff --git a/VERSION.txt b/VERSION.txt index 258f4326222e..77b6d45eba63 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -5.1.62 \ No newline at end of file +5.1.63 \ No newline at end of file diff --git a/app/Http/Controllers/LicenseController.php b/app/Http/Controllers/LicenseController.php index d762b69c9017..ba24a7d0650d 100644 --- a/app/Http/Controllers/LicenseController.php +++ b/app/Http/Controllers/LicenseController.php @@ -107,6 +107,12 @@ class LicenseController extends BaseController 'errors' => new stdClass, ]; + $account->plan_term = Account::PLAN_TERM_YEARLY; + $account->plan_paid = null; + $account->plan_expires = null; + $account->plan = Account::PLAN_FREE; + $account->save(); + return response()->json($error, 400); } else { $account = auth()->user()->company()->account; diff --git a/app/Http/Controllers/PaymentWebhookController.php b/app/Http/Controllers/PaymentWebhookController.php index f6681520a91d..881fce5b116d 100644 --- a/app/Http/Controllers/PaymentWebhookController.php +++ b/app/Http/Controllers/PaymentWebhookController.php @@ -21,13 +21,18 @@ class PaymentWebhookController extends Controller public function __invoke(PaymentWebhookRequest $request, string $company_key, string $company_gateway_id) { - MultiDB::findAndSetDbByCompanyKey($company_key); + // MultiDB::findAndSetDbByCompanyKey($company_key); $payment = $request->getPayment(); + + if(!$payment) + return response()->json(['message' => 'Payment record not found.'], 400); + $client = is_null($payment) ? $request->getClient() : $payment->client; - // $contact= $client->primary_contact()->first(); - // Auth::guard('contact')->login($contact, true); + if(!$client) + return response()->json(['message' => 'Client record not found.'], 400); + return $request->getCompanyGateway() ->driver($client) diff --git a/app/Http/Middleware/ApiSecretCheck.php b/app/Http/Middleware/ApiSecretCheck.php index 7e2aaac96f56..06cca298af3e 100644 --- a/app/Http/Middleware/ApiSecretCheck.php +++ b/app/Http/Middleware/ApiSecretCheck.php @@ -11,6 +11,7 @@ namespace App\Http\Middleware; +use App\Utils\Ninja; use Closure; use Illuminate\Http\Request; use stdClass; @@ -26,7 +27,7 @@ class ApiSecretCheck */ public function handle($request, Closure $next) { - if (! config('ninja.api_secret')) { + if (! config('ninja.api_secret') || Ninja::isHosted()) { return $next($request); } diff --git a/app/Http/Requests/Payments/PaymentWebhookRequest.php b/app/Http/Requests/Payments/PaymentWebhookRequest.php index f0b8927ab247..2642f2458e93 100644 --- a/app/Http/Requests/Payments/PaymentWebhookRequest.php +++ b/app/Http/Requests/Payments/PaymentWebhookRequest.php @@ -27,7 +27,7 @@ class PaymentWebhookRequest extends Request public function authorize() { - MultiDB::findAndSetDbByCompanyKey($this->getCompany()->company_key); + MultiDB::findAndSetDbByCompanyKey($this->company_key); return true; } @@ -45,7 +45,7 @@ class PaymentWebhookRequest extends Request * @param mixed $id * @return null|\App\Models\CompanyGateway */ - public function getCompanyGateway(): ?CompanyGateway + public function getCompanyGateway() { return CompanyGateway::findOrFail($this->decodePrimaryKey($this->company_gateway_id)); } @@ -56,13 +56,13 @@ class PaymentWebhookRequest extends Request * @param string $hash * @return null|\App\Models\PaymentHash */ - public function getPaymentHash(): ?PaymentHash + public function getPaymentHash() { if ($this->query('hash')) { return PaymentHash::where('hash', $this->query('hash'))->firstOrFail(); } - return null; + return false; } /** @@ -94,7 +94,7 @@ class PaymentWebhookRequest extends Request // If none of previously done logics is correct, we'll just display // not found page. - abort(404); + return false; } /** @@ -102,11 +102,14 @@ class PaymentWebhookRequest extends Request * * @return null|\App\Models\Client */ - public function getClient(): ?Client + public function getClient() { $hash = $this->getPaymentHash(); - return Client::find($hash->data->client_id)->firstOrFail(); + if($hash) + return Client::find($hash->data->client_id)->firstOrFail(); + + return false; } /** diff --git a/app/Http/Requests/Vendor/StoreVendorRequest.php b/app/Http/Requests/Vendor/StoreVendorRequest.php index 136fa82e5c0d..d1b801ffedac 100644 --- a/app/Http/Requests/Vendor/StoreVendorRequest.php +++ b/app/Http/Requests/Vendor/StoreVendorRequest.php @@ -15,6 +15,7 @@ use App\Http\Requests\Request; use App\Http\ValidationRules\ValidVendorGroupSettingsRule; use App\Models\Vendor; use App\Utils\Traits\MakesHash; +use Illuminate\Validation\Rule; class StoreVendorRequest extends Request { @@ -39,6 +40,9 @@ class StoreVendorRequest extends Request //$rules['settings'] = new ValidVendorGroupSettingsRule(); $rules['contacts.*.email'] = 'nullable|distinct'; + if (isset($this->number)) { + $rules['number'] = Rule::unique('vendors')->where('company_id', auth()->user()->company()->id); + } return $rules; } diff --git a/app/Jobs/Mail/NinjaMailerJob.php b/app/Jobs/Mail/NinjaMailerJob.php index 879057ff3409..f3730dece83b 100644 --- a/app/Jobs/Mail/NinjaMailerJob.php +++ b/app/Jobs/Mail/NinjaMailerJob.php @@ -116,10 +116,12 @@ class NinjaMailerJob implements ShouldQueue } catch (\Exception $e) { nlog("error failed with {$e->getMessage()}"); - // nlog($e); if($this->nmo->entity) $this->entityEmailFailed($e->getMessage()); + + if(Ninja::isHosted()) + app('sentry')->captureException($e); } } diff --git a/app/Jobs/Util/Import.php b/app/Jobs/Util/Import.php index 3659f52f6ba3..36a4da94843b 100644 --- a/app/Jobs/Util/Import.php +++ b/app/Jobs/Util/Import.php @@ -1618,6 +1618,9 @@ class Import implements ShouldQueue ->batch(); info(print_r($exception->getMessage(), 1)); + + if(Ninja::isHosted()) + app('sentry')->captureException($exception); } @@ -1642,7 +1645,7 @@ class Import implements ShouldQueue return $response->getBody(); } - private function buildNewUserPlan() :Client + private function buildNewUserPlan() { $local_company = Company::find($this->company->id); $owner = $local_company->owner(); @@ -1674,6 +1677,8 @@ class Import implements ShouldQueue $ninja_client_contact->phone = $owner->phone; $ninja_client_contact->save(); + + return $ninja_client; } private function processNinjaTokens(array $data) diff --git a/app/Jobs/Util/StartMigration.php b/app/Jobs/Util/StartMigration.php index e62b58d7f53e..4111cc967b8d 100644 --- a/app/Jobs/Util/StartMigration.php +++ b/app/Jobs/Util/StartMigration.php @@ -139,7 +139,7 @@ class StartMigration implements ShouldQueue $this->company->update_products = $update_product_flag; $this->company->save(); - Mail::to($this->user)->send(new MigrationFailed($e, $e->getMessage())); + Mail::to($this->user->email, $this->user->name())->send(new MigrationFailed($e, $e->getMessage())); if (app()->environment() !== 'production') { info($e->getMessage()); diff --git a/app/Services/Invoice/HandleRestore.php b/app/Services/Invoice/HandleRestore.php index fa346d3fb571..f79f1e4f5610 100644 --- a/app/Services/Invoice/HandleRestore.php +++ b/app/Services/Invoice/HandleRestore.php @@ -13,9 +13,13 @@ namespace App\Services\Invoice; use App\Models\Invoice; use App\Services\AbstractService; +use App\Utils\Ninja; +use App\Utils\Traits\GeneratesCounter; class HandleRestore extends AbstractService { + use GeneratesCounter; + private $invoice; private $payment_total = 0; @@ -100,10 +104,22 @@ class HandleRestore extends AbstractService } try { + + $exists = Invoice::where(['company_id' => $this->invoice->company_id, 'number' => $new_invoice_number])->exists(); + + if($exists) + $this->invoice->number = $this->getNextInvoiceNumber($this->invoice->client, $this->invoice, $this->invoice->recurring_id); + else $this->invoice->number = $new_invoice_number; + $this->invoice->save(); } catch (\Exception $e) { - info("I could not wind back the invoice number"); + nlog("I could not wind back the invoice number"); + + if(Ninja::isHosted()){ + \Sentry\captureMessage("I could not wind back the invoice number"); + app('sentry')->captureException($e); + } } } } diff --git a/config/ninja.php b/config/ninja.php index 2147204f6d0e..d8cf7f563232 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -14,8 +14,8 @@ return [ 'require_https' => env('REQUIRE_HTTPS', true), 'app_url' => rtrim(env('APP_URL', ''), '/'), 'app_domain' => env('APP_DOMAIN', 'invoicing.co'), - 'app_version' => '5.1.62', - 'app_tag' => '5.1.62-release', + 'app_version' => '5.1.63', + 'app_tag' => '5.1.63-release', 'minimum_client_version' => '5.0.16', 'terms_version' => '1.0.1', 'api_secret' => env('API_SECRET', ''), diff --git a/database/migrations/2021_05_06_211039_add_show_task_end_date_to_companies_table.php b/database/migrations/2021_05_06_211039_add_show_task_end_date_to_companies_tables.php similarity index 90% rename from database/migrations/2021_05_06_211039_add_show_task_end_date_to_companies_table.php rename to database/migrations/2021_05_06_211039_add_show_task_end_date_to_companies_tables.php index 336808a7aa06..8053de796c40 100644 --- a/database/migrations/2021_05_06_211039_add_show_task_end_date_to_companies_table.php +++ b/database/migrations/2021_05_06_211039_add_show_task_end_date_to_companies_tables.php @@ -4,7 +4,7 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -class AddShowTaskEndDateToCompaniesTable extends Migration +class AddShowTaskEndDateToCompaniesTables extends Migration { /** * Run the migrations.