From 0c9de66a804b3068287747cb5189d35fba10af71 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 24 Jun 2021 21:52:02 +1000 Subject: [PATCH 1/5] Set Transactions on the correct database --- app/Http/Controllers/PreviewController.php | 4 ++-- app/Repositories/SubscriptionRepository.php | 9 +++++---- app/Utils/TemplateEngine.php | 4 ++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/Http/Controllers/PreviewController.php b/app/Http/Controllers/PreviewController.php index 490ca3f30511..e0f30fb44fcb 100644 --- a/app/Http/Controllers/PreviewController.php +++ b/app/Http/Controllers/PreviewController.php @@ -155,7 +155,7 @@ class PreviewController extends BaseController $t = app('translator'); $t->replace(Ninja::transformTranslations(auth()->user()->company()->settings)); - DB::beginTransaction(); + DB::connection(config('database.default'))->beginTransaction(); $client = Client::factory()->create([ 'user_id' => auth()->user()->id, @@ -230,7 +230,7 @@ class PreviewController extends BaseController $file_path = PreviewPdf::dispatchNow($maker->getCompiledHTML(true), auth()->user()->company()); - DB::rollBack(); + DB::connection(config('database.default'))->rollBack(); $response = Response::make($file_path, 200); $response->header('Content-Type', 'application/pdf'); diff --git a/app/Repositories/SubscriptionRepository.php b/app/Repositories/SubscriptionRepository.php index 90ab10a12803..53fdad8a61d4 100644 --- a/app/Repositories/SubscriptionRepository.php +++ b/app/Repositories/SubscriptionRepository.php @@ -45,8 +45,8 @@ class SubscriptionRepository extends BaseRepository private function calculatePrice($subscription) :array { - DB::beginTransaction(); - + // DB::beginTransaction(); + DB::connection(config('database.default'))->beginTransaction(); $data = []; $client = Client::factory()->create([ @@ -90,8 +90,9 @@ class SubscriptionRepository extends BaseRepository $data['promo_price'] = $invoice->calc()->getTotal(); - DB::rollBack(); - + // DB::rollBack(); + DB::connection(config('database.default'))->rollBack(); + return $data; } diff --git a/app/Utils/TemplateEngine.php b/app/Utils/TemplateEngine.php index 83359064ac7b..f5f7c1b3a9de 100644 --- a/app/Utils/TemplateEngine.php +++ b/app/Utils/TemplateEngine.php @@ -239,7 +239,7 @@ class TemplateEngine private function mockEntity() { - DB::beginTransaction(); + DB::connection(config('database.default'))->beginTransaction(); $client = Client::factory()->create([ 'user_id' => auth()->user()->id, @@ -277,6 +277,6 @@ class TemplateEngine private function tearDown() { - DB::rollBack(); + DB::connection(config('database.default'))->rollBack(); } } From ec028ccf692934a122692487e25ff852b06c6115 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 25 Jun 2021 08:38:15 +1000 Subject: [PATCH 2/5] Fixes for WePay ACH --- app/Exceptions/Handler.php | 2 +- app/PaymentDrivers/WePay/ACH.php | 2 +- app/PaymentDrivers/WePay/WePayCommon.php | 7 ++++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 1c9454ce4a0a..f4c9b129abca 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -77,7 +77,7 @@ class Handler extends ExceptionHandler return; } - if(Ninja::isHosted()){ + if(Ninja::isHosted() && !($exception instanceof ValidationException)){ app('sentry')->configureScope(function (Scope $scope): void { diff --git a/app/PaymentDrivers/WePay/ACH.php b/app/PaymentDrivers/WePay/ACH.php index 467729fdf240..a8c00ccb8570 100644 --- a/app/PaymentDrivers/WePay/ACH.php +++ b/app/PaymentDrivers/WePay/ACH.php @@ -189,7 +189,7 @@ class ACH public function paymentResponse($request) { - nlog($request->all()); + // nlog($request->all()); $token = ClientGatewayToken::find($this->decodePrimaryKey($request->input('source'))); $token_meta = $token->meta; diff --git a/app/PaymentDrivers/WePay/WePayCommon.php b/app/PaymentDrivers/WePay/WePayCommon.php index 791ab7b31274..949cf42ad11f 100644 --- a/app/PaymentDrivers/WePay/WePayCommon.php +++ b/app/PaymentDrivers/WePay/WePayCommon.php @@ -24,8 +24,13 @@ trait WePayCommon private function processSuccessfulPayment($response, $payment_status, $gateway_type) { + if($gateway_type == GatewayType::BANK_TRANSFER) + $payment_type = PaymentType::ACH; + else + $payment_type = PaymentType::CREDIT_CARD_OTHER; + $data = [ - 'payment_type' => PaymentType::CREDIT_CARD_OTHER, + 'payment_type' => $payment_type, 'amount' => $response->amount, 'transaction_reference' => $response->checkout_id, 'gateway_type_id' => $gateway_type, From f59807d0639a119609572ad6cd3647c0ae218935 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 25 Jun 2021 10:14:45 +1000 Subject: [PATCH 3/5] Do no first archived recurring invoices --- app/Jobs/Cron/RecurringInvoicesCron.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/Jobs/Cron/RecurringInvoicesCron.php b/app/Jobs/Cron/RecurringInvoicesCron.php index cfb0d712664e..e9a57d854d35 100644 --- a/app/Jobs/Cron/RecurringInvoicesCron.php +++ b/app/Jobs/Cron/RecurringInvoicesCron.php @@ -45,6 +45,7 @@ class RecurringInvoicesCron if (! config('ninja.db.multi_db_enabled')) { $recurring_invoices = RecurringInvoice::where('next_send_date', '<=', now()->toDateTimeString()) ->whereNotNull('next_send_date') + ->whereNull('deleted_at') ->where('status_id', RecurringInvoice::STATUS_ACTIVE) ->where('remaining_cycles', '!=', '0') ->with('company') @@ -66,6 +67,7 @@ class RecurringInvoicesCron $recurring_invoices = RecurringInvoice::where('next_send_date', '<=', now()->toDateTimeString()) ->whereNotNull('next_send_date') + ->whereNull('deleted_at') ->where('status_id', RecurringInvoice::STATUS_ACTIVE) ->where('remaining_cycles', '!=', '0') ->with('company') From 0bf29ed65cf1e780a264956a35b713f0a6c0dcf7 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 25 Jun 2021 11:57:17 +1000 Subject: [PATCH 4/5] Fixes for timeshift when offset is negative causing the date to be set the day before --- app/Models/RecurringInvoice.php | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/app/Models/RecurringInvoice.php b/app/Models/RecurringInvoice.php index 616a7dd0560c..eda8187aba66 100644 --- a/app/Models/RecurringInvoice.php +++ b/app/Models/RecurringInvoice.php @@ -428,17 +428,14 @@ class RecurringInvoice extends BaseModel 'due_date' => $next_due_date_string ]; - $next_send_date = $this->nextDateByFrequency($next_send_date->format('Y-m-d')); + /* Fixes the timeshift in case the offset is negative which cause a infinite loop due to UTC +0*/ + if($this->client->timezone_offset() < 0){ + $next_send_date = $this->nextDateByFrequency($next_send_date->addDay()->format('Y-m-d')); + } + else + $next_send_date = $this->nextDateByFrequency($next_send_date->format('Y-m-d')); } - /*If no due date is set - unset the due_date value */ - // if(!$this->due_date_days || $this->due_date_days == 0){ - - // foreach($data as $key => $value) - // $data[$key]['due_date'] = ''; - - // } - return $data; } From fd81ac4ea3f98a0f81218d0d9e09d370ea511889 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 25 Jun 2021 12:20:08 +1000 Subject: [PATCH 5/5] Fixes for timeshift offsets when offset is negative --- app/Models/RecurringInvoice.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/Models/RecurringInvoice.php b/app/Models/RecurringInvoice.php index eda8187aba66..4fbcddbcb75c 100644 --- a/app/Models/RecurringInvoice.php +++ b/app/Models/RecurringInvoice.php @@ -224,6 +224,13 @@ class RecurringInvoice extends BaseModel $offset = $this->client->timezone_offset(); + /* + As we are firing at UTC+0 if our offset is negative it is technically firing the day before so we always need + to add ON a day - a day = 86400 seconds + */ + if($offset < 0) + $offset += 86400; + switch ($this->frequency_id) { case self::FREQUENCY_DAILY: return Carbon::parse($this->next_send_date)->startOfDay()->addDay()->addSeconds($offset);