From 108512068e71f512e19ab91ccede4bc60b08fc9b Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 9 Jul 2021 07:57:31 +1000 Subject: [PATCH 1/7] Form validation for contact password reset --- .../Auth/ContactForgotPasswordController.php | 4 +-- .../Contact/ContactPasswordResetRequest.php | 31 +++++++++++++++++++ .../Authorize/AuthorizeCreditCard.php | 1 + .../auth/passwords/request.blade.php | 3 +- 4 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 app/Http/Requests/ClientPortal/Contact/ContactPasswordResetRequest.php diff --git a/app/Http/Controllers/Auth/ContactForgotPasswordController.php b/app/Http/Controllers/Auth/ContactForgotPasswordController.php index 79d83e22dc3f..a3f515cdc2e9 100644 --- a/app/Http/Controllers/Auth/ContactForgotPasswordController.php +++ b/app/Http/Controllers/Auth/ContactForgotPasswordController.php @@ -12,6 +12,7 @@ namespace App\Http\Controllers\Auth; use App\Http\Controllers\Controller; +use App\Http\Requests\ClientPortal\Contact\ContactPasswordResetRequest; use App\Libraries\MultiDB; use App\Models\Account; use Illuminate\Contracts\View\Factory; @@ -73,9 +74,8 @@ class ContactForgotPasswordController extends Controller return Password::broker('contacts'); } - public function sendResetLinkEmail(Request $request) + public function sendResetLinkEmail(ContactPasswordResetRequest $request) { - //MultiDB::userFindAndSetDb($request->input('email')); $user = MultiDB::hasContact($request->input('email')); diff --git a/app/Http/Requests/ClientPortal/Contact/ContactPasswordResetRequest.php b/app/Http/Requests/ClientPortal/Contact/ContactPasswordResetRequest.php new file mode 100644 index 000000000000..ae18f4507cad --- /dev/null +++ b/app/Http/Requests/ClientPortal/Contact/ContactPasswordResetRequest.php @@ -0,0 +1,31 @@ + 'required', + ]; + } + +} diff --git a/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php b/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php index 692c34e39c7f..2de407899251 100644 --- a/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php +++ b/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php @@ -202,6 +202,7 @@ class AuthorizeCreditCard private function processFailedResponse($data, $request) { $response = $data['response']; + $amount = array_key_exists('amount_with_fee', $data) ? $data['amount_with_fee'] : 0; PaymentFailureMailer::dispatch($this->authorize->client, $response->getTransactionResponse()->getTransId(), $this->authorize->client->company, $data['amount_with_fee']); diff --git a/resources/views/portal/ninja2020/auth/passwords/request.blade.php b/resources/views/portal/ninja2020/auth/passwords/request.blade.php index 3cdd53724f49..f40fe51477a6 100644 --- a/resources/views/portal/ninja2020/auth/passwords/request.blade.php +++ b/resources/views/portal/ninja2020/auth/passwords/request.blade.php @@ -32,7 +32,8 @@ + autofocus + required> @error('email')
{{ $message }} From 87d0020152e097be9b5368624b558cefe1913e03 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 9 Jul 2021 08:01:37 +1000 Subject: [PATCH 2/7] Fixes for download invoices from client portal --- app/Http/Controllers/ClientPortal/InvoiceController.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/ClientPortal/InvoiceController.php b/app/Http/Controllers/ClientPortal/InvoiceController.php index 720508bd2bc1..0905bf74605b 100644 --- a/app/Http/Controllers/ClientPortal/InvoiceController.php +++ b/app/Http/Controllers/ClientPortal/InvoiceController.php @@ -24,6 +24,7 @@ use Illuminate\Contracts\View\Factory; use Illuminate\View\View; use ZipStream\Option\Archive; use ZipStream\ZipStream; +use Illuminate\Support\Facades\Storage; class InvoiceController extends Controller { @@ -170,8 +171,10 @@ class InvoiceController extends Controller $invitation = $invoice->invitations->first(); //$file = $invoice->pdf_file_path($invitation); $file = $invoice->service()->getInvoicePdf(auth()->user()); - return response()->download($file, basename($file), ['Cache-Control:' => 'no-cache'])->deleteFileAfterSend(true);; - + // return response()->download($file, basename($file), ['Cache-Control:' => 'no-cache'])->deleteFileAfterSend(true);; + return response()->streamDownload(function () use($file) { + echo Storage::get($file); + }, basename($file)); } // enable output of HTTP headers From 95767f8bdd4e0b031aa76e383ce06927325e5312 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 9 Jul 2021 08:43:01 +1000 Subject: [PATCH 3/7] Set Mime type of imported JSON file --- app/Http/Requests/Import/ImportJsonRequest.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/app/Http/Requests/Import/ImportJsonRequest.php b/app/Http/Requests/Import/ImportJsonRequest.php index d4fb6a12226e..6f1624dcc7a8 100644 --- a/app/Http/Requests/Import/ImportJsonRequest.php +++ b/app/Http/Requests/Import/ImportJsonRequest.php @@ -28,12 +28,7 @@ class ImportJsonRequest extends Request public function rules() { return [ - // 'import_type' => 'required', - // 'files' => 'required_without:hash|array|min:1|max:6', - // 'hash' => 'nullable|string', - // 'column_map' => 'required_with:hash|array', - // 'skip_header' => 'required_with:hash|boolean', - // 'files.*' => 'file|mimes:csv,txt', + 'files' => 'file|mimes:zip', ]; } } From a6b2165eecde3afab1ec6310aa90c336e0131069 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 9 Jul 2021 09:05:24 +1000 Subject: [PATCH 4/7] Fixes for Stripe Connect - initial account --- .../Controllers/StripeConnectController.php | 44 +++++++------------ 1 file changed, 16 insertions(+), 28 deletions(-) diff --git a/app/Http/Controllers/StripeConnectController.php b/app/Http/Controllers/StripeConnectController.php index ceb2aa4c39f3..34e95dbb5386 100644 --- a/app/Http/Controllers/StripeConnectController.php +++ b/app/Http/Controllers/StripeConnectController.php @@ -60,12 +60,6 @@ class StripeConnectController extends BaseController $redirect_uri = 'https://invoicing.co/stripe/completed'; $endpoint = "https://connect.stripe.com/oauth/authorize?response_type=code&client_id={$stripe_client_id}&redirect_uri={$redirect_uri}&scope=read_write&state={$token}"; - // if($email = $request->getContact()->email) - // $endpoint .= "&stripe_user[email]={$email}"; - - // $company_name = str_replace(" ", "_", $company->present()->name()); - // $endpoint .= "&stripe_user[business_name]={$company_name}"; - return redirect($endpoint); } @@ -87,18 +81,24 @@ class StripeConnectController extends BaseController } - // nlog($response); - $company = Company::where('company_key', $request->getTokenContent()['company_key'])->first(); - $company_gateway = CompanyGatewayFactory::create($company->id, $company->owner()->id); - $fees_and_limits = new \stdClass; - $fees_and_limits->{GatewayType::CREDIT_CARD} = new FeesAndLimits; - $company_gateway->gateway_key = 'd14dd26a47cecc30fdd65700bfb67b34'; - $company_gateway->fees_and_limits = $fees_and_limits; - $company_gateway->setConfig([]); - $company_gateway->token_billing = 'always'; - // $company_gateway->save(); + $company_gateway = CompanyGateway::query() + ->where('gateway_key', 'd14dd26a47cecc30fdd65700bfb67b34') + ->where('company_id', $company->id) + ->first(); + + if(!$company_gateway) + { + $company_gateway = CompanyGatewayFactory::create($company->id, $company->owner()->id); + $fees_and_limits = new \stdClass; + $fees_and_limits->{GatewayType::CREDIT_CARD} = new FeesAndLimits; + $company_gateway->gateway_key = 'd14dd26a47cecc30fdd65700bfb67b34'; + $company_gateway->fees_and_limits = $fees_and_limits; + $company_gateway->setConfig([]); + $company_gateway->token_billing = 'always'; + // $company_gateway->save(); + } $payload = [ 'account_id' => $response->stripe_user_id, @@ -111,18 +111,6 @@ class StripeConnectController extends BaseController "access_token" => $response->access_token ]; - /* Link account if existing account exists */ - // if($account_id = $this->checkAccountAlreadyLinkToEmail($company_gateway, $request->getContact()->email)) { - - // $payload['account_id'] = $account_id; - // $payload['stripe_user_id'] = $account_id; - // $company_gateway->setConfig($payload); - // $company_gateway->save(); - - // return view('auth.connect.existing'); - - // } - $company_gateway->setConfig($payload); $company_gateway->save(); From 57bd1f9c9dbece1da09c14c1f55b28b5b54cb2ad Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 9 Jul 2021 09:08:20 +1000 Subject: [PATCH 5/7] Log excessively large queries --- app/Http/Middleware/QueryLogging.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/Http/Middleware/QueryLogging.php b/app/Http/Middleware/QueryLogging.php index 9e66f6dacbab..cb44441b9dc0 100644 --- a/app/Http/Middleware/QueryLogging.php +++ b/app/Http/Middleware/QueryLogging.php @@ -51,10 +51,10 @@ class QueryLogging $count = count($queries); $timeEnd = microtime(true); $time = $timeEnd - $timeStart; - - //nlog($request->method().' - '.urldecode($request->url()).": $count queries - ".$time); - // if($count > 50) - //nlog($queries); + + if($count > 150) + nlog($queries); + $ip = ''; if(request()->header('Cf-Connecting-Ip')) From 5affb4a03649d9ce559ca57f73550c7764a16740 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 9 Jul 2021 09:46:18 +1000 Subject: [PATCH 6/7] Additional checks for payment method objects --- app/Models/Client.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/app/Models/Client.php b/app/Models/Client.php index 18103e595fba..4c42c32764e0 100644 --- a/app/Models/Client.php +++ b/app/Models/Client.php @@ -13,6 +13,7 @@ namespace App\Models; use App\DataMapper\ClientSettings; use App\DataMapper\CompanySettings; +use App\DataMapper\FeesAndLimits; use App\Models\CompanyGateway; use App\Models\Presenters\ClientPresenter; use App\Services\Client\ClientService; @@ -430,6 +431,13 @@ class Client extends BaseModel implements HasLocalePreference { $cg = CompanyGateway::find($pm['company_gateway_id']); + if($cg && !property_exists($cg->fees_and_limits, GatewayType::CREDIT_CARD)){ + $fees_and_limits = $cg->fees_and_limits; + $fees_and_limits->{GatewayType::CREDIT_CARD} = new FeesAndLimits; + $cg->fees_and_limits = $fees_and_limits; + $cg->save(); + } + if($cg && $cg->fees_and_limits->{GatewayType::CREDIT_CARD}->is_enabled) return $cg; @@ -455,6 +463,13 @@ class Client extends BaseModel implements HasLocalePreference { $cg = CompanyGateway::find($pm['company_gateway_id']); + if($$cg && !property_exists($cg->fees_and_limits, GatewayType::BANK_TRANSFER)){ + $fees_and_limits = $cg->fees_and_limits; + $fees_and_limits->{GatewayType::BANK_TRANSFER} = new FeesAndLimits; + $cg->fees_and_limits = $fees_and_limits; + $cg->save(); + } + if($cg && $cg->fees_and_limits->{GatewayType::BANK_TRANSFER}->is_enabled) return $cg; } From d1aae93c08e7597b13d4d874e0af1088d1867b09 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 9 Jul 2021 09:49:01 +1000 Subject: [PATCH 7/7] Fixes for Download Recurring Invoice --- app/Http/Controllers/RecurringInvoiceController.php | 8 ++++++-- app/Services/Recurring/GetInvoicePdf.php | 6 +++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/RecurringInvoiceController.php b/app/Http/Controllers/RecurringInvoiceController.php index 46c708d4b6f0..aef6b5e2e6ed 100644 --- a/app/Http/Controllers/RecurringInvoiceController.php +++ b/app/Http/Controllers/RecurringInvoiceController.php @@ -33,6 +33,7 @@ use App\Utils\Traits\SavesDocuments; use Carbon\Carbon; use Illuminate\Http\Request; use Illuminate\Http\Response; +use Illuminate\Support\Facades\Storage; /** * Class RecurringInvoiceController. @@ -500,9 +501,12 @@ class RecurringInvoiceController extends BaseController $contact = $invitation->contact; $recurring_invoice = $invitation->recurring_invoice; - $file_path = $recurring_invoice->service()->getInvoicePdf($contact); + $file = $recurring_invoice->service()->getInvoicePdf($contact); + + return response()->streamDownload(function () use($file) { + echo Storage::get($file); + }, basename($file)); - return response()->download($file_path, basename($file_path), ['Cache-Control:' => 'no-cache'])->deleteFileAfterSend(true); } /** diff --git a/app/Services/Recurring/GetInvoicePdf.php b/app/Services/Recurring/GetInvoicePdf.php index 2df250bd166f..ba50f3d9ce0b 100644 --- a/app/Services/Recurring/GetInvoicePdf.php +++ b/app/Services/Recurring/GetInvoicePdf.php @@ -41,14 +41,14 @@ class GetInvoicePdf extends AbstractService $file_path = $path.$this->entity->hashed_id.'.pdf'; - $disk = 'public'; + $disk = config('filesystems.default'); $file = Storage::disk($disk)->exists($file_path); if (! $file) { $file_path = CreateEntityPdf::dispatchNow($invitation); } - - return Storage::disk($disk)->path($file_path); + + return $file_path; } }