From 0b7891e24f4efed6a7ac710bbb18cc8530cfe954 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 21 May 2021 07:58:46 +1000 Subject: [PATCH 1/6] Fixes for restore invoice numbering --- app/Http/Controllers/LicenseController.php | 6 ++++++ app/Jobs/Mail/NinjaMailerJob.php | 4 +++- app/Jobs/Util/Import.php | 3 +++ app/Services/Invoice/HandleRestore.php | 18 +++++++++++++++++- 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/LicenseController.php b/app/Http/Controllers/LicenseController.php index d762b69c90..ba24a7d065 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/Jobs/Mail/NinjaMailerJob.php b/app/Jobs/Mail/NinjaMailerJob.php index 879057ff34..f3730dece8 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 3659f52f6b..8b8ea1ab5a 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); } diff --git a/app/Services/Invoice/HandleRestore.php b/app/Services/Invoice/HandleRestore.php index fa346d3fb5..f79f1e4f56 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); + } } } } From 99dd97443a0ea76b555c5697a234295598cd2d16 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 21 May 2021 10:23:37 +1000 Subject: [PATCH 2/6] Fixes for vendor requests --- app/Http/Requests/Vendor/StoreVendorRequest.php | 4 ++++ ..._06_211039_add_show_task_end_date_to_companies_tables.php} | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) rename database/migrations/{2021_05_06_211039_add_show_task_end_date_to_companies_table.php => 2021_05_06_211039_add_show_task_end_date_to_companies_tables.php} (90%) diff --git a/app/Http/Requests/Vendor/StoreVendorRequest.php b/app/Http/Requests/Vendor/StoreVendorRequest.php index 136fa82e5c..d1b801ffed 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/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 336808a7aa..8053de796c 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. From b58d3f390e176d198a21cf9bad190d61f9e5ed19 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 21 May 2021 15:47:05 +1000 Subject: [PATCH 3/6] Fixes for Stripe Connect --- .../Controllers/PaymentWebhookController.php | 11 ++++++++--- .../Requests/Payments/PaymentWebhookRequest.php | 17 ++++++++++------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/app/Http/Controllers/PaymentWebhookController.php b/app/Http/Controllers/PaymentWebhookController.php index f6681520a9..881fce5b11 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/Requests/Payments/PaymentWebhookRequest.php b/app/Http/Requests/Payments/PaymentWebhookRequest.php index f0b8927ab2..2642f2458e 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; } /** From cf98a03d0e14bbb2630cdecb730b0377b6a7223b Mon Sep 17 00:00:00 2001 From: = Date: Fri, 21 May 2021 17:20:50 +1000 Subject: [PATCH 4/6] Fixes for import --- app/Jobs/Util/Import.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/Jobs/Util/Import.php b/app/Jobs/Util/Import.php index 8b8ea1ab5a..36a4da9484 100644 --- a/app/Jobs/Util/Import.php +++ b/app/Jobs/Util/Import.php @@ -1645,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(); @@ -1677,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) From 5c26fc572ce64722985f1203baf9eb680f52ee18 Mon Sep 17 00:00:00 2001 From: = Date: Fri, 21 May 2021 17:24:35 +1000 Subject: [PATCH 5/6] fixes for migration --- app/Jobs/Util/StartMigration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Jobs/Util/StartMigration.php b/app/Jobs/Util/StartMigration.php index e62b58d7f5..4111cc967b 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()); From 735771eef2db6104eb1d5582d2f87cdf3fd62473 Mon Sep 17 00:00:00 2001 From: = Date: Fri, 21 May 2021 17:39:59 +1000 Subject: [PATCH 6/6] v5.1.63 --- VERSION.txt | 2 +- app/Http/Middleware/ApiSecretCheck.php | 3 ++- config/ninja.php | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/VERSION.txt b/VERSION.txt index 258f432622..77b6d45eba 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/Middleware/ApiSecretCheck.php b/app/Http/Middleware/ApiSecretCheck.php index 7e2aaac96f..06cca298af 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/config/ninja.php b/config/ninja.php index 2147204f6d..d8cf7f5632 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', ''),