From f258ccec167563bfff9d30eed83c250d7650442d Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 22 Jun 2021 08:01:50 +1000 Subject: [PATCH 1/5] force token_billing=always for system created gateways --- app/Http/Controllers/StripeConnectController.php | 2 +- app/Http/Controllers/StripeController.php | 2 -- app/Http/Controllers/WePayController.php | 1 - app/Http/Livewire/WepaySignup.php | 1 + app/PaymentDrivers/WePay/Setup.php | 1 - 5 files changed, 2 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/StripeConnectController.php b/app/Http/Controllers/StripeConnectController.php index d01a2f6a8206..ceb2aa4c39f3 100644 --- a/app/Http/Controllers/StripeConnectController.php +++ b/app/Http/Controllers/StripeConnectController.php @@ -1,5 +1,4 @@ gateway_key = 'd14dd26a47cecc30fdd65700bfb67b34'; $company_gateway->fees_and_limits = $fees_and_limits; $company_gateway->setConfig([]); + $company_gateway->token_billing = 'always'; // $company_gateway->save(); $payload = [ diff --git a/app/Http/Controllers/StripeController.php b/app/Http/Controllers/StripeController.php index 3976c183e12b..0c3647d76bd1 100644 --- a/app/Http/Controllers/StripeController.php +++ b/app/Http/Controllers/StripeController.php @@ -29,7 +29,6 @@ class StripeController extends BaseController } - return response()->json(['message' => 'Unauthorized'], 403); } @@ -44,7 +43,6 @@ class StripeController extends BaseController return response()->json(['message' => 'Processing'], 200); } - return response()->json(['message' => 'Unauthorized'], 403); } diff --git a/app/Http/Controllers/WePayController.php b/app/Http/Controllers/WePayController.php index b68bc0b72cfd..cd09d4dbcc4e 100644 --- a/app/Http/Controllers/WePayController.php +++ b/app/Http/Controllers/WePayController.php @@ -1,5 +1,4 @@ update_details = false; $cg->config = encrypt(config('ninja.testvars.checkout')); $cg->fees_and_limits = $fees_and_limits; + $cg->token_billing = 'always'; $cg->save(); } diff --git a/app/PaymentDrivers/WePay/Setup.php b/app/PaymentDrivers/WePay/Setup.php index 3498751bf5f6..b6e062b9904c 100644 --- a/app/PaymentDrivers/WePay/Setup.php +++ b/app/PaymentDrivers/WePay/Setup.php @@ -1,5 +1,4 @@ Date: Tue, 22 Jun 2021 08:39:08 +1000 Subject: [PATCH 2/5] Set exchange rates on invoices/payments when marking as paid --- app/DataMapper/CompanySettings.php | 2 ++ app/Services/Invoice/MarkPaid.php | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/app/DataMapper/CompanySettings.php b/app/DataMapper/CompanySettings.php index cbb75ee2291f..1d0e3b0ca559 100644 --- a/app/DataMapper/CompanySettings.php +++ b/app/DataMapper/CompanySettings.php @@ -28,6 +28,7 @@ class CompanySettings extends BaseSettings public $lock_invoices = 'off'; //off,when_sent,when_paid //@implemented public $enable_client_portal_tasks = false; //@ben to implement + public $show_all_tasks_client_portal = 'all'; // all, uninvoiced, invoiced public $enable_client_portal_password = false; //@implemented public $enable_client_portal = true; //@implemented public $enable_client_portal_dashboard = false; // @TODO There currently is no dashboard so this is pending @@ -268,6 +269,7 @@ class CompanySettings extends BaseSettings public $hide_empty_columns_on_pdf = false; public static $casts = [ + 'show_all_tasks_client_portal' => 'string', 'entity_send_time' => 'int', 'shared_invoice_credit_counter' => 'bool', 'reply_to_name' => 'string', diff --git a/app/Services/Invoice/MarkPaid.php b/app/Services/Invoice/MarkPaid.php index cb712890bc9a..df3cc60f8a7c 100644 --- a/app/Services/Invoice/MarkPaid.php +++ b/app/Services/Invoice/MarkPaid.php @@ -16,12 +16,14 @@ use App\Events\Payment\PaymentWasCreated; use App\Factory\PaymentFactory; use App\Jobs\Invoice\InvoiceWorkflowSettings; use App\Jobs\Payment\EmailPayment; +use App\Libraries\Currency\Conversion\CurrencyApi; use App\Models\Invoice; use App\Models\Payment; use App\Services\AbstractService; use App\Services\Client\ClientService; use App\Utils\Ninja; use App\Utils\Traits\GeneratesCounter; +use Illuminate\Support\Carbon; class MarkPaid extends AbstractService { @@ -63,6 +65,8 @@ class MarkPaid extends AbstractService /* Create a payment relationship to the invoice entity */ $payment->save(); + $this->setExchangeRate($payment); + $payment->invoices()->attach($this->invoice->id, [ 'amount' => $payment->amount, ]); @@ -96,4 +100,22 @@ class MarkPaid extends AbstractService return $this->invoice; } + + private function setExchangeRate(Payment $payment) + { + + $client_currency = $payment->client->getSetting('currency_id'); + $company_currency = $payment->client->company->settings->currency_id; + + if ($company_currency != $client_currency) { + + $exchange_rate = new CurrencyApi(); + + $payment->exchange_rate = $exchange_rate->exchangeRate($client_currency, $company_currency, Carbon::parse($payment->date)); + $payment->exchange_currency_id = $client_currency; + $payment->save(); + + } + + } } From a3a406b12263e12b7f1e2db1795202b4e51ee245 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 22 Jun 2021 08:41:15 +1000 Subject: [PATCH 3/5] Set Exchange Rates on invoice when marked as paid --- app/Services/Invoice/MarkPaid.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Services/Invoice/MarkPaid.php b/app/Services/Invoice/MarkPaid.php index df3cc60f8a7c..ff1e0a4b5c93 100644 --- a/app/Services/Invoice/MarkPaid.php +++ b/app/Services/Invoice/MarkPaid.php @@ -66,7 +66,7 @@ class MarkPaid extends AbstractService $payment->save(); $this->setExchangeRate($payment); - + $payment->invoices()->attach($this->invoice->id, [ 'amount' => $payment->amount, ]); @@ -74,6 +74,7 @@ class MarkPaid extends AbstractService $this->invoice->next_send_date = null; $this->invoice->service() + ->setExchangeRate() ->updateBalance($payment->amount * -1) ->updatePaidToDate($payment->amount) ->setStatus(Invoice::STATUS_PAID) From 8f78f93537674e0376145bf3769edcc993f89f3d Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 22 Jun 2021 10:51:43 +1000 Subject: [PATCH 4/5] Log exact IP if reported by cloudflare --- app/Http/Middleware/QueryLogging.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/Http/Middleware/QueryLogging.php b/app/Http/Middleware/QueryLogging.php index 6b9451b4877d..9e66f6dacbab 100644 --- a/app/Http/Middleware/QueryLogging.php +++ b/app/Http/Middleware/QueryLogging.php @@ -55,8 +55,15 @@ class QueryLogging //nlog($request->method().' - '.urldecode($request->url()).": $count queries - ".$time); // if($count > 50) //nlog($queries); + $ip = ''; - LightLogs::create(new DbQuery($request->method(), urldecode($request->url()), $count, $time, request()->ip())) + if(request()->header('Cf-Connecting-Ip')) + $ip = request()->header('Cf-Connecting-Ip'); + else{ + $ip = request()->ip(); + } + + LightLogs::create(new DbQuery($request->method(), urldecode($request->url()), $count, $time, $ip)) ->batch(); } From 12d040e163baa3e6749349542836339ca4722fa5 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 22 Jun 2021 11:13:01 +1000 Subject: [PATCH 5/5] Fixes for query --- app/Jobs/Cron/RecurringInvoicesCron.php | 4 ++-- app/Jobs/Util/ReminderJob.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Jobs/Cron/RecurringInvoicesCron.php b/app/Jobs/Cron/RecurringInvoicesCron.php index 8ced88244634..21df692fdef6 100644 --- a/app/Jobs/Cron/RecurringInvoicesCron.php +++ b/app/Jobs/Cron/RecurringInvoicesCron.php @@ -43,7 +43,7 @@ class RecurringInvoicesCron nlog("Sending recurring invoices ".Carbon::now()->format('Y-m-d h:i:s')); if (! config('ninja.db.multi_db_enabled')) { - $recurring_invoices = RecurringInvoice::whereDate('next_send_date', '<=', now()) + $recurring_invoices = RecurringInvoice::whereDate('next_send_date', '<=', now()->toDateTimeString()) ->whereNotNull('next_send_date') ->where('status_id', RecurringInvoice::STATUS_ACTIVE) ->where('remaining_cycles', '!=', '0') @@ -64,7 +64,7 @@ class RecurringInvoicesCron foreach (MultiDB::$dbs as $db) { MultiDB::setDB($db); - $recurring_invoices = RecurringInvoice::whereDate('next_send_date', '<=', now()) + $recurring_invoices = RecurringInvoice::whereDate('next_send_date', '<=', now()->toDateTimeString()) ->whereNotNull('next_send_date') ->where('status_id', RecurringInvoice::STATUS_ACTIVE) ->where('remaining_cycles', '!=', '0') diff --git a/app/Jobs/Util/ReminderJob.php b/app/Jobs/Util/ReminderJob.php index f9cd2e68cfea..7704940a94aa 100644 --- a/app/Jobs/Util/ReminderJob.php +++ b/app/Jobs/Util/ReminderJob.php @@ -55,7 +55,7 @@ class ReminderJob implements ShouldQueue { nlog("Sending invoice reminders " . now()->format('Y-m-d h:i:s')); - Invoice::whereDate('next_send_date', '<=', now()) + Invoice::whereDate('next_send_date', '<=', now()->toDateTimeString()) ->where('is_deleted', 0) ->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL]) ->where('balance', '>', 0)