From d025d058564c76dde3a38f50be3da0902a222264 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 17 Mar 2024 22:38:41 +1100 Subject: [PATCH 01/14] Tweaks for invoice number filtering --- app/Filters/InvoiceFilters.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/Filters/InvoiceFilters.php b/app/Filters/InvoiceFilters.php index c1b41dd4b7e2..bd03ca01d42a 100644 --- a/app/Filters/InvoiceFilters.php +++ b/app/Filters/InvoiceFilters.php @@ -329,7 +329,9 @@ class InvoiceFilters extends QueryFilters if($sort_col[0] == 'number') { // return $this->builder->orderByRaw('CAST(number AS UNSIGNED), number ' . $dir); - return $this->builder->orderByRaw('ABS(number) ' . $dir); + // return $this->builder->orderByRaw("number REGEXP '^[A-Za-z]+$',CAST(number as SIGNED INTEGER),CAST(REPLACE(number,'-','')AS SIGNED INTEGER) ,number"); + // return $this->builder->orderByRaw('ABS(number) ' . $dir); + return $this->builder->orderByRaw("REGEXP_REPLACE(number,'[^0-9]+','')+0 " . $dir); } return $this->builder->orderBy($sort_col[0], $dir); From 8e431a4138b17eff39fa60c29a3466ae6a6d79cb Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 17 Mar 2024 23:00:19 +1100 Subject: [PATCH 02/14] Updated lock --- app/DataMapper/CompanySettings.php | 2 +- composer.lock | 181 +++++++++++++++-------------- 2 files changed, 92 insertions(+), 91 deletions(-) diff --git a/app/DataMapper/CompanySettings.php b/app/DataMapper/CompanySettings.php index 17249805bb5a..8ddd16ea362d 100644 --- a/app/DataMapper/CompanySettings.php +++ b/app/DataMapper/CompanySettings.php @@ -229,7 +229,7 @@ class CompanySettings extends BaseSettings public $require_quote_signature = false; //@TODO ben to confirm //email settings - public $email_sending_method = 'default'; //enum 'default','gmail','office365' 'client_postmark', 'client_mailgun', 'mailgun' //@implemented + public $email_sending_method = 'default'; //enum 'default','gmail','office365' 'client_postmark', 'client_mailgun', 'mailgun', 'client_brevo' //@implemented public $gmail_sending_user_id = '0'; //@implemented diff --git a/composer.lock b/composer.lock index 94924c137001..f5797d572c29 100644 --- a/composer.lock +++ b/composer.lock @@ -5941,34 +5941,34 @@ }, { "name": "lcobucci/clock", - "version": "3.2.0", + "version": "3.0.0", "source": { "type": "git", "url": "https://github.com/lcobucci/clock.git", - "reference": "6f28b826ea01306b07980cb8320ab30b966cd715" + "reference": "039ef98c6b57b101d10bd11d8fdfda12cbd996dc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/lcobucci/clock/zipball/6f28b826ea01306b07980cb8320ab30b966cd715", - "reference": "6f28b826ea01306b07980cb8320ab30b966cd715", + "url": "https://api.github.com/repos/lcobucci/clock/zipball/039ef98c6b57b101d10bd11d8fdfda12cbd996dc", + "reference": "039ef98c6b57b101d10bd11d8fdfda12cbd996dc", "shasum": "" }, "require": { - "php": "~8.2.0 || ~8.3.0", + "php": "~8.1.0 || ~8.2.0", "psr/clock": "^1.0" }, "provide": { "psr/clock-implementation": "1.0" }, "require-dev": { - "infection/infection": "^0.27", - "lcobucci/coding-standard": "^11.0.0", - "phpstan/extension-installer": "^1.3.1", - "phpstan/phpstan": "^1.10.25", - "phpstan/phpstan-deprecation-rules": "^1.1.3", - "phpstan/phpstan-phpunit": "^1.3.13", - "phpstan/phpstan-strict-rules": "^1.5.1", - "phpunit/phpunit": "^10.2.3" + "infection/infection": "^0.26", + "lcobucci/coding-standard": "^9.0", + "phpstan/extension-installer": "^1.2", + "phpstan/phpstan": "^1.9.4", + "phpstan/phpstan-deprecation-rules": "^1.1.1", + "phpstan/phpstan-phpunit": "^1.3.2", + "phpstan/phpstan-strict-rules": "^1.4.4", + "phpunit/phpunit": "^9.5.27" }, "type": "library", "autoload": { @@ -5989,7 +5989,7 @@ "description": "Yet another clock abstraction", "support": { "issues": "https://github.com/lcobucci/clock/issues", - "source": "https://github.com/lcobucci/clock/tree/3.2.0" + "source": "https://github.com/lcobucci/clock/tree/3.0.0" }, "funding": [ { @@ -6001,7 +6001,7 @@ "type": "patreon" } ], - "time": "2023-11-17T17:00:27+00:00" + "time": "2022-12-19T15:00:24+00:00" }, { "name": "lcobucci/jwt", @@ -12263,20 +12263,20 @@ }, { "name": "symfony/css-selector", - "version": "v7.0.3", + "version": "v6.4.3", "source": { "type": "git", "url": "https://github.com/symfony/css-selector.git", - "reference": "ec60a4edf94e63b0556b6a0888548bb400a3a3be" + "reference": "ee0f7ed5cf298cc019431bb3b3977ebc52b86229" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/css-selector/zipball/ec60a4edf94e63b0556b6a0888548bb400a3a3be", - "reference": "ec60a4edf94e63b0556b6a0888548bb400a3a3be", + "url": "https://api.github.com/repos/symfony/css-selector/zipball/ee0f7ed5cf298cc019431bb3b3977ebc52b86229", + "reference": "ee0f7ed5cf298cc019431bb3b3977ebc52b86229", "shasum": "" }, "require": { - "php": ">=8.2" + "php": ">=8.1" }, "type": "library", "autoload": { @@ -12308,7 +12308,7 @@ "description": "Converts CSS selectors to XPath expressions", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/css-selector/tree/v7.0.3" + "source": "https://github.com/symfony/css-selector/tree/v6.4.3" }, "funding": [ { @@ -12324,7 +12324,7 @@ "type": "tidelift" } ], - "time": "2024-01-23T15:02:46+00:00" + "time": "2024-01-23T14:51:35+00:00" }, { "name": "symfony/deprecation-contracts", @@ -12470,24 +12470,24 @@ }, { "name": "symfony/event-dispatcher", - "version": "v7.0.3", + "version": "v6.4.3", "source": { "type": "git", "url": "https://github.com/symfony/event-dispatcher.git", - "reference": "834c28d533dd0636f910909d01b9ff45cc094b5e" + "reference": "ae9d3a6f3003a6caf56acd7466d8d52378d44fef" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/834c28d533dd0636f910909d01b9ff45cc094b5e", - "reference": "834c28d533dd0636f910909d01b9ff45cc094b5e", + "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/ae9d3a6f3003a6caf56acd7466d8d52378d44fef", + "reference": "ae9d3a6f3003a6caf56acd7466d8d52378d44fef", "shasum": "" }, "require": { - "php": ">=8.2", + "php": ">=8.1", "symfony/event-dispatcher-contracts": "^2.5|^3" }, "conflict": { - "symfony/dependency-injection": "<6.4", + "symfony/dependency-injection": "<5.4", "symfony/service-contracts": "<2.5" }, "provide": { @@ -12496,13 +12496,13 @@ }, "require-dev": { "psr/log": "^1|^2|^3", - "symfony/config": "^6.4|^7.0", - "symfony/dependency-injection": "^6.4|^7.0", - "symfony/error-handler": "^6.4|^7.0", - "symfony/expression-language": "^6.4|^7.0", - "symfony/http-foundation": "^6.4|^7.0", + "symfony/config": "^5.4|^6.0|^7.0", + "symfony/dependency-injection": "^5.4|^6.0|^7.0", + "symfony/error-handler": "^5.4|^6.0|^7.0", + "symfony/expression-language": "^5.4|^6.0|^7.0", + "symfony/http-foundation": "^5.4|^6.0|^7.0", "symfony/service-contracts": "^2.5|^3", - "symfony/stopwatch": "^6.4|^7.0" + "symfony/stopwatch": "^5.4|^6.0|^7.0" }, "type": "library", "autoload": { @@ -12530,7 +12530,7 @@ "description": "Provides tools that allow your application components to communicate with each other by dispatching events and listening to them", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/event-dispatcher/tree/v7.0.3" + "source": "https://github.com/symfony/event-dispatcher/tree/v6.4.3" }, "funding": [ { @@ -12546,7 +12546,7 @@ "type": "tidelift" } ], - "time": "2024-01-23T15:02:46+00:00" + "time": "2024-01-23T14:51:35+00:00" }, { "name": "symfony/event-dispatcher-contracts", @@ -13114,25 +13114,25 @@ }, { "name": "symfony/intl", - "version": "v7.0.3", + "version": "v6.4.3", "source": { "type": "git", "url": "https://github.com/symfony/intl.git", - "reference": "295995df4acf6790a35b9ce6ec32b313efb11ff8" + "reference": "2628ded562ca132ed7cdea72f5ec6aaf65d94414" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/intl/zipball/295995df4acf6790a35b9ce6ec32b313efb11ff8", - "reference": "295995df4acf6790a35b9ce6ec32b313efb11ff8", + "url": "https://api.github.com/repos/symfony/intl/zipball/2628ded562ca132ed7cdea72f5ec6aaf65d94414", + "reference": "2628ded562ca132ed7cdea72f5ec6aaf65d94414", "shasum": "" }, "require": { - "php": ">=8.2" + "php": ">=8.1" }, "require-dev": { - "symfony/filesystem": "^6.4|^7.0", - "symfony/finder": "^6.4|^7.0", - "symfony/var-exporter": "^6.4|^7.0" + "symfony/filesystem": "^5.4|^6.0|^7.0", + "symfony/finder": "^5.4|^6.0|^7.0", + "symfony/var-exporter": "^5.4|^6.0|^7.0" }, "type": "library", "autoload": { @@ -13176,7 +13176,7 @@ "localization" ], "support": { - "source": "https://github.com/symfony/intl/tree/v7.0.3" + "source": "https://github.com/symfony/intl/tree/v6.4.3" }, "funding": [ { @@ -13192,7 +13192,7 @@ "type": "tidelift" } ], - "time": "2024-01-23T15:02:46+00:00" + "time": "2024-01-23T14:51:35+00:00" }, { "name": "symfony/mailer", @@ -13429,20 +13429,20 @@ }, { "name": "symfony/options-resolver", - "version": "v7.0.0", + "version": "v6.4.0", "source": { "type": "git", "url": "https://github.com/symfony/options-resolver.git", - "reference": "700ff4096e346f54cb628ea650767c8130f1001f" + "reference": "22301f0e7fdeaacc14318928612dee79be99860e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/options-resolver/zipball/700ff4096e346f54cb628ea650767c8130f1001f", - "reference": "700ff4096e346f54cb628ea650767c8130f1001f", + "url": "https://api.github.com/repos/symfony/options-resolver/zipball/22301f0e7fdeaacc14318928612dee79be99860e", + "reference": "22301f0e7fdeaacc14318928612dee79be99860e", "shasum": "" }, "require": { - "php": ">=8.2", + "php": ">=8.1", "symfony/deprecation-contracts": "^2.5|^3" }, "type": "library", @@ -13476,7 +13476,7 @@ "options" ], "support": { - "source": "https://github.com/symfony/options-resolver/tree/v7.0.0" + "source": "https://github.com/symfony/options-resolver/tree/v6.4.0" }, "funding": [ { @@ -13492,7 +13492,7 @@ "type": "tidelift" } ], - "time": "2023-08-08T10:20:21+00:00" + "time": "2023-08-08T10:16:24+00:00" }, { "name": "symfony/polyfill-ctype", @@ -14676,20 +14676,20 @@ }, { "name": "symfony/string", - "version": "v7.0.4", + "version": "v6.4.4", "source": { "type": "git", "url": "https://github.com/symfony/string.git", - "reference": "f5832521b998b0bec40bee688ad5de98d4cf111b" + "reference": "4e465a95bdc32f49cf4c7f07f751b843bbd6dcd9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/string/zipball/f5832521b998b0bec40bee688ad5de98d4cf111b", - "reference": "f5832521b998b0bec40bee688ad5de98d4cf111b", + "url": "https://api.github.com/repos/symfony/string/zipball/4e465a95bdc32f49cf4c7f07f751b843bbd6dcd9", + "reference": "4e465a95bdc32f49cf4c7f07f751b843bbd6dcd9", "shasum": "" }, "require": { - "php": ">=8.2", + "php": ">=8.1", "symfony/polyfill-ctype": "~1.8", "symfony/polyfill-intl-grapheme": "~1.0", "symfony/polyfill-intl-normalizer": "~1.0", @@ -14699,11 +14699,11 @@ "symfony/translation-contracts": "<2.5" }, "require-dev": { - "symfony/error-handler": "^6.4|^7.0", - "symfony/http-client": "^6.4|^7.0", - "symfony/intl": "^6.4|^7.0", + "symfony/error-handler": "^5.4|^6.0|^7.0", + "symfony/http-client": "^5.4|^6.0|^7.0", + "symfony/intl": "^6.2|^7.0", "symfony/translation-contracts": "^2.5|^3.0", - "symfony/var-exporter": "^6.4|^7.0" + "symfony/var-exporter": "^5.4|^6.0|^7.0" }, "type": "library", "autoload": { @@ -14742,7 +14742,7 @@ "utf8" ], "support": { - "source": "https://github.com/symfony/string/tree/v7.0.4" + "source": "https://github.com/symfony/string/tree/v6.4.4" }, "funding": [ { @@ -14758,7 +14758,7 @@ "type": "tidelift" } ], - "time": "2024-02-01T13:17:36+00:00" + "time": "2024-02-01T13:16:41+00:00" }, { "name": "symfony/translation", @@ -16230,16 +16230,16 @@ }, { "name": "brianium/paratest", - "version": "v7.4.3", + "version": "v7.3.1", "source": { "type": "git", "url": "https://github.com/paratestphp/paratest.git", - "reference": "64fcfd0e28a6b8078a19dbf9127be2ee645b92ec" + "reference": "551f46f52a93177d873f3be08a1649ae886b4a30" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/paratestphp/paratest/zipball/64fcfd0e28a6b8078a19dbf9127be2ee645b92ec", - "reference": "64fcfd0e28a6b8078a19dbf9127be2ee645b92ec", + "url": "https://api.github.com/repos/paratestphp/paratest/zipball/551f46f52a93177d873f3be08a1649ae886b4a30", + "reference": "551f46f52a93177d873f3be08a1649ae886b4a30", "shasum": "" }, "require": { @@ -16247,27 +16247,28 @@ "ext-pcre": "*", "ext-reflection": "*", "ext-simplexml": "*", - "fidry/cpu-core-counter": "^1.1.0", + "fidry/cpu-core-counter": "^0.5.1 || ^1.0.0", "jean85/pretty-package-versions": "^2.0.5", - "php": "~8.2.0 || ~8.3.0", - "phpunit/php-code-coverage": "^10.1.11 || ^11.0.0", - "phpunit/php-file-iterator": "^4.1.0 || ^5.0.0", - "phpunit/php-timer": "^6.0.0 || ^7.0.0", - "phpunit/phpunit": "^10.5.9 || ^11.0.3", - "sebastian/environment": "^6.0.1 || ^7.0.0", - "symfony/console": "^6.4.3 || ^7.0.3", - "symfony/process": "^6.4.3 || ^7.0.3" + "php": "~8.1.0 || ~8.2.0 || ~8.3.0", + "phpunit/php-code-coverage": "^10.1.7", + "phpunit/php-file-iterator": "^4.1.0", + "phpunit/php-timer": "^6.0", + "phpunit/phpunit": "^10.4.2", + "sebastian/environment": "^6.0.1", + "symfony/console": "^6.3.4 || ^7.0.0", + "symfony/process": "^6.3.4 || ^7.0.0" }, "require-dev": { "doctrine/coding-standard": "^12.0.0", "ext-pcov": "*", "ext-posix": "*", - "phpstan/phpstan": "^1.10.58", + "infection/infection": "^0.27.6", + "phpstan/phpstan": "^1.10.40", "phpstan/phpstan-deprecation-rules": "^1.1.4", "phpstan/phpstan-phpunit": "^1.3.15", "phpstan/phpstan-strict-rules": "^1.5.2", - "squizlabs/php_codesniffer": "^3.9.0", - "symfony/filesystem": "^6.4.3 || ^7.0.3" + "squizlabs/php_codesniffer": "^3.7.2", + "symfony/filesystem": "^6.3.1 || ^7.0.0" }, "bin": [ "bin/paratest", @@ -16308,7 +16309,7 @@ ], "support": { "issues": "https://github.com/paratestphp/paratest/issues", - "source": "https://github.com/paratestphp/paratest/tree/v7.4.3" + "source": "https://github.com/paratestphp/paratest/tree/v7.3.1" }, "funding": [ { @@ -16320,7 +16321,7 @@ "type": "paypal" } ], - "time": "2024-02-20T07:24:02+00:00" + "time": "2023-10-31T09:24:17+00:00" }, { "name": "composer/class-map-generator", @@ -19405,20 +19406,20 @@ }, { "name": "symfony/stopwatch", - "version": "v7.0.3", + "version": "v6.4.3", "source": { "type": "git", "url": "https://github.com/symfony/stopwatch.git", - "reference": "983900d6fddf2b0cbaacacbbad07610854bd8112" + "reference": "416596166641f1f728b0a64f5b9dd07cceb410c1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/stopwatch/zipball/983900d6fddf2b0cbaacacbbad07610854bd8112", - "reference": "983900d6fddf2b0cbaacacbbad07610854bd8112", + "url": "https://api.github.com/repos/symfony/stopwatch/zipball/416596166641f1f728b0a64f5b9dd07cceb410c1", + "reference": "416596166641f1f728b0a64f5b9dd07cceb410c1", "shasum": "" }, "require": { - "php": ">=8.2", + "php": ">=8.1", "symfony/service-contracts": "^2.5|^3" }, "type": "library", @@ -19447,7 +19448,7 @@ "description": "Provides a way to profile code", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/stopwatch/tree/v7.0.3" + "source": "https://github.com/symfony/stopwatch/tree/v6.4.3" }, "funding": [ { @@ -19463,7 +19464,7 @@ "type": "tidelift" } ], - "time": "2024-01-23T15:02:46+00:00" + "time": "2024-01-23T14:35:58+00:00" }, { "name": "theseer/tokenizer", @@ -19533,5 +19534,5 @@ "platform-dev": { "php": "^8.1|^8.2" }, - "plugin-api-version": "2.6.0" + "plugin-api-version": "2.3.0" } From d2325bed7c3577f990cf4238128cb02e29d3c933 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 18 Mar 2024 09:03:34 +1100 Subject: [PATCH 03/14] Adjustments for auto billing --- app/Http/Controllers/SmtpController.php | 12 +++++++++++- app/Jobs/RecurringInvoice/SendRecurring.php | 4 ++-- app/Services/Invoice/InvoiceService.php | 4 ++-- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/SmtpController.php b/app/Http/Controllers/SmtpController.php index edfc24c38689..629a92bc1b48 100644 --- a/app/Http/Controllers/SmtpController.php +++ b/app/Http/Controllers/SmtpController.php @@ -55,7 +55,17 @@ class SmtpController extends BaseController (new \Illuminate\Mail\MailServiceProvider(app()))->register(); try { - Mail::mailer('smtp')->to($user->email, $user->present()->name())->send(new TestMailServer('Email Server Works!', strlen($company->settings->custom_sending_email) > 1 ? $company->settings->custom_sending_email : $user->email)); + + $sending_email = (isset($company->settings->custom_sending_email) && stripos($company->settings->custom_sending_email, "@")) ? $company->settings->custom_sending_email : $user->email; + $sending_user = (isset($company->settings->email_from_name) && strlen($company->settings->email_from_name) > 2) ? $company->settings->email_from_name : $user->name(); + + $mailable = new TestMailServer('Email Server Works!', $sending_email); + $mailable->from($sending_email,$sending_user); + + Mail::mailer('smtp') + ->to($user->email, $user->present()->name()) + ->send($mailable); + } catch (\Exception $e) { app('mail.manager')->forgetMailers(); return response()->json(['message' => $e->getMessage()], 400); diff --git a/app/Jobs/RecurringInvoice/SendRecurring.php b/app/Jobs/RecurringInvoice/SendRecurring.php index def24172b528..5bed2111b564 100644 --- a/app/Jobs/RecurringInvoice/SendRecurring.php +++ b/app/Jobs/RecurringInvoice/SendRecurring.php @@ -76,12 +76,12 @@ class SendRecurring implements ShouldQueue $invoice = $invoice->service() ->markSent() ->applyNumber() - ->fillDefaults() + ->fillDefaults(true) ->adjustInventory() ->save(); } else { $invoice = $invoice->service() - ->fillDefaults() + ->fillDefaults(true) ->save(); } diff --git a/app/Services/Invoice/InvoiceService.php b/app/Services/Invoice/InvoiceService.php index effe34daceba..dbe57e361b3c 100644 --- a/app/Services/Invoice/InvoiceService.php +++ b/app/Services/Invoice/InvoiceService.php @@ -544,7 +544,7 @@ class InvoiceService return $this; } - public function fillDefaults() + public function fillDefaults(bool $is_recurring = false) { $this->invoice->load('client.company'); @@ -571,7 +571,7 @@ class InvoiceService $this->invoice->exchange_rate = $this->invoice->client->setExchangeRate(); } - if ($this->invoice->client->getSetting('auto_bill_standard_invoices')) { + if ($is_recurring && $this->invoice->client->getSetting('auto_bill_standard_invoices')) { $this->invoice->auto_bill_enabled = true; } From e0b7d09d0c6bb5a831be7c5fcbde6a25e3cfe70e Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 18 Mar 2024 09:53:20 +1100 Subject: [PATCH 04/14] Fixes for Yodlee --- app/Jobs/Ninja/BankTransactionSync.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Jobs/Ninja/BankTransactionSync.php b/app/Jobs/Ninja/BankTransactionSync.php index 89a0b33e4df7..6e5ca84d69e8 100644 --- a/app/Jobs/Ninja/BankTransactionSync.php +++ b/app/Jobs/Ninja/BankTransactionSync.php @@ -74,7 +74,7 @@ class BankTransactionSync implements ShouldQueue if ($account->isEnterprisePaidClient()) { $account->bank_integrations()->where('integration_type', BankIntegration::INTEGRATION_TYPE_YODLEE)->where('auto_sync', true)->where('disabled_upstream', 0)->cursor()->each(function ($bank_integration) use ($account) { - (new ProcessBankTransactionsYodlee($account->id, $bank_integration))->handle(); + (new ProcessBankTransactionsYodlee($account->bank_integration_account_id, $bank_integration))->handle(); }); } From 48ac0a92d49f7d466374a118c0509882f28b89b0 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 18 Mar 2024 10:21:17 +1100 Subject: [PATCH 05/14] Add delays to nordigen for rate limits --- app/Jobs/Bank/ProcessBankTransactionsNordigen.php | 2 ++ app/Jobs/Ninja/BankTransactionSync.php | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/Jobs/Bank/ProcessBankTransactionsNordigen.php b/app/Jobs/Bank/ProcessBankTransactionsNordigen.php index dd7c6c657b9e..8ff86efd14a5 100644 --- a/app/Jobs/Bank/ProcessBankTransactionsNordigen.php +++ b/app/Jobs/Bank/ProcessBankTransactionsNordigen.php @@ -85,6 +85,8 @@ class ProcessBankTransactionsNordigen implements ShouldQueue $this->bank_integration->company->notification(new GenericNinjaAdminNotification($content))->ninja(); + sleep(5); + throw $e; } if (!$this->nordigen_account) { diff --git a/app/Jobs/Ninja/BankTransactionSync.php b/app/Jobs/Ninja/BankTransactionSync.php index 6e5ca84d69e8..a0d077a570c8 100644 --- a/app/Jobs/Ninja/BankTransactionSync.php +++ b/app/Jobs/Ninja/BankTransactionSync.php @@ -90,7 +90,14 @@ class BankTransactionSync implements ShouldQueue if ((Ninja::isSelfHost() || (Ninja::isHosted() && $account->isEnterprisePaidClient()))) { $account->bank_integrations()->where('integration_type', BankIntegration::INTEGRATION_TYPE_NORDIGEN)->where('auto_sync', true)->where('disabled_upstream', 0)->cursor()->each(function ($bank_integration) { - (new ProcessBankTransactionsNordigen($bank_integration))->handle(); + try { + (new ProcessBankTransactionsNordigen($bank_integration))->handle(); + } + catch(\Exception $e) { + sleep(20); + } + + sleep(5); }); } From 86fc7a06627e3c4b4bc4a7ea8bc2124c5c165998 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 18 Mar 2024 12:58:42 +1100 Subject: [PATCH 06/14] Working on importing customers --- app/Console/Commands/CreateSingleAccount.php | 132 +++++++++---- .../Controllers/CompanyGatewayController.php | 12 ++ app/Models/Account.php | 2 +- app/Models/CompanyGateway.php | 3 +- app/PaymentDrivers/AuthorizePaymentDriver.php | 7 + app/PaymentDrivers/BaseDriver.php | 5 + app/PaymentDrivers/BraintreePaymentDriver.php | 187 +++++++++++++++++- .../GoCardlessPaymentDriver.php | 4 +- app/PaymentDrivers/Stripe/ImportCustomers.php | 6 - config/ninja.php | 10 +- routes/api.php | 1 + 11 files changed, 309 insertions(+), 60 deletions(-) diff --git a/app/Console/Commands/CreateSingleAccount.php b/app/Console/Commands/CreateSingleAccount.php index eb9395c1b152..cfdf4177798d 100644 --- a/app/Console/Commands/CreateSingleAccount.php +++ b/app/Console/Commands/CreateSingleAccount.php @@ -11,53 +11,54 @@ namespace App\Console\Commands; -use App\DataMapper\ClientRegistrationFields; -use App\DataMapper\CompanySettings; -use App\DataMapper\FeesAndLimits; -use App\Events\Invoice\InvoiceWasCreated; -use App\Events\RecurringInvoice\RecurringInvoiceWasCreated; -use App\Factory\GroupSettingFactory; -use App\Factory\InvoiceFactory; -use App\Factory\InvoiceItemFactory; -use App\Factory\RecurringInvoiceFactory; -use App\Factory\SubscriptionFactory; -use App\Helpers\Invoice\InvoiceSum; -use App\Jobs\Company\CreateCompanyTaskStatuses; -use App\Libraries\MultiDB; -use App\Models\Account; -use App\Models\BankIntegration; -use App\Models\BankTransaction; -use App\Models\BankTransactionRule; +use stdClass; +use Carbon\Carbon; +use Faker\Factory; +use App\Models\Task; +use App\Models\User; +use App\Utils\Ninja; +use App\Models\Quote; use App\Models\Client; -use App\Models\ClientContact; -use App\Models\Company; -use App\Models\CompanyGateway; -use App\Models\CompanyToken; -use App\Models\Country; use App\Models\Credit; +use App\Models\Vendor; +use App\Models\Account; +use App\Models\Company; +use App\Models\Country; use App\Models\Expense; use App\Models\Invoice; use App\Models\Product; use App\Models\Project; -use App\Models\Quote; -use App\Models\RecurringInvoice; -use App\Models\Task; -use App\Models\TaskStatus; use App\Models\TaxRate; -use App\Models\User; -use App\Models\Vendor; +use App\Libraries\MultiDB; +use App\Models\TaskStatus; +use App\Models\CompanyToken; +use App\Models\ClientContact; use App\Models\VendorContact; -use App\Repositories\InvoiceRepository; -use App\Utils\Ninja; -use App\Utils\Traits\GeneratesCounter; +use App\Models\CompanyGateway; +use App\Factory\InvoiceFactory; +use App\Models\BankIntegration; +use App\Models\BankTransaction; use App\Utils\Traits\MakesHash; -use Carbon\Carbon; -use Faker\Factory; use Illuminate\Console\Command; -use Illuminate\Support\Facades\Cache; +use App\Models\RecurringInvoice; +use App\DataMapper\FeesAndLimits; +use App\DataMapper\ClientSettings; +use App\DataMapper\CompanySettings; +use App\Factory\InvoiceItemFactory; +use App\Helpers\Invoice\InvoiceSum; +use App\Models\BankTransactionRule; +use App\Factory\GroupSettingFactory; +use App\Factory\SubscriptionFactory; use Illuminate\Support\Facades\Hash; +use Illuminate\Support\Facades\Cache; +use App\Utils\Traits\GeneratesCounter; use Illuminate\Support\Facades\Schema; -use stdClass; +use App\Repositories\InvoiceRepository; +use App\Factory\RecurringInvoiceFactory; +use App\Events\Invoice\InvoiceWasCreated; +use App\DataMapper\ClientRegistrationFields; +use App\Jobs\Company\CreateCompanyTaskStatuses; +use App\Events\RecurringInvoice\RecurringInvoiceWasCreated; class CreateSingleAccount extends Command { @@ -951,7 +952,7 @@ class CreateSingleAccount extends Command } - if (config('ninja.testvars.paytrace.decrypted') && ($this->gateway == 'all' || $this->gateway == 'paytrace')) { + if (config('ninja.testvars.paytrace') && ($this->gateway == 'all' || $this->gateway == 'paytrace')) { $cg = new CompanyGateway(); $cg->company_id = $company->id; $cg->user_id = $user->id; @@ -960,7 +961,7 @@ class CreateSingleAccount extends Command $cg->require_billing_address = true; $cg->require_shipping_address = true; $cg->update_details = true; - $cg->config = encrypt(config('ninja.testvars.paytrace.decrypted')); + $cg->config = encrypt(config('ninja.testvars.paytrace')); $cg->save(); @@ -1015,6 +1016,63 @@ class CreateSingleAccount extends Command $cg->fees_and_limits = $fees_and_limits; $cg->save(); } + + if (config('ninja.testvars.eway') && ($this->gateway == 'all' || $this->gateway == 'eway')) { + $cg = new CompanyGateway(); + $cg->company_id = $company->id; + $cg->user_id = $user->id; + $cg->gateway_key = '944c20175bbe6b9972c05bcfe294c2c7'; + $cg->require_cvv = true; + $cg->require_billing_address = true; + $cg->require_shipping_address = true; + $cg->update_details = true; + $cg->config = encrypt(config('ninja.testvars.eway')); + $cg->save(); + + $gateway_types = $cg->driver()->gatewayTypes(); + + $fees_and_limits = new stdClass(); + $fees_and_limits->{$gateway_types[0]} = new FeesAndLimits(); + + $cg->fees_and_limits = $fees_and_limits; + $cg->save(); + } + + + if (config('ninja.testvars.gocardless') && ($this->gateway == 'all' || $this->gateway == 'gocardless')) { + + $c_settings = ClientSettings::defaults(); + $c_settings->currency_id = '2'; + + $client = Client::factory()->create([ + 'user_id' => $user->id, + 'company_id' => $company->id, + 'name' => 'cypress', + 'country_id' => 826, + 'settings' => $c_settings + ]); + + $cg = new CompanyGateway(); + $cg->company_id = $company->id; + $cg->user_id = $user->id; + $cg->gateway_key = 'b9886f9257f0c6ee7c302f1c74475f6c'; + $cg->require_cvv = true; + $cg->require_billing_address = true; + $cg->require_shipping_address = true; + $cg->update_details = true; + $cg->config = encrypt(config('ninja.testvars.gocardless')); + $cg->save(); + + $gateway_types = $cg->driver($client)->gatewayTypes(); + + $fees_and_limits = new stdClass(); + $fees_and_limits->{$gateway_types[0]} = new FeesAndLimits(); + + $cg->fees_and_limits = $fees_and_limits; + $cg->save(); + } + + } private function createRecurringInvoice(Client $client) diff --git a/app/Http/Controllers/CompanyGatewayController.php b/app/Http/Controllers/CompanyGatewayController.php index 732787b2d317..ec7c32cc78e6 100644 --- a/app/Http/Controllers/CompanyGatewayController.php +++ b/app/Http/Controllers/CompanyGatewayController.php @@ -23,6 +23,7 @@ use App\Http\Requests\CompanyGateway\StoreCompanyGatewayRequest; use App\Http\Requests\CompanyGateway\TestCompanyGatewayRequest; use App\Http\Requests\CompanyGateway\UpdateCompanyGatewayRequest; use App\Jobs\Util\ApplePayDomain; +use App\Libraries\MultiDB; use App\Models\Client; use App\Models\CompanyGateway; use App\PaymentDrivers\CheckoutCom\CheckoutSetupWebhook; @@ -544,4 +545,15 @@ class CompanyGatewayController extends BaseController } + public function importCustomers(TestCompanyGatewayRequest $request, CompanyGateway $company_gateway) + { + + dispatch(function () use($company_gateway) { + MultiDB::setDb($company_gateway->company->db); + $company_gateway->driver()->importCustomers(); + })->afterResponse(); + + return response()->json(['message' => ctrans('texts.import_started')], 200); + } + } diff --git a/app/Models/Account.php b/app/Models/Account.php index 4fc236da4971..adf95c62086f 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -494,7 +494,7 @@ class Account extends BaseModel return 0; } - if (Carbon::createFromTimestamp($this->created_at)->diffInWeeks() == 0) { + if (Carbon::createFromTimestamp($this->created_at)->diffInWeeks() <= 1) { return 20; } diff --git a/app/Models/CompanyGateway.php b/app/Models/CompanyGateway.php index 253af5585fe6..aa8f0438e5a2 100644 --- a/app/Models/CompanyGateway.php +++ b/app/Models/CompanyGateway.php @@ -132,6 +132,7 @@ class CompanyGateway extends BaseModel // const TYPE_EWAY = 313; // const TYPE_FORTE = 314; // const PAYPAL_PPCP = 323; + // const SQUARE = 320; public $gateway_consts = [ '38f2c48af60c7dd69e04248cbb24c36e' => 300, @@ -144,7 +145,7 @@ class CompanyGateway extends BaseModel '8fdeed552015b3c7b44ed6c8ebd9e992' => 309, 'd6814fc83f45d2935e7777071e629ef9' => 310, 'bbd736b3254b0aabed6ad7fda1298c88' => 311, - '1bd651fb213ca0c9d66ae3c336dc77e7' => 312, + '1bd651fb213ca0c9d66ae3c336dc77e8' => 312, '944c20175bbe6b9972c05bcfe294c2c7' => 313, 'kivcvjexxvdiyqtj3mju5d6yhpeht2xs' => 314, '65faab2ab6e3223dbe848b1686490baz' => 320, diff --git a/app/PaymentDrivers/AuthorizePaymentDriver.php b/app/PaymentDrivers/AuthorizePaymentDriver.php index 861df0c50993..87c74fdb9209 100644 --- a/app/PaymentDrivers/AuthorizePaymentDriver.php +++ b/app/PaymentDrivers/AuthorizePaymentDriver.php @@ -193,9 +193,16 @@ class AuthorizePaymentDriver extends BaseDriver public function import() { + $this->init(); + return (new AuthorizeCustomer($this))->importCustomers(); } + public function importCustomers() + { + return $this->import(); + } + public function auth(): bool { return $this->init()->getPublicClientKey() ?? false; diff --git a/app/PaymentDrivers/BaseDriver.php b/app/PaymentDrivers/BaseDriver.php index 5739a8d08321..a8ffd38cd61e 100644 --- a/app/PaymentDrivers/BaseDriver.php +++ b/app/PaymentDrivers/BaseDriver.php @@ -811,4 +811,9 @@ class BaseDriver extends AbstractPaymentDriver { return true; } + + public function importCustomers() + { + + } } diff --git a/app/PaymentDrivers/BraintreePaymentDriver.php b/app/PaymentDrivers/BraintreePaymentDriver.php index ec64d62f9a5f..23d067424c9d 100644 --- a/app/PaymentDrivers/BraintreePaymentDriver.php +++ b/app/PaymentDrivers/BraintreePaymentDriver.php @@ -12,29 +12,39 @@ namespace App\PaymentDrivers; -use App\Jobs\Util\SystemLogger; -use App\Models\ClientGatewayToken; -use App\Models\GatewayType; +use Exception; +use App\Models\Client; +use Braintree\Gateway; use App\Models\Invoice; use App\Models\Payment; +use App\Models\SystemLog; +use App\Models\GatewayType; use App\Models\PaymentHash; use App\Models\PaymentType; -use App\Models\SystemLog; +use App\Models\ClientContact; +use App\Factory\ClientFactory; +use App\Jobs\Util\SystemLogger; +use App\Models\ClientGatewayToken; +use App\Factory\ClientContactFactory; use App\PaymentDrivers\Braintree\ACH; -use App\PaymentDrivers\Braintree\CreditCard; +use App\Utils\Traits\GeneratesCounter; +use Illuminate\Database\QueryException; use App\PaymentDrivers\Braintree\PayPal; -use Braintree\Gateway; -use Exception; use Illuminate\Support\Facades\Validator; +use App\PaymentDrivers\Braintree\CreditCard; class BraintreePaymentDriver extends BaseDriver { + use GeneratesCounter; + public $refundable = true; public $token_billing = true; public $can_authorise_credit_card = true; + private bool $completed = true; + /** * @var Gateway; */ @@ -304,7 +314,7 @@ class BraintreePaymentDriver extends BaseDriver try { $ct =$this->init()->gateway->clientToken()->generate(); - nlog($ct); + return true; } catch(\Exception $e) { @@ -313,4 +323,165 @@ class BraintreePaymentDriver extends BaseDriver return false; } + + private function find(string $customer_id = '') { + + try { + return $this->init()->gateway->customer()->find($customer_id); + } + catch(\Exception $e){ + return false; + } + + return false; + } + + private function findTokens(string $gateway_customer_reference) + { + return ClientGatewayToken::where('company_id', $this->company_gateway->company_id) + ->where('gateway_customer_reference', $gateway_customer_reference) + ->exists(); + } + + private function findContact(string $email) { + return ClientContact::where('company_id', $this->company_gateway->company_id) + ->where('email', $email) + ->first()->client ?? false; + } + + private function addClientCards(Client $client, array $cards) + { + + $this->client = $client; + + foreach($cards as $card) { + + $payment_meta = new \stdClass(); + $payment_meta->exp_month = (string) $card->expirationMonth; + $payment_meta->exp_year = (string) $card->expirationYear; + $payment_meta->brand = (string) $card->cardType; + $payment_meta->last4 = (string) $card->last4; + $payment_meta->type = GatewayType::CREDIT_CARD; + + $data = [ + 'payment_meta' => $payment_meta, + 'token' => $card->token, + 'payment_method_id' => GatewayType::CREDIT_CARD, + ]; + + $this->storeGatewayToken($data, ['gateway_customer_reference' => $card->customerId]); + + nlog("adding card to customer payment profile"); + + } + + } + + public function createNinjaClient(mixed $customer): Client + { + + $client = ClientFactory::create($this->company_gateway->company_id, $this->company_gateway->user_id); + + $b_business_address = count($customer->addresses) >= 1 ? $customer->addresses[0] : false; + $b_shipping_address = count($customer->addresses) > 1 ? $customer->addresses[1] : false; + $import_client_data = []; + + if($b_business_address) { + + $braintree_address = + [ + 'address1' => $b_business_address->extendedAddress ?? '', + 'address2' => $b_business_address->streetAddress ?? '', + 'city' => $b_business_address->locality ?? '', + 'postal_code' => $b_business_address->postalCode ?? '', + 'state' => $b_business_address->region ?? '', + 'country_id' => $b_business_address->countryCodeNumeric ?? '840', + ]; + + $import_client_data = array_merge($import_client_data, $braintree_address); + } + + if($b_shipping_address) { + + $braintree_shipping_address = + [ + 'shipping_address1' => $b_shipping_address->extendedAddress ?? '', + 'shipping_address2' => $b_shipping_address->streetAddress ?? '', + 'shipping_city' => $b_shipping_address->locality ?? '', + 'shipping_postal_code' => $b_shipping_address->postalCode ?? '', + 'shipping_state' => $b_shipping_address->region ?? '', + 'shipping_country_id' => $b_shipping_address->countryCodeNumeric ?? '840', + ]; + + $import_client_data = array_merge($import_client_data, $braintree_shipping_address); + + } + + $client->fill($import_client_data); + + $client->phone = $customer->phone ?? ''; + $client->name = $customer->company ?? $customer->firstName; + + $settings = $client->settings; + $settings->currency_id = (string) $this->company_gateway->company->settings->currency_id; + $client->settings = $settings; + $client->save(); + + $contact = ClientContactFactory::create($this->company_gateway->company_id, $this->company_gateway->user_id); + $contact->first_name = $customer->firstName ?? ''; + $contact->last_name = $customer->lastName ?? ''; + $contact->email = $customer->email ?? ''; + $contact->phone = $customer->phone ?? ''; + $contact->client_id = $client->id; + $contact->saveQuietly(); + + if (! isset($client->number) || empty($client->number)) { + $x = 1; + + do { + try { + $client->number = $this->getNextClientNumber($client); + $client->saveQuietly(); + + $this->completed = false; + } catch (QueryException $e) { + $x++; + + if ($x > 10) { + $this->completed = false; + } + } + } while ($this->completed); + } else { + $client->saveQuietly(); + } + + return $client; + + } + + public function importCustomers() + { + $customers = $this->init()->gateway->customer()->all(); + + foreach($customers as $c){ + + $customer = $this->find($c->id); + + if(!$customer) + continue; + + if(!$this->findTokens($c->id) && !($client = $this->findContact($customer->email))) { + //customer is not referenced in the system - create client + $client = $this->createNinjaClient($customer); + nlog("Creating new Client"); + } + + + $this->addClientCards($client, $customer->creditCards); + + nlog("Adding Braintree Client: {$c->id} => {$client->id}"); + + } + } } diff --git a/app/PaymentDrivers/GoCardlessPaymentDriver.php b/app/PaymentDrivers/GoCardlessPaymentDriver.php index afd08c49a6aa..723a190f00be 100644 --- a/app/PaymentDrivers/GoCardlessPaymentDriver.php +++ b/app/PaymentDrivers/GoCardlessPaymentDriver.php @@ -84,11 +84,11 @@ class GoCardlessPaymentDriver extends BaseDriver $types[] = GatewayType::DIRECT_DEBIT; } - if (in_array($this->client->currency()->code, ['EUR', 'GBP'])) { + if ($this->client && in_array($this->client->currency()->code, ['EUR', 'GBP'])) { $types[] = GatewayType::SEPA; } - if ($this->client->currency()->code === 'GBP') { + if ($this->client && $this->client->currency()->code === 'GBP') { $types[] = GatewayType::INSTANT_BANK_PAY; } diff --git a/app/PaymentDrivers/Stripe/ImportCustomers.php b/app/PaymentDrivers/Stripe/ImportCustomers.php index 6001ed84298e..aa874444398d 100644 --- a/app/PaymentDrivers/Stripe/ImportCustomers.php +++ b/app/PaymentDrivers/Stripe/ImportCustomers.php @@ -62,12 +62,6 @@ class ImportCustomers $this->addCustomer($customer); } - //handle - // if(is_array($customers->data) && end($customers->data) && array_key_exists('id', end($customers->data))) - // $starting_after = end($customers->data)['id']; - // else - // break; - $starting_after = isset(end($customers->data)['id']) ? end($customers->data)['id'] : false; if (!$starting_after) { diff --git a/config/ninja.php b/config/ninja.php index 47ecd5b1aa42..98a742d15c6d 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -84,6 +84,11 @@ return [ 'username' => 'user@example.com', 'clientname' => 'client@example.com', 'password' => 'password', + 'gocardless' => env('GOCARDLESS_KEYS',''), + 'square' => env('SQUARE_KEYS',''), + 'eway' => env('EWAY_KEYS',''), + 'mollie', env('MOLLIE_KEYS',''), + 'paytrace' => env('PAYTRACE_KEYS',''), 'stripe' => env('STRIPE_KEYS', ''), 'paypal' => env('PAYPAL_KEYS', ''), 'ppcp' => env('PPCP_KEYS', ''), @@ -94,11 +99,6 @@ return [ 'test_email' => env('TEST_EMAIL', 'test@example.com'), 'wepay' => env('WEPAY_KEYS', ''), 'braintree' => env('BRAINTREE_KEYS', ''), - 'paytrace' => [ - 'username' => env('PAYTRACE_U', ''), - 'password' => env('PAYTRACE_P', ''), - 'decrypted' => env('PAYTRACE_KEYS', ''), - ], 'mollie' => env('MOLLIE_KEYS', ''), 'square' => env('SQUARE_KEYS', ''), ], diff --git a/routes/api.php b/routes/api.php index bf2be5dcbb0b..92596e03d8cb 100644 --- a/routes/api.php +++ b/routes/api.php @@ -198,6 +198,7 @@ Route::group(['middleware' => ['throttle:api', 'api_db', 'token_auth', 'locale'] Route::post('company_gateways/bulk', [CompanyGatewayController::class, 'bulk'])->name('company_gateways.bulk'); Route::post('company_gateways/{company_gateway}/test', [CompanyGatewayController::class, 'test'])->name('company_gateways.test'); + Route::post('company_gateways/{company_gateway}/import_customers', [CompanyGatewayController::class, 'importCustomers'])->name('company_gateways.import_customers'); Route::put('company_users/{user}', [CompanyUserController::class, 'update']); Route::put('company_users/{user}/preferences', [CompanyUserController::class, 'updatePreferences']); From 37e2e772f913632718cbcaa6cd22cc62041a1806 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 18 Mar 2024 13:50:12 +1100 Subject: [PATCH 07/14] Import payment methods for checkout --- .../Controllers/CompanyGatewayController.php | 36 +++--- app/PaymentDrivers/BraintreePaymentDriver.php | 27 +++- .../CheckoutComPaymentDriver.php | 118 ++++++++++++++---- 3 files changed, 140 insertions(+), 41 deletions(-) diff --git a/app/Http/Controllers/CompanyGatewayController.php b/app/Http/Controllers/CompanyGatewayController.php index ec7c32cc78e6..bdff0a8b1239 100644 --- a/app/Http/Controllers/CompanyGatewayController.php +++ b/app/Http/Controllers/CompanyGatewayController.php @@ -11,28 +11,29 @@ namespace App\Http\Controllers; +use App\Models\Client; +use App\Libraries\MultiDB; +use Illuminate\Http\Response; +use App\Models\CompanyGateway; +use App\Utils\Traits\MakesHash; use App\DataMapper\FeesAndLimits; +use App\Jobs\Util\ApplePayDomain; +use Illuminate\Support\Facades\Cache; use App\Factory\CompanyGatewayFactory; use App\Filters\CompanyGatewayFilters; +use App\Repositories\CompanyRepository; +use Illuminate\Foundation\Bus\DispatchesJobs; +use App\Transformers\CompanyGatewayTransformer; +use App\PaymentDrivers\Stripe\Jobs\StripeWebhook; +use App\PaymentDrivers\CheckoutCom\CheckoutSetupWebhook; use App\Http\Requests\CompanyGateway\BulkCompanyGatewayRequest; -use App\Http\Requests\CompanyGateway\CreateCompanyGatewayRequest; -use App\Http\Requests\CompanyGateway\DestroyCompanyGatewayRequest; use App\Http\Requests\CompanyGateway\EditCompanyGatewayRequest; use App\Http\Requests\CompanyGateway\ShowCompanyGatewayRequest; -use App\Http\Requests\CompanyGateway\StoreCompanyGatewayRequest; use App\Http\Requests\CompanyGateway\TestCompanyGatewayRequest; +use App\Http\Requests\CompanyGateway\StoreCompanyGatewayRequest; +use App\Http\Requests\CompanyGateway\CreateCompanyGatewayRequest; use App\Http\Requests\CompanyGateway\UpdateCompanyGatewayRequest; -use App\Jobs\Util\ApplePayDomain; -use App\Libraries\MultiDB; -use App\Models\Client; -use App\Models\CompanyGateway; -use App\PaymentDrivers\CheckoutCom\CheckoutSetupWebhook; -use App\PaymentDrivers\Stripe\Jobs\StripeWebhook; -use App\Repositories\CompanyRepository; -use App\Transformers\CompanyGatewayTransformer; -use App\Utils\Traits\MakesHash; -use Illuminate\Foundation\Bus\DispatchesJobs; -use Illuminate\Http\Response; +use App\Http\Requests\CompanyGateway\DestroyCompanyGatewayRequest; /** * Class CompanyGatewayController. @@ -547,12 +548,17 @@ class CompanyGatewayController extends BaseController public function importCustomers(TestCompanyGatewayRequest $request, CompanyGateway $company_gateway) { - + //Throttle here + // if (Cache::get("throttle_polling:import_customers:{$company_gateway->company->company_key}:{$company_gateway->hashed_id}")) + // return response()->json(['message' => ctrans('texts.import_started')], 200); + dispatch(function () use($company_gateway) { MultiDB::setDb($company_gateway->company->db); $company_gateway->driver()->importCustomers(); })->afterResponse(); + Cache::put("throttle_polling:import_customers:{$company_gateway->company->company_key}:{$company_gateway->hashed_id}", true, 300); + return response()->json(['message' => ctrans('texts.import_started')], 200); } diff --git a/app/PaymentDrivers/BraintreePaymentDriver.php b/app/PaymentDrivers/BraintreePaymentDriver.php index 23d067424c9d..cb214f62be02 100644 --- a/app/PaymentDrivers/BraintreePaymentDriver.php +++ b/app/PaymentDrivers/BraintreePaymentDriver.php @@ -23,6 +23,7 @@ use App\Models\PaymentHash; use App\Models\PaymentType; use App\Models\ClientContact; use App\Factory\ClientFactory; +use Illuminate\Support\Carbon; use App\Jobs\Util\SystemLogger; use App\Models\ClientGatewayToken; use App\Factory\ClientContactFactory; @@ -343,7 +344,17 @@ class BraintreePaymentDriver extends BaseDriver ->exists(); } - private function findContact(string $email) { + private function getToken(string $token, string $gateway_customer_reference) + { + + return ClientGatewayToken::where('company_id', $this->company_gateway->company_id) + ->where('gateway_customer_reference', $gateway_customer_reference) + ->where('token', $token) + ->first(); + + } + + private function findClient(string $email) { return ClientContact::where('company_id', $this->company_gateway->company_id) ->where('email', $email) ->first()->client ?? false; @@ -356,6 +367,9 @@ class BraintreePaymentDriver extends BaseDriver foreach($cards as $card) { + if($this->getToken($card->token, $card->customerId) || Carbon::createFromDate($card->expirationYear, $card->expirationMonth, '1')->lt(now())) + continue; + $payment_meta = new \stdClass(); $payment_meta->exp_month = (string) $card->expirationMonth; $payment_meta->exp_year = (string) $card->expirationYear; @@ -468,19 +482,22 @@ class BraintreePaymentDriver extends BaseDriver $customer = $this->find($c->id); + // nlog(count($customer->creditCards). " Exists for {$c->id}"); + if(!$customer) continue; - if(!$this->findTokens($c->id) && !($client = $this->findContact($customer->email))) { + $client = $this->findClient($customer->email); + + if(!$this->findTokens($c->id) && !$client) { //customer is not referenced in the system - create client $client = $this->createNinjaClient($customer); - nlog("Creating new Client"); + // nlog("Creating new Client"); } - $this->addClientCards($client, $customer->creditCards); - nlog("Adding Braintree Client: {$c->id} => {$client->id}"); + // nlog("Adding Braintree Client: {$c->id} => {$client->id}"); } } diff --git a/app/PaymentDrivers/CheckoutComPaymentDriver.php b/app/PaymentDrivers/CheckoutComPaymentDriver.php index 65b51718b8c4..23685ed6bce3 100644 --- a/app/PaymentDrivers/CheckoutComPaymentDriver.php +++ b/app/PaymentDrivers/CheckoutComPaymentDriver.php @@ -12,37 +12,38 @@ namespace App\PaymentDrivers; -use App\Exceptions\PaymentFailed; -use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest; -use App\Http\Requests\Gateways\Checkout3ds\Checkout3dsRequest; -use App\Http\Requests\Payments\PaymentWebhookRequest; -use App\Jobs\Util\SystemLogger; -use App\Models\ClientGatewayToken; +use Exception; use App\Models\Company; -use App\Models\GatewayType; use App\Models\Invoice; use App\Models\Payment; +use App\Models\SystemLog; +use Checkout\CheckoutSdk; +use Checkout\Environment; +use Checkout\Common\Phone; +use App\Models\GatewayType; use App\Models\PaymentHash; use App\Models\PaymentType; -use App\Models\SystemLog; -use App\PaymentDrivers\CheckoutCom\CheckoutWebhook; -use App\PaymentDrivers\CheckoutCom\CreditCard; -use App\PaymentDrivers\CheckoutCom\Utilities; -use App\Utils\Traits\SystemLogTrait; +use Illuminate\Support\Carbon; +use App\Jobs\Util\SystemLogger; +use App\Exceptions\PaymentFailed; +use App\Models\ClientGatewayToken; use Checkout\CheckoutApiException; +use App\Utils\Traits\SystemLogTrait; +use Checkout\Payments\RefundRequest; +use Illuminate\Support\Facades\Auth; use Checkout\CheckoutArgumentException; -use Checkout\CheckoutAuthorizationException; -use Checkout\CheckoutSdk; -use Checkout\Common\Phone; use Checkout\Customers\CustomerRequest; -use Checkout\Environment; +use Checkout\CheckoutAuthorizationException; +use App\PaymentDrivers\CheckoutCom\Utilities; +use Checkout\Payments\Request\PaymentRequest; +use App\PaymentDrivers\CheckoutCom\CreditCard; +use App\PaymentDrivers\CheckoutCom\CheckoutWebhook; +use App\Http\Requests\Payments\PaymentWebhookRequest; +use Checkout\Payments\Request\Source\RequestIdSource; +use App\Http\Requests\Gateways\Checkout3ds\Checkout3dsRequest; +use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest; use Checkout\Payments\Previous\PaymentRequest as PreviousPaymentRequest; use Checkout\Payments\Previous\Source\RequestIdSource as SourceRequestIdSource; -use Checkout\Payments\RefundRequest; -use Checkout\Payments\Request\PaymentRequest; -use Checkout\Payments\Request\Source\RequestIdSource; -use Exception; -use Illuminate\Support\Facades\Auth; class CheckoutComPaymentDriver extends BaseDriver { @@ -546,4 +547,79 @@ class CheckoutComPaymentDriver extends BaseDriver } return false; } + + private function getToken(string $token, $gateway_customer_reference) + { + return ClientGatewayToken::query() + ->where('company_id', $this->company_gateway->company_id) + ->where('gateway_customer_reference', $gateway_customer_reference) + ->where('token', $token) + ->first(); + } + + public function importCustomers() + { + $this->init(); + + $this->company_gateway + ->company + ->clients() + ->cursor() + ->each(function ($client){ + + nlog("1"); + + if(!str_contains($client->present()->email(), "@")) + return; + + +nlog("2"); +nlog($client->present()->email()); + + try{ + $customer = $this->gateway->getCustomersClient()->get($client->present()->email()); + } + catch(\Exception $e) { + nlog("returning due to exception"); + return; + } + +nlog("3"); + + $this->client = $client; + + nlog($customer['instruments']); + + foreach($customer['instruments'] as $card) + { + if( + $card['type'] != 'card' || + Carbon::createFromDate($card['expiry_year'], $card['expiry_month'], '1')->lt(now()) || + $this->getToken($card['id'], $customer['id']) + ) + continue; + + +nlog("4"); + + $payment_meta = new \stdClass(); + $payment_meta->exp_month = (string) $card['expiry_month']; + $payment_meta->exp_year = (string) $card['expiry_year']; + $payment_meta->brand = (string) $card['scheme']; + $payment_meta->last4 = (string) $card['last4']; + $payment_meta->type = (int) GatewayType::CREDIT_CARD; + + $data = [ + 'payment_meta' => $payment_meta, + 'token' => $card['id'], + 'payment_method_id' => GatewayType::CREDIT_CARD, + ]; + + $this->storeGatewayToken($data, ['gateway_customer_reference' => $customer['id']]); + + + } + + }); + } } From fc61065e6930fc194f12f25c88eb3b8887307614 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 18 Mar 2024 13:51:21 +1100 Subject: [PATCH 08/14] Checkout.com import customers --- .../CheckoutComPaymentDriver.php | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/app/PaymentDrivers/CheckoutComPaymentDriver.php b/app/PaymentDrivers/CheckoutComPaymentDriver.php index 23685ed6bce3..774bf6af64b5 100644 --- a/app/PaymentDrivers/CheckoutComPaymentDriver.php +++ b/app/PaymentDrivers/CheckoutComPaymentDriver.php @@ -556,7 +556,15 @@ class CheckoutComPaymentDriver extends BaseDriver ->where('token', $token) ->first(); } - + + /** + * ImportCustomers + * + * Only their methods because checkout.com + * does not have a list route for customers + * + * @return void + */ public function importCustomers() { $this->init(); @@ -567,29 +575,21 @@ class CheckoutComPaymentDriver extends BaseDriver ->cursor() ->each(function ($client){ - nlog("1"); - if(!str_contains($client->present()->email(), "@")) return; - -nlog("2"); -nlog($client->present()->email()); - try{ $customer = $this->gateway->getCustomersClient()->get($client->present()->email()); } catch(\Exception $e) { - nlog("returning due to exception"); + nlog("Checkout: Customer not found"); return; } -nlog("3"); - $this->client = $client; nlog($customer['instruments']); - + foreach($customer['instruments'] as $card) { if( @@ -598,9 +598,6 @@ nlog("3"); $this->getToken($card['id'], $customer['id']) ) continue; - - -nlog("4"); $payment_meta = new \stdClass(); $payment_meta->exp_month = (string) $card['expiry_month']; @@ -617,7 +614,6 @@ nlog("4"); $this->storeGatewayToken($data, ['gateway_customer_reference' => $customer['id']]); - } }); From 0a87aeaf8f4c4dac55f5e59f945e88ae1af6d189 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 18 Mar 2024 14:06:16 +1100 Subject: [PATCH 09/14] Working on importing Forte customers --- app/Console/Commands/CreateSingleAccount.php | 22 +++++++++++++++ app/PaymentDrivers/EwayPaymentDriver.php | 11 ++++++++ app/PaymentDrivers/FortePaymentDriver.php | 29 +++++++++++++++++--- config/ninja.php | 1 + 4 files changed, 59 insertions(+), 4 deletions(-) diff --git a/app/Console/Commands/CreateSingleAccount.php b/app/Console/Commands/CreateSingleAccount.php index cfdf4177798d..75258b35f3e7 100644 --- a/app/Console/Commands/CreateSingleAccount.php +++ b/app/Console/Commands/CreateSingleAccount.php @@ -1072,6 +1072,28 @@ class CreateSingleAccount extends Command $cg->save(); } + if (config('ninja.testvars.forte') && ($this->gateway == 'all' || $this->gateway == 'forte')) { + $cg = new CompanyGateway(); + $cg->company_id = $company->id; + $cg->user_id = $user->id; + $cg->gateway_key = 'kivcvjexxvdiyqtj3mju5d6yhpeht2xs'; + $cg->require_cvv = true; + $cg->require_billing_address = true; + $cg->require_shipping_address = true; + $cg->update_details = true; + $cg->config = encrypt(config('ninja.testvars.forte')); + $cg->save(); + + $gateway_types = $cg->driver()->gatewayTypes(); + + $fees_and_limits = new stdClass(); + $fees_and_limits->{$gateway_types[0]} = new FeesAndLimits(); + + $cg->fees_and_limits = $fees_and_limits; + $cg->save(); + } + + } diff --git a/app/PaymentDrivers/EwayPaymentDriver.php b/app/PaymentDrivers/EwayPaymentDriver.php index 2ce3deb8b986..0a772fb71758 100644 --- a/app/PaymentDrivers/EwayPaymentDriver.php +++ b/app/PaymentDrivers/EwayPaymentDriver.php @@ -220,4 +220,15 @@ class EwayPaymentDriver extends BaseDriver return (bool) count($response->getErrors()) == 0; } + + /** + * importCustomers + * + * No support + * @return void + */ + public function importCustomers() + { + return true; + } } diff --git a/app/PaymentDrivers/FortePaymentDriver.php b/app/PaymentDrivers/FortePaymentDriver.php index 3a246980a154..5a38a8b0bcca 100644 --- a/app/PaymentDrivers/FortePaymentDriver.php +++ b/app/PaymentDrivers/FortePaymentDriver.php @@ -204,8 +204,29 @@ class FortePaymentDriver extends BaseDriver return $response->successful(); } - // public function tokenBilling(ClientGatewayToken $cgt, PaymentHash $payment_hash) - // { - // return $this->payment_method->yourTokenBillingImplmentation(); - // } + + public function importCustomers() + { + + $forte_base_uri = "https://sandbox.forte.net/api/v3/"; + if ($this->company_gateway->getConfigField('testMode') == false) { + $forte_base_uri = "https://api.forte.net/v3/"; + } + $forte_api_access_id = $this->company_gateway->getConfigField('apiAccessId'); + $forte_secure_key = $this->company_gateway->getConfigField('secureKey'); + $forte_auth_organization_id = $this->company_gateway->getConfigField('authOrganizationId'); + $forte_organization_id = $this->company_gateway->getConfigField('organizationId'); + $forte_location_id = $this->company_gateway->getConfigField('locationId'); + + $response = Http::withBasicAuth($forte_api_access_id, $forte_secure_key) + ->withHeaders(['X-Forte-Auth-Organization-Id' => $forte_organization_id]) + ->get("{$forte_base_uri}/organizations/{$forte_organization_id}/locations/{$forte_location_id}/customers/"); + + if($response->successful()){ + + nlog($response->json()); + + } + + } } diff --git a/config/ninja.php b/config/ninja.php index 98a742d15c6d..41ae5ddcd8a6 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -92,6 +92,7 @@ return [ 'stripe' => env('STRIPE_KEYS', ''), 'paypal' => env('PAYPAL_KEYS', ''), 'ppcp' => env('PPCP_KEYS', ''), + 'forte' => env('FORTE_KEYS', ''), 'paypal_rest' => env('PAYPAL_REST_KEYS', ''), 'authorize' => env('AUTHORIZE_KEYS', ''), 'checkout' => env('CHECKOUT_KEYS', ''), From 79ed4e4305b5dd3388d055e2c2e3abfd2671cbb7 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 18 Mar 2024 17:01:00 +1100 Subject: [PATCH 10/14] Import Customers Forte --- .../Factory/ForteCustomerFactory.php | 134 ++++++++++++++++++ app/PaymentDrivers/FortePaymentDriver.php | 55 +++++-- 2 files changed, 181 insertions(+), 8 deletions(-) create mode 100644 app/PaymentDrivers/Factory/ForteCustomerFactory.php diff --git a/app/PaymentDrivers/Factory/ForteCustomerFactory.php b/app/PaymentDrivers/Factory/ForteCustomerFactory.php new file mode 100644 index 000000000000..1b127d58e7cf --- /dev/null +++ b/app/PaymentDrivers/Factory/ForteCustomerFactory.php @@ -0,0 +1,134 @@ + $customer['company_name'] ?? $customer['first_name'], + 'contacts' => [ + [ + 'first_name' => $customer['first_name'], + 'last_name' => $customer['last_name'], + 'email' => $this->getBillingAddress($customer)['email'], + 'phone' => $this->getBillingAddress($customer)['phone'], + ] + ], + 'currency_id' => $company->settings->currency_id, + + ])->merge($this->getBillingAddress($customer)) + ->merge($this->getShippingAddress($customer)) + ->toArray(); + + } + + // public function convertToGateway(Client $client): array + // { + + // } + + private function getBillingAddress(array $customer): array + { + if(isset($customer['default_billing_address_token'])) { + + foreach($customer['addresses'] as $address) { + + if($address['address_token'] != $customer['default_billing_address_token']) + continue; + + return [ + 'address1' => $address['physical_address']['street_line1'], + 'address2' => $address['physical_address']['street_line2'], + 'city' => $address['physical_address']['locality'], + 'state' => $address['physical_address']['region'], + 'postal_code' => $address['physical_address']['postal_code'], + 'country_id' => '840', + 'email' => $address['email'], + 'phone' => $address['phone'], + ]; + + } + + } + + if(isset($customer['addresses'][0])) { + + $address = $customer['addresses'][0]; + + return [ + 'address1' => $address['physical_address']['street_line1'], + 'address2' => $address['physical_address']['street_line2'], + 'city' => $address['physical_address']['locality'], + 'state' => $address['physical_address']['region'], + 'postal_code' => $address['physical_address']['postal_code'], + 'email' => $address['email'], + 'phone' => $address['phone'], + 'country_id' => '840', + ]; + + } + + return ['email' => '', 'phone' => '']; + + } + + private function getShippingAddress(array $customer): array + { + + if(isset($customer['default_shipping_address_token'])) { + + foreach($customer['addresses'] as $address) { + + if($address['address_token'] != $customer['default_shipping_address_token']) { + continue; + } + + return [ + 'address1' => $address['physical_address']['street_line1'], + 'address2' => $address['physical_address']['street_line2'], + 'city' => $address['physical_address']['locality'], + 'state' => $address['physical_address']['region'], + 'postal_code' => $address['physical_address']['postal_code'], + 'country_id' => '840', + ]; + + } + + } + + if(isset($customer['addresses'][1])){ + + $address = $customer['addresses'][1]; + + return [ + 'address1' => $address['physical_address']['street_line1'], + 'address2' => $address['physical_address']['street_line2'], + 'city' => $address['physical_address']['locality'], + 'state' => $address['physical_address']['region'], + 'postal_code' => $address['physical_address']['postal_code'], + 'country_id' => '840', + ]; + + } + + return ['email' => '', 'phone' => '']; + + } +} diff --git a/app/PaymentDrivers/FortePaymentDriver.php b/app/PaymentDrivers/FortePaymentDriver.php index 5a38a8b0bcca..5c3c4ce0d7b8 100644 --- a/app/PaymentDrivers/FortePaymentDriver.php +++ b/app/PaymentDrivers/FortePaymentDriver.php @@ -11,6 +11,7 @@ namespace App\PaymentDrivers; +use App\Factory\ClientFactory; use App\Models\Payment; use App\Models\SystemLog; use App\Models\GatewayType; @@ -18,7 +19,10 @@ use App\Jobs\Util\SystemLogger; use App\Utils\Traits\MakesHash; use App\PaymentDrivers\Forte\ACH; use Illuminate\Support\Facades\Http; +use App\Repositories\ClientRepository; use App\PaymentDrivers\Forte\CreditCard; +use App\Repositories\ClientContactRepository; +use App\PaymentDrivers\Factory\ForteCustomerFactory; class FortePaymentDriver extends BaseDriver { @@ -184,6 +188,9 @@ class FortePaymentDriver extends BaseDriver ]; } + //////////////////////////////////////////// + // DB + /////////////////////////////////////////// public function auth(): bool { @@ -204,29 +211,61 @@ class FortePaymentDriver extends BaseDriver return $response->successful(); } - - public function importCustomers() + + public function baseUri(): string { $forte_base_uri = "https://sandbox.forte.net/api/v3/"; if ($this->company_gateway->getConfigField('testMode') == false) { $forte_base_uri = "https://api.forte.net/v3/"; } + + return $forte_base_uri; + } + + private function getOrganisationId(): string + { + return $this->company_gateway->getConfigField('organizationId'); + } + + public function getLocationId(): string + { + return $this->company_gateway->getConfigField('locationId'); + } + + public function stubRequest() + { + $forte_api_access_id = $this->company_gateway->getConfigField('apiAccessId'); $forte_secure_key = $this->company_gateway->getConfigField('secureKey'); $forte_auth_organization_id = $this->company_gateway->getConfigField('authOrganizationId'); - $forte_organization_id = $this->company_gateway->getConfigField('organizationId'); - $forte_location_id = $this->company_gateway->getConfigField('locationId'); - $response = Http::withBasicAuth($forte_api_access_id, $forte_secure_key) - ->withHeaders(['X-Forte-Auth-Organization-Id' => $forte_organization_id]) - ->get("{$forte_base_uri}/organizations/{$forte_organization_id}/locations/{$forte_location_id}/customers/"); + return Http::withBasicAuth($forte_api_access_id, $forte_secure_key) + ->withHeaders(['X-Forte-Auth-Organization-Id' => $this->getOrganisationId()]); + } + + public function importCustomers() + { + + $response = $this->stubRequest() + ->withQueryParameters(['page_size' => 10000]) + ->get("{$this->baseUri()}/organizations/{$this->getOrganisationId()}/locations/{$this->getLocationId()}/customers"); if($response->successful()){ + + foreach($response->json()['results'] as $customer) + { - nlog($response->json()); + $client_repo = new ClientRepository(new ClientContactRepository()); + $factory = new ForteCustomerFactory(); + $data = $factory->convertToNinja($customer, $this->company_gateway->company); + + $client_repo->save($data, ClientFactory::create($this->company_gateway->company_id, $this->company_gateway->user_id)); + + } } } + } From 08e5d35955258e0351dd49f0cf6dbac5ae011d0d Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 18 Mar 2024 17:10:12 +1100 Subject: [PATCH 11/14] import clients - forte --- app/PaymentDrivers/FortePaymentDriver.php | 14 +++++++++++++- app/PaymentDrivers/PayPalPPCPPaymentDriver.php | 5 +++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/PaymentDrivers/FortePaymentDriver.php b/app/PaymentDrivers/FortePaymentDriver.php index 5c3c4ce0d7b8..5f6503af0e5f 100644 --- a/app/PaymentDrivers/FortePaymentDriver.php +++ b/app/PaymentDrivers/FortePaymentDriver.php @@ -11,10 +11,11 @@ namespace App\PaymentDrivers; -use App\Factory\ClientFactory; use App\Models\Payment; use App\Models\SystemLog; use App\Models\GatewayType; +use App\Models\ClientContact; +use App\Factory\ClientFactory; use App\Jobs\Util\SystemLogger; use App\Utils\Traits\MakesHash; use App\PaymentDrivers\Forte\ACH; @@ -244,6 +245,14 @@ class FortePaymentDriver extends BaseDriver ->withHeaders(['X-Forte-Auth-Organization-Id' => $this->getOrganisationId()]); } + private function getClient(?string $email) + { + return ClientContact::query() + ->where('company_id', $this->company_gateway->company_id) + ->where('email', $email) + ->first(); + } + public function importCustomers() { @@ -261,6 +270,9 @@ class FortePaymentDriver extends BaseDriver $data = $factory->convertToNinja($customer, $this->company_gateway->company); + if(strlen($customer['email']) == 0 || $this->getClient($customer['email'])) + continue; + $client_repo->save($data, ClientFactory::create($this->company_gateway->company_id, $this->company_gateway->user_id)); } diff --git a/app/PaymentDrivers/PayPalPPCPPaymentDriver.php b/app/PaymentDrivers/PayPalPPCPPaymentDriver.php index 25fb85094884..83ab1656ad11 100644 --- a/app/PaymentDrivers/PayPalPPCPPaymentDriver.php +++ b/app/PaymentDrivers/PayPalPPCPPaymentDriver.php @@ -574,4 +574,9 @@ class PayPalPPCPPaymentDriver extends BaseDriver return false; } + + public function importCustomers() + { + + } } From 3ef7d68eedb8f48f8f02f3ed4bae7c830437eb96 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 19 Mar 2024 10:38:54 +1100 Subject: [PATCH 12/14] Square factory --- .../Controllers/CompanyGatewayController.php | 17 ++ .../Factory/ForteCustomerFactory.php | 35 +-- .../Factory/PaytraceCustomerFactory.php | 59 +++++ .../Factory/SquareCustomerFactory.php | 132 +++++++++++ app/PaymentDrivers/FortePaymentDriver.php | 47 +++- .../PayPalPPCPPaymentDriver.php | 7 +- .../PayPalRestPaymentDriver.php | 8 +- app/PaymentDrivers/PayTrace/CreditCard.php | 3 + app/PaymentDrivers/PaytracePaymentDriver.php | 79 ++++++- app/PaymentDrivers/Square/CreditCard.php | 81 +------ app/PaymentDrivers/SquarePaymentDriver.php | 210 +++++++++++++++++- 11 files changed, 563 insertions(+), 115 deletions(-) create mode 100644 app/PaymentDrivers/Factory/PaytraceCustomerFactory.php create mode 100644 app/PaymentDrivers/Factory/SquareCustomerFactory.php diff --git a/app/Http/Controllers/CompanyGatewayController.php b/app/Http/Controllers/CompanyGatewayController.php index bdff0a8b1239..8d69b3738a1c 100644 --- a/app/Http/Controllers/CompanyGatewayController.php +++ b/app/Http/Controllers/CompanyGatewayController.php @@ -55,6 +55,9 @@ class CompanyGatewayController extends BaseController private string $checkout_key = '3758e7f7c6f4cecf0f4f348b9a00f456'; + private string $forte_key = 'kivcvjexxvdiyqtj3mju5d6yhpeht2xs'; + + /** * CompanyGatewayController constructor. * @param CompanyRepository $company_repo @@ -228,6 +231,13 @@ class CompanyGatewayController extends BaseController StripeWebhook::dispatch($company_gateway->company->company_key, $company_gateway->id); } elseif($company_gateway->gateway_key == $this->checkout_key) { CheckoutSetupWebhook::dispatch($company_gateway->company->company_key, $company_gateway->id); + } elseif($company_gateway->gateway_key == $this->forte_key) { + + dispatch(function () use ($company_gateway) { + MultiDB::setDb($company_gateway->company->db); + $company_gateway->driver()->updateFees(); + })->afterResponse(); + } return $this->itemResponse($company_gateway); @@ -410,6 +420,13 @@ class CompanyGatewayController extends BaseController if($company_gateway->gateway_key == $this->checkout_key) { CheckoutSetupWebhook::dispatch($company_gateway->company->company_key, $company_gateway->fresh()->id); + }elseif($company_gateway->gateway_key == $this->forte_key){ + + dispatch(function () use ($company_gateway) { + MultiDB::setDb($company_gateway->company->db); + $company_gateway->driver()->updateFees(); + })->afterResponse(); + } return $this->itemResponse($company_gateway); diff --git a/app/PaymentDrivers/Factory/ForteCustomerFactory.php b/app/PaymentDrivers/Factory/ForteCustomerFactory.php index 1b127d58e7cf..eb6336d778fb 100644 --- a/app/PaymentDrivers/Factory/ForteCustomerFactory.php +++ b/app/PaymentDrivers/Factory/ForteCustomerFactory.php @@ -31,10 +31,11 @@ class ForteCustomerFactory 'phone' => $this->getBillingAddress($customer)['phone'], ] ], - 'currency_id' => $company->settings->currency_id, - - ])->merge($this->getBillingAddress($customer)) - ->merge($this->getShippingAddress($customer)) + 'settings' => [ + 'currency_id' => $company->settings->currency_id, + ], + ])->merge($this->getShippingAddress($customer)) + ->merge($this->getBillingAddress($customer)) ->toArray(); } @@ -101,12 +102,12 @@ class ForteCustomerFactory } return [ - 'address1' => $address['physical_address']['street_line1'], - 'address2' => $address['physical_address']['street_line2'], - 'city' => $address['physical_address']['locality'], - 'state' => $address['physical_address']['region'], - 'postal_code' => $address['physical_address']['postal_code'], - 'country_id' => '840', + 'shipping_address1' => $address['physical_address']['street_line1'], + 'shipping_address2' => $address['physical_address']['street_line2'], + 'shipping_city' => $address['physical_address']['locality'], + 'shipping_state' => $address['physical_address']['region'], + 'shipping_postal_code' => $address['physical_address']['postal_code'], + 'shipping_country_id' => '840', ]; } @@ -118,12 +119,14 @@ class ForteCustomerFactory $address = $customer['addresses'][1]; return [ - 'address1' => $address['physical_address']['street_line1'], - 'address2' => $address['physical_address']['street_line2'], - 'city' => $address['physical_address']['locality'], - 'state' => $address['physical_address']['region'], - 'postal_code' => $address['physical_address']['postal_code'], - 'country_id' => '840', + 'shipping_address1' => $address['physical_address']['street_line1'], + 'shipping_address2' => $address['physical_address']['street_line2'], + 'shipping_city' => $address['physical_address']['locality'], + 'shipping_state' => $address['physical_address']['region'], + 'shipping_postal_code' => $address['physical_address']['postal_code'], + 'shipping_country_id' => '840', + 'email' => $address['email'], + 'phone' => $address['phone'], ]; } diff --git a/app/PaymentDrivers/Factory/PaytraceCustomerFactory.php b/app/PaymentDrivers/Factory/PaytraceCustomerFactory.php new file mode 100644 index 000000000000..731a6c7085f6 --- /dev/null +++ b/app/PaymentDrivers/Factory/PaytraceCustomerFactory.php @@ -0,0 +1,59 @@ + $customer->billing_address->name ?? $customer->shipping_address->name, + 'contacts' => [ + [ + 'first_name' => $customer->billing_address->name ?? $customer->shipping_address->name, + 'last_name' => '', + 'email' => $customer->email, + 'phone' => $customer->phone, + ] + ], + 'currency_id' => $company->settings->currency_id, + 'address1' => $customer->billing_address->street_address, + 'address2' => $customer->billing_address->street_address2, + 'city' => $customer->billing_address->city, + 'state' => $customer->billing_address->state, + 'postal_code' => $customer->billing_address->zip, + 'country_id' => '840', + 'shipping_address1' => $customer->shipping_address->street_address, + 'shipping_address2' => $customer->shipping_address->street_address2, + 'shipping_city' => $customer->shipping_address->city, + 'shipping_state' => $customer->shipping_address->state, + 'shipping_postal_code' => $customer->shipping_address->zip, + 'shipping_country_id' => '840', + 'settings' => [ + 'currency_id' => $company->settings->currency_id, + ], + 'card' => [ + 'token' => $customer->customer_id, + 'last4' => $customer->credit_card->masked_number, + 'expiry_month' => $customer->credit_card->expiration_month, + 'expiry_year' => $customer->credit_card->expiration_year, + ], + ]) + ->toArray(); + + } + +} diff --git a/app/PaymentDrivers/Factory/SquareCustomerFactory.php b/app/PaymentDrivers/Factory/SquareCustomerFactory.php new file mode 100644 index 000000000000..fa3d9ad71bfd --- /dev/null +++ b/app/PaymentDrivers/Factory/SquareCustomerFactory.php @@ -0,0 +1,132 @@ +getCards() ?? [] as $card){ + + $meta = new \stdClass; + $meta->exp_month = $card->getExpMonth(); + $meta->exp_year = $card->getExpYear(); + $meta->last4 = $card->getLast4(); + $meta->brand = $card->getCardBrand(); + $meta->type = GatewayType::CREDIT_CARD; + + $cards[] = [ + 'token' => $card->getId(), + 'payment_meta' => $meta, + 'payment_method_id' => GatewayType::CREDIT_CARD, + 'gateway_customer_reference' => $customer->getId(), + ]; + } + + $address = $customer->getAddress(); + + return + collect([ + 'name' => $customer->getCompanyName() ?? ($customer->getGivenName() ?? '' ." " . $customer->getFamilyName() ?? ''), + 'contacts' => [ + [ + 'first_name' => $customer->getGivenName(), + 'last_name' => $customer->getFamilyName(), + 'email' => $customer->getEmailAddress(), + 'phone' => $customer->getPhoneNumber(), + ] + ], + 'currency_id' => $company->settings->currency_id, + 'address1' => $address->getAddressLine1(), + 'address2' => $address->getAddressLine2(), + 'city' => $address->getLocality(), + 'state' => $address->getAdministrativeDistrictLevel1(), + 'postal_code' => $address->getPostalCode(), + 'country_id' => '840', + 'settings' => [ + 'currency_id' => $company->settings->currency_id, + ], + 'cards' => $cards, + ]) + ->toArray(); + + } + +} diff --git a/app/PaymentDrivers/FortePaymentDriver.php b/app/PaymentDrivers/FortePaymentDriver.php index 5f6503af0e5f..0cbf1e3883df 100644 --- a/app/PaymentDrivers/FortePaymentDriver.php +++ b/app/PaymentDrivers/FortePaymentDriver.php @@ -253,6 +253,50 @@ class FortePaymentDriver extends BaseDriver ->first(); } + public function getLocation() + { + + $response = $this->stubRequest() + ->withQueryParameters(['page_size' => 10000]) + ->get("{$this->baseUri()}/organizations/{$this->getOrganisationId()}/locations/{$this->getLocationId()}"); + + if($response->successful()) + return $response->json(); + + return false; + } + + public function updateFees() + { + $response = $this->getLocation(); + + if($response) + { + $body = $response['services']; + + $fees_and_limits = $this->company_gateway->fees_and_limits; + + if($body['card']['service_fee_percentage'] > 0 || $body['card']['service_fee_additional_amount'] > 0){ + + $fees_and_limits->{1}->fee_amount = $body['card']['service_fee_additional_amount']; + $fees_and_limits->{1}->fee_percent = $body['card']['service_fee_percentage']; + } + + if($body['debit']['service_fee_percentage'] > 0 || $body['debit']['service_fee_additional_amount'] > 0) { + + $fees_and_limits->{2}->fee_amount = $body['debit']['service_fee_additional_amount']; + $fees_and_limits->{2}->fee_percent = $body['debit']['service_fee_percentage']; + } + + $this->company_gateway->fees_and_limits = $fees_and_limits; + $this->company_gateway->save(); + + } + + return false; + + } + public function importCustomers() { @@ -270,11 +314,12 @@ class FortePaymentDriver extends BaseDriver $data = $factory->convertToNinja($customer, $this->company_gateway->company); - if(strlen($customer['email']) == 0 || $this->getClient($customer['email'])) + if(strlen($data['email']) == 0 || $this->getClient($data['email'])) continue; $client_repo->save($data, ClientFactory::create($this->company_gateway->company_id, $this->company_gateway->user_id)); + //persist any payment methods here! } } diff --git a/app/PaymentDrivers/PayPalPPCPPaymentDriver.php b/app/PaymentDrivers/PayPalPPCPPaymentDriver.php index 83ab1656ad11..5c86fae72acc 100644 --- a/app/PaymentDrivers/PayPalPPCPPaymentDriver.php +++ b/app/PaymentDrivers/PayPalPPCPPaymentDriver.php @@ -577,6 +577,11 @@ class PayPalPPCPPaymentDriver extends BaseDriver public function importCustomers() { + + // $response = $this->gatewayRequest('/v1/reporting/transactions', 'get', ['fields' => 'all','page_size' => 500,'start_date' => '2024-02-01T00:00:00-0000', 'end_date' => '2024-03-01T00:00:00-0000']); - } + // nlog($response->json()); + + return true; + } } diff --git a/app/PaymentDrivers/PayPalRestPaymentDriver.php b/app/PaymentDrivers/PayPalRestPaymentDriver.php index ae6d68e6f301..1d2bbd90bac3 100644 --- a/app/PaymentDrivers/PayPalRestPaymentDriver.php +++ b/app/PaymentDrivers/PayPalRestPaymentDriver.php @@ -424,7 +424,7 @@ class PayPalRestPaymentDriver extends BaseDriver SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::TYPE_PAYPAL, $this->client, - $this->client->company, + $this->client->company ?? $this->company_gateway->company, ); throw new PaymentFailed("Gateway failure - {$r->body()}", 401); @@ -474,4 +474,10 @@ class PayPalRestPaymentDriver extends BaseDriver return false; } + + public function importCustomers() + { + return true; + } + } diff --git a/app/PaymentDrivers/PayTrace/CreditCard.php b/app/PaymentDrivers/PayTrace/CreditCard.php index 0fa5f37991d1..b08a27088d1e 100644 --- a/app/PaymentDrivers/PayTrace/CreditCard.php +++ b/app/PaymentDrivers/PayTrace/CreditCard.php @@ -59,6 +59,9 @@ class CreditCard 'enc_key' => $data['enc_key'], 'integrator_id' => $this->paytrace->company_gateway->getConfigField('integratorId'), 'billing_address' => $this->buildBillingAddress(), + 'email' => $this->paytrace->client->present()->email(), + 'phone' => $this->paytrace->client->present()->phone(), + ]; $response = $this->paytrace->gatewayRequest('/v1/customer/pt_protect_create', $post_data); diff --git a/app/PaymentDrivers/PaytracePaymentDriver.php b/app/PaymentDrivers/PaytracePaymentDriver.php index 2d262e105cae..05278300bc7c 100644 --- a/app/PaymentDrivers/PaytracePaymentDriver.php +++ b/app/PaymentDrivers/PaytracePaymentDriver.php @@ -11,19 +11,24 @@ namespace App\PaymentDrivers; -use App\Exceptions\SystemError; -use App\Http\Requests\Payments\PaymentWebhookRequest; -use App\Jobs\Util\SystemLogger; -use App\Models\ClientGatewayToken; -use App\Models\GatewayType; use App\Models\Invoice; use App\Models\Payment; +use App\Utils\CurlUtils; +use App\Models\SystemLog; +use App\Models\GatewayType; use App\Models\PaymentHash; use App\Models\PaymentType; -use App\Models\SystemLog; -use App\PaymentDrivers\PayTrace\CreditCard; -use App\Utils\CurlUtils; +use App\Factory\ClientFactory; +use App\Exceptions\SystemError; +use App\Jobs\Util\SystemLogger; use App\Utils\Traits\MakesHash; +use App\Models\ClientGatewayToken; +use App\Repositories\ClientRepository; +use App\PaymentDrivers\PayTrace\CreditCard; +use App\Repositories\ClientContactRepository; +use App\Http\Requests\Payments\PaymentWebhookRequest; +use App\Models\ClientContact; +use App\PaymentDrivers\Factory\PaytraceCustomerFactory; class PaytracePaymentDriver extends BaseDriver { @@ -260,4 +265,62 @@ class PaytracePaymentDriver extends BaseDriver return false; } + + public function importCustomers() + { + + $data = [ + 'integrator_id' => $this->company_gateway->getConfigField('integratorId'), + ]; + + $response = $this->gatewayRequest('/v1/customer/export', $data); + + nlog($response); + + if ($response && $response->success) { + + $client_repo = new ClientRepository(new ClientContactRepository()); + $factory = new PaytraceCustomerFactory(); + + foreach($response->customers as $customer) + { + $data = $factory->convertToNinja($customer, $this->company_gateway->company); + + $client = false; + + if(str_contains($data['contacts'][0]['email'], "@")) + { + $client = ClientContact::query() + ->where('company_id', $this->company_gateway->company_id) + ->where('email', $data['contacts'][0]['email']) + ->first()->client ?? false; + } + + if(!$client) + $client = $client_repo->save($data, ClientFactory::create($this->company_gateway->company_id, $this->company_gateway->user_id)); + + $this->client = $client; + + if(ClientGatewayToken::query()->where('client_id', $client->id)->where('token',$data['card']['token'])->exists()) + continue; + + $cgt = []; + $cgt['token'] = $data['card']['token']; + $cgt['payment_method_id'] = GatewayType::CREDIT_CARD; + + $payment_meta = new \stdClass(); + $payment_meta->exp_month = $data['card']['expiry_month']; + $payment_meta->exp_year = $data['card']['expiry_year']; + $payment_meta->brand = 'CC'; + $payment_meta->last4 = $data['card']['last4']; + $payment_meta->type = GatewayType::CREDIT_CARD; + + $cgt['payment_meta'] = $payment_meta; + + $token = $this->storeGatewayToken($cgt, []); + + } + } + + } } diff --git a/app/PaymentDrivers/Square/CreditCard.php b/app/PaymentDrivers/Square/CreditCard.php index da53d36a2610..80b48fb5a15a 100644 --- a/app/PaymentDrivers/Square/CreditCard.php +++ b/app/PaymentDrivers/Square/CreditCard.php @@ -197,7 +197,7 @@ class CreditCard implements MethodInterface { $square_card = new \Square\Models\Card(); - $square_card->setCustomerId($this->findOrCreateClient()); + $square_card->setCustomerId($this->square_driver->findOrCreateClient()); $body = new \Square\Models\CreateCardRequest(uniqid("st", true), $source_id, $square_card); @@ -238,82 +238,5 @@ class CreditCard implements MethodInterface return false; } - private function findOrCreateClient() - { - $email_address = new \Square\Models\CustomerTextFilter(); - $email_address->setExact($this->square_driver->client->present()->email()); - - $filter = new \Square\Models\CustomerFilter(); - $filter->setEmailAddress($email_address); - - $query = new \Square\Models\CustomerQuery(); - $query->setFilter($filter); - - $body = new \Square\Models\SearchCustomersRequest(); - $body->setQuery($query); - - $api_response = $this->square_driver - ->init() - ->square - ->getCustomersApi() - ->searchCustomers($body); - - $customers = false; - - if ($api_response->isSuccess()) { - $customers = $api_response->getBody(); - $customers = json_decode($customers); - - if (count([$api_response->getBody(), 1]) == 0) { - $customers = false; - } - } else { - $errors = $api_response->getErrors(); - } - - if ($customers && property_exists($customers, 'customers')) { - return $customers->customers[0]->id; - } - - return $this->createClient(); - } - - private function createClient() - { - $country = $this->square_driver->client->country ? $this->square_driver->client->country->iso_3166_2 : $this->square_driver->client->company->country()->iso_3166_2; - - /* Step two - create the customer */ - $billing_address = new \Square\Models\Address(); - $billing_address->setAddressLine1($this->square_driver->client->address1); - $billing_address->setAddressLine2($this->square_driver->client->address2); - $billing_address->setLocality($this->square_driver->client->city); - $billing_address->setAdministrativeDistrictLevel1($this->square_driver->client->state); - $billing_address->setPostalCode($this->square_driver->client->postal_code); - $billing_address->setCountry($country); - - $body = new \Square\Models\CreateCustomerRequest(); - $body->setGivenName($this->square_driver->client->present()->name()); - $body->setFamilyName(''); - $body->setEmailAddress($this->square_driver->client->present()->email()); - $body->setAddress($billing_address); - // $body->setPhoneNumber($this->square_driver->client->phone); - $body->setReferenceId($this->square_driver->client->number); - $body->setNote('Created by Invoice Ninja.'); - - $api_response = $this->square_driver - ->init() - ->square - ->getCustomersApi() - ->createCustomer($body); - - if ($api_response->isSuccess()) { - $result = $api_response->getResult(); - - return $result->getCustomer()->getId(); - } else { - $errors = $api_response->getErrors(); - nlog($errors); - return $this->processUnsuccessfulPayment($api_response); - } - } + } diff --git a/app/PaymentDrivers/SquarePaymentDriver.php b/app/PaymentDrivers/SquarePaymentDriver.php index f0420f1af8e3..e77df79aa981 100644 --- a/app/PaymentDrivers/SquarePaymentDriver.php +++ b/app/PaymentDrivers/SquarePaymentDriver.php @@ -11,22 +11,27 @@ namespace App\PaymentDrivers; -use App\Http\Requests\Payments\PaymentWebhookRequest; -use App\Jobs\Util\SystemLogger; -use App\Models\ClientGatewayToken; -use App\Models\GatewayType; use App\Models\Invoice; use App\Models\Payment; +use App\Models\SystemLog; +use App\Models\GatewayType; use App\Models\PaymentHash; use App\Models\PaymentType; -use App\Models\SystemLog; +use App\Models\ClientContact; +use App\Factory\ClientFactory; +use App\Jobs\Util\SystemLogger; +use App\Utils\Traits\MakesHash; +use Square\Utils\WebhooksHelper; +use App\Models\ClientGatewayToken; +use App\Repositories\ClientRepository; +use Square\Models\WebhookSubscription; use App\PaymentDrivers\Square\CreditCard; use App\PaymentDrivers\Square\SquareWebhook; -use App\Utils\Traits\MakesHash; -use Square\Models\Builders\RefundPaymentRequestBuilder; +use App\Repositories\ClientContactRepository; use Square\Models\CreateWebhookSubscriptionRequest; -use Square\Models\WebhookSubscription; -use Square\Utils\WebhooksHelper; +use App\Http\Requests\Payments\PaymentWebhookRequest; +use App\PaymentDrivers\Factory\SquareCustomerFactory; +use Square\Models\Builders\RefundPaymentRequestBuilder; class SquarePaymentDriver extends BaseDriver { @@ -442,4 +447,191 @@ class SquarePaymentDriver extends BaseDriver return (bool) count($api_response->getErrors()) == 0; } + + public function importCustomers() + { + + $limit = 100; + + $api_response = $this->init() + ->square + ->getCustomersApi() + ->listCustomers(null, + $limit, + 'DEFAULT', + 'DESC' + ); + + if ($api_response->isSuccess()) { + + while ($api_response->getResult()->getCustomers()) { + + $customers = $api_response->getResult()->getCustomers(); + + $client_repo = new ClientRepository(new ClientContactRepository()); + + nlog($customers); + + foreach($customers as $customer) + { + + $data = (new SquareCustomerFactory())->convertToNinja($customer, $this->company_gateway->company); + $client = ClientContact::where('company_id', $this->company_gateway->company_id)->where('email', $customer->getEmailAddress())->first()->client ?? false; + + if(!$client) + $client = $client_repo->save($data, ClientFactory::create($this->company_gateway->company_id, $this->company_gateway->user_id)); + + $this->client = $client; + + foreach($data['cards'] as $card) { + + if(ClientGatewayToken::where('company_id', $this->company_gateway->company_id)->where('token', $card['token'])->exists()) + continue; + + $this->storeGatewayToken($card); + + } + } + + $c = $api_response->getCursor(); + if ($c) { + + $api_response = $client->getCustomersApi()->listCustomers( + $c, + $limit, + 'DEFAULT', + 'DESC' + ); + } else { + break; + } + + + } + + } + } + + private function findClient($email = null) + { + + $email_address_string = $email ?? $this->client->present()->email(); + + $email_address = new \Square\Models\CustomerTextFilter(); + $email_address->setExact($email_address_string); + + $filter = new \Square\Models\CustomerFilter(); + $filter->setEmailAddress($email_address); + + $query = new \Square\Models\CustomerQuery(); + $query->setFilter($filter); + + $body = new \Square\Models\SearchCustomersRequest(); + $body->setQuery($query); + + $api_response = $this->init() + ->square + ->getCustomersApi() + ->searchCustomers($body); + + $customers = false; + + if ($api_response->isSuccess()) { + $customers = $api_response->getBody(); + $customers = json_decode($customers); + + if (count([$api_response->getBody(), 1]) == 0) { + $customers = false; + } + } else { + $errors = $api_response->getErrors(); + } + + if ($customers && property_exists($customers, 'customers')) { + return $customers->customers[0]->id; + } + + return false; + + } + + public function findOrCreateClient() + { + if($customer_id = $this->findClient()) + return $customer_id; + + return $this->createClient(); + } + + private function createClient() + { + $country = $this->client->country ? $this->client->country->iso_3166_2 : $this->client->company->country()->iso_3166_2; + + /* Step two - create the customer */ + $billing_address = new \Square\Models\Address(); + $billing_address->setAddressLine1($this->client->address1); + $billing_address->setAddressLine2($this->client->address2); + $billing_address->setLocality($this->client->city); + $billing_address->setAdministrativeDistrictLevel1($this->client->state); + $billing_address->setPostalCode($this->client->postal_code); + $billing_address->setCountry($country); + + $body = new \Square\Models\CreateCustomerRequest(); + $body->setGivenName($this->client->present()->name()); + $body->setFamilyName(''); + $body->setEmailAddress($this->client->present()->email()); + $body->setAddress($billing_address); + $body->setReferenceId($this->client->number); + $body->setNote('Created by Invoice Ninja.'); + + $api_response = $this->init() + ->square + ->getCustomersApi() + ->createCustomer($body); + + if ($api_response->isSuccess()) { + $result = $api_response->getResult(); + + return $result->getCustomer()->getId(); + } else { + $errors = $api_response->getErrors(); + nlog($errors); + + $error = end($errors); + + $data = [ + 'response' => $error->getDetail(), + 'error' => $error->getDetail(), + 'error_code' => $error->getCode(), + ]; + + return $this->processUnsuccessfulTransaction($data); + + } + } + + + + + + + + + + + + + + + + + + + + + + + + + } From 136c07662309093b9c0a7de3bf9c68522af701bd Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 19 Mar 2024 10:40:11 +1100 Subject: [PATCH 13/14] Fixes for square pagination --- app/PaymentDrivers/SquarePaymentDriver.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/app/PaymentDrivers/SquarePaymentDriver.php b/app/PaymentDrivers/SquarePaymentDriver.php index e77df79aa981..079ef5c3626b 100644 --- a/app/PaymentDrivers/SquarePaymentDriver.php +++ b/app/PaymentDrivers/SquarePaymentDriver.php @@ -470,8 +470,6 @@ class SquarePaymentDriver extends BaseDriver $client_repo = new ClientRepository(new ClientContactRepository()); - nlog($customers); - foreach($customers as $customer) { @@ -496,12 +494,15 @@ class SquarePaymentDriver extends BaseDriver $c = $api_response->getCursor(); if ($c) { - $api_response = $client->getCustomersApi()->listCustomers( - $c, - $limit, - 'DEFAULT', - 'DESC' - ); + $api_response = $this->init() + ->square + ->getCustomersApi() + ->listCustomers( + $c, + $limit, + 'DEFAULT', + 'DESC' + ); } else { break; } From 08eb30785db693f4d8f2cb55d2893a2e139f3cab Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 19 Mar 2024 10:46:57 +1100 Subject: [PATCH 14/14] Add .env var for extensions --- .../BankIntegration/UploadBankIntegrationRequest.php | 8 ++++---- .../BankTransaction/UploadBankTransactionRequest.php | 8 ++++---- app/Http/Requests/Client/StoreClientRequest.php | 8 ++++---- app/Http/Requests/Client/UpdateClientRequest.php | 8 ++++---- app/Http/Requests/Client/UploadClientRequest.php | 8 ++++---- app/Http/Requests/Company/UploadCompanyRequest.php | 8 ++++---- app/Http/Requests/Credit/StoreCreditRequest.php | 8 ++++---- app/Http/Requests/Credit/UpdateCreditRequest.php | 8 ++++---- app/Http/Requests/Credit/UploadCreditRequest.php | 8 ++++---- app/Http/Requests/Expense/UploadExpenseRequest.php | 8 ++++---- .../GroupSetting/UploadGroupSettingRequest.php | 8 ++++---- app/Http/Requests/Invoice/StoreInvoiceRequest.php | 8 ++++---- app/Http/Requests/Invoice/UpdateInvoiceRequest.php | 8 ++++---- app/Http/Requests/Invoice/UploadInvoiceRequest.php | 8 ++++---- app/Http/Requests/Payment/StorePaymentRequest.php | 8 ++++---- app/Http/Requests/Payment/UpdatePaymentRequest.php | 8 ++++---- app/Http/Requests/Payment/UploadPaymentRequest.php | 8 ++++---- app/Http/Requests/Product/StoreProductRequest.php | 8 ++++---- app/Http/Requests/Product/UpdateProductRequest.php | 8 ++++---- app/Http/Requests/Product/UploadProductRequest.php | 8 ++++---- app/Http/Requests/Project/StoreProjectRequest.php | 8 ++++---- app/Http/Requests/Project/UpdateProjectRequest.php | 8 ++++---- app/Http/Requests/Project/UploadProjectRequest.php | 8 ++++---- .../PurchaseOrder/StorePurchaseOrderRequest.php | 8 ++++---- .../PurchaseOrder/UpdatePurchaseOrderRequest.php | 8 ++++---- .../PurchaseOrder/UploadPurchaseOrderRequest.php | 8 ++++---- app/Http/Requests/Quote/StoreQuoteRequest.php | 8 ++++---- app/Http/Requests/Quote/UpdateQuoteRequest.php | 8 ++++---- app/Http/Requests/Quote/UploadQuoteRequest.php | 8 ++++---- .../RecurringExpense/StoreRecurringExpenseRequest.php | 8 ++++---- .../UpdateRecurringExpenseRequest.php | 8 ++++---- .../UploadRecurringExpenseRequest.php | 8 ++++---- .../RecurringInvoice/StoreRecurringInvoiceRequest.php | 8 ++++---- .../UpdateRecurringInvoiceRequest.php | 8 ++++---- .../UploadRecurringInvoiceRequest.php | 8 ++++---- .../RecurringQuote/StoreRecurringQuoteRequest.php | 8 ++++---- .../RecurringQuote/UpdateRecurringQuoteRequest.php | 8 ++++---- .../RecurringQuote/UploadRecurringQuoteRequest.php | 8 ++++---- app/Http/Requests/Request.php | 11 ++++++++++- app/Http/Requests/Task/StoreTaskRequest.php | 8 ++++---- app/Http/Requests/Task/UpdateTaskRequest.php | 8 ++++---- app/Http/Requests/Task/UploadTaskRequest.php | 8 ++++---- app/Http/Requests/Vendor/StoreVendorRequest.php | 8 ++++---- app/Http/Requests/Vendor/UpdateVendorRequest.php | 8 ++++---- app/Http/Requests/Vendor/UploadVendorRequest.php | 8 ++++---- config/ninja.php | 2 ++ 46 files changed, 188 insertions(+), 177 deletions(-) diff --git a/app/Http/Requests/BankIntegration/UploadBankIntegrationRequest.php b/app/Http/Requests/BankIntegration/UploadBankIntegrationRequest.php index 560a44d02c74..700e3e47daa8 100644 --- a/app/Http/Requests/BankIntegration/UploadBankIntegrationRequest.php +++ b/app/Http/Requests/BankIntegration/UploadBankIntegrationRequest.php @@ -33,15 +33,15 @@ class UploadBankIntegrationRequest extends Request $rules = []; if ($this->file('documents') && is_array($this->file('documents'))) { - $rules['documents.*'] = $this->file_validation; + $rules['documents.*'] = $this->fileValidation(); } elseif ($this->file('documents')) { - $rules['documents'] = $this->file_validation; + $rules['documents'] = $this->fileValidation(); } if ($this->file('file') && is_array($this->file('file'))) { - $rules['file.*'] = $this->file_validation; + $rules['file.*'] = $this->fileValidation(); } elseif ($this->file('file')) { - $rules['file'] = $this->file_validation; + $rules['file'] = $this->fileValidation(); } $rules['is_public'] = 'sometimes|boolean'; diff --git a/app/Http/Requests/BankTransaction/UploadBankTransactionRequest.php b/app/Http/Requests/BankTransaction/UploadBankTransactionRequest.php index 9c014cc008cb..c6b88410a929 100644 --- a/app/Http/Requests/BankTransaction/UploadBankTransactionRequest.php +++ b/app/Http/Requests/BankTransaction/UploadBankTransactionRequest.php @@ -33,15 +33,15 @@ class UploadBankTransactionRequest extends Request $rules = []; if ($this->file('documents') && is_array($this->file('documents'))) { - $rules['documents.*'] = $this->file_validation; + $rules['documents.*'] = $this->fileValidation(); } elseif ($this->file('documents')) { - $rules['documents'] = $this->file_validation; + $rules['documents'] = $this->fileValidation(); } if ($this->file('file') && is_array($this->file('file'))) { - $rules['file.*'] = $this->file_validation; + $rules['file.*'] = $this->fileValidation(); } elseif ($this->file('file')) { - $rules['file'] = $this->file_validation; + $rules['file'] = $this->fileValidation(); } $rules['is_public'] = 'sometimes|boolean'; diff --git a/app/Http/Requests/Client/StoreClientRequest.php b/app/Http/Requests/Client/StoreClientRequest.php index a0d807d7d6dd..d3b4d3982e0a 100644 --- a/app/Http/Requests/Client/StoreClientRequest.php +++ b/app/Http/Requests/Client/StoreClientRequest.php @@ -45,18 +45,18 @@ class StoreClientRequest extends Request $user = auth()->user(); if ($this->file('documents') && is_array($this->file('documents'))) { - $rules['documents.*'] = $this->file_validation; + $rules['documents.*'] = $this->fileValidation(); } elseif ($this->file('documents')) { - $rules['documents'] = $this->file_validation; + $rules['documents'] = $this->fileValidation(); } else { $rules['documents'] = 'bail|sometimes|array'; } if ($this->file('file') && is_array($this->file('file'))) { - $rules['file.*'] = $this->file_validation; + $rules['file.*'] = $this->fileValidation(); } elseif ($this->file('file')) { - $rules['file'] = $this->file_validation; + $rules['file'] = $this->fileValidation(); } /* Ensure we have a client name, and that all emails are unique*/ diff --git a/app/Http/Requests/Client/UpdateClientRequest.php b/app/Http/Requests/Client/UpdateClientRequest.php index 3ffea3250f05..9ed1acde3fc3 100644 --- a/app/Http/Requests/Client/UpdateClientRequest.php +++ b/app/Http/Requests/Client/UpdateClientRequest.php @@ -44,15 +44,15 @@ class UpdateClientRequest extends Request $user = auth()->user(); if ($this->file('documents') && is_array($this->file('documents'))) { - $rules['documents.*'] = $this->file_validation; + $rules['documents.*'] = $this->fileValidation(); } elseif ($this->file('documents')) { - $rules['documents'] = $this->file_validation; + $rules['documents'] = $this->fileValidation(); } if ($this->file('file') && is_array($this->file('file'))) { - $rules['file.*'] = $this->file_validation; + $rules['file.*'] = $this->fileValidation(); } elseif ($this->file('file')) { - $rules['file'] = $this->file_validation; + $rules['file'] = $this->fileValidation(); } else { $rules['documents'] = 'bail|sometimes|array'; } diff --git a/app/Http/Requests/Client/UploadClientRequest.php b/app/Http/Requests/Client/UploadClientRequest.php index bf12d3c8df00..17e159b2ee37 100644 --- a/app/Http/Requests/Client/UploadClientRequest.php +++ b/app/Http/Requests/Client/UploadClientRequest.php @@ -33,15 +33,15 @@ class UploadClientRequest extends Request $rules = []; if ($this->file('documents') && is_array($this->file('documents'))) { - $rules['documents.*'] = $this->file_validation; + $rules['documents.*'] = $this->fileValidation(); } elseif ($this->file('documents')) { - $rules['documents'] = $this->file_validation; + $rules['documents'] = $this->fileValidation(); } if ($this->file('file') && is_array($this->file('file'))) { - $rules['file.*'] = $this->file_validation; + $rules['file.*'] = $this->fileValidation(); } elseif ($this->file('file')) { - $rules['file'] = $this->file_validation; + $rules['file'] = $this->fileValidation(); } $rules['is_public'] = 'sometimes|boolean'; diff --git a/app/Http/Requests/Company/UploadCompanyRequest.php b/app/Http/Requests/Company/UploadCompanyRequest.php index 2b85f6a1ff08..0e3a545e2d05 100644 --- a/app/Http/Requests/Company/UploadCompanyRequest.php +++ b/app/Http/Requests/Company/UploadCompanyRequest.php @@ -30,15 +30,15 @@ class UploadCompanyRequest extends Request $rules = []; if ($this->file('documents') && is_array($this->file('documents'))) { - $rules['documents.*'] = $this->file_validation; + $rules['documents.*'] = $this->fileValidation(); } elseif ($this->file('documents')) { - $rules['documents'] = $this->file_validation; + $rules['documents'] = $this->fileValidation(); } if ($this->file('file') && is_array($this->file('file'))) { - $rules['file.*'] = $this->file_validation; + $rules['file.*'] = $this->fileValidation(); } elseif ($this->file('file')) { - $rules['file'] = $this->file_validation; + $rules['file'] = $this->fileValidation(); } return $rules; diff --git a/app/Http/Requests/Credit/StoreCreditRequest.php b/app/Http/Requests/Credit/StoreCreditRequest.php index c24005063d68..7520dd465060 100644 --- a/app/Http/Requests/Credit/StoreCreditRequest.php +++ b/app/Http/Requests/Credit/StoreCreditRequest.php @@ -47,17 +47,17 @@ class StoreCreditRequest extends Request $rules = []; if ($this->file('documents') && is_array($this->file('documents'))) { - $rules['documents.*'] = $this->file_validation; + $rules['documents.*'] = $this->fileValidation(); } elseif ($this->file('documents')) { - $rules['documents'] = $this->file_validation; + $rules['documents'] = $this->fileValidation(); }else { $rules['documents'] = 'bail|sometimes|array'; } if ($this->file('file') && is_array($this->file('file'))) { - $rules['file.*'] = $this->file_validation; + $rules['file.*'] = $this->fileValidation(); } elseif ($this->file('file')) { - $rules['file'] = $this->file_validation; + $rules['file'] = $this->fileValidation(); } /** @var \App\Models\User $user */ diff --git a/app/Http/Requests/Credit/UpdateCreditRequest.php b/app/Http/Requests/Credit/UpdateCreditRequest.php index 7c0c3adc0274..d521ce39db58 100644 --- a/app/Http/Requests/Credit/UpdateCreditRequest.php +++ b/app/Http/Requests/Credit/UpdateCreditRequest.php @@ -49,17 +49,17 @@ class UpdateCreditRequest extends Request $rules = []; if ($this->file('documents') && is_array($this->file('documents'))) { - $rules['documents.*'] = $this->file_validation; + $rules['documents.*'] = $this->fileValidation(); } elseif ($this->file('documents')) { - $rules['documents'] = $this->file_validation; + $rules['documents'] = $this->fileValidation(); }else { $rules['documents'] = 'bail|sometimes|array'; } if ($this->file('file') && is_array($this->file('file'))) { - $rules['file.*'] = $this->file_validation; + $rules['file.*'] = $this->fileValidation(); } elseif ($this->file('file')) { - $rules['file'] = $this->file_validation; + $rules['file'] = $this->fileValidation(); } $rules['number'] = ['bail', 'sometimes', 'nullable', Rule::unique('credits')->where('company_id', $user->company()->id)->ignore($this->credit->id)]; diff --git a/app/Http/Requests/Credit/UploadCreditRequest.php b/app/Http/Requests/Credit/UploadCreditRequest.php index 6e78de9cd4ef..3411ad44739e 100644 --- a/app/Http/Requests/Credit/UploadCreditRequest.php +++ b/app/Http/Requests/Credit/UploadCreditRequest.php @@ -33,15 +33,15 @@ class UploadCreditRequest extends Request $rules = []; if ($this->file('documents') && is_array($this->file('documents'))) { - $rules['documents.*'] = $this->file_validation; + $rules['documents.*'] = $this->fileValidation(); } elseif ($this->file('documents')) { - $rules['documents'] = $this->file_validation; + $rules['documents'] = $this->fileValidation(); } if ($this->file('file') && is_array($this->file('file'))) { - $rules['file.*'] = $this->file_validation; + $rules['file.*'] = $this->fileValidation(); } elseif ($this->file('file')) { - $rules['file'] = $this->file_validation; + $rules['file'] = $this->fileValidation(); } $rules['is_public'] = 'sometimes|boolean'; diff --git a/app/Http/Requests/Expense/UploadExpenseRequest.php b/app/Http/Requests/Expense/UploadExpenseRequest.php index d50f6af80df7..867cfc34390c 100644 --- a/app/Http/Requests/Expense/UploadExpenseRequest.php +++ b/app/Http/Requests/Expense/UploadExpenseRequest.php @@ -33,15 +33,15 @@ class UploadExpenseRequest extends Request $rules = []; if ($this->file('documents') && is_array($this->file('documents'))) { - $rules['documents.*'] = $this->file_validation; + $rules['documents.*'] = $this->fileValidation(); } elseif ($this->file('documents')) { - $rules['documents'] = $this->file_validation; + $rules['documents'] = $this->fileValidation(); } if ($this->file('file') && is_array($this->file('file'))) { - $rules['file.*'] = $this->file_validation; + $rules['file.*'] = $this->fileValidation(); } elseif ($this->file('file')) { - $rules['file'] = $this->file_validation; + $rules['file'] = $this->fileValidation(); } $rules['is_public'] = 'sometimes|boolean'; diff --git a/app/Http/Requests/GroupSetting/UploadGroupSettingRequest.php b/app/Http/Requests/GroupSetting/UploadGroupSettingRequest.php index 9a142a689029..baa92c483f5d 100644 --- a/app/Http/Requests/GroupSetting/UploadGroupSettingRequest.php +++ b/app/Http/Requests/GroupSetting/UploadGroupSettingRequest.php @@ -30,15 +30,15 @@ class UploadGroupSettingRequest extends Request $rules = []; if ($this->file('documents') && is_array($this->file('documents'))) { - $rules['documents.*'] = $this->file_validation; + $rules['documents.*'] = $this->fileValidation(); } elseif ($this->file('documents')) { - $rules['documents'] = $this->file_validation; + $rules['documents'] = $this->fileValidation(); } if ($this->file('file') && is_array($this->file('file'))) { - $rules['file.*'] = $this->file_validation; + $rules['file.*'] = $this->fileValidation(); } elseif ($this->file('file')) { - $rules['file'] = $this->file_validation; + $rules['file'] = $this->fileValidation(); } return $rules; diff --git a/app/Http/Requests/Invoice/StoreInvoiceRequest.php b/app/Http/Requests/Invoice/StoreInvoiceRequest.php index 393ada465aa0..df893bed2716 100644 --- a/app/Http/Requests/Invoice/StoreInvoiceRequest.php +++ b/app/Http/Requests/Invoice/StoreInvoiceRequest.php @@ -44,17 +44,17 @@ class StoreInvoiceRequest extends Request $user = auth()->user(); if ($this->file('documents') && is_array($this->file('documents'))) { - $rules['documents.*'] = $this->file_validation; + $rules['documents.*'] = $this->fileValidation(); } elseif ($this->file('documents')) { - $rules['documents'] = $this->file_validation; + $rules['documents'] = $this->fileValidation(); }else { $rules['documents'] = 'bail|sometimes|array'; } if ($this->file('file') && is_array($this->file('file'))) { - $rules['file.*'] = $this->file_validation; + $rules['file.*'] = $this->fileValidation(); } elseif ($this->file('file')) { - $rules['file'] = $this->file_validation; + $rules['file'] = $this->fileValidation(); } $rules['client_id'] = 'bail|required|exists:clients,id,company_id,'.$user->company()->id.',is_deleted,0'; diff --git a/app/Http/Requests/Invoice/UpdateInvoiceRequest.php b/app/Http/Requests/Invoice/UpdateInvoiceRequest.php index 42d32ef81479..d863c5323cd8 100644 --- a/app/Http/Requests/Invoice/UpdateInvoiceRequest.php +++ b/app/Http/Requests/Invoice/UpdateInvoiceRequest.php @@ -46,17 +46,17 @@ class UpdateInvoiceRequest extends Request $rules = []; if ($this->file('documents') && is_array($this->file('documents'))) { - $rules['documents.*'] = $this->file_validation; + $rules['documents.*'] = $this->fileValidation(); } elseif ($this->file('documents')) { - $rules['documents'] = $this->file_validation; + $rules['documents'] = $this->fileValidation(); }else { $rules['documents'] = 'bail|sometimes|array'; } if ($this->file('file') && is_array($this->file('file'))) { - $rules['file.*'] = $this->file_validation; + $rules['file.*'] = $this->fileValidation(); } elseif ($this->file('file')) { - $rules['file'] = $this->file_validation; + $rules['file'] = $this->fileValidation(); } // $rules['id'] = new LockedInvoiceRule($this->invoice); diff --git a/app/Http/Requests/Invoice/UploadInvoiceRequest.php b/app/Http/Requests/Invoice/UploadInvoiceRequest.php index 3f5b0f8b8bad..8ca57bd1edca 100644 --- a/app/Http/Requests/Invoice/UploadInvoiceRequest.php +++ b/app/Http/Requests/Invoice/UploadInvoiceRequest.php @@ -33,15 +33,15 @@ class UploadInvoiceRequest extends Request $rules = []; if ($this->file('documents') && is_array($this->file('documents'))) { - $rules['documents.*'] = $this->file_validation; + $rules['documents.*'] = $this->fileValidation(); } elseif ($this->file('documents')) { - $rules['documents'] = $this->file_validation; + $rules['documents'] = $this->fileValidation(); } if ($this->file('file') && is_array($this->file('file'))) { - $rules['file.*'] = $this->file_validation; + $rules['file.*'] = $this->fileValidation(); } elseif ($this->file('file')) { - $rules['file'] = $this->file_validation; + $rules['file'] = $this->fileValidation(); } $rules['is_public'] = 'sometimes|boolean'; diff --git a/app/Http/Requests/Payment/StorePaymentRequest.php b/app/Http/Requests/Payment/StorePaymentRequest.php index 25b3b43500c6..1bb5808b82e8 100644 --- a/app/Http/Requests/Payment/StorePaymentRequest.php +++ b/app/Http/Requests/Payment/StorePaymentRequest.php @@ -123,17 +123,17 @@ class StorePaymentRequest extends Request ]; if ($this->file('documents') && is_array($this->file('documents'))) { - $rules['documents.*'] = $this->file_validation; + $rules['documents.*'] = $this->fileValidation(); } elseif ($this->file('documents')) { - $rules['documents'] = $this->file_validation; + $rules['documents'] = $this->fileValidation(); }else { $rules['documents'] = 'bail|sometimes|array'; } if ($this->file('file') && is_array($this->file('file'))) { - $rules['file.*'] = $this->file_validation; + $rules['file.*'] = $this->fileValidation(); } elseif ($this->file('file')) { - $rules['file'] = $this->file_validation; + $rules['file'] = $this->fileValidation(); } return $rules; diff --git a/app/Http/Requests/Payment/UpdatePaymentRequest.php b/app/Http/Requests/Payment/UpdatePaymentRequest.php index 52a3c29d895b..f4b90758adcf 100644 --- a/app/Http/Requests/Payment/UpdatePaymentRequest.php +++ b/app/Http/Requests/Payment/UpdatePaymentRequest.php @@ -52,17 +52,17 @@ class UpdatePaymentRequest extends Request } if ($this->file('documents') && is_array($this->file('documents'))) { - $rules['documents.*'] = $this->file_validation; + $rules['documents.*'] = $this->fileValidation(); } elseif ($this->file('documents')) { - $rules['documents'] = $this->file_validation; + $rules['documents'] = $this->fileValidation(); }else { $rules['documents'] = 'bail|sometimes|array'; } if ($this->file('file') && is_array($this->file('file'))) { - $rules['file.*'] = $this->file_validation; + $rules['file.*'] = $this->fileValidation(); } elseif ($this->file('file')) { - $rules['file'] = $this->file_validation; + $rules['file'] = $this->fileValidation(); } return $rules; diff --git a/app/Http/Requests/Payment/UploadPaymentRequest.php b/app/Http/Requests/Payment/UploadPaymentRequest.php index bf8d88d44464..a52d0a68f098 100644 --- a/app/Http/Requests/Payment/UploadPaymentRequest.php +++ b/app/Http/Requests/Payment/UploadPaymentRequest.php @@ -33,15 +33,15 @@ class UploadPaymentRequest extends Request $rules = []; if ($this->file('documents') && is_array($this->file('documents'))) { - $rules['documents.*'] = $this->file_validation; + $rules['documents.*'] = $this->fileValidation(); } elseif ($this->file('documents')) { - $rules['documents'] = $this->file_validation; + $rules['documents'] = $this->fileValidation(); } if ($this->file('file') && is_array($this->file('file'))) { - $rules['file.*'] = $this->file_validation; + $rules['file.*'] = $this->fileValidation(); } elseif ($this->file('file')) { - $rules['file'] = $this->file_validation; + $rules['file'] = $this->fileValidation(); } $rules['is_public'] = 'sometimes|boolean'; diff --git a/app/Http/Requests/Product/StoreProductRequest.php b/app/Http/Requests/Product/StoreProductRequest.php index c53ad07edbea..8d696bc132a4 100644 --- a/app/Http/Requests/Product/StoreProductRequest.php +++ b/app/Http/Requests/Product/StoreProductRequest.php @@ -32,17 +32,17 @@ class StoreProductRequest extends Request public function rules() { if ($this->file('documents') && is_array($this->file('documents'))) { - $rules['documents.*'] = $this->file_validation; + $rules['documents.*'] = $this->fileValidation(); } elseif ($this->file('documents')) { - $rules['documents'] = $this->file_validation; + $rules['documents'] = $this->fileValidation(); }else { $rules['documents'] = 'bail|sometimes|array'; } if ($this->file('file') && is_array($this->file('file'))) { - $rules['file.*'] = $this->file_validation; + $rules['file.*'] = $this->fileValidation(); } elseif ($this->file('file')) { - $rules['file'] = $this->file_validation; + $rules['file'] = $this->fileValidation(); } $rules['cost'] = 'sometimes|numeric'; diff --git a/app/Http/Requests/Product/UpdateProductRequest.php b/app/Http/Requests/Product/UpdateProductRequest.php index 0a76f6a4ab08..1572ddbc1b82 100644 --- a/app/Http/Requests/Product/UpdateProductRequest.php +++ b/app/Http/Requests/Product/UpdateProductRequest.php @@ -35,17 +35,17 @@ class UpdateProductRequest extends Request public function rules() { if ($this->file('documents') && is_array($this->file('documents'))) { - $rules['documents.*'] = $this->file_validation; + $rules['documents.*'] = $this->fileValidation(); } elseif ($this->file('documents')) { - $rules['documents'] = $this->file_validation; + $rules['documents'] = $this->fileValidation(); }else { $rules['documents'] = 'bail|sometimes|array'; } if ($this->file('file') && is_array($this->file('file'))) { - $rules['file.*'] = $this->file_validation; + $rules['file.*'] = $this->fileValidation(); } elseif ($this->file('file')) { - $rules['file'] = $this->file_validation; + $rules['file'] = $this->fileValidation(); } $rules['cost'] = 'numeric'; diff --git a/app/Http/Requests/Product/UploadProductRequest.php b/app/Http/Requests/Product/UploadProductRequest.php index d5eaf1e7e391..ef6b6d49db82 100644 --- a/app/Http/Requests/Product/UploadProductRequest.php +++ b/app/Http/Requests/Product/UploadProductRequest.php @@ -32,15 +32,15 @@ class UploadProductRequest extends Request { $rules = []; if ($this->file('documents') && is_array($this->file('documents'))) { - $rules['documents.*'] = $this->file_validation; + $rules['documents.*'] = $this->fileValidation(); } elseif ($this->file('documents')) { - $rules['documents'] = $this->file_validation; + $rules['documents'] = $this->fileValidation(); } if ($this->file('file') && is_array($this->file('file'))) { - $rules['file.*'] = $this->file_validation; + $rules['file.*'] = $this->fileValidation(); } elseif ($this->file('file')) { - $rules['file'] = $this->file_validation; + $rules['file'] = $this->fileValidation(); } $rules['is_public'] = 'sometimes|boolean'; diff --git a/app/Http/Requests/Project/StoreProjectRequest.php b/app/Http/Requests/Project/StoreProjectRequest.php index 3bc1bca1bc52..365cfaf8ea46 100644 --- a/app/Http/Requests/Project/StoreProjectRequest.php +++ b/app/Http/Requests/Project/StoreProjectRequest.php @@ -51,17 +51,17 @@ class StoreProjectRequest extends Request } if ($this->file('documents') && is_array($this->file('documents'))) { - $rules['documents.*'] = $this->file_validation; + $rules['documents.*'] = $this->fileValidation(); } elseif ($this->file('documents')) { - $rules['documents'] = $this->file_validation; + $rules['documents'] = $this->fileValidation(); }else { $rules['documents'] = 'bail|sometimes|array'; } if ($this->file('file') && is_array($this->file('file'))) { - $rules['file.*'] = $this->file_validation; + $rules['file.*'] = $this->fileValidation(); } elseif ($this->file('file')) { - $rules['file'] = $this->file_validation; + $rules['file'] = $this->fileValidation(); } return $this->globalRules($rules); diff --git a/app/Http/Requests/Project/UpdateProjectRequest.php b/app/Http/Requests/Project/UpdateProjectRequest.php index cbcf6882cf89..a0d0eaf39dc5 100644 --- a/app/Http/Requests/Project/UpdateProjectRequest.php +++ b/app/Http/Requests/Project/UpdateProjectRequest.php @@ -48,17 +48,17 @@ class UpdateProjectRequest extends Request $rules['budgeted_hours'] = 'sometimes|numeric'; if ($this->file('documents') && is_array($this->file('documents'))) { - $rules['documents.*'] = $this->file_validation; + $rules['documents.*'] = $this->fileValidation(); } elseif ($this->file('documents')) { - $rules['documents'] = $this->file_validation; + $rules['documents'] = $this->fileValidation(); }else { $rules['documents'] = 'bail|sometimes|array'; } if ($this->file('file') && is_array($this->file('file'))) { - $rules['file.*'] = $this->file_validation; + $rules['file.*'] = $this->fileValidation(); } elseif ($this->file('file')) { - $rules['file'] = $this->file_validation; + $rules['file'] = $this->fileValidation(); } return $this->globalRules($rules); diff --git a/app/Http/Requests/Project/UploadProjectRequest.php b/app/Http/Requests/Project/UploadProjectRequest.php index 08d66f2b048b..6b8f9909b759 100644 --- a/app/Http/Requests/Project/UploadProjectRequest.php +++ b/app/Http/Requests/Project/UploadProjectRequest.php @@ -33,15 +33,15 @@ class UploadProjectRequest extends Request $rules = []; if ($this->file('documents') && is_array($this->file('documents'))) { - $rules['documents.*'] = $this->file_validation; + $rules['documents.*'] = $this->fileValidation(); } elseif ($this->file('documents')) { - $rules['documents'] = $this->file_validation; + $rules['documents'] = $this->fileValidation(); } if ($this->file('file') && is_array($this->file('file'))) { - $rules['file.*'] = $this->file_validation; + $rules['file.*'] = $this->fileValidation(); } elseif ($this->file('file')) { - $rules['file'] = $this->file_validation; + $rules['file'] = $this->fileValidation(); } $rules['is_public'] = 'sometimes|boolean'; diff --git a/app/Http/Requests/PurchaseOrder/StorePurchaseOrderRequest.php b/app/Http/Requests/PurchaseOrder/StorePurchaseOrderRequest.php index 91564eab092d..2b28882b297e 100644 --- a/app/Http/Requests/PurchaseOrder/StorePurchaseOrderRequest.php +++ b/app/Http/Requests/PurchaseOrder/StorePurchaseOrderRequest.php @@ -54,17 +54,17 @@ class StorePurchaseOrderRequest extends Request $rules['line_items'] = 'array'; if ($this->file('documents') && is_array($this->file('documents'))) { - $rules['documents.*'] = $this->file_validation; + $rules['documents.*'] = $this->fileValidation(); } elseif ($this->file('documents')) { - $rules['documents'] = $this->file_validation; + $rules['documents'] = $this->fileValidation(); } else { $rules['documents'] = 'bail|sometimes|array'; } if ($this->file('file') && is_array($this->file('file'))) { - $rules['file.*'] = $this->file_validation; + $rules['file.*'] = $this->fileValidation(); } elseif ($this->file('file')) { - $rules['file'] = $this->file_validation; + $rules['file'] = $this->fileValidation(); } $rules['status_id'] = 'nullable|integer|in:1,2,3,4,5'; diff --git a/app/Http/Requests/PurchaseOrder/UpdatePurchaseOrderRequest.php b/app/Http/Requests/PurchaseOrder/UpdatePurchaseOrderRequest.php index 66984cd29a51..55abc60559c4 100644 --- a/app/Http/Requests/PurchaseOrder/UpdatePurchaseOrderRequest.php +++ b/app/Http/Requests/PurchaseOrder/UpdatePurchaseOrderRequest.php @@ -56,17 +56,17 @@ class UpdatePurchaseOrderRequest extends Request $rules['is_amount_discount'] = ['boolean']; if ($this->file('documents') && is_array($this->file('documents'))) { - $rules['documents.*'] = $this->file_validation; + $rules['documents.*'] = $this->fileValidation(); } elseif ($this->file('documents')) { - $rules['documents'] = $this->file_validation; + $rules['documents'] = $this->fileValidation(); }else { $rules['documents'] = 'bail|sometimes|array'; } if ($this->file('file') && is_array($this->file('file'))) { - $rules['file.*'] = $this->file_validation; + $rules['file.*'] = $this->fileValidation(); } elseif ($this->file('file')) { - $rules['file'] = $this->file_validation; + $rules['file'] = $this->fileValidation(); } $rules['status_id'] = 'sometimes|integer|in:1,2,3,4,5'; diff --git a/app/Http/Requests/PurchaseOrder/UploadPurchaseOrderRequest.php b/app/Http/Requests/PurchaseOrder/UploadPurchaseOrderRequest.php index c41de6989e62..9c5b4ed4f5ec 100644 --- a/app/Http/Requests/PurchaseOrder/UploadPurchaseOrderRequest.php +++ b/app/Http/Requests/PurchaseOrder/UploadPurchaseOrderRequest.php @@ -33,15 +33,15 @@ class UploadPurchaseOrderRequest extends Request $rules = []; if ($this->file('documents') && is_array($this->file('documents'))) { - $rules['documents.*'] = $this->file_validation; + $rules['documents.*'] = $this->fileValidation(); } elseif ($this->file('documents')) { - $rules['documents'] = $this->file_validation; + $rules['documents'] = $this->fileValidation(); } if ($this->file('file') && is_array($this->file('file'))) { - $rules['file.*'] = $this->file_validation; + $rules['file.*'] = $this->fileValidation(); } elseif ($this->file('file')) { - $rules['file'] = $this->file_validation; + $rules['file'] = $this->fileValidation(); } $rules['is_public'] = 'sometimes|boolean'; diff --git a/app/Http/Requests/Quote/StoreQuoteRequest.php b/app/Http/Requests/Quote/StoreQuoteRequest.php index 3e0a498610cc..59f3409abb2e 100644 --- a/app/Http/Requests/Quote/StoreQuoteRequest.php +++ b/app/Http/Requests/Quote/StoreQuoteRequest.php @@ -46,17 +46,17 @@ class StoreQuoteRequest extends Request $rules['client_id'] = 'required|exists:clients,id,company_id,'.$user->company()->id; if ($this->file('documents') && is_array($this->file('documents'))) { - $rules['documents.*'] = $this->file_validation; + $rules['documents.*'] = $this->fileValidation(); } elseif ($this->file('documents')) { - $rules['documents'] = $this->file_validation; + $rules['documents'] = $this->fileValidation(); }else { $rules['documents'] = 'bail|sometimes|array'; } if ($this->file('file') && is_array($this->file('file'))) { - $rules['file.*'] = $this->file_validation; + $rules['file.*'] = $this->fileValidation(); } elseif ($this->file('file')) { - $rules['file'] = $this->file_validation; + $rules['file'] = $this->fileValidation(); } $rules['number'] = ['nullable', Rule::unique('quotes')->where('company_id', $user->company()->id)]; diff --git a/app/Http/Requests/Quote/UpdateQuoteRequest.php b/app/Http/Requests/Quote/UpdateQuoteRequest.php index 4644e5af691c..4e93c58d560e 100644 --- a/app/Http/Requests/Quote/UpdateQuoteRequest.php +++ b/app/Http/Requests/Quote/UpdateQuoteRequest.php @@ -43,17 +43,17 @@ class UpdateQuoteRequest extends Request $rules = []; if ($this->file('documents') && is_array($this->file('documents'))) { - $rules['documents.*'] = $this->file_validation; + $rules['documents.*'] = $this->fileValidation(); } elseif ($this->file('documents')) { - $rules['documents'] = $this->file_validation; + $rules['documents'] = $this->fileValidation(); }else { $rules['documents'] = 'bail|sometimes|array'; } if ($this->file('file') && is_array($this->file('file'))) { - $rules['file.*'] = $this->file_validation; + $rules['file.*'] = $this->fileValidation(); } elseif ($this->file('file')) { - $rules['file'] = $this->file_validation; + $rules['file'] = $this->fileValidation(); } diff --git a/app/Http/Requests/Quote/UploadQuoteRequest.php b/app/Http/Requests/Quote/UploadQuoteRequest.php index 3c5a4395d73e..d7883c8b6ae9 100644 --- a/app/Http/Requests/Quote/UploadQuoteRequest.php +++ b/app/Http/Requests/Quote/UploadQuoteRequest.php @@ -33,15 +33,15 @@ class UploadQuoteRequest extends Request $rules = []; if ($this->file('documents') && is_array($this->file('documents'))) { - $rules['documents.*'] = $this->file_validation; + $rules['documents.*'] = $this->fileValidation(); } elseif ($this->file('documents')) { - $rules['documents'] = $this->file_validation; + $rules['documents'] = $this->fileValidation(); } if ($this->file('file') && is_array($this->file('file'))) { - $rules['file.*'] = $this->file_validation; + $rules['file.*'] = $this->fileValidation(); } elseif ($this->file('file')) { - $rules['file'] = $this->file_validation; + $rules['file'] = $this->fileValidation(); } $rules['is_public'] = 'sometimes|boolean'; diff --git a/app/Http/Requests/RecurringExpense/StoreRecurringExpenseRequest.php b/app/Http/Requests/RecurringExpense/StoreRecurringExpenseRequest.php index 3607edae7870..a334b97fbde0 100644 --- a/app/Http/Requests/RecurringExpense/StoreRecurringExpenseRequest.php +++ b/app/Http/Requests/RecurringExpense/StoreRecurringExpenseRequest.php @@ -57,15 +57,15 @@ class StoreRecurringExpenseRequest extends Request $rules['currency_id'] = 'bail|required|integer|exists:currencies,id'; if ($this->file('documents') && is_array($this->file('documents'))) { - $rules['documents.*'] = $this->file_validation; + $rules['documents.*'] = $this->fileValidation(); } elseif ($this->file('documents')) { - $rules['documents'] = $this->file_validation; + $rules['documents'] = $this->fileValidation(); } if ($this->file('file') && is_array($this->file('file'))) { - $rules['file.*'] = $this->file_validation; + $rules['file.*'] = $this->fileValidation(); } elseif ($this->file('file')) { - $rules['file'] = $this->file_validation; + $rules['file'] = $this->fileValidation(); } return $this->globalRules($rules); diff --git a/app/Http/Requests/RecurringExpense/UpdateRecurringExpenseRequest.php b/app/Http/Requests/RecurringExpense/UpdateRecurringExpenseRequest.php index e36333566fda..80a5759f0f10 100644 --- a/app/Http/Requests/RecurringExpense/UpdateRecurringExpenseRequest.php +++ b/app/Http/Requests/RecurringExpense/UpdateRecurringExpenseRequest.php @@ -49,15 +49,15 @@ class UpdateRecurringExpenseRequest extends Request $rules['category_id'] = 'bail|nullable|sometimes|exists:expense_categories,id,company_id,'.auth()->user()->company()->id.',is_deleted,0'; if ($this->file('documents') && is_array($this->file('documents'))) { - $rules['documents.*'] = $this->file_validation; + $rules['documents.*'] = $this->fileValidation(); } elseif ($this->file('documents')) { - $rules['documents'] = $this->file_validation; + $rules['documents'] = $this->fileValidation(); } if ($this->file('file') && is_array($this->file('file'))) { - $rules['file.*'] = $this->file_validation; + $rules['file.*'] = $this->fileValidation(); } elseif ($this->file('file')) { - $rules['file'] = $this->file_validation; + $rules['file'] = $this->fileValidation(); } return $this->globalRules($rules); diff --git a/app/Http/Requests/RecurringExpense/UploadRecurringExpenseRequest.php b/app/Http/Requests/RecurringExpense/UploadRecurringExpenseRequest.php index fa6b04c92580..fb1d50b5f769 100644 --- a/app/Http/Requests/RecurringExpense/UploadRecurringExpenseRequest.php +++ b/app/Http/Requests/RecurringExpense/UploadRecurringExpenseRequest.php @@ -30,15 +30,15 @@ class UploadRecurringExpenseRequest extends Request $rules = []; if ($this->file('documents') && is_array($this->file('documents'))) { - $rules['documents.*'] = $this->file_validation; + $rules['documents.*'] = $this->fileValidation(); } elseif ($this->file('documents')) { - $rules['documents'] = $this->file_validation; + $rules['documents'] = $this->fileValidation(); } if ($this->file('file') && is_array($this->file('file'))) { - $rules['file.*'] = $this->file_validation; + $rules['file.*'] = $this->fileValidation(); } elseif ($this->file('file')) { - $rules['file'] = $this->file_validation; + $rules['file'] = $this->fileValidation(); } return $rules; diff --git a/app/Http/Requests/RecurringInvoice/StoreRecurringInvoiceRequest.php b/app/Http/Requests/RecurringInvoice/StoreRecurringInvoiceRequest.php index 7d69a2587e1d..94cd8caba951 100644 --- a/app/Http/Requests/RecurringInvoice/StoreRecurringInvoiceRequest.php +++ b/app/Http/Requests/RecurringInvoice/StoreRecurringInvoiceRequest.php @@ -46,17 +46,17 @@ class StoreRecurringInvoiceRequest extends Request $rules = []; if ($this->file('documents') && is_array($this->file('documents'))) { - $rules['documents.*'] = $this->file_validation; + $rules['documents.*'] = $this->fileValidation(); } elseif ($this->file('documents')) { - $rules['documents'] = $this->file_validation; + $rules['documents'] = $this->fileValidation(); }else { $rules['documents'] = 'bail|sometimes|array'; } if ($this->file('file') && is_array($this->file('file'))) { - $rules['file.*'] = $this->file_validation; + $rules['file.*'] = $this->fileValidation(); } elseif ($this->file('file')) { - $rules['file'] = $this->file_validation; + $rules['file'] = $this->fileValidation(); } $rules['client_id'] = 'required|exists:clients,id,company_id,'.$user->company()->id; diff --git a/app/Http/Requests/RecurringInvoice/UpdateRecurringInvoiceRequest.php b/app/Http/Requests/RecurringInvoice/UpdateRecurringInvoiceRequest.php index f59edc91d61a..8aa9da8ed5cd 100644 --- a/app/Http/Requests/RecurringInvoice/UpdateRecurringInvoiceRequest.php +++ b/app/Http/Requests/RecurringInvoice/UpdateRecurringInvoiceRequest.php @@ -45,17 +45,17 @@ class UpdateRecurringInvoiceRequest extends Request $rules = []; if ($this->file('documents') && is_array($this->file('documents'))) { - $rules['documents.*'] = $this->file_validation; + $rules['documents.*'] = $this->fileValidation(); } elseif ($this->file('documents')) { - $rules['documents'] = $this->file_validation; + $rules['documents'] = $this->fileValidation(); }else { $rules['documents'] = 'bail|sometimes|array'; } if ($this->file('file') && is_array($this->file('file'))) { - $rules['file.*'] = $this->file_validation; + $rules['file.*'] = $this->fileValidation(); } elseif ($this->file('file')) { - $rules['file'] = $this->file_validation; + $rules['file'] = $this->fileValidation(); } $rules['number'] = ['bail', 'sometimes', Rule::unique('recurring_invoices')->where('company_id', $user->company()->id)->ignore($this->recurring_invoice->id)]; diff --git a/app/Http/Requests/RecurringInvoice/UploadRecurringInvoiceRequest.php b/app/Http/Requests/RecurringInvoice/UploadRecurringInvoiceRequest.php index 345e566434c4..e401ef6958b4 100644 --- a/app/Http/Requests/RecurringInvoice/UploadRecurringInvoiceRequest.php +++ b/app/Http/Requests/RecurringInvoice/UploadRecurringInvoiceRequest.php @@ -33,15 +33,15 @@ class UploadRecurringInvoiceRequest extends Request $rules = []; if ($this->file('documents') && is_array($this->file('documents'))) { - $rules['documents.*'] = $this->file_validation; + $rules['documents.*'] = $this->fileValidation(); } elseif ($this->file('documents')) { - $rules['documents'] = $this->file_validation; + $rules['documents'] = $this->fileValidation(); } if ($this->file('file') && is_array($this->file('file'))) { - $rules['file.*'] = $this->file_validation; + $rules['file.*'] = $this->fileValidation(); } elseif ($this->file('file')) { - $rules['file'] = $this->file_validation; + $rules['file'] = $this->fileValidation(); } $rules['is_public'] = 'sometimes|boolean'; diff --git a/app/Http/Requests/RecurringQuote/StoreRecurringQuoteRequest.php b/app/Http/Requests/RecurringQuote/StoreRecurringQuoteRequest.php index 0cb7ef56d378..12b2c4441081 100644 --- a/app/Http/Requests/RecurringQuote/StoreRecurringQuoteRequest.php +++ b/app/Http/Requests/RecurringQuote/StoreRecurringQuoteRequest.php @@ -46,15 +46,15 @@ class StoreRecurringQuoteRequest extends Request $rules = []; if ($this->file('documents') && is_array($this->file('documents'))) { - $rules['documents.*'] = $this->file_validation; + $rules['documents.*'] = $this->fileValidation(); } elseif ($this->file('documents')) { - $rules['documents'] = $this->file_validation; + $rules['documents'] = $this->fileValidation(); } if ($this->file('file') && is_array($this->file('file'))) { - $rules['file.*'] = $this->file_validation; + $rules['file.*'] = $this->fileValidation(); } elseif ($this->file('file')) { - $rules['file'] = $this->file_validation; + $rules['file'] = $this->fileValidation(); } $rules['client_id'] = 'required|exists:clients,id,company_id,'.$user->company()->id; diff --git a/app/Http/Requests/RecurringQuote/UpdateRecurringQuoteRequest.php b/app/Http/Requests/RecurringQuote/UpdateRecurringQuoteRequest.php index a0290e252744..d52f4b0974c7 100644 --- a/app/Http/Requests/RecurringQuote/UpdateRecurringQuoteRequest.php +++ b/app/Http/Requests/RecurringQuote/UpdateRecurringQuoteRequest.php @@ -38,15 +38,15 @@ class UpdateRecurringQuoteRequest extends Request $rules = []; if ($this->file('documents') && is_array($this->file('documents'))) { - $rules['documents.*'] = $this->file_validation; + $rules['documents.*'] = $this->fileValidation(); } elseif ($this->file('documents')) { - $rules['documents'] = $this->file_validation; + $rules['documents'] = $this->fileValidation(); } if ($this->file('file') && is_array($this->file('file'))) { - $rules['file.*'] = $this->file_validation; + $rules['file.*'] = $this->fileValidation(); } elseif ($this->file('file')) { - $rules['file'] = $this->file_validation; + $rules['file'] = $this->fileValidation(); } if ($this->number) { diff --git a/app/Http/Requests/RecurringQuote/UploadRecurringQuoteRequest.php b/app/Http/Requests/RecurringQuote/UploadRecurringQuoteRequest.php index 0631ec361579..3c8b91f96e0a 100644 --- a/app/Http/Requests/RecurringQuote/UploadRecurringQuoteRequest.php +++ b/app/Http/Requests/RecurringQuote/UploadRecurringQuoteRequest.php @@ -30,15 +30,15 @@ class UploadRecurringQuoteRequest extends Request $rules = []; if ($this->file('documents') && is_array($this->file('documents'))) { - $rules['documents.*'] = $this->file_validation; + $rules['documents.*'] = $this->fileValidation(); } elseif ($this->file('documents')) { - $rules['documents'] = $this->file_validation; + $rules['documents'] = $this->fileValidation(); } if ($this->file('file') && is_array($this->file('file'))) { - $rules['file.*'] = $this->file_validation; + $rules['file.*'] = $this->fileValidation(); } elseif ($this->file('file')) { - $rules['file'] = $this->file_validation; + $rules['file'] = $this->fileValidation(); } return $rules; diff --git a/app/Http/Requests/Request.php b/app/Http/Requests/Request.php index e70c7f6b3a55..3f7c3f23008e 100644 --- a/app/Http/Requests/Request.php +++ b/app/Http/Requests/Request.php @@ -20,7 +20,7 @@ class Request extends FormRequest use MakesHash; use RuntimeFormRequest; - protected $file_validation = 'sometimes|file|mimes:png,ai,jpeg,tiff,pdf,gif,psd,txt,doc,xls,ppt,xlsx,docx,pptx,webp,xml,zip,csv,ods,odt,odp|max:100000'; + protected $file_validation = 'sometimes|file|max:100000|mimes:png,ai,jpeg,tiff,pdf,gif,psd,txt,doc,xls,ppt,xlsx,docx,pptx,webp,xml,zip,csv,ods,odt,odp'; /** * Get the validation rules that apply to the request. * @@ -31,6 +31,15 @@ class Request extends FormRequest return []; } + public function fileValidation() + { + if(config('ninja.upload_extensions')) + return $this->file_validation. ",".config('ninja.upload_extensions'); + + return $this->file_validation; + + } + public function globalRules($rules) { $merge_rules = []; diff --git a/app/Http/Requests/Task/StoreTaskRequest.php b/app/Http/Requests/Task/StoreTaskRequest.php index e5fee49132a0..66577a23d97c 100644 --- a/app/Http/Requests/Task/StoreTaskRequest.php +++ b/app/Http/Requests/Task/StoreTaskRequest.php @@ -79,17 +79,17 @@ class StoreTaskRequest extends Request }]; if ($this->file('documents') && is_array($this->file('documents'))) { - $rules['documents.*'] = $this->file_validation; + $rules['documents.*'] = $this->fileValidation(); } elseif ($this->file('documents')) { - $rules['documents'] = $this->file_validation; + $rules['documents'] = $this->fileValidation(); }else { $rules['documents'] = 'bail|sometimes|array'; } if ($this->file('file') && is_array($this->file('file'))) { - $rules['file.*'] = $this->file_validation; + $rules['file.*'] = $this->fileValidation(); } elseif ($this->file('file')) { - $rules['file'] = $this->file_validation; + $rules['file'] = $this->fileValidation(); } diff --git a/app/Http/Requests/Task/UpdateTaskRequest.php b/app/Http/Requests/Task/UpdateTaskRequest.php index 299905d8cd58..c71c7f0452e0 100644 --- a/app/Http/Requests/Task/UpdateTaskRequest.php +++ b/app/Http/Requests/Task/UpdateTaskRequest.php @@ -85,17 +85,17 @@ class UpdateTaskRequest extends Request }]; if ($this->file('documents') && is_array($this->file('documents'))) { - $rules['documents.*'] = $this->file_validation; + $rules['documents.*'] = $this->fileValidation(); } elseif ($this->file('documents')) { - $rules['documents'] = $this->file_validation; + $rules['documents'] = $this->fileValidation(); }else { $rules['documents'] = 'bail|sometimes|array'; } if ($this->file('file') && is_array($this->file('file'))) { - $rules['file.*'] = $this->file_validation; + $rules['file.*'] = $this->fileValidation(); } elseif ($this->file('file')) { - $rules['file'] = $this->file_validation; + $rules['file'] = $this->fileValidation(); } return $this->globalRules($rules); diff --git a/app/Http/Requests/Task/UploadTaskRequest.php b/app/Http/Requests/Task/UploadTaskRequest.php index 99737bd71536..4415cf8a995e 100644 --- a/app/Http/Requests/Task/UploadTaskRequest.php +++ b/app/Http/Requests/Task/UploadTaskRequest.php @@ -33,15 +33,15 @@ class UploadTaskRequest extends Request $rules = []; if ($this->file('documents') && is_array($this->file('documents'))) { - $rules['documents.*'] = $this->file_validation; + $rules['documents.*'] = $this->fileValidation(); } elseif ($this->file('documents')) { - $rules['documents'] = $this->file_validation; + $rules['documents'] = $this->fileValidation(); } if ($this->file('file') && is_array($this->file('file'))) { - $rules['file.*'] = $this->file_validation; + $rules['file.*'] = $this->fileValidation(); } elseif ($this->file('file')) { - $rules['file'] = $this->file_validation; + $rules['file'] = $this->fileValidation(); } $rules['is_public'] = 'sometimes|boolean'; diff --git a/app/Http/Requests/Vendor/StoreVendorRequest.php b/app/Http/Requests/Vendor/StoreVendorRequest.php index 7cb6fc14f193..3c282aeaeaf9 100644 --- a/app/Http/Requests/Vendor/StoreVendorRequest.php +++ b/app/Http/Requests/Vendor/StoreVendorRequest.php @@ -61,17 +61,17 @@ class StoreVendorRequest extends Request $rules['currency_id'] = 'bail|required|exists:currencies,id'; if ($this->file('documents') && is_array($this->file('documents'))) { - $rules['documents.*'] = $this->file_validation; + $rules['documents.*'] = $this->fileValidation(); } elseif ($this->file('documents')) { - $rules['documents'] = $this->file_validation; + $rules['documents'] = $this->fileValidation(); }else { $rules['documents'] = 'bail|sometimes|array'; } if ($this->file('file') && is_array($this->file('file'))) { - $rules['file.*'] = $this->file_validation; + $rules['file.*'] = $this->fileValidation(); } elseif ($this->file('file')) { - $rules['file'] = $this->file_validation; + $rules['file'] = $this->fileValidation(); } $rules['language_id'] = 'bail|nullable|sometimes|exists:languages,id'; diff --git a/app/Http/Requests/Vendor/UpdateVendorRequest.php b/app/Http/Requests/Vendor/UpdateVendorRequest.php index b06b861adfe6..3049a9c2d1b6 100644 --- a/app/Http/Requests/Vendor/UpdateVendorRequest.php +++ b/app/Http/Requests/Vendor/UpdateVendorRequest.php @@ -62,17 +62,17 @@ class UpdateVendorRequest extends Request $rules['currency_id'] = 'bail|sometimes|exists:currencies,id'; if ($this->file('documents') && is_array($this->file('documents'))) { - $rules['documents.*'] = $this->file_validation; + $rules['documents.*'] = $this->fileValidation(); } elseif ($this->file('documents')) { - $rules['documents'] = $this->file_validation; + $rules['documents'] = $this->fileValidation(); }else { $rules['documents'] = 'bail|sometimes|array'; } if ($this->file('file') && is_array($this->file('file'))) { - $rules['file.*'] = $this->file_validation; + $rules['file.*'] = $this->fileValidation(); } elseif ($this->file('file')) { - $rules['file'] = $this->file_validation; + $rules['file'] = $this->fileValidation(); } $rules['language_id'] = 'bail|nullable|sometimes|exists:languages,id'; diff --git a/app/Http/Requests/Vendor/UploadVendorRequest.php b/app/Http/Requests/Vendor/UploadVendorRequest.php index 80b6195c600d..826a5ed14d65 100644 --- a/app/Http/Requests/Vendor/UploadVendorRequest.php +++ b/app/Http/Requests/Vendor/UploadVendorRequest.php @@ -30,15 +30,15 @@ class UploadVendorRequest extends Request $rules = []; if ($this->file('documents') && is_array($this->file('documents'))) { - $rules['documents.*'] = $this->file_validation; + $rules['documents.*'] = $this->fileValidation(); } elseif ($this->file('documents')) { - $rules['documents'] = $this->file_validation; + $rules['documents'] = $this->fileValidation(); } if ($this->file('file') && is_array($this->file('file'))) { - $rules['file.*'] = $this->file_validation; + $rules['file.*'] = $this->fileValidation(); } elseif ($this->file('file')) { - $rules['file'] = $this->file_validation; + $rules['file'] = $this->fileValidation(); } $rules['is_public'] = 'sometimes|boolean'; diff --git a/config/ninja.php b/config/ninja.php index 41ae5ddcd8a6..35b1eb1e05e3 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -244,4 +244,6 @@ return [ 'public_key' => env('NINJA_PUBLIC_KEY', false), 'private_key' => env('NINJA_PRIVATE_KEY', false), ], + 'upload_extensions' => env('ADDITIONAL_UPLOAD_EXTENSIONS', false), + ];