diff --git a/app/Http/Controllers/CompanyUserController.php b/app/Http/Controllers/CompanyUserController.php index 22d1a0ee2a..c3d1c6ed45 100644 --- a/app/Http/Controllers/CompanyUserController.php +++ b/app/Http/Controllers/CompanyUserController.php @@ -111,8 +111,9 @@ class CompanyUserController extends BaseController */ public function update(UpdateCompanyUserRequest $request, User $user) { - - $company = auth()->user()->company(); + /** @var \App\Models\User $auth_user */ + $auth_user = auth()->user(); + $company = $auth_user->company(); $company_user = CompanyUser::whereUserId($user->id)->whereCompanyId($company->id)->first(); @@ -122,7 +123,7 @@ class CompanyUserController extends BaseController return; } - if (auth()->user()->isAdmin()) { + if ($auth_user->isAdmin()) { $company_user->fill($request->input('company_user')); } else { $company_user->settings = $request->input('company_user')['settings']; @@ -136,8 +137,11 @@ class CompanyUserController extends BaseController public function updatePreferences(UpdateCompanyUserPreferencesRequest $request, User $user) { + /** @var \App\Models\User $auth_user */ + $auth_user = auth()->user(); + $company = $auth_user->company(); - $company = auth()->user()->company(); + $company = $auth_user->company(); $company_user = CompanyUser::whereUserId($user->id)->whereCompanyId($company->id)->first(); diff --git a/app/Http/Controllers/CreditController.php b/app/Http/Controllers/CreditController.php index f64b5efce9..b84bc40e26 100644 --- a/app/Http/Controllers/CreditController.php +++ b/app/Http/Controllers/CreditController.php @@ -592,11 +592,8 @@ class CreditController extends BaseController } break; case 'download': - // $file = $credit->pdf_file_path(); $file = $credit->service()->getCreditPdf($credit->invitations->first()); - // return response()->download($file, basename($file), ['Cache-Control:' => 'no-cache'])->deleteFileAfterSend(true); - return response()->streamDownload(function () use ($file) { echo Storage::get($file); }, basename($file), ['Content-Type' => 'application/pdf']); diff --git a/app/Http/Controllers/OneTimeTokenController.php b/app/Http/Controllers/OneTimeTokenController.php index b065a50529..b51cfcc111 100644 --- a/app/Http/Controllers/OneTimeTokenController.php +++ b/app/Http/Controllers/OneTimeTokenController.php @@ -74,7 +74,7 @@ class OneTimeTokenController extends BaseController 'user_id' => $user->id, 'company_key'=> $user->company()->company_key, 'context' => $request->input('context'), - 'is_react' => $request->has('react') && $request->query('react') == 'true' ? true : false, + 'is_react' => $request->request()->hasHeader('X-REACT') ? true : false, ]; Cache::put($hash, $data, 3600); diff --git a/app/Http/Controllers/StripeConnectController.php b/app/Http/Controllers/StripeConnectController.php index d9ab04eccf..5f8900e670 100644 --- a/app/Http/Controllers/StripeConnectController.php +++ b/app/Http/Controllers/StripeConnectController.php @@ -15,11 +15,9 @@ use App\DataMapper\FeesAndLimits; use App\Factory\CompanyGatewayFactory; use App\Http\Requests\StripeConnect\InitializeStripeConnectRequest; use App\Libraries\MultiDB; -use App\Models\Client; use App\Models\Company; use App\Models\CompanyGateway; use App\Models\GatewayType; -use App\PaymentDrivers\Stripe\Jobs\StripeWebhook; use Stripe\Exception\ApiErrorException; class StripeConnectController extends BaseController @@ -124,12 +122,27 @@ class StripeConnectController extends BaseController $company_gateway->setConfig($payload); $company_gateway->save(); + try{ + $stripe = $company_gateway->driver()->init(); + $a = \Stripe\Account::retrieve($response->stripe_user_id, $stripe->stripe_connect_auth); + + if($a->business_name ?? false) { + $company_gateway->label = substr("Stripe - {$a->business_name}", 0, 250); + $company_gateway->save(); + } + } + catch(\Exception $e){ + nlog("could not harvest stripe company name"); + } + + // nlog("Stripe Connect Redirect URI = {$redirect_uri}"); + // StripeWebhook::dispatch($company->company_key, $company_gateway->id); - // if(isset($request->getTokenContent()['is_react']) && $request->getTokenContent()['is_react']) { + if(isset($request->getTokenContent()['is_react']) && $request->getTokenContent()['is_react']) { $redirect_uri = 'https://app.invoicing.co/#/settings/online_payments'; - // } else { - // $redirect_uri = 'https://invoicing.co/stripe/completed'; - // } + } else { + $redirect_uri = 'https://invoicing.co/stripe/completed'; + } //response here return view('auth.connect.completed', ['url' => $redirect_uri]); diff --git a/app/Utils/Traits/PaymentEmailBuilder.php b/app/Utils/Traits/PaymentEmailBuilder.php deleted file mode 100644 index db1924343c..0000000000 --- a/app/Utils/Traits/PaymentEmailBuilder.php +++ /dev/null @@ -1,89 +0,0 @@ -client; - - //Need to determine which email template we are producing - return $this->generateTemplateData($reminder_template, $contact); - } - - private function generateTemplateData(string $reminder_template, $contact) :array - { - $data = []; - - $client = $this->client; - - $body_template = $client->getSetting('email_template_'.$reminder_template); - - /* Use default translations if a custom message has not been set*/ - if (iconv_strlen($body_template) == 0) { - $body_template = trans('texts.payment_message', ['amount'=>$this->present()->amount(), 'account'=>$this->company->present()->name()], null, $this->client->locale()); - } - - $subject_template = $client->getSetting('payment_subject'); - - if (iconv_strlen($subject_template) == 0) { - $subject_template = trans('texts.invoice_subject', ['number'=>$this->present()->invoice_number(), 'account'=>$this->company->present()->name()], null, $this->client->locale()); - } - - $data['body'] = $this->parseTemplate($body_template, false, $contact); - $data['subject'] = $this->parseTemplate($subject_template, true, $contact); - - if ($client->getSetting('pdf_email_attachment') !== false) { - $data['files'][] = $this->pdf_file_path(); - } - - return $data; - } - - private function parseTemplate(string $template_data, bool $is_markdown, $contact) :string - { - //$invoice_variables = $this->makeValues($contact); - - //process variables - //$data = str_replace(array_keys($invoice_variables), array_values($invoice_variables), $template_data); - - $data = strtr($template_data, $invoice_variables); - - //process markdown - if ($is_markdown) { - //$data = Parsedown::instance()->line($data); - - $converter = new CommonMarkConverter([ - 'html_input' => 'strip', - 'allow_unsafe_links' => false, - ]); - - $data = $converter->convert($data); - } - - return $data; - } -} diff --git a/app/Utils/Traits/QuoteEmailBuilder.php b/app/Utils/Traits/QuoteEmailBuilder.php deleted file mode 100644 index 6aa136d815..0000000000 --- a/app/Utils/Traits/QuoteEmailBuilder.php +++ /dev/null @@ -1,136 +0,0 @@ -calculateTemplate('quote'); - } - - //Need to determine which email template we are producing - return $this->generateTemplateData($reminder_template, $contact); - } - - private function generateTemplateData(string $reminder_template, $contact) :array - { - $data = []; - - $client = $this->client; - - $body_template = $client->getSetting('email_template_'.$reminder_template); - - /* Use default translations if a custom message has not been set*/ - if (iconv_strlen($body_template) == 0) { - $body_template = trans('texts.quote_message', ['amount'=>$this->present()->amount(), 'account'=>$this->company->present()->name()], null, $this->client->locale()); - } - - $subject_template = $client->getSetting('email_subject_'.$reminder_template); - - if (iconv_strlen($subject_template) == 0) { - if ($reminder_template == 'quote') { - $subject_template = trans('texts.quote_subject', ['number'=>$this->present()->invoice_number(), 'account'=>$this->company->present()->name()], null, $this->client->locale()); - } else { - $subject_template = trans('texts.reminder_subject', ['number'=>$this->present()->invoice_number(), 'account'=>$this->company->present()->name()], null, $this->client->locale()); - } - } - - $data['body'] = $this->parseTemplate($body_template, true, $contact); - $data['subject'] = $this->parseTemplate($subject_template, false, $contact); - - if ($client->getSetting('pdf_email_attachment') !== false) { - $data['files'][] = $this->pdf_file_path(); - } - - return $data; - } - - private function parseTemplate(string $template_data, bool $is_markdown, $contact) :string - { - // $quote_variables = $this->makeValues($contact); - - //process variables -// $data = str_replace(array_keys($quote_variables), array_values($quote_variables), $template_data); - $data = strtr($template_data, $quote_variables); - - //process markdown - if ($is_markdown) { - //$data = Parsedown::instance()->line($data); - - $converter = new CommonMarkConverter([ - 'html_input' => 'allow', - 'allow_unsafe_links' => true, - ]); - - $data = $converter->convert($data); - } - - return $data; - } - - private function calculateTemplate() :string - { - //if invoice is currently a draft, or being marked as sent, this will be the initial email - $client = $this->client; - - //if the invoice - if ($this->status_id == Quote::STATUS_DRAFT || Carbon::parse($this->due_date) > now()) { - return 'quote'; - } elseif ($client->getSetting('enable_reminder1') !== false && $this->inReminderWindow($client->getSetting('schedule_reminder1'), $client->getSetting('num_days_reminder1'))) { - return 'template1'; - } elseif ($client->getSetting('enable_reminder2') !== false && $this->inReminderWindow($client->getSetting('schedule_reminder2'), $client->getSetting('num_days_reminder2'))) { - return 'template2'; - } elseif ($client->getSetting('enable_reminder3') !== false && $this->inReminderWindow($client->getSetting('schedule_reminder3'), $client->getSetting('num_days_reminder3'))) { - return 'template3'; - } else { - return 'quote'; - } - - //also implement endless reminders here - } - - private function inReminderWindow($schedule_reminder, $num_days_reminder) - { - switch ($schedule_reminder) { - case 'after_invoice_date': - return Carbon::parse($this->date)->addDays($num_days_reminder)->startOfDay()->eq(Carbon::now()->startOfDay()); - break; - case 'before_due_date': - return Carbon::parse($this->due_date)->subDays($num_days_reminder)->startOfDay()->eq(Carbon::now()->startOfDay()); - break; - case 'after_due_date': - return Carbon::parse($this->due_date)->addDays($num_days_reminder)->startOfDay()->eq(Carbon::now()->startOfDay()); - break; - default: - // code... - break; - } - } -}