diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index 7825d8f939f3..ff8a4ae98a25 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -7,6 +7,9 @@ name: phpunit jobs: phpunit: runs-on: ubuntu-latest + strategy: + matrix: + php-versions: ['7.3', '7.4'] env: DB_DATABASE1: ninja DB_USERNAME1: root diff --git a/app/Console/Commands/CreateTestData.php b/app/Console/Commands/CreateTestData.php index 46bf28984805..8d4ab8041e4a 100644 --- a/app/Console/Commands/CreateTestData.php +++ b/app/Console/Commands/CreateTestData.php @@ -26,6 +26,7 @@ use App\Models\PaymentType; use App\Models\Product; use App\Models\User; use App\Repositories\InvoiceRepository; +use App\Utils\Ninja; use App\Utils\Traits\GeneratesCounter; use App\Utils\Traits\MakesHash; use Carbon\Carbon; @@ -510,7 +511,7 @@ class CreateTestData extends Command } //@todo this slow things down, but gives us PDFs of the invoices for inspection whilst debugging. - event(new InvoiceWasCreated($invoice, $invoice->company)); + event(new InvoiceWasCreated($invoice, $invoice->company, Ninja::eventVars())); } private function createCredit($client) diff --git a/app/Console/Commands/DemoMode.php b/app/Console/Commands/DemoMode.php index 286a121fe394..e4eaf0cda946 100644 --- a/app/Console/Commands/DemoMode.php +++ b/app/Console/Commands/DemoMode.php @@ -12,6 +12,7 @@ use App\Models\Country; use App\Models\Product; use App\Models\User; use App\Repositories\InvoiceRepository; +use App\Utils\Ninja; use App\Utils\Traits\GeneratesCounter; use App\Utils\Traits\MakesHash; use Carbon\Carbon; @@ -362,7 +363,7 @@ class DemoMode extends Command } //@todo this slow things down, but gives us PDFs of the invoices for inspection whilst debugging. - event(new InvoiceWasCreated($invoice, $invoice->company)); + event(new InvoiceWasCreated($invoice, $invoice->company, Ninja::eventVars())); } private function createCredit($client) diff --git a/app/Console/Commands/TestData/CreateTestCreditJob.php b/app/Console/Commands/TestData/CreateTestCreditJob.php index 47b72d75d211..471e652b3335 100644 --- a/app/Console/Commands/TestData/CreateTestCreditJob.php +++ b/app/Console/Commands/TestData/CreateTestCreditJob.php @@ -22,6 +22,7 @@ use App\Models\Client; use App\Models\Payment; use App\Models\PaymentType; use App\Models\Product; +use App\Utils\Ninja; use App\Utils\Traits\MakesHash; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; @@ -92,7 +93,7 @@ class CreateTestCreditJob implements ShouldQueue $credit->save(); - event(new CreateCreditInvitation($credit)); + event(new CreateCreditInvitation($credit, $credit->company, Ninja::eventVars())); } diff --git a/app/Console/Commands/TestData/CreateTestInvoiceJob.php b/app/Console/Commands/TestData/CreateTestInvoiceJob.php index 9ad587373a33..7e64d4e1150d 100644 --- a/app/Console/Commands/TestData/CreateTestInvoiceJob.php +++ b/app/Console/Commands/TestData/CreateTestInvoiceJob.php @@ -21,6 +21,7 @@ use App\Models\Client; use App\Models\Payment; use App\Models\PaymentType; use App\Models\Product; +use App\Utils\Ninja; use App\Utils\Traits\MakesHash; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; @@ -111,13 +112,13 @@ class CreateTestInvoiceJob implements ShouldQueue $payment->invoices()->save($invoice); - event(new PaymentWasCreated($payment, $payment->company)); + event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars())); $payment->service()->updateInvoicePayment(); //UpdateInvoicePayment::dispatchNow($payment, $payment->company); } //@todo this slow things down, but gives us PDFs of the invoices for inspection whilst debugging. - event(new InvoiceWasCreated($invoice, $invoice->company)); + event(new InvoiceWasCreated($invoice, $invoice->company, Ninja::eventVars())); } diff --git a/app/Events/Account/AccountCreated.php b/app/Events/Account/AccountCreated.php index 463050f8d2f3..85aa5f373d74 100644 --- a/app/Events/Account/AccountCreated.php +++ b/app/Events/Account/AccountCreated.php @@ -33,15 +33,18 @@ class AccountCreated public $user; public $company; + + public $event_vars; /** * Create a new event instance. * * @return void */ - public function __construct($user, $company) + public function __construct($user, $company, $event_vars) { $this->user = $user; $this->company = $company; + $this->event_vars = $event_vars; } /** diff --git a/app/Events/Client/ClientWasArchived.php b/app/Events/Client/ClientWasArchived.php index 550b7516ea48..a2b81637e55a 100644 --- a/app/Events/Client/ClientWasArchived.php +++ b/app/Events/Client/ClientWasArchived.php @@ -34,15 +34,20 @@ class ClientWasArchived public $client; public $company; + + public $event_vars; + /** * Create a new event instance. * * @param Client $client */ - public function __construct(Client $client, Company $company) + public function __construct(Client $client, Company $company, array $event_vars) { $this->client = $client; $this->company = $company; + $this->event_vars = $event_vars; + } /** diff --git a/app/Events/Client/ClientWasCreated.php b/app/Events/Client/ClientWasCreated.php index 4e1a50044c34..79434bcde5d6 100644 --- a/app/Events/Client/ClientWasCreated.php +++ b/app/Events/Client/ClientWasCreated.php @@ -28,14 +28,19 @@ class ClientWasCreated public $client; public $company; + + public $event_vars; + /** * Create a new event instance. * * @param Client $client */ - public function __construct(Client $client, Company $company) + public function __construct(Client $client, Company $company, array $event_vars) { $this->client = $client; $this->company = $company; + $this->event_vars = $event_vars; + } } diff --git a/app/Events/Client/ClientWasDeleted.php b/app/Events/Client/ClientWasDeleted.php index e788f7ace92f..70b9c4027128 100644 --- a/app/Events/Client/ClientWasDeleted.php +++ b/app/Events/Client/ClientWasDeleted.php @@ -27,14 +27,19 @@ class ClientWasDeleted public $client; public $company; + + public $event_vars; + /** * Create a new event instance. * * @param Client $client */ - public function __construct(Client $client, Company $company) + public function __construct(Client $client, Company $company, array $event_vars) { $this->client = $client; $this->company = $company; + $this->event_vars = $event_vars; + } } diff --git a/app/Events/Client/ClientWasRestored.php b/app/Events/Client/ClientWasRestored.php index 81a3d1a14e67..0bd4e9945b0c 100644 --- a/app/Events/Client/ClientWasRestored.php +++ b/app/Events/Client/ClientWasRestored.php @@ -27,14 +27,19 @@ class ClientWasRestored public $client; public $company; + + public $event_vars; + /** * Create a new event instance. * * @param Client $client */ - public function __construct(Client $client, Company $company) + public function __construct(Client $client, Company $company, array $event_vars) { $this->client = $client; $this->company = $company; + $this->event_vars = $event_vars; + } } diff --git a/app/Events/Client/ClientWasUpdated.php b/app/Events/Client/ClientWasUpdated.php index e761a7148ab4..0c01aa2e80a8 100644 --- a/app/Events/Client/ClientWasUpdated.php +++ b/app/Events/Client/ClientWasUpdated.php @@ -27,14 +27,19 @@ class ClientWasUpdated public $client; public $company; + + public $event_vars; + /** * Create a new event instance. * * @param Client $client */ - public function __construct(Client $client, Company $company) + public function __construct(Client $client, Company $company, array $event_vars) { $this->client = $client; $this->company = $company; + $this->event_vars = $event_vars; + } } diff --git a/app/Events/Company/CompanyWasDeleted.php b/app/Events/Company/CompanyDocumentsDeleted.php similarity index 76% rename from app/Events/Company/CompanyWasDeleted.php rename to app/Events/Company/CompanyDocumentsDeleted.php index 60a6172bff86..22a6d84717f1 100644 --- a/app/Events/Company/CompanyWasDeleted.php +++ b/app/Events/Company/CompanyDocumentsDeleted.php @@ -1,4 +1,13 @@ client_contact = $client_contact; $this->company = $company; + $this->event_vars = $event_vars; } /** diff --git a/app/Events/Credit/CreditWasCreated.php b/app/Events/Credit/CreditWasCreated.php index 6e24a0c4408c..0049c682685d 100644 --- a/app/Events/Credit/CreditWasCreated.php +++ b/app/Events/Credit/CreditWasCreated.php @@ -1,4 +1,14 @@ credit = $credit; $this->company = $company; + $this->event_vars = $event_vars; } } diff --git a/app/Events/Credit/CreditWasEmailed.php b/app/Events/Credit/CreditWasEmailed.php index 0cddca9deefc..b958ad69b9dd 100644 --- a/app/Events/Credit/CreditWasEmailed.php +++ b/app/Events/Credit/CreditWasEmailed.php @@ -1,4 +1,13 @@ credit = $credit; $this->company = $company; + $this->event_vars = $event_vars; } } diff --git a/app/Events/Credit/CreditWasEmailedAndFailed.php b/app/Events/Credit/CreditWasEmailedAndFailed.php index a780282a5752..bc663dedb70d 100644 --- a/app/Events/Credit/CreditWasEmailedAndFailed.php +++ b/app/Events/Credit/CreditWasEmailedAndFailed.php @@ -1,4 +1,13 @@ credit = $credit; $this->company = $company; $this->errors = $errors; + + $this->event_vars = $event_vars; } } diff --git a/app/Events/Credit/CreditWasMarkedSent.php b/app/Events/Credit/CreditWasMarkedSent.php index 2b38ae04c860..ab792c227b51 100644 --- a/app/Events/Credit/CreditWasMarkedSent.php +++ b/app/Events/Credit/CreditWasMarkedSent.php @@ -1,4 +1,14 @@ credit = $credit; $this->company = $company; + $this->event_vars = $event_vars; } } diff --git a/app/Events/Credit/CreditWasUpdated.php b/app/Events/Credit/CreditWasUpdated.php index 20ac02e1e777..2a1dc4220d58 100644 --- a/app/Events/Credit/CreditWasUpdated.php +++ b/app/Events/Credit/CreditWasUpdated.php @@ -1,4 +1,13 @@ invoice = $credit; + $this->credit = $credit; $this->company = $company; + $this->event_vars = $event_vars; } } diff --git a/app/Events/Design/DesignWasArchived.php b/app/Events/Design/DesignWasArchived.php index 8207d1671a84..a3ae1f75f7a2 100644 --- a/app/Events/Design/DesignWasArchived.php +++ b/app/Events/Design/DesignWasArchived.php @@ -11,14 +11,15 @@ namespace App\Events\Design; +use App\Models\Company; use App\Models\Design; use Illuminate\Broadcasting\Channel; -use Illuminate\Queue\SerializesModels; -use Illuminate\Broadcasting\PrivateChannel; -use Illuminate\Broadcasting\PresenceChannel; -use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Broadcasting\InteractsWithSockets; +use Illuminate\Broadcasting\PresenceChannel; +use Illuminate\Broadcasting\PrivateChannel; use Illuminate\Contracts\Broadcasting\ShouldBroadcast; +use Illuminate\Foundation\Events\Dispatchable; +use Illuminate\Queue\SerializesModels; /** * Class DesignWasArchived. @@ -33,16 +34,20 @@ class DesignWasArchived public $design; public $company; + + public $event_vars; /** * Create a new event instance. * * @param Design $design */ - public function __construct(Design $design, $company) + public function __construct(Design $design, Company $company, array $event_vars) { $this->design = $design; $this->company = $company; + + $this->event_vars = $event_vars; } /** diff --git a/app/Events/Design/DesignWasCreated.php b/app/Events/Design/DesignWasCreated.php index 9e2b0bed6998..339a7fd7d5dd 100644 --- a/app/Events/Design/DesignWasCreated.php +++ b/app/Events/Design/DesignWasCreated.php @@ -11,6 +11,7 @@ namespace App\Events\Design; +use App\Models\Company; use App\Models\Design; use Illuminate\Queue\SerializesModels; @@ -27,16 +28,20 @@ class DesignWasCreated public $design; public $company; + + public $event_vars; /** * Create a new event instance. * * @param Design $design */ - public function __construct(Design $design, $company) + public function __construct(Design $design, Company $company, array $event_vars) { $this->design = $design; $this->company = $company; + + $this->event_vars = $event_vars; } /** diff --git a/app/Events/Design/DesignWasDeleted.php b/app/Events/Design/DesignWasDeleted.php index 7944333d4bf7..99a24d502595 100644 --- a/app/Events/Design/DesignWasDeleted.php +++ b/app/Events/Design/DesignWasDeleted.php @@ -11,6 +11,7 @@ namespace App\Events\Design; +use App\Models\Company; use App\Models\Design; use Illuminate\Queue\SerializesModels; @@ -27,16 +28,20 @@ class DesignWasDeleted public $design; public $company; + + public $event_vars; /** * Create a new event instance. * * @param Design $design */ - public function __construct(Design $design, $company) + public function __construct(Design $design, Company $company, array $event_vars) { $this->design = $design; $this->company = $company; + + $this->event_vars = $event_vars; } /** diff --git a/app/Events/Design/DesignWasRestored.php b/app/Events/Design/DesignWasRestored.php index 3de5053c3b8c..42ada223ec1f 100644 --- a/app/Events/Design/DesignWasRestored.php +++ b/app/Events/Design/DesignWasRestored.php @@ -11,6 +11,7 @@ namespace App\Events\Design; +use App\Models\Company; use App\Models\Design; use Illuminate\Queue\SerializesModels; @@ -20,23 +21,27 @@ use Illuminate\Queue\SerializesModels; class DesignWasRestored { use SerializesModels; - + /** * @var Design */ public $design; public $company; + + public $event_vars; /** * Create a new event instance. * * @param Design $design */ - public function __construct(Design $design, $company) + public function __construct(Design $design, Company $company, array $event_vars) { $this->design = $design; $this->company = $company; + + $this->event_vars = $event_vars; } /** diff --git a/app/Events/Design/DesignWasUpdated.php b/app/Events/Design/DesignWasUpdated.php index 25bd8f164833..8b5f10ea324e 100644 --- a/app/Events/Design/DesignWasUpdated.php +++ b/app/Events/Design/DesignWasUpdated.php @@ -11,6 +11,7 @@ namespace App\Events\Design; +use App\Models\Company; use App\Models\Design; use Illuminate\Queue\SerializesModels; @@ -27,18 +28,21 @@ class DesignWasUpdated public $design; public $company; + + public $event_vars; /** * Create a new event instance. * * @param Design $design */ - public function __construct(Design $design, $company) + public function __construct(Design $design, Company $company, array $event_vars) { $this->design = $design; $this->company = $company; - } + $this->event_vars = $event_vars; + } /** * Get the channels the event should broadcast on. * diff --git a/app/Events/Document/DocumentWasArchived.php b/app/Events/Document/DocumentWasArchived.php index 70cb9d524750..ec6651f43af9 100644 --- a/app/Events/Document/DocumentWasArchived.php +++ b/app/Events/Document/DocumentWasArchived.php @@ -11,14 +11,15 @@ namespace App\Events\Document; +use App\Models\Company; use App\Models\Document; use Illuminate\Broadcasting\Channel; -use Illuminate\Queue\SerializesModels; -use Illuminate\Broadcasting\PrivateChannel; -use Illuminate\Broadcasting\PresenceChannel; -use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Broadcasting\InteractsWithSockets; +use Illuminate\Broadcasting\PresenceChannel; +use Illuminate\Broadcasting\PrivateChannel; use Illuminate\Contracts\Broadcasting\ShouldBroadcast; +use Illuminate\Foundation\Events\Dispatchable; +use Illuminate\Queue\SerializesModels; /** * Class DocumentWasArchived. @@ -33,15 +34,19 @@ class DocumentWasArchived public $document; public $company; + + public $event_vars; + /** * Create a new event instance. * * @param Document $document */ - public function __construct(Document $document, $company) + public function __construct(Document $document, Company $company, array $event_vars) { $this->document = $document; $this->company = $company; + $this->event_vars = $event_vars; } /** diff --git a/app/Events/Document/DocumentWasCreated.php b/app/Events/Document/DocumentWasCreated.php index caf45ac264f1..df66626d50f7 100644 --- a/app/Events/Document/DocumentWasCreated.php +++ b/app/Events/Document/DocumentWasCreated.php @@ -11,6 +11,7 @@ namespace App\Events\Document; +use App\Models\Company; use App\Models\Document; use Illuminate\Queue\SerializesModels; @@ -27,14 +28,18 @@ class DocumentWasCreated public $document; public $company; + + public $event_vars; + /** * Create a new event instance. * * @param Document $document */ - public function __construct(Document $document, $company) + public function __construct(Document $document, Company $company, array $event_vars) { $this->document = $document; $this->company = $company; + $this->event_vars = $event_vars; } } diff --git a/app/Events/Document/DocumentWasDeleted.php b/app/Events/Document/DocumentWasDeleted.php index 3d0f9f4357a1..e0e6ed15fd3f 100644 --- a/app/Events/Document/DocumentWasDeleted.php +++ b/app/Events/Document/DocumentWasDeleted.php @@ -11,6 +11,7 @@ namespace App\Events\Document; +use App\Models\Company; use App\Models\Document; use Illuminate\Queue\SerializesModels; @@ -27,14 +28,18 @@ class DocumentWasDeleted public $document; public $company; + + public $event_vars; + /** * Create a new event instance. * * @param Document $document */ - public function __construct(Document $document, $company) + public function __construct(Document $document, Company $company, array $event_vars) { $this->document = $document; $this->company = $company; + $this->event_vars = $event_vars; } } diff --git a/app/Events/Document/DocumentWasRestored.php b/app/Events/Document/DocumentWasRestored.php index ab138a647857..c0c1624ee50f 100644 --- a/app/Events/Document/DocumentWasRestored.php +++ b/app/Events/Document/DocumentWasRestored.php @@ -11,6 +11,7 @@ namespace App\Events\Document; +use App\Models\Company; use App\Models\Document; use Illuminate\Queue\SerializesModels; @@ -27,14 +28,18 @@ class DocumentWasRestored public $document; public $company; + + public $event_vars; + /** * Create a new event instance. * * @param Document $document */ - public function __construct(Document $document, $company) + public function __construct(Document $document, Company $company, array $event_vars) { $this->document = $document; $this->company = $company; + $this->event_vars = $event_vars; } } diff --git a/app/Events/Document/DocumentWasUpdated.php b/app/Events/Document/DocumentWasUpdated.php index 1797b61353bf..60cc8adc44a6 100644 --- a/app/Events/Document/DocumentWasUpdated.php +++ b/app/Events/Document/DocumentWasUpdated.php @@ -11,6 +11,7 @@ namespace App\Events\Document; +use App\Models\Company; use App\Models\Document; use Illuminate\Queue\SerializesModels; @@ -27,14 +28,18 @@ class DocumentWasUpdated public $document; public $company; + + public $event_vars; + /** * Create a new event instance. * * @param Document $document */ - public function __construct(Document $document, $company) + public function __construct(Document $document, Company $company, array $event_vars) { $this->document = $document; $this->company = $company; + $this->event_vars = $event_vars; } } diff --git a/app/Events/Expense/ExpenseWasArchived.php b/app/Events/Expense/ExpenseWasArchived.php index 195daa295a4c..262b2942e61b 100644 --- a/app/Events/Expense/ExpenseWasArchived.php +++ b/app/Events/Expense/ExpenseWasArchived.php @@ -11,6 +11,7 @@ namespace App\Events\Expense; +use App\Models\Company; use App\Models\Expense; use Illuminate\Queue\SerializesModels; @@ -27,14 +28,17 @@ class ExpenseWasArchived public $expense; public $company; + + public $event_vars; /** * Create a new event instance. * * @param Expense $expense */ - public function __construct(Expense $expense, $company) + public function __construct(Expense $expense, Company $company, array $event_vars) { $this->expense = $expense; $this->company = $company; + $this->event_vars = $event_vars; } } diff --git a/app/Events/Expense/ExpenseWasCreated.php b/app/Events/Expense/ExpenseWasCreated.php index 5cb4351deaa2..f5bf2557b886 100644 --- a/app/Events/Expense/ExpenseWasCreated.php +++ b/app/Events/Expense/ExpenseWasCreated.php @@ -11,6 +11,7 @@ namespace App\Events\Expense; +use App\Models\Company; use App\Models\Expense; use Illuminate\Queue\SerializesModels; @@ -27,14 +28,17 @@ class ExpenseWasCreated public $expense; public $company; + + public $event_vars; /** * Create a new event instance. * * @param Expense $expense */ - public function __construct(Expense $expense, $company) + public function __construct(Expense $expense, Company $company, array $event_vars) { $this->expense = $expense; $this->company = $company; + $this->event_vars = $event_vars; } } diff --git a/app/Events/Expense/ExpenseWasDeleted.php b/app/Events/Expense/ExpenseWasDeleted.php index d79d78498d90..96a5acd0aa0e 100644 --- a/app/Events/Expense/ExpenseWasDeleted.php +++ b/app/Events/Expense/ExpenseWasDeleted.php @@ -11,6 +11,7 @@ namespace App\Events\Expense; +use App\Models\Company; use App\Models\Expense; use Illuminate\Queue\SerializesModels; @@ -27,14 +28,17 @@ class ExpenseWasDeleted public $expense; public $company; + + public $event_vars; /** * Create a new event instance. * * @param Expense $expense */ - public function __construct(Expense $expense, $company) + public function __construct(Expense $expense, Company $company, array $event_vars) { $this->expense = $expense; $this->company = $company; + $this->event_vars = $event_vars; } } diff --git a/app/Events/Expense/ExpenseWasRestored.php b/app/Events/Expense/ExpenseWasRestored.php index 84f8843ae48b..e3c54a481aeb 100644 --- a/app/Events/Expense/ExpenseWasRestored.php +++ b/app/Events/Expense/ExpenseWasRestored.php @@ -11,6 +11,7 @@ namespace App\Events\Expense; +use App\Models\Company; use App\Models\Expense; use Illuminate\Queue\SerializesModels; @@ -27,14 +28,17 @@ class ExpenseWasRestored public $expense; public $company; + + public $event_vars; /** * Create a new event instance. * * @param Expense $expense */ - public function __construct(Expense $expense, $company) + public function __construct(Expense $expense, Company $company, array $event_vars) { $this->expense = $expense; $this->company = $company; + $this->event_vars = $event_vars; } } diff --git a/app/Events/Expense/ExpenseWasUpdated.php b/app/Events/Expense/ExpenseWasUpdated.php index 6a1029b7266a..214b1f763212 100644 --- a/app/Events/Expense/ExpenseWasUpdated.php +++ b/app/Events/Expense/ExpenseWasUpdated.php @@ -11,6 +11,7 @@ namespace App\Events\Expense; +use App\Models\Company; use App\Models\Expense; use Illuminate\Queue\SerializesModels; @@ -27,14 +28,17 @@ class ExpenseWasUpdated public $expense; public $company; + + public $event_vars; /** * Create a new event instance. * * @param Expense $expense */ - public function __construct(Expense $expense, $company) + public function __construct(Expense $expense, Company $company, array $event_vars) { $this->expense = $expense; $this->company = $company; + $this->event_vars = $event_vars; } } diff --git a/app/Events/Invoice/InvoiceWasArchived.php b/app/Events/Invoice/InvoiceWasArchived.php index 7b59934ff42d..cce42ef01c1a 100644 --- a/app/Events/Invoice/InvoiceWasArchived.php +++ b/app/Events/Invoice/InvoiceWasArchived.php @@ -11,6 +11,7 @@ namespace App\Events\Invoice; +use App\Models\Company; use App\Models\Invoice; use Illuminate\Queue\SerializesModels; @@ -27,14 +28,17 @@ class InvoiceWasArchived public $invoice; public $company; + + public $event_vars; /** * Create a new event instance. * * @param Invoice $invoice */ - public function __construct(Invoice $invoice, $company) + public function __construct(Invoice $invoice, Company $company, array $event_vars) { $this->invoice = $invoice; $this->company = $company; + $this->event_vars = $event_vars; } } diff --git a/app/Events/Invoice/InvoiceWasCancelled.php b/app/Events/Invoice/InvoiceWasCancelled.php index b6ce0f72db87..43259dfdca1c 100644 --- a/app/Events/Invoice/InvoiceWasCancelled.php +++ b/app/Events/Invoice/InvoiceWasCancelled.php @@ -11,6 +11,7 @@ namespace App\Events\Invoice; +use App\Models\Company; use App\Models\Invoice; use Illuminate\Queue\SerializesModels; @@ -27,14 +28,17 @@ class InvoiceWasCancelled public $invoice; public $company; + + public $event_vars; /** * Create a new event instance. * * @param Invoice $invoice */ - public function __construct(Invoice $invoice, $company) + public function __construct(Invoice $invoice, Company $company, array $event_vars) { $this->invoice = $invoice; $this->company = $company; + $this->event_vars = $event_vars; } } diff --git a/app/Events/Invoice/InvoiceWasCreated.php b/app/Events/Invoice/InvoiceWasCreated.php index 5b2d1c023067..9708a1613b79 100644 --- a/app/Events/Invoice/InvoiceWasCreated.php +++ b/app/Events/Invoice/InvoiceWasCreated.php @@ -28,14 +28,17 @@ class InvoiceWasCreated public $invoice; public $company; + + public $event_vars; /** * Create a new event instance. * * @param Invoice $invoice */ - public function __construct(Invoice $invoice, Company $company) + public function __construct(Invoice $invoice, Company $company, array $event_vars) { $this->invoice = $invoice; $this->company = $company; + $this->event_vars = $event_vars; } } diff --git a/app/Events/Invoice/InvoiceWasDeleted.php b/app/Events/Invoice/InvoiceWasDeleted.php index 3515d916e2f5..a3691c3633d9 100644 --- a/app/Events/Invoice/InvoiceWasDeleted.php +++ b/app/Events/Invoice/InvoiceWasDeleted.php @@ -11,6 +11,7 @@ namespace App\Events\Invoice; +use App\Models\Company; use App\Models\Invoice; use Illuminate\Queue\SerializesModels; @@ -27,14 +28,17 @@ class InvoiceWasDeleted public $invoice; public $company; + + public $event_vars; /** * Create a new event instance. * * @param Invoice $invoice */ - public function __construct(Invoice $invoice, $company) + public function __construct(Invoice $invoice, Company $company, array $event_vars) { $this->invoice = $invoice; $this->company = $company; + $this->event_vars = $event_vars; } } diff --git a/app/Events/Invoice/InvoiceWasEmailed.php b/app/Events/Invoice/InvoiceWasEmailed.php index 8e31ccfe7a79..19f88da296e5 100644 --- a/app/Events/Invoice/InvoiceWasEmailed.php +++ b/app/Events/Invoice/InvoiceWasEmailed.php @@ -11,6 +11,7 @@ namespace App\Events\Invoice; +use App\Models\Company; use App\Models\InvoiceInvitation; use Illuminate\Queue\SerializesModels; @@ -27,14 +28,17 @@ class InvoiceWasEmailed public $invitation; public $company; + + public $event_vars; /** * Create a new event instance. * * @param Invoice $invoice */ - public function __construct(InvoiceInvitation $invitation, $company) + public function __construct(InvoiceInvitation $invitation, Company $company, array $event_vars) { $this->invitation = $invitation; $this->company = $company; + $this->event_vars = $event_vars; } } diff --git a/app/Events/Invoice/InvoiceWasEmailedAndFailed.php b/app/Events/Invoice/InvoiceWasEmailedAndFailed.php index 26a909914008..b81b900c4c3d 100644 --- a/app/Events/Invoice/InvoiceWasEmailedAndFailed.php +++ b/app/Events/Invoice/InvoiceWasEmailedAndFailed.php @@ -11,6 +11,7 @@ namespace App\Events\Invoice; +use App\Models\Company; use App\Models\Invoice; use Illuminate\Queue\SerializesModels; @@ -31,19 +32,22 @@ class InvoiceWasEmailedAndFailed */ public $errors; - public $company; + + public $event_vars; /** * Create a new event instance. * * @param Invoice $invoice */ - public function __construct(Invoice $invoice, $company, array $errors) + public function __construct(Invoice $invoice, Company $company, array $errors, array $event_vars) { $this->invoice = $invoice; $this->company = $company; $this->errors = $errors; + + $this->event_vars = $event_vars; } } diff --git a/app/Events/Invoice/InvoiceWasMarkedSent.php b/app/Events/Invoice/InvoiceWasMarkedSent.php index 350204966e08..037b3703844a 100644 --- a/app/Events/Invoice/InvoiceWasMarkedSent.php +++ b/app/Events/Invoice/InvoiceWasMarkedSent.php @@ -29,15 +29,16 @@ class InvoiceWasMarkedSent public $company; + public $event_vars; /** * Create a new event instance. * * @param Invoice $invoice */ - public function __construct(Invoice $invoice, Company $company) + public function __construct(Invoice $invoice, Company $company, array $event_vars) { $this->invoice = $invoice; - $this->company = $company; + $this->event_vars = $event_vars; } } diff --git a/app/Events/Invoice/InvoiceWasPaid.php b/app/Events/Invoice/InvoiceWasPaid.php index 309f72bf9760..1d7b852dde6d 100644 --- a/app/Events/Invoice/InvoiceWasPaid.php +++ b/app/Events/Invoice/InvoiceWasPaid.php @@ -29,14 +29,16 @@ class InvoiceWasPaid public $company; + public $event_vars; /** * Create a new event instance. * * @param Invoice $invoice */ - public function __construct(Invoice $invoice, Company $company) + public function __construct(Invoice $invoice, Company $company, array $event_vars) { $this->invoice = $invoice; $this->company = $company; + $this->event_vars = $event_vars; } } diff --git a/app/Events/Invoice/InvoiceWasRestored.php b/app/Events/Invoice/InvoiceWasRestored.php index bd0592a932df..4204d7c93bca 100644 --- a/app/Events/Invoice/InvoiceWasRestored.php +++ b/app/Events/Invoice/InvoiceWasRestored.php @@ -11,6 +11,7 @@ namespace App\Events\Invoice; +use App\Models\Company; use App\Models\Invoice; use Illuminate\Queue\SerializesModels; @@ -29,16 +30,19 @@ class InvoiceWasRestored public $fromDeleted; public $company; + + public $event_vars; /** * Create a new event instance. * * @param Invoice $invoice * @param $fromDeleted */ - public function __construct(Invoice $invoice, $fromDeleted, $company) + public function __construct(Invoice $invoice, $fromDeleted, Company $company, array $event_vars) { $this->invoice = $invoice; $this->fromDeleted = $fromDeleted; $this->company = $company; + $this->event_vars = $event_vars; } } diff --git a/app/Events/Invoice/InvoiceWasReversed.php b/app/Events/Invoice/InvoiceWasReversed.php index 3e76f334bc49..330cc859c310 100644 --- a/app/Events/Invoice/InvoiceWasReversed.php +++ b/app/Events/Invoice/InvoiceWasReversed.php @@ -11,6 +11,7 @@ namespace App\Events\Invoice; +use App\Models\Company; use App\Models\Invoice; use Illuminate\Queue\SerializesModels; @@ -27,14 +28,17 @@ class InvoiceWasReversed public $invoice; public $company; + + public $event_vars; /** * Create a new event instance. * * @param Invoice $invoice */ - public function __construct(Invoice $invoice, $company) + public function __construct(Invoice $invoice, Company $company, array $event_vars) { $this->invoice = $invoice; $this->company = $company; + $this->event_vars = $event_vars; } } diff --git a/app/Events/Invoice/InvoiceWasUpdated.php b/app/Events/Invoice/InvoiceWasUpdated.php index d9bd7b946e23..b3da877b4e47 100644 --- a/app/Events/Invoice/InvoiceWasUpdated.php +++ b/app/Events/Invoice/InvoiceWasUpdated.php @@ -28,14 +28,17 @@ class InvoiceWasUpdated public $invoice; public $company; + + public $event_vars; /** * Create a new event instance. * * @param Invoice $invoice */ - public function __construct(Invoice $invoice, Company $company) + public function __construct(Invoice $invoice, Company $company, array $event_vars) { $this->invoice = $invoice; $this->company = $company; + $this->event_vars = $event_vars; } } diff --git a/app/Events/Misc/InvitationWasViewed.php b/app/Events/Misc/InvitationWasViewed.php index 25b8dffe15be..9508bb6ef7f0 100644 --- a/app/Events/Misc/InvitationWasViewed.php +++ b/app/Events/Misc/InvitationWasViewed.php @@ -29,15 +29,18 @@ class InvitationWasViewed public $entity; public $company; + + public $event_vars; /** * Create a new event instance. * * @param Invoice $invoice */ - public function __construct($entity, $invitation, $company) + public function __construct($entity, $invitation, $company, $event_vars) { $this->entity = $entity; $this->invitation = $invitation; $this->company = $company; + $this->event_vars = $event_vars; } } diff --git a/app/Events/Payment/Methods/MethodDeleted.php b/app/Events/Payment/Methods/MethodDeleted.php index 508f1d86be82..6f83d2be2e0c 100644 --- a/app/Events/Payment/Methods/MethodDeleted.php +++ b/app/Events/Payment/Methods/MethodDeleted.php @@ -1,8 +1,18 @@ payment_method = $payment_method; $this->company = $company; + $this->event_vars = $event_vars; } /** diff --git a/app/Events/Payment/PaymentCompleted.php b/app/Events/Payment/PaymentCompleted.php index 6476dc2919d3..8666891ecf15 100644 --- a/app/Events/Payment/PaymentCompleted.php +++ b/app/Events/Payment/PaymentCompleted.php @@ -11,6 +11,7 @@ namespace App\Events\Payment; +use App\Models\Company; use App\Models\Payment; use Illuminate\Queue\SerializesModels; @@ -26,15 +27,18 @@ class PaymentCompleted */ public $payment; - public $company + public $company; + + public $event_vars; /** * Create a new event instance. * * @param Payment $payment */ - public function __construct(Payment $payment, $company) + public function __construct(Payment $payment, Company $company, array $event_vars) { $this->payment = $payment; $this->company = $company; + $this->event_vars = $event_vars; } } diff --git a/app/Events/Payment/PaymentFailed.php b/app/Events/Payment/PaymentFailed.php index f39b7ce953f8..ba7312e1f3c9 100644 --- a/app/Events/Payment/PaymentFailed.php +++ b/app/Events/Payment/PaymentFailed.php @@ -11,6 +11,7 @@ namespace App\Events\Payment; +use App\Models\Company; use App\Models\Payment; use Illuminate\Queue\SerializesModels; @@ -21,20 +22,24 @@ class PaymentFailed { use SerializesModels; + /** * @var Payment */ public $payment; - public $company + public $company; + + public $event_vars; /** * Create a new event instance. * * @param Payment $payment */ - public function __construct(Payment $payment, $company) + public function __construct(Payment $payment, Company $company, array $event_vars) { $this->payment = $payment; $this->company = $company; + $this->event_vars = $event_vars; } } diff --git a/app/Events/Payment/PaymentWasArchived.php b/app/Events/Payment/PaymentWasArchived.php index 3b05d9ea8e60..a44b8dadb730 100644 --- a/app/Events/Payment/PaymentWasArchived.php +++ b/app/Events/Payment/PaymentWasArchived.php @@ -11,6 +11,7 @@ namespace App\Events\Payment; +use App\Models\Company; use App\Models\Payment; use Illuminate\Queue\SerializesModels; @@ -21,20 +22,24 @@ class PaymentWasArchived { use SerializesModels; + /** * @var Payment */ public $payment; - public $company + public $company; + + public $event_vars; /** * Create a new event instance. * * @param Payment $payment */ - public function __construct(Payment $payment, $company) + public function __construct(Payment $payment, Company $company, array $event_vars) { $this->payment = $payment; $this->company = $company; + $this->event_vars = $event_vars; } } diff --git a/app/Events/Payment/PaymentWasCreated.php b/app/Events/Payment/PaymentWasCreated.php index 92940cd80234..904230c78ad1 100644 --- a/app/Events/Payment/PaymentWasCreated.php +++ b/app/Events/Payment/PaymentWasCreated.php @@ -23,19 +23,22 @@ class PaymentWasCreated use SerializesModels; /** - * @var array $payment + * @var Payment */ public $payment; public $company; + + public $event_vars; /** * Create a new event instance. * * @param Payment $payment */ - public function __construct(Payment $payment, Company $company) + public function __construct(Payment $payment, Company $company, array $event_vars) { $this->payment = $payment; $this->company = $company; + $this->event_vars = $event_vars; } } diff --git a/app/Events/Payment/PaymentWasDeleted.php b/app/Events/Payment/PaymentWasDeleted.php index 0fdb7f228bb6..c0a60bfaa9ec 100644 --- a/app/Events/Payment/PaymentWasDeleted.php +++ b/app/Events/Payment/PaymentWasDeleted.php @@ -11,6 +11,7 @@ namespace App\Events\Payment; +use App\Models\Company; use App\Models\Payment; use Illuminate\Queue\SerializesModels; @@ -21,20 +22,24 @@ class PaymentWasDeleted { use SerializesModels; + /** * @var Payment */ public $payment; - public $company + public $company; + + public $event_vars; /** * Create a new event instance. * * @param Payment $payment */ - public function __construct(Payment $payment, $company) + public function __construct(Payment $payment, Company $company, array $event_vars) { $this->payment = $payment; $this->company = $company; + $this->event_vars = $event_vars; } } diff --git a/app/Events/Payment/PaymentWasEmailed.php b/app/Events/Payment/PaymentWasEmailed.php index 9f165d206052..575801866849 100644 --- a/app/Events/Payment/PaymentWasEmailed.php +++ b/app/Events/Payment/PaymentWasEmailed.php @@ -11,6 +11,7 @@ namespace App\Events\Payment; +use App\Models\Company; use App\Models\Payment; use Illuminate\Queue\SerializesModels; @@ -21,20 +22,24 @@ class PaymentWasEmailed { use SerializesModels; + /** * @var Payment */ public $payment; - public $company + public $company; + + public $event_vars; /** * Create a new event instance. * * @param Payment $payment */ - public function __construct(Payment $payment, $company) + public function __construct(Payment $payment, Company $company, array $event_vars) { $this->payment = $payment; $this->company = $company; + $this->event_vars = $event_vars; } } diff --git a/app/Events/Payment/PaymentWasEmailedAndFailed.php b/app/Events/Payment/PaymentWasEmailedAndFailed.php index c4059cec2de8..a9b83f7ccca6 100644 --- a/app/Events/Payment/PaymentWasEmailedAndFailed.php +++ b/app/Events/Payment/PaymentWasEmailedAndFailed.php @@ -26,23 +26,24 @@ class PaymentWasEmailedAndFailed */ public $payment; - /** - * @var array - */ public $errors; public $company; + + public $event_vars; /** * PaymentWasEmailedAndFailed constructor. * @param Payment $payment * @param array $errors */ - public function __construct(Payment $payment, $company, array $errors) + public function __construct(Payment $payment, $company, array $errors, array $event_vars) { $this->payment = $payment; $this->errors = $errors; $this->company = $company; + + $this->event_vars = $event_vars; } } diff --git a/app/Events/Payment/PaymentWasRefunded.php b/app/Events/Payment/PaymentWasRefunded.php index eed020b5ee38..0c32e8f768d4 100644 --- a/app/Events/Payment/PaymentWasRefunded.php +++ b/app/Events/Payment/PaymentWasRefunded.php @@ -11,6 +11,7 @@ namespace App\Events\Payment; +use App\Models\Company; use App\Models\Payment; use Illuminate\Queue\SerializesModels; @@ -29,16 +30,19 @@ class PaymentWasRefunded public $refund_amount; public $company; + + public $event_vars; /** * Create a new event instance. * * @param Payment $payment * @param $refund_amount */ - public function __construct(Payment $payment, $refund_amount, $company) + public function __construct(Payment $payment, float $refund_amount, Company $company, array $event_vars) { $this->payment = $payment; $this->refund_amount = $refund_amount; $this->company = $company; + $this->event_vars = $event_vars; } } diff --git a/app/Events/Payment/PaymentWasRestored.php b/app/Events/Payment/PaymentWasRestored.php index 5a20d46ea50b..50419ef550de 100644 --- a/app/Events/Payment/PaymentWasRestored.php +++ b/app/Events/Payment/PaymentWasRestored.php @@ -11,6 +11,7 @@ namespace App\Events\Payment; +use App\Models\Company; use App\Models\Payment; use Illuminate\Queue\SerializesModels; @@ -27,16 +28,18 @@ class PaymentWasRestored public $payment; public $fromDeleted; public $company; + public $event_vars; /** * Create a new event instance. * * @param Payment $payment * @param $fromDeleted */ - public function __construct(Payment $payment, $fromDeleted, $company) + public function __construct(Payment $payment, $fromDeleted, Company $company, array $event_vars) { $this->payment = $payment; $this->fromDeleted = $fromDeleted; $this->company = $company; + $this->event_vars = $event_vars; } } diff --git a/app/Events/Payment/PaymentWasVoided.php b/app/Events/Payment/PaymentWasVoided.php index 555f30c8d9e4..f7ca7c908d6b 100644 --- a/app/Events/Payment/PaymentWasVoided.php +++ b/app/Events/Payment/PaymentWasVoided.php @@ -11,6 +11,7 @@ namespace App\Events\Payment; +use App\Models\Company; use App\Models\Payment; use Illuminate\Queue\SerializesModels; @@ -21,20 +22,24 @@ class PaymentWasVoided { use SerializesModels; + /** * @var Payment */ public $payment; - public $company + public $company; + + public $event_vars; /** * Create a new event instance. * * @param Payment $payment */ - public function __construct(Payment $payment, $company) + public function __construct(Payment $payment, Company $company, array $event_vars) { $this->payment = $payment; $this->company = $company; + $this->event_vars = $event_vars; } } diff --git a/app/Events/Product/ProductWasArchived.php b/app/Events/Product/ProductWasArchived.php new file mode 100644 index 000000000000..34469d18de1f --- /dev/null +++ b/app/Events/Product/ProductWasArchived.php @@ -0,0 +1,40 @@ +product = $product; + $this->company = $company; + $this->event_vars = $event_vars; + } +} diff --git a/app/Events/Product/ProductWasCreated.php b/app/Events/Product/ProductWasCreated.php index 54cea9bd9903..773512b46a11 100644 --- a/app/Events/Product/ProductWasCreated.php +++ b/app/Events/Product/ProductWasCreated.php @@ -11,6 +11,7 @@ namespace App\Events\Product; +use App\Models\Company; use App\Models\Product; use Illuminate\Queue\SerializesModels; @@ -23,22 +24,21 @@ class ProductWasCreated */ public $product; - /** - * @var array - **/ public $input; public $company; + public $event_vars; /** * Create a new event instance. * * @return void */ - public function __construct(Product $product, $input = null, $company) + public function __construct(Product $product, $input = null, Company $company, array $event_vars) { $this->product = $product; $this->input = $input; $this->company = $company; + $this->event_vars = $event_vars; } } diff --git a/app/Events/Product/ProductWasDeleted.php b/app/Events/Product/ProductWasDeleted.php index 8ae67cefe06d..97326b3438e9 100644 --- a/app/Events/Product/ProductWasDeleted.php +++ b/app/Events/Product/ProductWasDeleted.php @@ -11,6 +11,7 @@ namespace App\Events\Product; +use App\Models\Company; use App\Models\Product; use Illuminate\Queue\SerializesModels; @@ -24,14 +25,17 @@ class ProductWasDeleted public $product; public $company; + + public $event_vars; /** * Create a new event instance. * * @return void */ - public function __construct(Product $product, $company) + public function __construct(Product $product, Company $company, array $event_vars) { $this->product = $product; $this->company = $company; + $this->event_vars = $event_vars; } } diff --git a/app/Events/Product/ProductWasUpdated.php b/app/Events/Product/ProductWasUpdated.php index 4473bf801400..85649bc36b19 100644 --- a/app/Events/Product/ProductWasUpdated.php +++ b/app/Events/Product/ProductWasUpdated.php @@ -23,22 +23,18 @@ class ProductWasUpdated */ public $product; - /** - * @var array - **/ - public $input; - public $company; + public $event_vars; /** * Create a new event instance. * * @return void */ - public function __construct(Product $product, $input = null, $company) + public function __construct(Product $product, Company $company, array $event_vars) { $this->product = $product; - $this->input = $input; $this->company = $company; + $this->event_vars = $event_vars; } } diff --git a/app/Events/Quote/QuoteWasApproved.php b/app/Events/Quote/QuoteWasApproved.php index a879db7c3cbc..ee8ba01cec2a 100644 --- a/app/Events/Quote/QuoteWasApproved.php +++ b/app/Events/Quote/QuoteWasApproved.php @@ -1,7 +1,17 @@ quote = $quote; $this->company = $company; + $this->event_vars = $event_vars; } } diff --git a/app/Events/Quote/QuoteWasArchived.php b/app/Events/Quote/QuoteWasArchived.php index 7dd633434854..fbf45a6741f8 100644 --- a/app/Events/Quote/QuoteWasArchived.php +++ b/app/Events/Quote/QuoteWasArchived.php @@ -11,6 +11,7 @@ namespace App\Events\Quote; +use App\Models\Company; use Illuminate\Queue\SerializesModels; class QuoteWasArchived @@ -18,15 +19,19 @@ class QuoteWasArchived use SerializesModels; public $quote; + public $company; + + public $event_vars; /** * Create a new event instance. * * @return void */ - public function __construct(Quote $quote, $company) + public function __construct(Quote $quote, Company $company, array $event_vars) { $this->quote = $quote; $this->company = $company; + $this->event_vars = $event_vars; } } diff --git a/app/Events/Quote/QuoteWasCreated.php b/app/Events/Quote/QuoteWasCreated.php index 4d9ac9d11d74..7afe19211e30 100644 --- a/app/Events/Quote/QuoteWasCreated.php +++ b/app/Events/Quote/QuoteWasCreated.php @@ -11,6 +11,7 @@ namespace App\Events\Quote; +use App\Models\Company; use Illuminate\Queue\SerializesModels; /** @@ -21,15 +22,19 @@ class QuoteWasCreated use SerializesModels; public $quote; + public $company; + + public $event_vars; /** * Create a new event instance. * * @return void */ - public function __construct(Quote $quote, $company) + public function __construct(Quote $quote, Company $company, array $event_vars) { $this->quote = $quote; $this->company = $company; + $this->event_vars = $event_vars; } } diff --git a/app/Events/Quote/QuoteWasDeleted.php b/app/Events/Quote/QuoteWasDeleted.php index 06cb17a247ec..02de057130ac 100644 --- a/app/Events/Quote/QuoteWasDeleted.php +++ b/app/Events/Quote/QuoteWasDeleted.php @@ -11,6 +11,7 @@ namespace App\Events\Quote; +use App\Models\Company; use Illuminate\Queue\SerializesModels; /** @@ -19,17 +20,21 @@ use Illuminate\Queue\SerializesModels; class QuoteWasDeleted { use SerializesModels; + public $quote; public $company; + + public $event_vars; /** * Create a new event instance. * * @return void */ - public function __construct(Quote $quote, $company) + public function __construct(Quote $quote, Company $company, array $event_vars) { $this->quote = $quote; $this->company = $company; + $this->event_vars = $event_vars; } } diff --git a/app/Events/Quote/QuoteWasEmailed.php b/app/Events/Quote/QuoteWasEmailed.php index 3c1895c65434..87b8c52d9b32 100644 --- a/app/Events/Quote/QuoteWasEmailed.php +++ b/app/Events/Quote/QuoteWasEmailed.php @@ -11,6 +11,8 @@ namespace App\Events\Quote; +use App\Models\Company; +use App\Models\Quote; use Illuminate\Queue\SerializesModels; /** @@ -24,21 +26,20 @@ class QuoteWasEmailed public $company; - /** - * @var string - */ public $notes; + public $event_vars; /** * Create a new event instance. * * @param $quote */ - public function __construct($quote, $notes, $company) + public function __construct(Quote $quote, string $notes, Company $company, array $event_vars) { $this->quote = $quote; $this->notes = $notes; $this->company = $company; + $this->event_vars = $event_vars; } } diff --git a/app/Events/Quote/QuoteWasEmailedAndFailed.php b/app/Events/Quote/QuoteWasEmailedAndFailed.php index a6326f90c847..a726bb59cf22 100644 --- a/app/Events/Quote/QuoteWasEmailedAndFailed.php +++ b/app/Events/Quote/QuoteWasEmailedAndFailed.php @@ -11,6 +11,7 @@ namespace App\Events\Quote; +use App\Models\Company; use App\Models\Quote; use Illuminate\Queue\SerializesModels; @@ -28,22 +29,22 @@ class QuoteWasEmailedAndFailed public $company; - /** - * @var array - */ public $errors; + public $event_vars; /** * QuoteWasEmailedAndFailed constructor. * @param Quote $quote * @param array $errors */ - public function __construct(Quote $quote, array $errors, $company) + public function __construct(Quote $quote, array $errors, Company $company, array $event_vars) { $this->quote = $quote; $this->errors = $errors; $this->company = $company; + + $this->event_vars = $event_vars; } } diff --git a/app/Events/Quote/QuoteWasMarkedApproved.php b/app/Events/Quote/QuoteWasMarkedApproved.php index 087ad138b270..3d45048fbb1f 100644 --- a/app/Events/Quote/QuoteWasMarkedApproved.php +++ b/app/Events/Quote/QuoteWasMarkedApproved.php @@ -1,4 +1,14 @@ quote = $quote; $this->company = $company; + $this->event_vars = $event_vars; } } diff --git a/app/Events/Quote/QuoteWasMarkedSent.php b/app/Events/Quote/QuoteWasMarkedSent.php index b27c59484df6..de772d696807 100644 --- a/app/Events/Quote/QuoteWasMarkedSent.php +++ b/app/Events/Quote/QuoteWasMarkedSent.php @@ -1,4 +1,14 @@ quote = $quote; $this->company = $company; + $this->event_vars = $event_vars; } } diff --git a/app/Events/Quote/QuoteWasRestored.php b/app/Events/Quote/QuoteWasRestored.php index c98173af65e3..e322d470d103 100644 --- a/app/Events/Quote/QuoteWasRestored.php +++ b/app/Events/Quote/QuoteWasRestored.php @@ -11,6 +11,7 @@ namespace App\Events\Quote; +use App\Models\Company; use Illuminate\Queue\SerializesModels; /** @@ -19,17 +20,21 @@ use Illuminate\Queue\SerializesModels; class QuoteWasRestored { use SerializesModels; + public $quote; public $company; + + public $event_vars; /** * Create a new event instance. * * @return void */ - public function __construct(Quote $quote, $company) + public function __construct(Quote $quote, Company $company, array $event_vars) { $this->quote = $quote; $this->company = $company; + $this->event_vars = $event_vars; } } diff --git a/app/Events/Quote/QuoteWasUpdated.php b/app/Events/Quote/QuoteWasUpdated.php index 540a9056f0fb..d6ccf8933bd7 100644 --- a/app/Events/Quote/QuoteWasUpdated.php +++ b/app/Events/Quote/QuoteWasUpdated.php @@ -19,16 +19,21 @@ use Illuminate\Queue\SerializesModels; class QuoteWasUpdated { use SerializesModels; + public $quote; public $company; + + public $event_vars; /** * Create a new event instance. * * @return void */ - public function __construct(Quote $quote, $company) + public function __construct(Quote $quote, Company $company, array $event_vars) { $this->quote = $quote; $this->company = $company; + $this->event_vars = $event_vars; } +} \ No newline at end of file diff --git a/app/Events/Task/TaskWasArchived.php b/app/Events/Task/TaskWasArchived.php index 19ef5edcdac6..658a68d71bd4 100644 --- a/app/Events/Task/TaskWasArchived.php +++ b/app/Events/Task/TaskWasArchived.php @@ -11,6 +11,7 @@ namespace App\Events\Task; +use App\Models\Company; use App\Models\Task; use Illuminate\Queue\SerializesModels; @@ -28,14 +29,16 @@ class TaskWasArchived public $company; + public $event_vars; /** * Create a new event instance. * * @param Task $task */ - public function __construct(Task $task, $company) + public function __construct(Task $task, Company $company, array $event_vars) { $this->task = $task; $this->company = $company; + $this->event_vars = $event_vars; } } diff --git a/app/Events/Task/TaskWasCreated.php b/app/Events/Task/TaskWasCreated.php index 704805fa5f1c..37f8ad477c13 100644 --- a/app/Events/Task/TaskWasCreated.php +++ b/app/Events/Task/TaskWasCreated.php @@ -11,6 +11,7 @@ namespace App\Events\Task; +use App\Models\Company; use App\Models\Task; use Illuminate\Queue\SerializesModels; @@ -20,7 +21,7 @@ use Illuminate\Queue\SerializesModels; class TaskWasCreated { use SerializesModels; - + /** * @var Task */ @@ -28,14 +29,16 @@ class TaskWasCreated public $company; + public $event_vars; /** * Create a new event instance. * * @param Task $task */ - public function __construct(Task $task, $company) + public function __construct(Task $task, Company $company, array $event_vars) { $this->task = $task; $this->company = $company; + $this->event_vars = $event_vars; } } diff --git a/app/Events/Task/TaskWasDeleted.php b/app/Events/Task/TaskWasDeleted.php index 17da40f6b54a..408f8cdd69b2 100644 --- a/app/Events/Task/TaskWasDeleted.php +++ b/app/Events/Task/TaskWasDeleted.php @@ -11,6 +11,7 @@ namespace App\Events\Task; +use App\Models\Company; use App\Models\Task; use Illuminate\Queue\SerializesModels; @@ -28,14 +29,16 @@ class TaskWasDeleted public $company; + public $event_vars; /** * Create a new event instance. * * @param Task $task */ - public function __construct(Task $task, $company) + public function __construct(Task $task, Company $company, array $event_vars) { $this->task = $task; $this->company = $company; + $this->event_vars = $event_vars; } } diff --git a/app/Events/Task/TaskWasRestored.php b/app/Events/Task/TaskWasRestored.php index a028cc3f504e..e263bc58e52f 100644 --- a/app/Events/Task/TaskWasRestored.php +++ b/app/Events/Task/TaskWasRestored.php @@ -11,6 +11,7 @@ namespace App\Events\Task; +use App\Models\Company; use App\Models\Task; use Illuminate\Queue\SerializesModels; @@ -28,14 +29,16 @@ class TaskWasRestored public $company; + public $event_vars; /** * Create a new event instance. * * @param Task $task */ - public function __construct(Task $task, $company) + public function __construct(Task $task, Company $company, array $event_vars) { $this->task = $task; $this->company = $company; + $this->event_vars = $event_vars; } -} +} \ No newline at end of file diff --git a/app/Events/Task/TaskWasUpdated.php b/app/Events/Task/TaskWasUpdated.php index 8b913f39250b..f22f7b14a384 100644 --- a/app/Events/Task/TaskWasUpdated.php +++ b/app/Events/Task/TaskWasUpdated.php @@ -11,6 +11,7 @@ namespace App\Events\Task; +use App\Models\Company; use App\Models\Task; use Illuminate\Queue\SerializesModels; @@ -28,14 +29,16 @@ class TaskWasUpdated public $company; + public $event_vars; /** * Create a new event instance. * * @param Task $task */ - public function __construct(Task $task, $company) + public function __construct(Task $task, Company $company, array $event_vars) { $this->task = $task; $this->company = $company; + $this->event_vars = $event_vars; } } diff --git a/app/Events/User/UserLoggedIn.php b/app/Events/User/UserLoggedIn.php index e27b352f67f0..5158225f1ef1 100644 --- a/app/Events/User/UserLoggedIn.php +++ b/app/Events/User/UserLoggedIn.php @@ -11,13 +11,15 @@ namespace App\Events\User; +use App\Models\Company; +use App\Models\User; use Illuminate\Broadcasting\Channel; -use Illuminate\Queue\SerializesModels; -use Illuminate\Broadcasting\PrivateChannel; -use Illuminate\Broadcasting\PresenceChannel; -use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Broadcasting\InteractsWithSockets; +use Illuminate\Broadcasting\PresenceChannel; +use Illuminate\Broadcasting\PrivateChannel; use Illuminate\Contracts\Broadcasting\ShouldBroadcast; +use Illuminate\Foundation\Events\Dispatchable; +use Illuminate\Queue\SerializesModels; /** * Class UserLoggedIn @@ -33,15 +35,18 @@ class UserLoggedIn public $user; public $company; + + public $event_vars; /** * Create a new event instance. * * @return void */ - public function __construct($user, $company) + public function __construct(User $user, Company $company, array $event_vars) { $this->user = $user; $this->company = $company; + $this->event_vars = $event_vars; } /** diff --git a/app/Events/User/UserWasArchived.php b/app/Events/User/UserWasArchived.php index 93e3b660dd88..02bbae126483 100644 --- a/app/Events/User/UserWasArchived.php +++ b/app/Events/User/UserWasArchived.php @@ -11,13 +11,15 @@ namespace App\Events\User; +use App\Models\Company; +use App\Models\User; use Illuminate\Broadcasting\Channel; -use Illuminate\Queue\SerializesModels; -use Illuminate\Broadcasting\PrivateChannel; -use Illuminate\Broadcasting\PresenceChannel; -use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Broadcasting\InteractsWithSockets; +use Illuminate\Broadcasting\PresenceChannel; +use Illuminate\Broadcasting\PrivateChannel; use Illuminate\Contracts\Broadcasting\ShouldBroadcast; +use Illuminate\Foundation\Events\Dispatchable; +use Illuminate\Queue\SerializesModels; /** * Class UserWasArchived @@ -32,20 +34,19 @@ class UserWasArchived */ public $user; - /** - * @var $company - */ - public $company; + + public $event_vars; /** * Create a new event instance. * * @return void */ - public function __construct($user, $company) + public function __construct(User $user, Company $company, array $event_vars) { $this->user = $user; $this->company = $company; + $this->event_vars = $event_vars; } /** diff --git a/app/Events/User/UserWasCreated.php b/app/Events/User/UserWasCreated.php index f33f751c0537..b13618d33c43 100644 --- a/app/Events/User/UserWasCreated.php +++ b/app/Events/User/UserWasCreated.php @@ -11,13 +11,15 @@ namespace App\Events\User; +use App\Models\Company; +use App\Models\User; use Illuminate\Broadcasting\Channel; -use Illuminate\Queue\SerializesModels; -use Illuminate\Broadcasting\PrivateChannel; -use Illuminate\Broadcasting\PresenceChannel; -use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Broadcasting\InteractsWithSockets; +use Illuminate\Broadcasting\PresenceChannel; +use Illuminate\Broadcasting\PrivateChannel; use Illuminate\Contracts\Broadcasting\ShouldBroadcast; +use Illuminate\Foundation\Events\Dispatchable; +use Illuminate\Queue\SerializesModels; /** * Class UserWasCreated @@ -32,20 +34,19 @@ class UserWasCreated */ public $user; - /** - * @var $company - */ - public $company; + + public $event_vars; /** * Create a new event instance. * * @return void */ - public function __construct($user, $company) + public function __construct(User $user, Company $company, array $event_vars) { $this->user = $user; $this->company = $company; + $this->event_vars = $event_vars; } /** diff --git a/app/Events/User/UserWasDeleted.php b/app/Events/User/UserWasDeleted.php index f96acfc83706..f4a7cdcd1086 100644 --- a/app/Events/User/UserWasDeleted.php +++ b/app/Events/User/UserWasDeleted.php @@ -11,13 +11,15 @@ namespace App\Events\User; +use App\Models\Company; +use App\Models\User; use Illuminate\Broadcasting\Channel; -use Illuminate\Queue\SerializesModels; -use Illuminate\Broadcasting\PrivateChannel; -use Illuminate\Broadcasting\PresenceChannel; -use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Broadcasting\InteractsWithSockets; +use Illuminate\Broadcasting\PresenceChannel; +use Illuminate\Broadcasting\PrivateChannel; use Illuminate\Contracts\Broadcasting\ShouldBroadcast; +use Illuminate\Foundation\Events\Dispatchable; +use Illuminate\Queue\SerializesModels; /** * Class UserWasDeleted @@ -32,20 +34,19 @@ class UserWasDeleted */ public $user; - /** - * @var $company - */ - public $company; + + public $event_vars; /** * Create a new event instance. * * @return void */ - public function __construct($user, $company) + public function __construct(User $user, Company $company, array $event_vars) { $this->user = $user; $this->company = $company; + $this->event_vars = $event_vars; } /** diff --git a/app/Events/User/UserWasRestored.php b/app/Events/User/UserWasRestored.php index 56d51411c978..23e2689c724f 100644 --- a/app/Events/User/UserWasRestored.php +++ b/app/Events/User/UserWasRestored.php @@ -11,13 +11,15 @@ namespace App\Events\User; +use App\Models\Company; +use App\Models\User; use Illuminate\Broadcasting\Channel; -use Illuminate\Queue\SerializesModels; -use Illuminate\Broadcasting\PrivateChannel; -use Illuminate\Broadcasting\PresenceChannel; -use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Broadcasting\InteractsWithSockets; +use Illuminate\Broadcasting\PresenceChannel; +use Illuminate\Broadcasting\PrivateChannel; use Illuminate\Contracts\Broadcasting\ShouldBroadcast; +use Illuminate\Foundation\Events\Dispatchable; +use Illuminate\Queue\SerializesModels; /** * Class UserWasRestored @@ -32,20 +34,19 @@ class UserWasRestored */ public $user; - /** - * @var $company - */ - public $company; + + public $event_vars; /** * Create a new event instance. * * @return void */ - public function __construct($user, $company) + public function __construct(User $user, Company $company, array $event_vars) { $this->user = $user; $this->company = $company; + $this->event_vars = $event_vars; } /** diff --git a/app/Events/User/UserWasUpdated.php b/app/Events/User/UserWasUpdated.php index 03fa6c514223..be9185b0823f 100644 --- a/app/Events/User/UserWasUpdated.php +++ b/app/Events/User/UserWasUpdated.php @@ -11,13 +11,15 @@ namespace App\Events\User; +use App\Models\Company; +use App\Models\User; use Illuminate\Broadcasting\Channel; -use Illuminate\Queue\SerializesModels; -use Illuminate\Broadcasting\PrivateChannel; -use Illuminate\Broadcasting\PresenceChannel; -use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Broadcasting\InteractsWithSockets; +use Illuminate\Broadcasting\PresenceChannel; +use Illuminate\Broadcasting\PrivateChannel; use Illuminate\Contracts\Broadcasting\ShouldBroadcast; +use Illuminate\Foundation\Events\Dispatchable; +use Illuminate\Queue\SerializesModels; /** * Class UserWasUpdated @@ -32,22 +34,20 @@ class UserWasUpdated */ public $user; - /** - * @var $company - */ - public $company; + + public $event_vars; /** * Create a new event instance. * * @return void */ - public function __construct($user, $company) + public function __construct(User $user, Company $company, array $event_vars) { $this->user = $user; $this->company = $company; + $this->event_vars = $event_vars; } - /** * Get the channels the event should broadcast on. * diff --git a/app/Events/Vendor/VendorWasArchived.php b/app/Events/Vendor/VendorWasArchived.php index 96c10ee9a7d3..d8faea7f1af5 100644 --- a/app/Events/Vendor/VendorWasArchived.php +++ b/app/Events/Vendor/VendorWasArchived.php @@ -11,6 +11,7 @@ namespace App\Events\Vendor; +use App\Models\Company; use App\Models\Vendor; use Illuminate\Queue\SerializesModels; @@ -28,14 +29,17 @@ class VendorWasArchived public $vendor; public $company; + + public $event_vars; /** * Create a new event instance. * * @param Vendor $vendor */ - public function __construct(Vendor $vendor, $company) + public function __construct(Vendor $vendor, Company $company, array $event_vars) { $this->vendor = $vendor; $this->company = $company; + $this->event_vars = $event_vars; } } diff --git a/app/Events/Vendor/VendorWasCreated.php b/app/Events/Vendor/VendorWasCreated.php index cbe164bb8630..4dd7d24e4033 100644 --- a/app/Events/Vendor/VendorWasCreated.php +++ b/app/Events/Vendor/VendorWasCreated.php @@ -11,6 +11,7 @@ namespace App\Events\Vendor; +use App\Models\Company; use App\Models\Vendor; use Illuminate\Queue\SerializesModels; @@ -27,14 +28,17 @@ class VendorWasCreated public $vendor; public $company; + + public $event_vars; /** * Create a new event instance. * * @param Vendor $vendor */ - public function __construct(Vendor $vendor, $company) + public function __construct(Vendor $vendor, Company $company, array $event_vars) { $this->vendor = $vendor; $this->company = $company; + $this->event_vars = $event_vars; } } diff --git a/app/Events/Vendor/VendorWasDeleted.php b/app/Events/Vendor/VendorWasDeleted.php index abfe4e2a9f56..c769f42946a8 100644 --- a/app/Events/Vendor/VendorWasDeleted.php +++ b/app/Events/Vendor/VendorWasDeleted.php @@ -11,6 +11,7 @@ namespace App\Events\Vendor; +use App\Models\Company; use App\Models\Vendor; use Illuminate\Queue\SerializesModels; @@ -27,14 +28,17 @@ class VendorWasDeleted public $vendor; public $company; + + public $event_vars; /** * Create a new event instance. * * @param Vendor $vendor */ - public function __construct(Vendor $vendor, $company) + public function __construct(Vendor $vendor, Company $company, array $event_vars) { $this->vendor = $vendor; $this->company = $company; + $this->event_vars = $event_vars; } } diff --git a/app/Events/Vendor/VendorWasRestored.php b/app/Events/Vendor/VendorWasRestored.php index c2d27fe1afd8..98610e460359 100644 --- a/app/Events/Vendor/VendorWasRestored.php +++ b/app/Events/Vendor/VendorWasRestored.php @@ -11,6 +11,7 @@ namespace App\Events\Vendor; +use App\Models\Company; use App\Models\Vendor; use Illuminate\Queue\SerializesModels; @@ -27,14 +28,18 @@ class VendorWasRestored public $vendor; public $company; + + public $event_vars; /** * Create a new event instance. * * @param Vendor $vendor */ - public function __construct(Vendor $vendor, $company) + public function __construct(Vendor $vendor, Company $company, array $event_vars) { $this->vendor = $vendor; $this->company = $company; + $this->event_vars = $event_vars; } + } diff --git a/app/Events/Vendor/VendorWasUpdated.php b/app/Events/Vendor/VendorWasUpdated.php index 2f9192d24329..2b2b29bfbec1 100644 --- a/app/Events/Vendor/VendorWasUpdated.php +++ b/app/Events/Vendor/VendorWasUpdated.php @@ -11,6 +11,7 @@ namespace App\Events\Vendor; +use App\Models\Company; use App\Models\Vendor; use Illuminate\Queue\SerializesModels; @@ -27,14 +28,17 @@ class VendorWasUpdated public $vendor; public $company; + + public $event_vars; /** * Create a new event instance. * * @param Vendor $vendor */ - public function __construct(Vendor $vendor, $company) + public function __construct(Vendor $vendor, Company $company, array $event_vars) { $this->vendor = $vendor; $this->company = $company; + $this->event_vars = $event_vars; } } diff --git a/app/Http/Controllers/Auth/ContactLoginController.php b/app/Http/Controllers/Auth/ContactLoginController.php index 5a1a805008e7..41643128b433 100644 --- a/app/Http/Controllers/Auth/ContactLoginController.php +++ b/app/Http/Controllers/Auth/ContactLoginController.php @@ -14,6 +14,7 @@ namespace App\Http\Controllers\Auth; use App\Events\Contact\ContactLoggedIn; use App\Http\Controllers\Controller; use App\Models\ClientContact; +use App\Utils\Ninja; use Auth; use Illuminate\Foundation\Auth\AuthenticatesUsers; use Illuminate\Http\Request; @@ -63,7 +64,7 @@ class ContactLoginController extends Controller { Auth::guard('contact')->login($client, true); - event(new ContactLoggedIn($client, $client->company)); + event(new ContactLoggedIn($client, $client->company, Ninja::eventVars())); if (session()->get('url.intended')) { return redirect(session()->get('url.intended')); diff --git a/app/Http/Controllers/ClientController.php b/app/Http/Controllers/ClientController.php index 1edba051e169..0a17a3c0a147 100644 --- a/app/Http/Controllers/ClientController.php +++ b/app/Http/Controllers/ClientController.php @@ -12,6 +12,7 @@ namespace App\Http\Controllers; use App\DataMapper\ClientSettings; +use App\Events\Client\ClientWasCreated; use App\Factory\ClientFactory; use App\Filters\ClientFilters; use App\Http\Requests\Client\BulkClientRequest; @@ -34,6 +35,7 @@ use App\Models\Size; use App\Repositories\BaseRepository; use App\Repositories\ClientRepository; use App\Transformers\ClientTransformer; +use App\Utils\Ninja; use App\Utils\Traits\BulkOptions; use App\Utils\Traits\MakesHash; use App\Utils\Traits\Uploadable; @@ -384,6 +386,8 @@ class ClientController extends BaseController $this->uploadLogo($request->file('company_logo'), $client->company, $client); + event(new ClientWasCreated($client, $client->company, Ninja::eventVars())); + return $this->itemResponse($client); } diff --git a/app/Http/Controllers/ClientPortal/InvitationController.php b/app/Http/Controllers/ClientPortal/InvitationController.php index f833cdbd3021..8258c04f5840 100644 --- a/app/Http/Controllers/ClientPortal/InvitationController.php +++ b/app/Http/Controllers/ClientPortal/InvitationController.php @@ -14,6 +14,7 @@ namespace App\Http\Controllers\ClientPortal; use App\Events\Misc\InvitationWasViewed; use App\Http\Controllers\Controller; use App\Models\InvoiceInvitation; +use App\Utils\Ninja; use App\Utils\Traits\MakesDates; use App\Utils\Traits\MakesHash; use Illuminate\Http\Request; @@ -47,7 +48,7 @@ class InvitationController extends Controller if (!request()->has('silent')) { $invitation->markViewed(); - event(new InvitationWasViewed($entity, $invitation, $entity->company)); + event(new InvitationWasViewed($entity, $invitation, $entity->company, Ninja::eventVars())); } return redirect()->route('client.'.$entity.'.show', [$entity => $this->encodePrimaryKey($invitation->{$key})]); diff --git a/app/Http/Controllers/ClientPortal/PaymentMethodController.php b/app/Http/Controllers/ClientPortal/PaymentMethodController.php index 8792c2f89f03..fe5d3aaa77c1 100644 --- a/app/Http/Controllers/ClientPortal/PaymentMethodController.php +++ b/app/Http/Controllers/ClientPortal/PaymentMethodController.php @@ -19,6 +19,7 @@ use App\Models\ClientGatewayToken; use App\Models\CompanyGateway; use App\Models\GatewayType; use App\PaymentDrivers\AuthorizePaymentDriver; +use App\Utils\Ninja; use App\Utils\Traits\MakesDates; use Illuminate\Http\Request; use Illuminate\Support\Facades\Log; @@ -135,7 +136,7 @@ class PaymentMethodController extends Controller public function destroy(ClientGatewayToken $payment_method) { try { - event(new MethodDeleted($payment_method, auth('contact')->user()->company)); + event(new MethodDeleted($payment_method, auth('contact')->user()->company, Ninja::eventVars())); $payment_method->delete(); } catch (\Exception $e) { Log::error(json_encode($e)); diff --git a/app/Http/Controllers/ClientPortal/QuoteController.php b/app/Http/Controllers/ClientPortal/QuoteController.php index 56b7e3963851..5ccfeae0ff70 100644 --- a/app/Http/Controllers/ClientPortal/QuoteController.php +++ b/app/Http/Controllers/ClientPortal/QuoteController.php @@ -8,6 +8,7 @@ use App\Http\Requests\ClientPortal\ProcessQuotesInBulkRequest; use App\Http\Requests\ClientPortal\ShowQuoteRequest; use App\Models\Company; use App\Models\Quote; +use App\Utils\Ninja; use App\Utils\TempFile; use App\Utils\Traits\MakesHash; use ZipStream\Option\Archive; @@ -108,7 +109,7 @@ class QuoteController extends Controller if ($process) { foreach ($quotes as $quote) { $quote->service()->approve()->save(); - event(new QuoteWasApproved($quote)); + event(new QuoteWasApproved($quote, $quote->company, Ninja::eventVars())); } return route('client.quotes.index')->withSuccess('Quote(s) approved successfully.'); diff --git a/app/Http/Controllers/CompanyController.php b/app/Http/Controllers/CompanyController.php index 19abc337cb65..f7f91bc472b0 100644 --- a/app/Http/Controllers/CompanyController.php +++ b/app/Http/Controllers/CompanyController.php @@ -482,8 +482,7 @@ class CompanyController extends BaseController $account->delete(); } else { - - + $company_id = $company->id; $company->delete(); diff --git a/app/Http/Controllers/CreditController.php b/app/Http/Controllers/CreditController.php index 6e2d4e214512..73588356f343 100644 --- a/app/Http/Controllers/CreditController.php +++ b/app/Http/Controllers/CreditController.php @@ -22,6 +22,7 @@ use App\Models\Client; use App\Models\Credit; use App\Repositories\CreditRepository; use App\Transformers\CreditTransformer; +use App\Utils\Ninja; use App\Utils\TempFile; use App\Utils\Traits\MakesHash; @@ -191,7 +192,7 @@ class CreditController extends BaseController $credit = StoreCredit::dispatchNow($credit, $request->all(), $credit->company); - event(new CreditWasCreated($credit, $credit->company)); + event(new CreditWasCreated($credit, $credit->company, Ninja::eventVars())); return $this->itemResponse($credit); } @@ -369,7 +370,7 @@ class CreditController extends BaseController $credit = $this->credit_repository->save($request->all(), $credit); - event(new CreditWasUpdated($credit, $credit->company)); + event(new CreditWasUpdated($credit, $credit->company, Ninja::eventVars())); return $this->itemResponse($credit); } diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index e93eda2846fc..8033d1ad1923 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -36,6 +36,7 @@ use App\Models\Invoice; use App\Models\InvoiceInvitation; use App\Repositories\InvoiceRepository; use App\Transformers\InvoiceTransformer; +use App\Utils\Ninja; use App\Utils\TempFile; use App\Utils\Traits\MakesHash; use Illuminate\Http\Request; @@ -213,7 +214,7 @@ class InvoiceController extends BaseController $invoice = $this->invoice_repo->save($request->all(), InvoiceFactory::create(auth()->user()->company()->id, auth()->user()->id)); - event(new InvoiceWasCreated($invoice, $invoice->company)); + event(new InvoiceWasCreated($invoice, $invoice->company, Ninja::eventVars())); $invoice = $invoice->service()->triggeredActions($request)->save(); @@ -393,7 +394,7 @@ class InvoiceController extends BaseController $invoice = $this->invoice_repo->save($request->all(), $invoice); - event(new InvoiceWasUpdated($invoice, $invoice->company)); + event(new InvoiceWasUpdated($invoice, $invoice->company, Ninja::eventVars())); return $this->itemResponse($invoice); } @@ -718,7 +719,7 @@ class InvoiceController extends BaseController }); if ($invoice->invitations->count() > 0) { - event(new InvoiceWasEmailed($invoice->invitations->first(), $invoice->company)); + event(new InvoiceWasEmailed($invoice->invitations->first(), $invoice->company, Ninja::eventVars())); } if (!$bulk) { diff --git a/app/Http/Controllers/OpenAPI/CompanyTokenSchema.php b/app/Http/Controllers/OpenAPI/CompanyTokenSchema.php index d3b77814b369..192eb3fbf54f 100644 --- a/app/Http/Controllers/OpenAPI/CompanyTokenSchema.php +++ b/app/Http/Controllers/OpenAPI/CompanyTokenSchema.php @@ -5,5 +5,6 @@ * type="object", * @OA\Property(property="name", type="string", example="Token Name", description="The token name"), * @OA\Property(property="token", type="string", example="AS3df3jUUH765fhfd9KJuidj3JShjA", description="The token value"), + * @OA\Property(property="is_system", type="boolean", example="true", description="Determines whether the token is created by the system rather than a user"), * ) */ diff --git a/app/Http/Controllers/OpenAPI/SubscriptionSchema.php b/app/Http/Controllers/OpenAPI/WebhookSchema.php similarity index 94% rename from app/Http/Controllers/OpenAPI/SubscriptionSchema.php rename to app/Http/Controllers/OpenAPI/WebhookSchema.php index ba59cfaa64fc..210e1ade77c5 100644 --- a/app/Http/Controllers/OpenAPI/SubscriptionSchema.php +++ b/app/Http/Controllers/OpenAPI/WebhookSchema.php @@ -1,7 +1,7 @@ guard('contact')->login($client_contact, false); - event(new ContactLoggedIn($client_contact, $client_contact->company)); //todo + event(new ContactLoggedIn($client_contact, $client_contact->company, Ninja::eventVars())); //todo } else { $error = [ 'message' => 'Invalid token', diff --git a/app/Http/Middleware/TokenAuth.php b/app/Http/Middleware/TokenAuth.php index 28e18655c1dc..b3f840fa6ece 100644 --- a/app/Http/Middleware/TokenAuth.php +++ b/app/Http/Middleware/TokenAuth.php @@ -14,6 +14,7 @@ namespace App\Http\Middleware; use App\Events\User\UserLoggedIn; use App\Models\CompanyToken; use App\Models\User; +use App\Utils\Ninja; use Closure; class TokenAuth @@ -67,7 +68,7 @@ class TokenAuth //stateless, don't remember the user. auth()->login($user, false); - event(new UserLoggedIn($user, $company_token->company)); + event(new UserLoggedIn($user, $company_token->company, Ninja::eventVars())); } else { $error = [ 'message' => 'Invalid token', diff --git a/app/Jobs/Account/CreateAccount.php b/app/Jobs/Account/CreateAccount.php index daedb63e4fb3..10826f35b40b 100644 --- a/app/Jobs/Account/CreateAccount.php +++ b/app/Jobs/Account/CreateAccount.php @@ -72,7 +72,7 @@ class CreateAccount $sp2d97e8 = CreateCompanyToken::dispatchNow($sp035a66, $spaa9f78, $spafe62e); if ($spaa9f78) { - event(new AccountCreated($spaa9f78, $sp035a66)); + event(new AccountCreated($spaa9f78, $sp035a66, Ninja::eventVars())); } $spaa9f78->fresh(); diff --git a/app/Jobs/Credit/EmailCredit.php b/app/Jobs/Credit/EmailCredit.php index c045b4e5305a..c4d3810be6d1 100644 --- a/app/Jobs/Credit/EmailCredit.php +++ b/app/Jobs/Credit/EmailCredit.php @@ -18,6 +18,7 @@ use App\Libraries\MultiDB; use App\Mail\TemplateEmail; use App\Models\Credit; use App\Models\SystemLog; +use App\Utils\Ninja; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; @@ -69,13 +70,13 @@ class EmailCredit implements ShouldQueue ->send(new TemplateEmail($message_array, $template_style, $invitation->contact->user, $invitation->contact->client)); if (count(Mail::failures()) > 0) { - event(new CreditWasEmailedAndFailed($this->credit, $this->credit->company, Mail::failures())); + event(new CreditWasEmailedAndFailed($this->credit, $this->credit->company, Mail::failures(), Ninja::eventVars())); return $this->logMailError($errors); } //fire any events - event(new CreditWasEmailed($this->credit, $this->company)); + event(new CreditWasEmailed($this->credit, $this->company, Ninja::eventVars())); //sleep(5); } diff --git a/app/Jobs/Payment/EmailPayment.php b/app/Jobs/Payment/EmailPayment.php index 46eb387c765b..6a7266fd8165 100644 --- a/app/Jobs/Payment/EmailPayment.php +++ b/app/Jobs/Payment/EmailPayment.php @@ -13,6 +13,7 @@ use App\Mail\TemplateEmail; use App\Models\Company; use App\Models\Payment; use App\Models\SystemLog; +use App\Utils\Ninja; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; @@ -57,13 +58,13 @@ class EmailPayment implements ShouldQueue ->send(new TemplateEmail($this->email_builder, $this->contact->user, $this->contact->customer)); if (count(Mail::failures()) > 0) { - event(new PaymentWasEmailedAndFailed($this->payment, Mail::failures())); + event(new PaymentWasEmailedAndFailed($this->payment, Mail::failures(), Ninja::eventVars())); return $this->logMailError(Mail::failures()); } //fire any events - event(new PaymentWasEmailed($this->payment)); + event(new PaymentWasEmailed($this->payment, $this->payment->company, Ninja::eventVars())); //sleep(5); } diff --git a/app/Jobs/User/CreateUser.php b/app/Jobs/User/CreateUser.php index f193b0f99f01..e49f2de86310 100644 --- a/app/Jobs/User/CreateUser.php +++ b/app/Jobs/User/CreateUser.php @@ -16,6 +16,7 @@ use App\DataMapper\DefaultSettings; use App\Events\User\UserWasCreated; use App\Models\CompanyUser; use App\Models\User; +use App\Utils\Ninja; use App\Utils\Traits\MakesHash; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Http\Request; @@ -77,7 +78,7 @@ class CreateUser 'settings' => null, ]); - event(new UserWasCreated($user, $this->company)); + event(new UserWasCreated($user, $this->company, Ninja::eventVars())); return $user; } diff --git a/app/Jobs/Util/ReminderJob.php b/app/Jobs/Util/ReminderJob.php index 0c1510af3733..030b1598c053 100644 --- a/app/Jobs/Util/ReminderJob.php +++ b/app/Jobs/Util/ReminderJob.php @@ -18,6 +18,7 @@ use App\Libraries\MultiDB; use App\Models\Account; use App\Models\Invoice; use App\Utils\ClientPortal\CustomMessage\invitation; +use App\Utils\Ninja; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; @@ -74,7 +75,7 @@ class ReminderJob implements ShouldQueue }); if ($invoice->invitations->count() > 0) { - event(new InvoiceWasEmailed($invoice->invitations->first(), $invoice->company)); + event(new InvoiceWasEmailed($invoice->invitations->first(), $invoice->company, Ninja::eventVars())); } } else { diff --git a/app/Listeners/Activity/CreatedClientActivity.php b/app/Listeners/Activity/CreatedClientActivity.php index 932aabfe5440..399329c59c7c 100644 --- a/app/Listeners/Activity/CreatedClientActivity.php +++ b/app/Listeners/Activity/CreatedClientActivity.php @@ -48,6 +48,6 @@ class CreatedClientActivity implements ShouldQueue $fields->company_id = $event->client->company_id; $fields->activity_type_id = Activity::CREATE_CLIENT; - $this->activity_repo->save($fields, $event->client); + $this->activity_repo->save($fields, $event->client, $event->event_vars); } } diff --git a/app/Listeners/Activity/PaymentCreatedActivity.php b/app/Listeners/Activity/PaymentCreatedActivity.php index fb1d4e4e38a3..b2bcdabd4327 100644 --- a/app/Listeners/Activity/PaymentCreatedActivity.php +++ b/app/Listeners/Activity/PaymentCreatedActivity.php @@ -54,7 +54,6 @@ class PaymentCreatedActivity implements ShouldQueue $fields->company_id = $payment->company_id; $fields->activity_type_id = Activity::CREATE_PAYMENT; - foreach ($invoices as $invoice) { //todo we may need to add additional logic if in the future we apply payments to other entity Types, not just invoices $fields->invoice_id = $invoice->id; @@ -64,7 +63,7 @@ class PaymentCreatedActivity implements ShouldQueue } if (count($invoices) == 0) { - $this->activity_repo->save($fields, $payment); + $this->activity_repo->save($fields, $payment, $event->event_vars); } } } diff --git a/app/Listeners/Activity/PaymentDeletedActivity.php b/app/Listeners/Activity/PaymentDeletedActivity.php index 9655eb672efa..171ee63f189c 100644 --- a/app/Listeners/Activity/PaymentDeletedActivity.php +++ b/app/Listeners/Activity/PaymentDeletedActivity.php @@ -54,15 +54,14 @@ class PaymentDeletedActivity implements ShouldQueue $fields->company_id = $payment->company_id; $fields->activity_type_id = Activity::DELETE_PAYMENT; - foreach ($invoices as $invoice) { //todo we may need to add additional logic if in the future we apply payments to other entity Types, not just invoices $fields->invoice_id = $invoice->id; - $this->activity_repo->save($fields, $invoice); + $this->activity_repo->save($fields, $invoice, $event->event_vars); } if (count($invoices) == 0) { - $this->activity_repo->save($fields, $payment); + $this->activity_repo->save($fields, $payment, $event->event_vars); } } } diff --git a/app/Listeners/Activity/PaymentRefundedActivity.php b/app/Listeners/Activity/PaymentRefundedActivity.php index be19507a4ead..67c75af9cdc4 100644 --- a/app/Listeners/Activity/PaymentRefundedActivity.php +++ b/app/Listeners/Activity/PaymentRefundedActivity.php @@ -47,7 +47,7 @@ class PaymentRefundedActivity implements ShouldQueue $fields->company_id = $event->payment->company_id; $fields->activity_type_id = Activity::REFUNDED_PAYMENT; $fields->payment_id = $event->payment->id; - - $this->activity_repo->save($fields, $event->client); + + $this->activity_repo->save($fields, $event->client, $event->event_vars); } } diff --git a/app/Listeners/Activity/PaymentVoidedActivity.php b/app/Listeners/Activity/PaymentVoidedActivity.php index e82ab32148bb..9149675b9257 100644 --- a/app/Listeners/Activity/PaymentVoidedActivity.php +++ b/app/Listeners/Activity/PaymentVoidedActivity.php @@ -48,7 +48,7 @@ class PaymentVoidedActivity implements ShouldQueue $fields->company_id = $event->payment->company_id; $fields->activity_type_id = Activity::VOIDED_PAYMENT; $fields->payment_id = $event->payment->id; - - $this->activity_repo->save($fields, $event->client); + + $this->activity_repo->save($fields, $event->client, $event->event_vars); } } diff --git a/app/Listeners/Document/DeleteCompanyDocuments.php b/app/Listeners/Document/DeleteCompanyDocuments.php index 1e81d3627c0d..90d3197de28f 100644 --- a/app/Listeners/Document/DeleteCompanyDocuments.php +++ b/app/Listeners/Document/DeleteCompanyDocuments.php @@ -2,7 +2,6 @@ namespace App\Listeners\Document; -use App\Events\Company\CompanyWasDeleted; use App\Libraries\MultiDB; use App\Models\Document; use Illuminate\Contracts\Queue\ShouldQueue; @@ -28,12 +27,12 @@ class DeleteCompanyDocuments * @param CompanyWasDeleted $event * @return void */ - public function handle(CompanyWasDeleted $event) + public function handle($event) { - MultiDB::setDb($event->company->db); + MultiDB::setDb($event->company->db); - $path = sprintf('%s/%s', storage_path('app/public'), $event->company->company_key); + $path = sprintf('%s/%s', storage_path('app/public'), $event->company->company_key); // Remove all files & folders, under company's path. // This will delete directory itself, as well. @@ -42,5 +41,6 @@ class DeleteCompanyDocuments Storage::deleteDirectory($event->company->company_key); Document::whereCompanyId($event->company->id)->delete(); + } } diff --git a/app/Listeners/Invoice/CreateInvoiceActivity.php b/app/Listeners/Invoice/CreateInvoiceActivity.php index ed5f56cc8f00..c9d94d625519 100644 --- a/app/Listeners/Invoice/CreateInvoiceActivity.php +++ b/app/Listeners/Invoice/CreateInvoiceActivity.php @@ -51,6 +51,6 @@ class CreateInvoiceActivity implements ShouldQueue $fields->company_id = $event->invoice->company_id; $fields->activity_type_id = Activity::CREATE_INVOICE; - $this->activity_repo->save($fields, $event->invoice, $event->invoice->company->db); + $this->activity_repo->save($fields, $event->invoice, $event->event_vars); } } diff --git a/app/Listeners/Invoice/CreateInvoiceHtmlBackup.php b/app/Listeners/Invoice/CreateInvoiceHtmlBackup.php index 4e015245d44a..1f4e4b73bdb0 100644 --- a/app/Listeners/Invoice/CreateInvoiceHtmlBackup.php +++ b/app/Listeners/Invoice/CreateInvoiceHtmlBackup.php @@ -47,6 +47,6 @@ class CreateInvoiceHtmlBackup implements ShouldQueue $fields->company_id = $event->invoice->company_id; $fields->activity_type_id = Activity::MARK_SENT_INVOICE; - $this->activity_repo->save($fields, $event->invoice); + $this->activity_repo->save($fields, $event->invoice, $event->event_vars); } } diff --git a/app/Listeners/Invoice/InvoiceCancelledActivity.php b/app/Listeners/Invoice/InvoiceCancelledActivity.php index 3c267a1c2342..efb816ff5159 100644 --- a/app/Listeners/Invoice/InvoiceCancelledActivity.php +++ b/app/Listeners/Invoice/InvoiceCancelledActivity.php @@ -52,6 +52,6 @@ class InvoiceCancelledActivity implements ShouldQueue $fields->company_id = $event->invoice->company_id; $fields->activity_type_id = Activity::CANCELLED_INVOICE; - $this->activity_repo->save($fields, $event->invoice); + $this->activity_repo->save($fields, $event->invoice, $event->event_vars); } } diff --git a/app/Listeners/Invoice/InvoiceDeletedActivity.php b/app/Listeners/Invoice/InvoiceDeletedActivity.php index f304d55c3afd..436232b0f672 100644 --- a/app/Listeners/Invoice/InvoiceDeletedActivity.php +++ b/app/Listeners/Invoice/InvoiceDeletedActivity.php @@ -52,6 +52,6 @@ class InvoiceDeletedActivity implements ShouldQueue $fields->company_id = $event->invoice->company_id; $fields->activity_type_id = Activity::DELETE_INVOICE; - $this->activity_repo->save($fields, $event->invoice); + $this->activity_repo->save($fields, $event->invoice, $event->event_vars); } } diff --git a/app/Listeners/Invoice/InvoiceEmailActivity.php b/app/Listeners/Invoice/InvoiceEmailActivity.php index 0d583e3a858d..e61144d093a7 100644 --- a/app/Listeners/Invoice/InvoiceEmailActivity.php +++ b/app/Listeners/Invoice/InvoiceEmailActivity.php @@ -52,6 +52,6 @@ class InvoiceEmailActivity implements ShouldQueue $fields->client_contact_id = $event->invitation->invoice->client_contact_id; $fields->activity_type_id = Activity::EMAIL_INVOICE; - $this->activity_repo->save($fields, $event->invitation->invoice); + $this->activity_repo->save($fields, $event->invitation->invoice, $event->event_vars); } } diff --git a/app/Listeners/Invoice/InvoiceEmailFailedActivity.php b/app/Listeners/Invoice/InvoiceEmailFailedActivity.php index 069853539c63..6a4f0287386c 100644 --- a/app/Listeners/Invoice/InvoiceEmailFailedActivity.php +++ b/app/Listeners/Invoice/InvoiceEmailFailedActivity.php @@ -51,6 +51,6 @@ class InvoiceEmailFailedActivity implements ShouldQueue $fields->company_id = $event->invoice->company_id; $fields->activity_type_id = Activity::EMAIL_INVOICE_FAILED; - $this->activity_repo->save($fields, $event->invoice); + $this->activity_repo->save($fields, $event->invoice, $event->event_vars); } } diff --git a/app/Listeners/Invoice/InvoiceReversedActivity.php b/app/Listeners/Invoice/InvoiceReversedActivity.php index ecaee30ad19c..8d42772dde86 100644 --- a/app/Listeners/Invoice/InvoiceReversedActivity.php +++ b/app/Listeners/Invoice/InvoiceReversedActivity.php @@ -51,6 +51,6 @@ class InvoiceReversedActivity implements ShouldQueue $fields->company_id = $event->invoice->company_id; $fields->activity_type_id = Activity::REVERSED_INVOICE; - $this->activity_repo->save($fields, $event->invoice); + $this->activity_repo->save($fields, $event->invoice, $event->event_vars); } } diff --git a/app/Listeners/Invoice/UpdateInvoiceActivity.php b/app/Listeners/Invoice/UpdateInvoiceActivity.php index 5f7bbd8cad62..d7704c27bcd4 100644 --- a/app/Listeners/Invoice/UpdateInvoiceActivity.php +++ b/app/Listeners/Invoice/UpdateInvoiceActivity.php @@ -52,6 +52,6 @@ class UpdateInvoiceActivity implements ShouldQueue $fields->activity_type_id = Activity::UPDATE_INVOICE; $fields->invoice_id = $event->invoice->id; - $this->activity_repo->save($fields, $event->invoice); + $this->activity_repo->save($fields, $event->invoice, $event->event_vars); } } diff --git a/app/Listeners/User/ArchivedUserActivity.php b/app/Listeners/User/ArchivedUserActivity.php index 1680987a4311..fc14607c0f3d 100644 --- a/app/Listeners/User/ArchivedUserActivity.php +++ b/app/Listeners/User/ArchivedUserActivity.php @@ -51,6 +51,6 @@ class ArchivedUserActivity implements ShouldQueue $fields->company_id = $event->user->company_id; $fields->activity_type_id = Activity::ARCHIVE_USER; - $this->activityRepo->save($fields, $event->user); + $this->activityRepo->save($fields, $event->user, $event->event_vars); } } diff --git a/app/Listeners/User/CreatedUserActivity.php b/app/Listeners/User/CreatedUserActivity.php index 0c80966b38aa..a37ee9c48f95 100644 --- a/app/Listeners/User/CreatedUserActivity.php +++ b/app/Listeners/User/CreatedUserActivity.php @@ -51,6 +51,6 @@ class CreatedUserActivity implements ShouldQueue $fields->company_id = $event->user->company_id; $fields->activity_type_id = Activity::CREATE_USER; - $this->activityRepo->save($fields, $event->user); + $this->activityRepo->save($fields, $event->user, $event->event_vars); } } diff --git a/app/Listeners/User/DeletedUserActivity.php b/app/Listeners/User/DeletedUserActivity.php index 9774696521f6..ffed3dc68d3a 100644 --- a/app/Listeners/User/DeletedUserActivity.php +++ b/app/Listeners/User/DeletedUserActivity.php @@ -56,6 +56,6 @@ class DeletedUserActivity implements ShouldQueue $fields->company_id = $event->company->id; $fields->activity_type_id = Activity::DELETE_USER; - $this->activityRepo->save($fields, $event->user); + $this->activityRepo->save($fields, $event->user, $event->event_vars); } } diff --git a/app/Listeners/User/RestoredUserActivity.php b/app/Listeners/User/RestoredUserActivity.php index ce23094b9c99..060ff4af9451 100644 --- a/app/Listeners/User/RestoredUserActivity.php +++ b/app/Listeners/User/RestoredUserActivity.php @@ -51,6 +51,6 @@ class RestoredUserActivity implements ShouldQueue $fields->company_id = $event->user->company_id; $fields->activity_type_id = Activity::RESTORE_USER; - $this->activityRepo->save($fields, $event->user); + $this->activityRepo->save($fields, $event->user, $event->event_vars); } } diff --git a/app/Listeners/User/UpdatedUserActivity.php b/app/Listeners/User/UpdatedUserActivity.php index e33a06c8c13e..359ea0821d4c 100644 --- a/app/Listeners/User/UpdatedUserActivity.php +++ b/app/Listeners/User/UpdatedUserActivity.php @@ -51,6 +51,6 @@ class UpdatedUserActivity implements ShouldQueue $fields->company_id = $event->user->company_id; $fields->activity_type_id = Activity::UPDATE_USER; - $this->activityRepo->save($fields, $event->user); + $this->activityRepo->save($fields, $event->user, $event->event_vars); } } diff --git a/app/Models/Client.php b/app/Models/Client.php index 754119dc6a2c..7624067aac7d 100644 --- a/app/Models/Client.php +++ b/app/Models/Client.php @@ -448,22 +448,29 @@ class Client extends BaseModel implements HasLocalePreference if ($company_gateways) { $gateways = $this->company->company_gateways->whereIn('id', $payment_gateways); //this will never hit } else { - $gateways = $this->company->company_gateways; + $gateways = $this->company->company_gateways->where('is_deleted', false); } - $gateways->filter(function ($method) use ($amount) { - if ($method->min_limit !== null && $amount < $method->min_limit) { - return false; - } + $valid_gateways = $gateways->filter(function ($method) use ($amount) { - if ($method->max_limit !== null && $amount > $method->min_limit) { + if(isset($method->fees_and_limits)) + $fees_and_limits = $method->fees_and_limits->{"1"}; + else + return true; + + if ((property_exists($fees_and_limits, 'min_limit')) && $fees_and_limits->min_limit !== null && $amount < $fees_and_limits->min_limit) + return false; + + if ((property_exists($fees_and_limits, 'max_limit')) && $fees_and_limits->max_limit !== null && $amount > $fees_and_limits->max_limit) return false; - } - }); + + return true; + + })->all(); $payment_methods = []; - foreach ($gateways as $gateway) { + foreach ($valid_gateways as $gateway) { foreach ($gateway->driver($this)->gatewayTypes() as $type) { $payment_methods[] = [$gateway->id => $type]; } diff --git a/app/Models/ClientGatewayToken.php b/app/Models/ClientGatewayToken.php index f80064ab6c9c..ab65290ed5d3 100644 --- a/app/Models/ClientGatewayToken.php +++ b/app/Models/ClientGatewayToken.php @@ -44,7 +44,7 @@ class ClientGatewayToken extends BaseModel public function gateway() { - return $this->hasOne(CompanyGateway::class); + return $this->hasOne(CompanyGateway::class, 'id', 'company_gateway_id'); } public function gateway_type() diff --git a/app/Models/Company.php b/app/Models/Company.php index 63da858ca36d..761bcaefe305 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -12,7 +12,7 @@ namespace App\Models; use App\DataMapper\CompanySettings; -use App\Events\Company\CompanyWasDeleted; +use App\Events\Company\CompanyDocumentsDeleted; use App\Models\Account; use App\Models\Client; use App\Models\CompanyGateway; @@ -67,10 +67,6 @@ class Company extends BaseModel protected $presenter = 'App\Models\Presenters\CompanyPresenter'; - protected $dispatchesEvents = [ - 'deleted' => CompanyWasDeleted::class, - ]; - protected $fillable = [ 'enabled_item_tax_rates', 'fill_products', diff --git a/app/Models/Credit.php b/app/Models/Credit.php index 78261cacae42..944ca7c9aa85 100644 --- a/app/Models/Credit.php +++ b/app/Models/Credit.php @@ -18,6 +18,7 @@ use App\Jobs\Credit\CreateCreditPdf; use App\Models\Filterable; use App\Services\Credit\CreditService; use App\Services\Ledger\LedgerService; +use App\Utils\Ninja; use App\Utils\Traits\MakesDates; use App\Utils\Traits\MakesHash; use App\Utils\Traits\MakesInvoiceValues; @@ -240,10 +241,10 @@ class Credit extends BaseModel } if (!$invitation) { - event(new CreditWasUpdated($this, $this->company)); + event(new CreditWasUpdated($this, $this->company, Ninja::eventVars())); CreateCreditPdf::dispatchNow($this, $this->company, $this->client->primary_contact()->first()); } else { - event(new CreditWasUpdated($this, $this->company)); + event(new CreditWasUpdated($this, $this->company, Ninja::eventVars())); CreateCreditPdf::dispatchNow($invitation->credit, $invitation->company, $invitation->contact); } diff --git a/app/Models/CreditInvitation.php b/app/Models/CreditInvitation.php index d9470f2bb212..3220a568711f 100644 --- a/app/Models/CreditInvitation.php +++ b/app/Models/CreditInvitation.php @@ -14,6 +14,7 @@ namespace App\Models; use App\Events\Credit\CreditWasUpdated; use App\Jobs\Credit\CreateCreditPdf; use App\Models\Invoice; +use App\Utils\Ninja; use App\Utils\Traits\Inviteable; use App\Utils\Traits\MakesDates; use Illuminate\Database\Eloquent\Model; @@ -126,7 +127,7 @@ class CreditInvitation extends BaseModel $storage_path = Storage::url($this->credit->client->quote_filepath() . $this->credit->number . '.pdf'); if (!Storage::exists($this->credit->client->credit_filepath() . $this->credit->number . '.pdf')) { - event(new CreditWasUpdated($this, $this->company)); + event(new CreditWasUpdated($this, $this->company, Ninja::eventVars())); CreateCreditPdf::dispatchNow($this); } diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index 50cffcfd250b..c3128d5a3ded 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -26,6 +26,7 @@ use App\Models\Filterable; use App\Models\PaymentTerm; use App\Services\Invoice\InvoiceService; use App\Services\Ledger\LedgerService; +use App\Utils\Ninja; use App\Utils\Number; use App\Utils\Traits\Archivable; use App\Utils\Traits\InvoiceEmailBuilder; @@ -268,7 +269,9 @@ class Invoice extends BaseModel public function isPayable(): bool { - if ($this->status_id == Invoice::STATUS_SENT && $this->is_deleted == false) { + if($this->status_id == Invoice::STATUS_DRAFT && $this->is_deleted == false){ + return true; + }else if ($this->status_id == Invoice::STATUS_SENT && $this->is_deleted == false) { return true; } elseif ($this->status_id == Invoice::STATUS_PARTIAL && $this->is_deleted == false) { return true; @@ -402,7 +405,7 @@ class Invoice extends BaseModel $storage_path = Storage::url($this->client->invoice_filepath() . $this->number . '.pdf'); if (!Storage::exists($this->client->invoice_filepath() . $this->number . '.pdf')) { - event(new InvoiceWasUpdated($this, $this->company)); + event(new InvoiceWasUpdated($this, $this->company, Ninja::eventVars())); CreateInvoicePdf::dispatchNow($invitation); } diff --git a/app/Models/InvoiceInvitation.php b/app/Models/InvoiceInvitation.php index 304b52352b91..e41a310d13b6 100644 --- a/app/Models/InvoiceInvitation.php +++ b/app/Models/InvoiceInvitation.php @@ -14,6 +14,7 @@ namespace App\Models; use App\Events\Invoice\InvoiceWasUpdated; use App\Jobs\Invoice\CreateInvoicePdf; use App\Models\Invoice; +use App\Utils\Ninja; use App\Utils\Traits\Inviteable; use App\Utils\Traits\MakesDates; use Illuminate\Database\Eloquent\SoftDeletes; @@ -134,7 +135,7 @@ class InvoiceInvitation extends BaseModel $storage_path = Storage::url($this->invoice->client->invoice_filepath() . $this->invoice->number . '.pdf'); if (!Storage::exists($this->invoice->client->invoice_filepath() . $this->invoice->number . '.pdf')) { - event(new InvoiceWasUpdated($this->invoice, $this->company)); + event(new InvoiceWasUpdated($this->invoice, $this->company, Ninja::eventVars())); CreateInvoicePdf::dispatchNow($this); } diff --git a/app/Models/Payment.php b/app/Models/Payment.php index b902d17441bc..64b7e8edf0a1 100644 --- a/app/Models/Payment.php +++ b/app/Models/Payment.php @@ -19,6 +19,7 @@ use App\Models\Filterable; use App\Models\Paymentable; use App\Services\Ledger\LedgerService; use App\Services\Payment\PaymentService; +use App\Utils\Ninja; use App\Utils\Number; use App\Utils\Traits\MakesDates; use App\Utils\Traits\MakesHash; @@ -240,7 +241,7 @@ class Payment extends BaseModel $this->status_id = $this->refunded == $this->amount ? self::STATUS_REFUNDED : self::STATUS_PARTIALLY_REFUNDED; $this->save(); - event(new PaymentWasRefunded($this, $refund_change)); + event(new PaymentWasRefunded($this, $refund_change, $this->company, Ninja::eventVars())); } return true; @@ -277,6 +278,6 @@ class Payment extends BaseModel $this->status_id = self::STATUS_CANCELLED; $this->save(); - event(new PaymentWasVoided($this)); + event(new PaymentWasVoided($this, $this->company, Ninja::eventVars())); } } diff --git a/app/Models/Quote.php b/app/Models/Quote.php index 5f64ce2a9795..ccb8d743de41 100644 --- a/app/Models/Quote.php +++ b/app/Models/Quote.php @@ -18,6 +18,7 @@ use App\Jobs\Invoice\CreateInvoicePdf; use App\Jobs\Quote\CreateQuotePdf; use App\Models\Filterable; use App\Services\Quote\QuoteService; +use App\Utils\Ninja; use App\Utils\Traits\Archivable; use App\Utils\Traits\MakesDates; use App\Utils\Traits\MakesHash; @@ -197,7 +198,7 @@ class Quote extends BaseModel return $storage_path; } - event(new QuoteWasUpdated($this, $this->company)); + event(new QuoteWasUpdated($this, $this->company, Ninja::eventVars())); CreateQuotePdf::dispatchNow($invitation); diff --git a/app/Models/QuoteInvitation.php b/app/Models/QuoteInvitation.php index eef652324de8..b8b37cda9227 100644 --- a/app/Models/QuoteInvitation.php +++ b/app/Models/QuoteInvitation.php @@ -14,6 +14,7 @@ namespace App\Models; use App\Events\Quote\QuoteWasUpdated; use App\Jobs\Quote\CreateQuotePdf; use App\Models\Quote; +use App\Utils\Ninja; use App\Utils\Traits\Inviteable; use App\Utils\Traits\MakesDates; use Illuminate\Database\Eloquent\Model; @@ -124,7 +125,7 @@ class QuoteInvitation extends BaseModel $storage_path = Storage::url($this->quote->client->quote_filepath() . $this->quote->number . '.pdf'); if (!Storage::exists($this->quote->client->quote_filepath() . $this->quote->number . '.pdf')) { - event(new QuoteWasUpdated($this, $this->company)); + event(new QuoteWasUpdated($this, $this->company, Ninja::eventVars())); CreateQuotePdf::dispatchNow($this); } diff --git a/app/Observers/ClientObserver.php b/app/Observers/ClientObserver.php index e13e1d7f1f0e..5a59a6b5807f 100644 --- a/app/Observers/ClientObserver.php +++ b/app/Observers/ClientObserver.php @@ -11,7 +11,6 @@ namespace App\Observers; -use App\Events\Client\ClientWasCreated; use App\Jobs\Util\WebhookHandler; use App\Models\Client; use App\Models\Webhook; @@ -26,8 +25,6 @@ class ClientObserver */ public function created(Client $client) { - event(new ClientWasCreated($client, $client->company)); - WebhookHandler::dispatch(Webhook::EVENT_CREATE_CLIENT, $client); } diff --git a/app/Observers/CompanyObserver.php b/app/Observers/CompanyObserver.php index 78e3fd056b37..ce47b7894ba1 100644 --- a/app/Observers/CompanyObserver.php +++ b/app/Observers/CompanyObserver.php @@ -11,7 +11,9 @@ namespace App\Observers; +use App\Events\Company\CompanyDocumentsDeleted; use App\Models\Company; +use App\Utils\Ninja; class CompanyObserver { @@ -45,7 +47,7 @@ class CompanyObserver */ public function deleted(Company $company) { - // + event(new CompanyDocumentsDeleted($company)); } /** diff --git a/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php b/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php index 1eeb7b5cabaf..d19e6698786f 100644 --- a/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php +++ b/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php @@ -24,6 +24,7 @@ use App\PaymentDrivers\AuthorizePaymentDriver; use App\PaymentDrivers\Authorize\AuthorizeCreateCustomer; use App\PaymentDrivers\Authorize\AuthorizePaymentMethod; use App\PaymentDrivers\Authorize\ChargePaymentProfile; +use App\Utils\Ninja; use App\Utils\Traits\MakesHash; use Illuminate\Support\Carbon; @@ -99,10 +100,13 @@ class AuthorizeCreditCard return $this->handleResponse($data, $request); } - private function handleResponse($data, $request) + private function tokenBilling($cgt, $amount, $invoice) { - //info(print_r( $response->getTransactionResponse()->getMessages(),1)); - + + } + + private function handleResponse($data, $request) + { $response = $data['response']; if($response != null && $response->getMessages()->getResultCode() == "Ok") @@ -134,7 +138,7 @@ class AuthorizeCreditCard $payment->service()->updateInvoicePayment(); - event(new PaymentWasCreated($payment, $payment->company)); + event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars())); $logger_message = [ 'server_response' => $response->getTransactionResponse()->getTransId(), diff --git a/app/PaymentDrivers/AuthorizePaymentDriver.php b/app/PaymentDrivers/AuthorizePaymentDriver.php index d9a60dd5cdb5..da502665b6f6 100644 --- a/app/PaymentDrivers/AuthorizePaymentDriver.php +++ b/app/PaymentDrivers/AuthorizePaymentDriver.php @@ -17,6 +17,7 @@ use App\Models\GatewayType; use App\Models\Payment; use App\PaymentDrivers\Authorize\AuthorizeCreditCard; use App\PaymentDrivers\Authorize\AuthorizePaymentMethod; +use App\PaymentDrivers\Authorize\ChargePaymentProfile; use App\PaymentDrivers\Authorize\RefundTransaction; use net\authorize\api\constants\ANetEnvironment; use net\authorize\api\contract\v1\CreateTransactionRequest; @@ -136,4 +137,12 @@ class AuthorizePaymentDriver extends BaseDriver ->where('company_gateway_id', $this->company_gateway->id) ->first(); } + + public function tokenBilling(ClientGatewayToken $cgt, float $amount, ?Invoice $invoice = null) + { + $this->setPaymentMethod($cgt->gateway_type_id); + + $this->payment_method->tokenBilling($cgt, $amount, $invoice); + } + } diff --git a/app/PaymentDrivers/BaseDriver.php b/app/PaymentDrivers/BaseDriver.php index eaa32f860fda..5f80c8385e8f 100644 --- a/app/PaymentDrivers/BaseDriver.php +++ b/app/PaymentDrivers/BaseDriver.php @@ -13,6 +13,7 @@ namespace App\PaymentDrivers; use App\Models\Client; +use App\Models\ClientGatewayToken; use App\Models\CompanyGateway; use App\Models\Invoice; use App\Models\Payment; @@ -48,6 +49,7 @@ class BaseDriver extends AbstractPaymentDriver /* The client */ public $client; + /* The initiated gateway driver class*/ public $payment_method; public static $methods = []; @@ -117,4 +119,14 @@ class BaseDriver extends AbstractPaymentDriver return $payment; } + + /** + * Process an unattended payment + * + * @param ClientGatewayToken $cgt The client gateway token object + * @param float $amount The amount to bill + * @param Invoice $invoice Optional Invoice object being paid + * @return Response The payment response + */ + public function tokenBilling(ClientGatewayToken $cgt, float $amount, ?Invoice $invoice = null) {} } diff --git a/app/PaymentDrivers/CheckoutComPaymentDriver.php b/app/PaymentDrivers/CheckoutComPaymentDriver.php index 7ea15c1a3f1f..ff058296e1cb 100644 --- a/app/PaymentDrivers/CheckoutComPaymentDriver.php +++ b/app/PaymentDrivers/CheckoutComPaymentDriver.php @@ -21,6 +21,7 @@ use App\Models\Payment; use App\Models\PaymentType; use App\Models\SystemLog; use App\PaymentDrivers\CheckoutCom\Utilities; +use App\Utils\Ninja; use App\Utils\Traits\SystemLogTrait; use Checkout\CheckoutApi; use Checkout\Library\Exceptions\CheckoutHttpException; @@ -167,7 +168,7 @@ class CheckoutComPaymentDriver extends BasePaymentDriver $payment->service()->updateInvoicePayment(); - event(new PaymentWasCreated($payment, $payment->company)); + event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars())); $logger_message = [ 'server_response' => $state['payment_response'], @@ -199,7 +200,7 @@ class CheckoutComPaymentDriver extends BasePaymentDriver $payment->service()->updateInvoicePayment(); - event(new PaymentWasCreated($payment, $payment->company)); + event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars())); $logger_message = [ 'server_response' => $state['payment_response'], @@ -311,4 +312,7 @@ class CheckoutComPaymentDriver extends BasePaymentDriver ]; } } + + public function tokenBilling(ClientGatewayToken $cgt, float $amount) {} + } diff --git a/app/PaymentDrivers/PayPalExpressPaymentDriver.php b/app/PaymentDrivers/PayPalExpressPaymentDriver.php index 4440e1911b41..4b4808389a0d 100644 --- a/app/PaymentDrivers/PayPalExpressPaymentDriver.php +++ b/app/PaymentDrivers/PayPalExpressPaymentDriver.php @@ -20,6 +20,7 @@ use App\Models\GatewayType; use App\Models\Payment; use App\Models\PaymentType; use App\Models\SystemLog; +use App\Utils\Ninja; use App\Utils\Traits\MakesHash; use Omnipay\Common\Item; @@ -167,7 +168,7 @@ class PayPalExpressPaymentDriver extends BasePaymentDriver $payment->service()->UpdateInvoicePayment(); - event(new PaymentWasCreated($payment, $payment->company)); + event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars())); return redirect()->route('client.payments.show', ['payment' => $this->encodePrimaryKey($payment->id)]); } diff --git a/app/PaymentDrivers/Stripe/ACH.php b/app/PaymentDrivers/Stripe/ACH.php index a0b698b652b2..8358b19cf681 100644 --- a/app/PaymentDrivers/Stripe/ACH.php +++ b/app/PaymentDrivers/Stripe/ACH.php @@ -21,6 +21,7 @@ use App\Models\Payment; use App\Models\PaymentType; use App\Models\SystemLog; use App\PaymentDrivers\StripePaymentDriver; +use App\Utils\Ninja; use Stripe\Exception\InvalidRequestException; class ACH @@ -194,7 +195,7 @@ class ACH $payment->service()->updateInvoicePayment(); - event(new PaymentWasCreated($payment, $payment->company)); + event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars())); $logger_message = [ 'server_response' => $state['charge'], diff --git a/app/PaymentDrivers/Stripe/Alipay.php b/app/PaymentDrivers/Stripe/Alipay.php index 784a9088d81c..150d3985f491 100644 --- a/app/PaymentDrivers/Stripe/Alipay.php +++ b/app/PaymentDrivers/Stripe/Alipay.php @@ -21,6 +21,7 @@ use App\Models\Payment; use App\Models\PaymentType; use App\Models\SystemLog; use App\PaymentDrivers\StripePaymentDriver; +use App\Utils\Ninja; class Alipay { @@ -87,7 +88,7 @@ class Alipay $this->stripe->attachInvoices($payment, $state['hashed_ids']); } - event(new PaymentWasCreated($payment, $payment->company)); + event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars())); $logger_message = [ 'server_response' => $state, diff --git a/app/PaymentDrivers/Stripe/CreditCard.php b/app/PaymentDrivers/Stripe/CreditCard.php index bfb73f4230cb..b0a585db6cd5 100644 --- a/app/PaymentDrivers/Stripe/CreditCard.php +++ b/app/PaymentDrivers/Stripe/CreditCard.php @@ -22,6 +22,7 @@ use App\Models\Payment; use App\Models\PaymentType; use App\Models\SystemLog; use App\PaymentDrivers\StripePaymentDriver; +use App\Utils\Ninja; use Stripe\PaymentMethod; class CreditCard @@ -184,7 +185,7 @@ class CreditCard $payment->service()->updateInvoicePayment(); - event(new PaymentWasCreated($payment, $payment->company)); + event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars())); $logger_message = [ 'server_response' => $state['payment_intent'], diff --git a/app/PaymentDrivers/Stripe/SOFORT.php b/app/PaymentDrivers/Stripe/SOFORT.php index f2e521f4fdbc..55ed95508e65 100644 --- a/app/PaymentDrivers/Stripe/SOFORT.php +++ b/app/PaymentDrivers/Stripe/SOFORT.php @@ -20,6 +20,7 @@ use App\Models\Payment; use App\Models\PaymentType; use App\Models\SystemLog; use App\PaymentDrivers\StripePaymentDriver; +use App\Utils\Ninja; class SOFORT { @@ -88,7 +89,7 @@ class SOFORT $this->stripe->attachInvoices($payment, $state['hashed_ids']); } - event(new PaymentWasCreated($payment, $payment->company)); + event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars())); $logger_message = [ 'server_response' => $state, diff --git a/app/PaymentDrivers/StripePaymentDriver.php b/app/PaymentDrivers/StripePaymentDriver.php index bbb82246fae4..d0c96407d0d1 100644 --- a/app/PaymentDrivers/StripePaymentDriver.php +++ b/app/PaymentDrivers/StripePaymentDriver.php @@ -366,5 +366,7 @@ class StripePaymentDriver extends BasePaymentDriver return response([], 200); } - /************************************** Omnipay API methods **********************************************************/ + public function tokenBilling(ClientGatewayToken $cgt, float $amount) {} + + } diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 3e1f1718bdd1..9b8a3348f145 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -19,7 +19,7 @@ use App\Events\Client\ClientWasUpdated; use App\Events\Client\DesignWasDeleted; use App\Events\Client\DesignWasRestored; use App\Events\Client\DesignWasUpdated; -use App\Events\Company\CompanyWasDeleted; +use App\Events\Company\CompanyDocumentsDeleted; use App\Events\Contact\ContactLoggedIn; use App\Events\Credit\CreditWasEmailedAndFailed; use App\Events\Credit\CreditWasMarkedSent; @@ -170,7 +170,7 @@ class EventServiceProvider extends ServiceProvider InvitationWasViewed::class => [ InvitationViewedListener::class ], - CompanyWasDeleted::class => [ + CompanyDocumentsDeleted::class => [ DeleteCompanyDocuments::class, ], QuoteWasApproved::class => [ diff --git a/app/Repositories/ActivityRepository.php b/app/Repositories/ActivityRepository.php index 311d22e7147d..d6be055ad411 100644 --- a/app/Repositories/ActivityRepository.php +++ b/app/Repositories/ActivityRepository.php @@ -15,6 +15,7 @@ use App\Libraries\MultiDB; use App\Models\Activity; use App\Models\Backup; use App\Models\Client; +use App\Models\CompanyToken; use App\Models\Invoice; use App\Models\User; use App\Utils\Traits\MakesInvoiceHtml; @@ -32,20 +33,24 @@ class ActivityRepository extends BaseRepository * @param stdClass $fields The fields * @param Collection $entity The entity that you wish to have backed up (typically Invoice, Quote etc etc rather than Payment) */ - public function save($fields, $entity, $db = null) + public function save($fields, $entity, $event_vars) { if($db) MultiDB::setDB($db); $activity = new Activity(); - $activity->is_system = app()->runningInConsole(); - $activity->ip = request()->getClientIp(); - foreach ($fields as $key => $value) { $activity->{$key} = $value; } + if($token_id = $this->getTokenId($event_vars)){ + $fields->token_id = $token_id; + } + + $fields->ip = $event_vars['ip']; + $fields->is_system = $event_vars['is_system']; + $activity->save(); $this->createBackup($entity, $activity); @@ -85,4 +90,21 @@ class ActivityRepository extends BaseRepository $backup->json_backup = $entity->toJson(); $backup->save(); } + + public function getTokenId(array $event_vars) + { + + if($event_vars['token']) + { + + $company_token = CompanyToken::whereRaw("BINARY `token`= ?", [$event_vars['token']])->first(); + + if($company_token) + return $company_token->id; + + } + + return false; + + } } diff --git a/app/Repositories/BaseRepository.php b/app/Repositories/BaseRepository.php index e9487feb08c5..fe6a6d2586e8 100644 --- a/app/Repositories/BaseRepository.php +++ b/app/Repositories/BaseRepository.php @@ -19,10 +19,12 @@ use App\Factory\QuoteInvitationFactory; use App\Jobs\Product\UpdateOrCreateProduct; use App\Models\Client; use App\Models\ClientContact; +use App\Models\Company; use App\Models\Credit; use App\Models\Invoice; use App\Models\InvoiceInvitation; use App\Models\Quote; +use App\Utils\Ninja; use App\Utils\Traits\MakesHash; use App\Utils\Traits\SavesDocuments; use ReflectionClass; @@ -78,7 +80,7 @@ class BaseRepository $className = $this->getEventClass($entity, 'Archived'); if (class_exists($className)) { - event(new $className($entity, $entity->company)); + event(new $className($entity, $entity->company, Ninja::eventVars())); } } @@ -104,7 +106,7 @@ class BaseRepository $className = $this->getEventClass($entity, 'Restored'); if (class_exists($className)) { - event(new $className($entity, $fromDeleted, $entity->company)); + event(new $className($entity, $fromDeleted, $entity->company, Ninja::eventVars())); } } @@ -124,8 +126,8 @@ class BaseRepository $className = $this->getEventClass($entity, 'Deleted'); - if (class_exists($className)) { - event(new $className($entity, $entity->company)); + if (class_exists($className) && !($entity instanceOf Company)) { + event(new $className($entity, $entity->company, Ninja::eventVars())); } } diff --git a/app/Repositories/DocumentRepository.php b/app/Repositories/DocumentRepository.php index 3620985bb954..f9b657c9645f 100644 --- a/app/Repositories/DocumentRepository.php +++ b/app/Repositories/DocumentRepository.php @@ -12,6 +12,7 @@ namespace App\Repositories; use App\Models\Document; +use App\Utils\Ninja; /** * Class for document repository. @@ -44,7 +45,7 @@ class DocumentRepository extends BaseRepository $document->restore(); if (class_exists($className)) { - event(new $className($document)); + event(new $className($document, $document->company, Ninja::eventVars())); } } } diff --git a/app/Repositories/PaymentRepository.php b/app/Repositories/PaymentRepository.php index e2b0004c6465..e9d5c38aaa68 100644 --- a/app/Repositories/PaymentRepository.php +++ b/app/Repositories/PaymentRepository.php @@ -20,6 +20,7 @@ use App\Models\Credit; use App\Models\Invoice; use App\Models\Payment; use App\Repositories\CreditRepository; +use App\Utils\Ninja; use App\Utils\Traits\MakesHash; use App\Utils\Traits\SavesDocuments; use Illuminate\Http\Request; @@ -149,7 +150,7 @@ class PaymentRepository extends BaseRepository } } - event(new PaymentWasCreated($payment, $payment->company)); + event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars())); $invoice_totals -= $credit_totals; diff --git a/app/Repositories/UserRepository.php b/app/Repositories/UserRepository.php index 7b78c8e5f371..ff3cd9af71b4 100644 --- a/app/Repositories/UserRepository.php +++ b/app/Repositories/UserRepository.php @@ -16,6 +16,7 @@ use App\Events\User\UserWasDeleted; use App\Factory\CompanyUserFactory; use App\Models\CompanyUser; use App\Models\User; +use App\Utils\Ninja; use Illuminate\Http\Request; /** @@ -112,7 +113,7 @@ class UserRepository extends BaseRepository $user->delete(); - event(new UserWasDeleted($user, $company)); + event(new UserWasDeleted($user, $company, Ninja::eventVars())); return $user->fresh(); } @@ -137,7 +138,7 @@ class UserRepository extends BaseRepository $user->save(); $user->delete(); - event(new UserWasDeleted($user, $company)); + event(new UserWasDeleted($user, $company, Ninja::eventVars())); return $user->fresh(); } diff --git a/app/Services/Credit/MarkSent.php b/app/Services/Credit/MarkSent.php index f36b38dfe538..9595ec6569db 100644 --- a/app/Services/Credit/MarkSent.php +++ b/app/Services/Credit/MarkSent.php @@ -14,6 +14,7 @@ namespace App\Services\Credit; use App\Events\Credit\CreditWasMarkedSent; use App\Models\Credit; +use App\Utils\Ninja; class MarkSent { @@ -37,7 +38,7 @@ class MarkSent $this->credit->markInvitationsSent(); - event(new CreditWasMarkedSent($this->credit, $this->credit->company)); + event(new CreditWasMarkedSent($this->credit, $this->credit->company, Ninja::eventVars())); $this->credit ->service() diff --git a/app/Services/Invoice/AutoBillInvoice.php b/app/Services/Invoice/AutoBillInvoice.php new file mode 100644 index 000000000000..578c8f8b4943 --- /dev/null +++ b/app/Services/Invoice/AutoBillInvoice.php @@ -0,0 +1,171 @@ +invoice = $invoice; + + $this->client = $invoice->client; + } + + public function run() + { + + if(!$this->invoice->isPayable()) + return $this->invoice; + + if($this->invoice->balance > 0) + $gateway_token = $this->getGateway($this->invoice->balance); + else + return $this->invoice->service()->markPaid()->save(); + + $fee = $gateway_token->gateway->calcGatewayFee($this->invoice->balance); + + if($fee > 0) + $this->purgeStaleGatewayFees()->addFeeToInvoice($fee); + + $response = $gateway_token->gateway->driver($this->client)->tokenBilling($gateway_token, $amount, $this->invoice); + + //if response was successful, toggle the fee type_id to paid + } + + private function getGateway($amount) + { + + $gateway_tokens = $this->client->gateway_tokens()->orderBy('is_default', 'DESC'); + + return $gateway_tokens->filter(function ($token) use ($amount){ + + return $this->validGatewayLimits($token, $amount); + + })->all()->first(); + + } + + /** + * Adds a gateway fee to the invoice + * + * @param float $fee The fee amount. + */ + private function addFeeToInvoice(float $fee) + { + + //todo if we increase the invoice balance here, we will also need to adjust UP the client balance and ledger? + $starting_amount = $this->invoice->amount; + + $item = new InvoiceItem; + $item->quantity = 1; + $item->cost = $fee; + $item->notes = ctrans('texts.online_payment_surcharge'); + $item->type_id = 3; + + $items = (array)$this->invoice->line_items; + $items[] = $item; + + $this->invoice->line_items = $items; + $this->invoice->save(); + + $this->invoice = $this->invoice->calc()->getInvoice()->save(); + + if($starting_amount != $this->invoice->amount && $this->invoice->status_id != Invoice::STATUS_DRAFT){ + $this->invoice->client->service()->updateBalance($this->invoice->amount - $starting_amount)->save(); + $this->invoice->ledger()->updateInvoiceBalance($this->invoice->amount - $starting_amount, 'Invoice balance updated after stale gateway fee removed')->save(); + } + + return $this; + } + + /** + * Removes any existing unpaid gateway fees + * due to previous payment failure. + * + * @return $this + */ + private function purgeStaleGatewayFees() + { + $starting_amount = $this->invoice->amount; + + $line_items = $this->invoice->line_items; + + $new_items = []; + + foreach($line_items as $item) + { + + if($item->type_id != 3) + $new_items[] = $item; + + } + + $this->invoice->line_items = $new_items; + $this->invoice->save(); + + $this->invoice = $this->invoice->calc()->getInvoice()->save(); + + if($starting_amount != $this->invoice->amount && $this->invoice->status_id != Invoice::STATUS_DRAFT){ + $this->invoice->client->service()->updateBalance($this->invoice->amount - $starting_amount)->save(); + $this->invoice->ledger()->updateInvoiceBalance($this->invoice->amount - $starting_amount, 'Invoice balance updated after stale gateway fee removed')->save(); + } + + return $this; + } + + /** + * Checks whether a given gateway token is able + * to process the payment after passing through the + * fees and limits check + * + * @param CompanyGateway $cg The CompanyGateway instance + * @param float $amount The amount to be paid + * @return bool + */ + public function validGatewayLimits($cg, $amount) : bool + { + if(isset($cg->fees_and_limits)) + $fees_and_limits = $cg->fees_and_limits->{"1"}; + else + $passes = true; + + if ((property_exists($fees_and_limits, 'min_limit')) && $fees_and_limits->min_limit !== null && $amount < $fees_and_limits->min_limit) { + info("amount {$amount} less than ". $fees_and_limits->min_limit); + $passes = false; + } + else if ((property_exists($fees_and_limits, 'max_limit')) && $fees_and_limits->max_limit !== null && $amount > $fees_and_limits->max_limit){ + info("amount {$amount} greater than ". $fees_and_limits->max_limit); + $passes = false; + } + else + $passes = true; + + return $passes; + } + +} diff --git a/app/Services/Invoice/HandleCancellation.php b/app/Services/Invoice/HandleCancellation.php index 9ec42f86c412..360e3d8b1eb6 100644 --- a/app/Services/Invoice/HandleCancellation.php +++ b/app/Services/Invoice/HandleCancellation.php @@ -24,6 +24,7 @@ use App\Models\Paymentable; use App\Services\AbstractService; use App\Services\Client\ClientService; use App\Services\Payment\PaymentService; +use App\Utils\Ninja; use App\Utils\Traits\GeneratesCounter; class HandleCancellation extends AbstractService @@ -57,7 +58,7 @@ class HandleCancellation extends AbstractService //adjust client balance $this->invoice->client->service()->updateBalance($adjustment)->save(); - event(new InvoiceWasCancelled($this->invoice, $this->invoice->company)); + event(new InvoiceWasCancelled($this->invoice, $this->invoice->company, Ninja::eventVars())); return $this->invoice; diff --git a/app/Services/Invoice/HandleReversal.php b/app/Services/Invoice/HandleReversal.php index 961dfd6d18f8..2bb5a43cc8a9 100644 --- a/app/Services/Invoice/HandleReversal.php +++ b/app/Services/Invoice/HandleReversal.php @@ -24,6 +24,7 @@ use App\Models\Paymentable; use App\Services\AbstractService; use App\Services\Client\ClientService; use App\Services\Payment\PaymentService; +use App\Utils\Ninja; use App\Utils\Traits\GeneratesCounter; class HandleReversal extends AbstractService @@ -109,7 +110,7 @@ class HandleReversal extends AbstractService ->updatePaidToDate($total_paid*-1) ->save(); - event(new InvoiceWasReversed($this->invoice, $this->invoice->company)); + event(new InvoiceWasReversed($this->invoice, $this->invoice->company, Ninja::eventVars())); return $this->invoice; //create a ledger row for this with the resulting Credit ( also include an explanation in the notes section ) diff --git a/app/Services/Invoice/InvoiceService.php b/app/Services/Invoice/InvoiceService.php index 45e1e80d6779..c1999ec42edb 100644 --- a/app/Services/Invoice/InvoiceService.php +++ b/app/Services/Invoice/InvoiceService.php @@ -16,6 +16,7 @@ use App\Models\Payment; use App\Services\Client\ClientService; use App\Services\Invoice\ApplyNumber; use App\Services\Invoice\ApplyPayment; +use App\Services\Invoice\AutoBillInvoice; use App\Services\Invoice\CreateInvitations; use App\Services\Invoice\GetInvoicePdf; use App\Services\Invoice\HandleCancellation; @@ -103,7 +104,6 @@ class InvoiceService return $this; } - public function getInvoicePdf($contact = null) { return (new GetInvoicePdf($this->invoice, $contact))->run(); @@ -144,6 +144,13 @@ class InvoiceService return $this; } + public function autoBill() + { + $this->invoice = (new AutoBillInvoice($this->invoice))->run(); + + return $this; + } + public function markViewed() { $this->invoice->last_viewed = Carbon::now()->format('Y-m-d H:i'); diff --git a/app/Services/Invoice/MarkPaid.php b/app/Services/Invoice/MarkPaid.php index 8778a4ebd346..8ae30079c316 100644 --- a/app/Services/Invoice/MarkPaid.php +++ b/app/Services/Invoice/MarkPaid.php @@ -18,6 +18,7 @@ use App\Models\Payment; use App\Services\AbstractService; use App\Services\Client\ClientService; use App\Services\Payment\PaymentService; +use App\Utils\Ninja; use App\Utils\Traits\GeneratesCounter; class MarkPaid extends AbstractService @@ -65,7 +66,7 @@ class MarkPaid extends AbstractService ->save(); /* Update Invoice balance */ - event(new PaymentWasCreated($payment, $payment->company)); + event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars())); $payment->ledger() ->updatePaymentBalance($payment->amount*-1); diff --git a/app/Services/Invoice/MarkSent.php b/app/Services/Invoice/MarkSent.php index 314777d35769..50348669a9cf 100644 --- a/app/Services/Invoice/MarkSent.php +++ b/app/Services/Invoice/MarkSent.php @@ -14,6 +14,7 @@ namespace App\Services\Invoice; use App\Events\Invoice\InvoiceWasMarkedSent; use App\Models\Invoice; use App\Services\AbstractService; +use App\Utils\Ninja; class MarkSent extends AbstractService { @@ -39,7 +40,7 @@ class MarkSent extends AbstractService $this->invoice->setReminder(); - event(new InvoiceWasMarkedSent($this->invoice, $this->invoice->company)); + event(new InvoiceWasMarkedSent($this->invoice, $this->invoice->company, Ninja::eventVars())); $this->invoice ->service() @@ -48,12 +49,8 @@ class MarkSent extends AbstractService ->setDueDate() ->save(); - info("marking invoice sent currently client balance = {$this->client->balance}"); - $this->client->service()->updateBalance($this->invoice->balance)->save(); - info("after marking invoice sent currently client balance = {$this->client->balance}"); - $this->invoice->ledger()->updateInvoiceBalance($this->invoice->balance); return $this->invoice->fresh(); diff --git a/app/Services/Invoice/TriggeredActions.php b/app/Services/Invoice/TriggeredActions.php index 5d1d53b7c200..e14017fdcc7d 100644 --- a/app/Services/Invoice/TriggeredActions.php +++ b/app/Services/Invoice/TriggeredActions.php @@ -22,6 +22,7 @@ use App\Models\Payment; use App\Services\AbstractService; use App\Services\Client\ClientService; use App\Services\Payment\PaymentService; +use App\Utils\Ninja; use App\Utils\Traits\GeneratesCounter; use Illuminate\Http\Request; @@ -42,18 +43,17 @@ class TriggeredActions extends AbstractService public function run() { - //the request may have buried in it additional actions we should automatically perform on the invoice - - if($this->request->has('send_email')) { - - } if($this->request->has('auto_bill')) { - + $this->invoice->service()->autoBill()->save(); + } + + if($this->request->has('paid') && (bool)$this->request->input('paid') !== false) { + $this->invoice->service()->markPaid()->save(); } - if($this->request->has('paid')) { - + if($this->request->has('send_email') && (bool)$this->request->input('send_email') !== false) { + $this->sendEmail(); } return $this->invoice; @@ -73,7 +73,7 @@ class TriggeredActions extends AbstractService }); if ($this->invoice->invitations->count() > 0) { - event(new InvoiceWasEmailed($this->invoice->invitations->first(), $this->invoice->company)); + event(new InvoiceWasEmailed($this->invoice->invitations->first(), $this->invoice->company, Ninja::eventVars())); } } diff --git a/app/Services/Quote/MarkApproved.php b/app/Services/Quote/MarkApproved.php index 45eee09a5294..265cd13c0d79 100644 --- a/app/Services/Quote/MarkApproved.php +++ b/app/Services/Quote/MarkApproved.php @@ -14,6 +14,7 @@ namespace App\Services\Quote; use App\Events\Quote\QuoteWasMarkedApproved; use App\Models\Quote; +use App\Utils\Ninja; class MarkApproved { @@ -33,7 +34,7 @@ class MarkApproved $quote->service()->setStatus(Quote::STATUS_APPROVED)->applyNumber()->save(); - event(new QuoteWasMarkedApproved($quote, $quote->company)); + event(new QuoteWasMarkedApproved($quote, $quote->company, Ninja::eventVars())); return $quote; } diff --git a/app/Services/Quote/MarkSent.php b/app/Services/Quote/MarkSent.php index fb224d476d94..9014589e1438 100644 --- a/app/Services/Quote/MarkSent.php +++ b/app/Services/Quote/MarkSent.php @@ -14,6 +14,7 @@ namespace App\Services\Quote; use App\Events\Quote\QuoteWasMarkedSent; use App\Models\Quote; +use App\Utils\Ninja; class MarkSent { @@ -37,7 +38,7 @@ class MarkSent $this->quote->markInvitationsSent(); - event(new QuoteWasMarkedSent($this->quote, $this->quote->company)); + event(new QuoteWasMarkedSent($this->quote, $this->quote->company, Ninja::eventVars())); $this->quote ->service() diff --git a/app/Transformers/ActivityTransformer.php b/app/Transformers/ActivityTransformer.php index dd919f03be0b..e07161f0e9fc 100644 --- a/app/Transformers/ActivityTransformer.php +++ b/app/Transformers/ActivityTransformer.php @@ -48,6 +48,7 @@ class ActivityTransformer extends EntityTransformer 'is_system' => (bool) $activity->is_system, 'contact_id' => $activity->contact_id ? (string) $this->encodePrimaryKey($activity->contact_id) : '', 'task_id' => $activity->task_id ? (string) $this->encodePrimaryKey($activity->task_id) : '', + 'token_id' => $activity->token_id ? (string) $this->encodePrimaryKey($activity->token_id) : '', 'notes' => $activity->notes ? (string) $activity->notes : '', 'ip' => (string) $activity->ip, diff --git a/app/Utils/Ninja.php b/app/Utils/Ninja.php index 70800c7fed41..dba0f3cdb9c5 100644 --- a/app/Utils/Ninja.php +++ b/app/Utils/Ninja.php @@ -112,4 +112,13 @@ class Ninja curl_exec($ch); curl_close($ch); } + + public static function eventVars() + { + return [ + 'ip' => request()->getClientIp(), + 'token' => request()->header('X-API-TOKEN'), + 'is_system' => app()->runningInConsole(), + ]; + } } diff --git a/app/Utils/Traits/CompanyGatewayFeesAndLimitsSaver.php b/app/Utils/Traits/CompanyGatewayFeesAndLimitsSaver.php index f2c1e6de5817..b5802eebe75c 100644 --- a/app/Utils/Traits/CompanyGatewayFeesAndLimitsSaver.php +++ b/app/Utils/Traits/CompanyGatewayFeesAndLimitsSaver.php @@ -103,15 +103,16 @@ trait CompanyGatewayFeesAndLimitsSaver $new_arr = []; foreach ($fees_and_limits as $key => $value) { - $fal = new FeesAndLimits; + $fal = new FeesAndLimits; + // $fal->{$key} = $value; - $fal->{$key} = $value; - // foreach ($value as $k => $v) { - // $fal->{$k} = $v; - // $fal->{$k} = BaseSettings::castAttribute(FeesAndLimits::$casts[$k], $v); - // } + foreach ($value as $k => $v) { -// $new_arr[$key] = (array)$fal; + $fal->{$k} = $v; + $fal->{$k} = BaseSettings::castAttribute(FeesAndLimits::$casts[$k], $v); + } + + $new_arr[$key] = (array)$fal; } return $new_arr; diff --git a/app/Utils/Traits/MakesReminders.php b/app/Utils/Traits/MakesReminders.php index f2af721d15c0..1da4e1c8de5c 100644 --- a/app/Utils/Traits/MakesReminders.php +++ b/app/Utils/Traits/MakesReminders.php @@ -193,17 +193,17 @@ trait MakesReminders $client->getSetting('schedule_reminder1'), $client->getSetting('num_days_reminder1') )) { - return 'template1'; + return 'reminder1'; } elseif ($client->getSetting('enable_reminder2') !== false && $this->inReminderWindow( $client->getSetting('schedule_reminder2'), $client->getSetting('num_days_reminder2') )) { - return 'template2'; + return 'reminder2'; } elseif ($client->getSetting('enable_reminder3') !== false && $this->inReminderWindow( $client->getSetting('schedule_reminder3'), $client->getSetting('num_days_reminder3') )) { - return 'template3'; + return 'reminder3'; } else { return 'invoice'; } diff --git a/database/migrations/2020_07_08_065301_add_token_id_to_activity_table.php b/database/migrations/2020_07_08_065301_add_token_id_to_activity_table.php new file mode 100644 index 000000000000..b2e87940799b --- /dev/null +++ b/database/migrations/2020_07_08_065301_add_token_id_to_activity_table.php @@ -0,0 +1,30 @@ +unsignedInteger('token_id')->nullable(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + + } +} diff --git a/database/seeds/RandomDataSeeder.php b/database/seeds/RandomDataSeeder.php index 9efae51a33de..10f6b1faad2a 100644 --- a/database/seeds/RandomDataSeeder.php +++ b/database/seeds/RandomDataSeeder.php @@ -27,6 +27,7 @@ use App\Models\UserAccount; use App\Repositories\CreditRepository; use App\Repositories\InvoiceRepository; use App\Repositories\QuoteRepository; +use App\Utils\Ninja; use Illuminate\Database\Seeder; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Schema; @@ -199,7 +200,7 @@ class RandomDataSeeder extends Seeder $invoice->ledger()->updateInvoiceBalance($invoice->balance); - event(new InvoiceWasMarkedSent($invoice, $company)); + event(new InvoiceWasMarkedSent($invoice, $company, Ninja::eventVars())); if (rand(0, 1)) { $payment = App\Models\Payment::create([ @@ -215,7 +216,7 @@ class RandomDataSeeder extends Seeder $payment->invoices()->save($invoice); - event(new PaymentWasCreated($payment, $payment->company)); + event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars())); $payment->service()->updateInvoicePayment(); diff --git a/tests/Feature/CompanyGatewayTest.php b/tests/Feature/CompanyGatewayTest.php new file mode 100644 index 000000000000..5ee1de4482d3 --- /dev/null +++ b/tests/Feature/CompanyGatewayTest.php @@ -0,0 +1,104 @@ +makeTestData(); + + if (!config('ninja.testvars.stripe')) { + $this->markTestSkipped('Skip test no company gateways installed'); + } + } + + public function testGatewayExists() + { + + $company_gateway = CompanyGateway::first(); + $this->assertNotNull($company_gateway); + + } + + public function testFeesAndLimitsExists() + { + $data = []; + $data[1]['min_limit'] = 234; + $data[1]['max_limit'] = 65317; + $data[1]['fee_amount'] = 0.00; + $data[1]['fee_percent'] = 0.000; + $data[1]['fee_tax_name1'] = ''; + $data[1]['fee_tax_rate1'] = ''; + $data[1]['fee_tax_name2'] = ''; + $data[1]['fee_tax_rate2'] = ''; + $data[1]['fee_tax_name3'] = ''; + $data[1]['fee_tax_rate3'] = 0; + + $cg = new CompanyGateway; + $cg->company_id = $this->company->id; + $cg->user_id = $this->user->id; + $cg->gateway_key = 'd14dd26a37cecc30fdd65700bfb55b23'; + $cg->require_cvv = true; + $cg->show_billing_address = true; + $cg->show_shipping_address = true; + $cg->update_details = true; + $cg->config = encrypt(config('ninja.testvars.stripe')); + $cg->fees_and_limits = $data; + $cg->save(); + + $this->assertNotNull($cg->fees_and_limits); + $this->assertNotNull($cg->fees_and_limits->{"1"}); + + + //confirm amount filtering works + $amount = 100; + + $this->assertFalse($this->checkSieve($cg, $amount)); + + $amount = 235; + + $this->assertTrue($this->checkSieve($cg, $amount)); + + $amount = 70000; + + $this->assertFalse($this->checkSieve($cg, $amount)); + + } + + public function checkSieve($cg, $amount) + { + if(isset($cg->fees_and_limits)) + $fees_and_limits = $cg->fees_and_limits->{"1"}; + else + $passes = true; + + if ((property_exists($fees_and_limits, 'min_limit')) && $fees_and_limits->min_limit !== null && $amount < $fees_and_limits->min_limit) { + info("amount {$amount} less than ". $fees_and_limits->min_limit); + $passes = false; + } + else if ((property_exists($fees_and_limits, 'max_limit')) && $fees_and_limits->max_limit !== null && $amount > $fees_and_limits->max_limit){ + info("amount {$amount} greater than ". $fees_and_limits->max_limit); + $passes = false; + } + else + $passes = true; + + return $passes; + } +} \ No newline at end of file diff --git a/tests/MockAccountData.php b/tests/MockAccountData.php index 62b96fa5e553..5c5105b607f8 100644 --- a/tests/MockAccountData.php +++ b/tests/MockAccountData.php @@ -11,9 +11,11 @@ namespace Tests; +use App\DataMapper\BaseSettings; use App\DataMapper\ClientSettings; use App\DataMapper\CompanySettings; use App\DataMapper\DefaultSettings; +use App\DataMapper\FeesAndLimits; use App\Factory\ClientFactory; use App\Factory\CompanyUserFactory; use App\Factory\CreditFactory; @@ -32,6 +34,7 @@ use App\Models\InvoiceInvitation; use App\Models\Quote; use App\Models\RecurringInvoice; use App\Models\User; +use App\Utils\Traits\CompanyGatewayFeesAndLimitsSaver; use App\Utils\Traits\GeneratesCounter; use App\Utils\Traits\MakesHash; use Illuminate\Support\Carbon; @@ -341,17 +344,18 @@ trait MockAccountData $gs->save(); if (config('ninja.testvars.stripe')) { - $cg = new CompanyGateway; - $cg->company_id = $this->company->id; - $cg->user_id = $this->user->id; - $cg->gateway_key = 'd14dd26a37cecc30fdd65700bfb55b23'; - $cg->require_cvv = true; - $cg->show_billing_address = true; - $cg->show_shipping_address = true; - $cg->update_details = true; - $cg->config = encrypt(config('ninja.testvars.stripe')); - $cg->save(); + $data = []; + $data[1]['min_limit'] = 234; + $data[1]['max_limit'] = 65317; + $data[1]['fee_amount'] = 0.00; + $data[1]['fee_percent'] = 0.000; + $data[1]['fee_tax_name1'] = ''; + $data[1]['fee_tax_rate1'] = ''; + $data[1]['fee_tax_name2'] = ''; + $data[1]['fee_tax_rate2'] = ''; + $data[1]['fee_tax_name3'] = ''; + $data[1]['fee_tax_rate3'] = 0; $cg = new CompanyGateway; $cg->company_id = $this->company->id; @@ -362,11 +366,26 @@ trait MockAccountData $cg->show_shipping_address = true; $cg->update_details = true; $cg->config = encrypt(config('ninja.testvars.stripe')); + $cg->fees_and_limits = $data; $cg->save(); + + $cg = new CompanyGateway; + $cg->company_id = $this->company->id; + $cg->user_id = $this->user->id; + $cg->gateway_key = 'd14dd26a37cecc30fdd65700bfb55b23'; + $cg->require_cvv = true; + $cg->show_billing_address = true; + $cg->show_shipping_address = true; + $cg->update_details = true; + $cg->fees_and_limits = $data; + $cg->config = encrypt(config('ninja.testvars.stripe')); + $cg->save(); + } } + private function buildLineItems() { $line_items = []; @@ -377,46 +396,6 @@ trait MockAccountData $line_items[] = $item; - // $line_items[] = $item; - // $line_items[] = $item; - // $line_items[] = $item; - // $line_items[] = $item; - // $line_items[] = $item; - // $line_items[] = $item; - // $line_items[] = $item; - // $line_items[] = $item; - // $line_items[] = $item; - // $line_items[] = $item; - // $line_items[] = $item; - // $line_items[] = $item; - // $line_items[] = $item; - // $line_items[] = $item; - // $line_items[] = $item; - // $line_items[] = $item; - // $line_items[] = $item; - // $line_items[] = $item; - // $line_items[] = $item; - // $line_items[] = $item; - // $line_items[] = $item; - // $line_items[] = $item; - // $line_items[] = $item; - // $line_items[] = $item; - // $line_items[] = $item; - // $line_items[] = $item; - // $line_items[] = $item; - // $line_items[] = $item; - // $line_items[] = $item; - // $line_items[] = $item; - // $line_items[] = $item; - // $line_items[] = $item; - // $line_items[] = $item; - // $line_items[] = $item; - // $line_items[] = $item; - // $line_items[] = $item; - // $line_items[] = $item; - // $line_items[] = $item; - // $line_items[] = $item; - return $line_items; } } diff --git a/tests/Unit/CompanyDocumentsTest.php b/tests/Unit/CompanyDocumentsTest.php index e669dbc70826..1ba9dc1ad28d 100644 --- a/tests/Unit/CompanyDocumentsTest.php +++ b/tests/Unit/CompanyDocumentsTest.php @@ -32,7 +32,6 @@ class CompanyDocumentsTest extends TestCase { $company_key = $this->company->company_key; - $original_count = Document::whereCompanyId($this->company->id)->count(); $image = UploadedFile::fake()->image('avatar.jpg'); diff --git a/tests/Unit/Migration/FeesAndLimitsTest.php b/tests/Unit/Migration/FeesAndLimitsTest.php index 79a84a1c2bde..0df50f9623f4 100644 --- a/tests/Unit/Migration/FeesAndLimitsTest.php +++ b/tests/Unit/Migration/FeesAndLimitsTest.php @@ -22,14 +22,17 @@ class FeesAndLimitsTest extends TestCase $data['max_limit'] = 65317; $data['fee_amount'] = 0.00; $data['fee_percent'] = 0.000; - $data['tax_name1'] = '' ; - $data['tax_rate1'] = ''; - $data['tax_name2'] = ''; - $data['tax_rate2'] = ''; - $data['tax_name3'] = ''; - $data['tax_rate3'] = 0; + $data['fee_tax_name1'] = ''; + $data['fee_tax_rate1'] = ''; + $data['fee_tax_name2'] = ''; + $data['fee_tax_rate2'] = ''; + $data['fee_tax_name3'] = ''; + $data['fee_tax_rate3'] = 0; - $transformed = $this->cleanFeesAndLimits($data); + $fees_and_limits_array = []; + $fees_and_limits_array[] = $data; + + $transformed = $this->cleanFeesAndLimits($fees_and_limits_array); $this->assertTrue(is_array($transformed)); } @@ -40,15 +43,16 @@ class FeesAndLimitsTest extends TestCase $new_arr = []; foreach ($fees_and_limits as $key => $value) { - $fal = new FeesAndLimits; + $fal = new FeesAndLimits; + // $fal->{$key} = $value; - $fal->{$key} = $value; - // foreach ($value as $k => $v) { - // $fal->{$k} = $v; - // $fal->{$k} = BaseSettings::castAttribute(FeesAndLimits::$casts[$k], $v); - // } + foreach ($value as $k => $v) { -// $new_arr[$key] = (array)$fal; + $fal->{$k} = $v; + $fal->{$k} = BaseSettings::castAttribute(FeesAndLimits::$casts[$k], $v); + } + + $new_arr[$key] = (array)$fal; } return $new_arr;