diff --git a/app/Exceptions/PaymentFailed.php b/app/Exceptions/PaymentFailed.php index 7c0f2cb67711..b509df02fa77 100644 --- a/app/Exceptions/PaymentFailed.php +++ b/app/Exceptions/PaymentFailed.php @@ -13,7 +13,7 @@ class PaymentFailed extends Exception public function render($request) { - if (auth()->user() || ($request->has('cko-session-id') && $request->query('cko-session-id') )) { + if (auth()->guard('contact')->user() || ($request->has('cko-session-id') && $request->query('cko-session-id') )) { return render('gateways.unsuccessful', [ 'message' => $this->getMessage(), 'code' => $this->getCode(), diff --git a/app/Filters/QuoteFilters.php b/app/Filters/QuoteFilters.php index 9990575753d4..1c1d298eba21 100644 --- a/app/Filters/QuoteFilters.php +++ b/app/Filters/QuoteFilters.php @@ -94,6 +94,9 @@ class QuoteFilters extends QueryFilters { $sort_col = explode('|', $sort); + if($sort_col[0] == 'valid_until') + $sort_col[0] = 'due_date'; + return $this->builder->orderBy($sort_col[0], $sort_col[1]); } diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index bd5afef4678f..5d7c8dcf1382 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -334,11 +334,12 @@ class LoginController extends BaseController } elseif (request()->input('provider') == 'microsoft') { return $this->handleMicrosoftOauth(); } elseif (request()->input('provider') == 'apple') { - // if (request()->has('token')) { - // return $this->handleSocialiteLogin('apple', request()->get('token')); - // } else { - // $message = 'Token is missing for the apple login'; - // } + if (request()->has('token') || request()->has('auth_code')) { + $token = request()->has('token') ? request()->input('token') : request()->input('auth_code'); + return $this->handleSocialiteLogin('apple', $token); + } else { + $message = 'Token is missing for the apple login'; + } } return response() @@ -355,6 +356,7 @@ class LoginController extends BaseController private function handleSocialiteLogin($provider, $token) { $user = $this->getSocialiteUser($provider, $token); + nlog($user); if ($user) { return $this->loginOrCreateFromSocialite($user, $provider); } diff --git a/app/Http/Controllers/RecurringInvoiceController.php b/app/Http/Controllers/RecurringInvoiceController.php index 404898086b00..44b1ec4333b1 100644 --- a/app/Http/Controllers/RecurringInvoiceController.php +++ b/app/Http/Controllers/RecurringInvoiceController.php @@ -204,10 +204,6 @@ class RecurringInvoiceController extends BaseController { $recurring_invoice = $this->recurring_invoice_repo->save($request->all(), RecurringInvoiceFactory::create(auth()->user()->company()->id, auth()->user()->id)); - // $offset = $recurring_invoice->client->timezone_offset(); - // $recurring_invoice->next_send_date = Carbon::parse($recurring_invoice->next_send_date)->startOfDay()->addSeconds($offset); - // $recurring_invoice->saveQuietly(); - $recurring_invoice->service() ->triggeredActions($request) ->save(); @@ -702,6 +698,15 @@ class RecurringInvoiceController extends BaseController $this->itemResponse($recurring_invoice); } + break; + + case 'send_now': + $recurring_invoice = $recurring_invoice->service()->sendNow(); + + if (! $bulk) { + $this->itemResponse($recurring_invoice); + } + break; default: // code... diff --git a/app/Http/Controllers/StripeConnectController.php b/app/Http/Controllers/StripeConnectController.php index 4ac4566e7d61..faafe25feeba 100644 --- a/app/Http/Controllers/StripeConnectController.php +++ b/app/Http/Controllers/StripeConnectController.php @@ -21,6 +21,7 @@ use App\Models\Company; use App\Models\CompanyGateway; use App\Models\GatewayType; use App\PaymentDrivers\Stripe\Connect\Account; +use App\PaymentDrivers\Stripe\Jobs\StripeWebhook; use Exception; use Illuminate\Http\Request; use Stripe\Exception\ApiErrorException; @@ -119,6 +120,8 @@ class StripeConnectController extends BaseController $company_gateway->setConfig($payload); $company_gateway->save(); + StripeWebhook::dispatch($company->company_key, $company_gateway->id); + //response here return view('auth.connect.completed'); } diff --git a/app/Http/ValidationRules/ValidCreditsPresentRule.php b/app/Http/ValidationRules/ValidCreditsPresentRule.php index d2ad2f7fb72b..3cc5dab68028 100644 --- a/app/Http/ValidationRules/ValidCreditsPresentRule.php +++ b/app/Http/ValidationRules/ValidCreditsPresentRule.php @@ -44,7 +44,7 @@ class ValidCreditsPresentRule implements Rule { //todo need to ensure the clients credits are here not random ones! - if (request()->input('credits') && is_array(request()->input('credits'))) { + if (request()->input('credits') && is_array(request()->input('credits')) && count(request()->input('credits')) > 0) { $credit_collection = Credit::whereIn('id', $this->transformKeys(array_column(request()->input('credits'), 'credit_id'))) ->count(); diff --git a/app/Jobs/PostMark/ProcessPostmarkWebhook.php b/app/Jobs/PostMark/ProcessPostmarkWebhook.php index 57c958ba5e89..64b590ad0917 100644 --- a/app/Jobs/PostMark/ProcessPostmarkWebhook.php +++ b/app/Jobs/PostMark/ProcessPostmarkWebhook.php @@ -220,8 +220,8 @@ class ProcessPostmarkWebhook implements ShouldQueue SystemLogger::dispatch($this->request, SystemLog::CATEGORY_MAIL, SystemLog::EVENT_MAIL_BOUNCED, SystemLog::TYPE_WEBHOOK_RESPONSE, $this->invitation->contact->client, $this->invitation->company); - if(config('ninja.notification.slack')) - $this->invitation->company->notification(new EmailBounceNotification($this->invitation->company->account))->ninja(); + // if(config('ninja.notification.slack')) + // $this->invitation->company->notification(new EmailBounceNotification($this->invitation->company->account))->ninja(); } diff --git a/app/Models/Account.php b/app/Models/Account.php index 04c254919e57..ebbbb18934c5 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -491,4 +491,17 @@ class Account extends BaseModel ->where('id', $this->decodePrimaryKey($value))->firstOrFail(); } + public function getTrialDays() + { + if($this->payment_id) + return 0; + + $plan_expires = Carbon::parse($this->plan_expires); + + if(!$this->payment_id && $plan_expires->gt(now())) + return $plan_expires->diffInDays(); + + return 0; + } + } diff --git a/app/Repositories/PaymentRepository.php b/app/Repositories/PaymentRepository.php index 53170d76e718..1bdb4942949b 100644 --- a/app/Repositories/PaymentRepository.php +++ b/app/Repositories/PaymentRepository.php @@ -83,7 +83,7 @@ class PaymentRepository extends BaseRepository { $client->service()->updatePaidToDate($data['amount'])->save(); } - // elseif($data['amount'] >0){ + else{ //this fixes an edge case with unapplied payments $client->service()->updatePaidToDate($data['amount'])->save(); diff --git a/app/Services/Payment/UpdateInvoicePayment.php b/app/Services/Payment/UpdateInvoicePayment.php index 12eecad1d1a2..d07308730158 100644 --- a/app/Services/Payment/UpdateInvoicePayment.php +++ b/app/Services/Payment/UpdateInvoicePayment.php @@ -14,6 +14,7 @@ namespace App\Services\Payment; use App\Events\Invoice\InvoiceWasUpdated; use App\Jobs\Invoice\InvoiceWorkflowSettings; use App\Jobs\Ninja\TransactionLog; +use App\Models\Client; use App\Models\Invoice; use App\Models\Payment; use App\Models\PaymentHash; @@ -48,8 +49,6 @@ class UpdateInvoicePayment collect($paid_invoices)->each(function ($paid_invoice) use ($invoices, $client) { - $client = $client->fresh(); - $invoice = $invoices->first(function ($inv) use ($paid_invoice) { return $paid_invoice->invoice_id == $inv->hashed_id; }); @@ -63,9 +62,15 @@ class UpdateInvoicePayment $paid_amount = $paid_invoice->amount; } - $client->paid_to_date += $paid_amount; - $client->balance -= $paid_amount; - $client->save(); + \DB::connection(config('database.default'))->transaction(function () use($client, $paid_amount){ + + $update_client = Client::withTrashed()->where('id', $client->id)->lockForUpdate()->first(); + + $update_client->paid_to_date += $paid_amount; + $update_client->balance -= $paid_amount; + $update_client->save(); + + }, 1); /* Need to determine here is we have an OVER payment - if YES only apply the max invoice amount */ if($paid_amount > $invoice->partial && $paid_amount > $invoice->balance) diff --git a/app/Services/Recurring/RecurringService.php b/app/Services/Recurring/RecurringService.php index 3174ba47809c..5f4f3c49c1f8 100644 --- a/app/Services/Recurring/RecurringService.php +++ b/app/Services/Recurring/RecurringService.php @@ -11,6 +11,7 @@ namespace App\Services\Recurring; +use App\Jobs\RecurringInvoice\SendRecurring; use App\Jobs\Util\UnlinkFile; use App\Models\RecurringInvoice; use App\Services\Recurring\GetInvoicePdf; @@ -106,6 +107,10 @@ class RecurringService $this->stop(); } + if ($request->has('send_now') && $request->input('send_now') == 'true' && $this->recurring_entity->invoices()->count() == 0) { + $this->sendNow(); + } + if(isset($this->recurring_entity->client)) { $offset = $this->recurring_entity->client->timezone_offset(); @@ -115,6 +120,16 @@ class RecurringService return $this; } + public function sendNow() + { + + if($this->recurring_entity instanceof RecurringInvoice) + SendRecurring::dispatchNow($this->recurring_entity, $this->recurring_entity->company->db); + + return $this->recurring_entity; + + } + public function fillDefaults() { diff --git a/app/Transformers/AccountTransformer.php b/app/Transformers/AccountTransformer.php index 9536a9dc422f..c8c0b10274b5 100644 --- a/app/Transformers/AccountTransformer.php +++ b/app/Transformers/AccountTransformer.php @@ -86,7 +86,8 @@ class AccountTransformer extends EntityTransformer 'hosted_client_count' => (int) $account->hosted_client_count, 'hosted_company_count' => (int) $account->hosted_company_count, 'is_hosted' => (bool) Ninja::isHosted(), - 'set_react_as_default_ap' => (bool) $account->set_react_as_default_ap + 'set_react_as_default_ap' => (bool) $account->set_react_as_default_ap, + 'trial_days_left' => Ninja::isHosted() ? (int) $account->getTrialDays() : 0, ]; } @@ -110,6 +111,5 @@ class AccountTransformer extends EntityTransformer return $this->includeItem(auth()->user(), $transformer, User::class); -// return $this->includeItem($account->default_company->owner(), $transformer, User::class); } } diff --git a/composer.lock b/composer.lock index e4c1ea78da04..5255d2df8c23 100644 --- a/composer.lock +++ b/composer.lock @@ -434,16 +434,16 @@ }, { "name": "aws/aws-sdk-php", - "version": "3.230.0", + "version": "3.231.2", "source": { "type": "git", "url": "https://github.com/aws/aws-sdk-php.git", - "reference": "474f351aff22cc7a61016c1de79d7d2fe6c80d2b" + "reference": "9a7c2a8c4b7f95074749e1a7b575e6b4486bdcab" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/474f351aff22cc7a61016c1de79d7d2fe6c80d2b", - "reference": "474f351aff22cc7a61016c1de79d7d2fe6c80d2b", + "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/9a7c2a8c4b7f95074749e1a7b575e6b4486bdcab", + "reference": "9a7c2a8c4b7f95074749e1a7b575e6b4486bdcab", "shasum": "" }, "require": { @@ -461,6 +461,7 @@ "andrewsville/php-token-reflection": "^1.4", "aws/aws-php-sns-message-validator": "~1.0", "behat/behat": "~3.0", + "composer/composer": "^1.10.22", "doctrine/cache": "~1.4", "ext-dom": "*", "ext-openssl": "*", @@ -519,9 +520,9 @@ "support": { "forum": "https://forums.aws.amazon.com/forum.jspa?forumID=80", "issues": "https://github.com/aws/aws-sdk-php/issues", - "source": "https://github.com/aws/aws-sdk-php/tree/3.230.0" + "source": "https://github.com/aws/aws-sdk-php/tree/3.231.2" }, - "time": "2022-07-05T18:19:42+00:00" + "time": "2022-07-08T18:16:11+00:00" }, { "name": "bacon/bacon-qr-code", @@ -2244,16 +2245,16 @@ }, { "name": "gocardless/gocardless-pro", - "version": "4.17.0", + "version": "4.18.0", "source": { "type": "git", "url": "https://github.com/gocardless/gocardless-pro-php.git", - "reference": "59ccdcbfbbf1a18b55c749ed121137dce6d6f3ae" + "reference": "dee046abbb7a37ef0a60bb03e2a467afc79a92a5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/gocardless/gocardless-pro-php/zipball/59ccdcbfbbf1a18b55c749ed121137dce6d6f3ae", - "reference": "59ccdcbfbbf1a18b55c749ed121137dce6d6f3ae", + "url": "https://api.github.com/repos/gocardless/gocardless-pro-php/zipball/dee046abbb7a37ef0a60bb03e2a467afc79a92a5", + "reference": "dee046abbb7a37ef0a60bb03e2a467afc79a92a5", "shasum": "" }, "require": { @@ -2293,9 +2294,9 @@ ], "support": { "issues": "https://github.com/gocardless/gocardless-pro-php/issues", - "source": "https://github.com/gocardless/gocardless-pro-php/tree/v4.17.0" + "source": "https://github.com/gocardless/gocardless-pro-php/tree/v4.18.0" }, - "time": "2022-06-29T12:55:58+00:00" + "time": "2022-07-08T14:38:42+00:00" }, { "name": "google/apiclient", @@ -2369,16 +2370,16 @@ }, { "name": "google/apiclient-services", - "version": "v0.256.0", + "version": "v0.257.0", "source": { "type": "git", "url": "https://github.com/googleapis/google-api-php-client-services.git", - "reference": "122e51021eb19b53f831904918460671d1e7259d" + "reference": "ae109202ee831a1fb70ba824181852e6179c848b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/googleapis/google-api-php-client-services/zipball/122e51021eb19b53f831904918460671d1e7259d", - "reference": "122e51021eb19b53f831904918460671d1e7259d", + "url": "https://api.github.com/repos/googleapis/google-api-php-client-services/zipball/ae109202ee831a1fb70ba824181852e6179c848b", + "reference": "ae109202ee831a1fb70ba824181852e6179c848b", "shasum": "" }, "require": { @@ -2407,9 +2408,9 @@ ], "support": { "issues": "https://github.com/googleapis/google-api-php-client-services/issues", - "source": "https://github.com/googleapis/google-api-php-client-services/tree/v0.256.0" + "source": "https://github.com/googleapis/google-api-php-client-services/tree/v0.257.0" }, - "time": "2022-07-04T01:10:37+00:00" + "time": "2022-07-08T01:28:13+00:00" }, { "name": "google/auth", @@ -5123,16 +5124,16 @@ }, { "name": "microsoft/microsoft-graph", - "version": "1.70.0", + "version": "1.71.0", "source": { "type": "git", "url": "https://github.com/microsoftgraph/msgraph-sdk-php.git", - "reference": "7d85293be037c4a2891a03cb953eb204bf68387e" + "reference": "f17ae778614d6ebf326d33292d09519d39b017a8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/microsoftgraph/msgraph-sdk-php/zipball/7d85293be037c4a2891a03cb953eb204bf68387e", - "reference": "7d85293be037c4a2891a03cb953eb204bf68387e", + "url": "https://api.github.com/repos/microsoftgraph/msgraph-sdk-php/zipball/f17ae778614d6ebf326d33292d09519d39b017a8", + "reference": "f17ae778614d6ebf326d33292d09519d39b017a8", "shasum": "" }, "require": { @@ -5168,9 +5169,9 @@ "homepage": "https://developer.microsoft.com/en-us/graph", "support": { "issues": "https://github.com/microsoftgraph/msgraph-sdk-php/issues", - "source": "https://github.com/microsoftgraph/msgraph-sdk-php/tree/1.70.0" + "source": "https://github.com/microsoftgraph/msgraph-sdk-php/tree/1.71.0" }, - "time": "2022-06-21T13:37:02+00:00" + "time": "2022-07-07T10:04:08+00:00" }, { "name": "mollie/mollie-api-php", @@ -7659,16 +7660,16 @@ }, { "name": "psy/psysh", - "version": "v0.11.6", + "version": "v0.11.7", "source": { "type": "git", "url": "https://github.com/bobthecow/psysh.git", - "reference": "3f5b5f8aaa979fbd0d1783173f4c82ad529fe621" + "reference": "77fc7270031fbc28f9a7bea31385da5c4855cb7a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/bobthecow/psysh/zipball/3f5b5f8aaa979fbd0d1783173f4c82ad529fe621", - "reference": "3f5b5f8aaa979fbd0d1783173f4c82ad529fe621", + "url": "https://api.github.com/repos/bobthecow/psysh/zipball/77fc7270031fbc28f9a7bea31385da5c4855cb7a", + "reference": "77fc7270031fbc28f9a7bea31385da5c4855cb7a", "shasum": "" }, "require": { @@ -7729,9 +7730,9 @@ ], "support": { "issues": "https://github.com/bobthecow/psysh/issues", - "source": "https://github.com/bobthecow/psysh/tree/v0.11.6" + "source": "https://github.com/bobthecow/psysh/tree/v0.11.7" }, - "time": "2022-07-03T16:40:23+00:00" + "time": "2022-07-07T13:49:11+00:00" }, { "name": "ralouphie/getallheaders", diff --git a/resources/views/index/index.blade.php b/resources/views/index/index.blade.php index 1409f8f6b2f3..644a663e95d7 100644 --- a/resources/views/index/index.blade.php +++ b/resources/views/index/index.blade.php @@ -8,6 +8,7 @@ +