From b5c0e678cb68107eeca5cd1a1cc34fa6332c690b Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 28 Apr 2022 12:40:07 +1000 Subject: [PATCH] Improve WePay guardian --- app/Jobs/Mail/PaymentFailedMailer.php | 2 +- app/Listeners/Invoice/InvoiceFailedEmailNotification.php | 4 ---- app/Listeners/Payment/PaymentNotification.php | 1 - app/Models/CompanyGateway.php | 3 +++ app/PaymentDrivers/BaseDriver.php | 4 ++-- app/PaymentDrivers/WePay/ACH.php | 7 +++++++ app/Services/Invoice/MarkPaid.php | 2 +- app/Services/Invoice/MarkSent.php | 2 +- routes/client.php | 2 +- 9 files changed, 16 insertions(+), 11 deletions(-) diff --git a/app/Jobs/Mail/PaymentFailedMailer.php b/app/Jobs/Mail/PaymentFailedMailer.php index b255558df60b..5a53e8c17ce8 100644 --- a/app/Jobs/Mail/PaymentFailedMailer.php +++ b/app/Jobs/Mail/PaymentFailedMailer.php @@ -111,7 +111,7 @@ class PaymentFailedMailer implements ShouldQueue //add client payment failures here. // - if($contact = $this->client->primary_contact()->first()) + if($contact = $this->client->primary_contact()->first() && $this->payment_hash) { $mail_obj = (new ClientPaymentFailureObject($this->client, $this->error, $this->company, $this->payment_hash))->build(); diff --git a/app/Listeners/Invoice/InvoiceFailedEmailNotification.php b/app/Listeners/Invoice/InvoiceFailedEmailNotification.php index 64a89ff34b7d..bd78286a6794 100644 --- a/app/Listeners/Invoice/InvoiceFailedEmailNotification.php +++ b/app/Listeners/Invoice/InvoiceFailedEmailNotification.php @@ -54,8 +54,6 @@ class InvoiceFailedEmailNotification foreach ($event->invitation->company->company_users as $company_user) { $user = $company_user->user; - // $notification = new EntitySentNotification($event->invitation, 'invoice'); - $methods = $this->findUserNotificationTypes($event->invitation, $company_user, 'invoice', ['all_notifications', 'invoice_sent', 'invoice_sent_all']); if (($key = array_search('mail', $methods)) !== false) { @@ -68,9 +66,7 @@ class InvoiceFailedEmailNotification $first_notification_sent = false; } - // $notification->method = $methods; - // $user->notify($notification); } } } diff --git a/app/Listeners/Payment/PaymentNotification.php b/app/Listeners/Payment/PaymentNotification.php index 2cd336daf252..3dd580cd2e63 100644 --- a/app/Listeners/Payment/PaymentNotification.php +++ b/app/Listeners/Payment/PaymentNotification.php @@ -28,7 +28,6 @@ class PaymentNotification implements ShouldQueue public $delay = 5; - /** * Create the event listener. * diff --git a/app/Models/CompanyGateway.php b/app/Models/CompanyGateway.php index 4b8eb0430897..5fc15f2a6d36 100644 --- a/app/Models/CompanyGateway.php +++ b/app/Models/CompanyGateway.php @@ -85,6 +85,9 @@ class CompanyGateway extends BaseModel '8fdeed552015b3c7b44ed6c8ebd9e992' => 309, 'd6814fc83f45d2935e7777071e629ef9' => 310, 'bbd736b3254b0aabed6ad7fda1298c88' => 311, + '65faab2ab6e3223dbe848b1686490baz' => 320, + 'b9886f9257f0c6ee7c302f1c74475f6c' => 321, + 'hxd6gwg3ekb9tb3v9lptgx1mqyg69zu9' => 322, ]; protected $touches = []; diff --git a/app/PaymentDrivers/BaseDriver.php b/app/PaymentDrivers/BaseDriver.php index 0e8c9ef933e5..2a2b58ccc5e2 100644 --- a/app/PaymentDrivers/BaseDriver.php +++ b/app/PaymentDrivers/BaseDriver.php @@ -502,8 +502,8 @@ class BaseDriver extends AbstractPaymentDriver /*Generic Global unsuccessful transaction method when the client is present*/ public function processUnsuccessfulTransaction($response, $client_present = true) { - $error = $response['error']; - $error_code = $response['error_code']; + $error = array_key_exists('error', $response) ? $response['error'] : 'Undefined Error'; + $error_code = array_key_exists('error_code', $response) ? $response['error_code'] : 'Undefined Error Code'; $this->unWindGatewayFees($this->payment_hash); diff --git a/app/PaymentDrivers/WePay/ACH.php b/app/PaymentDrivers/WePay/ACH.php index 8d31c43701c5..2052562db28c 100644 --- a/app/PaymentDrivers/WePay/ACH.php +++ b/app/PaymentDrivers/WePay/ACH.php @@ -22,6 +22,7 @@ use App\PaymentDrivers\WePayPaymentDriver; use App\PaymentDrivers\WePay\WePayCommon; use App\Utils\Traits\MakesHash; use Illuminate\Http\Request; +use Illuminate\Notifications\Messages\SlackMessage; use Illuminate\Support\Str; class ACH @@ -86,6 +87,12 @@ class ACH $this->wepay_payment_driver->client->company, ); + (new SlackMessage) + ->success() + ->from(ctrans('texts.notification_bot')) + ->image('https://app.invoiceninja.com/favicon.png') + ->content("New WePay ACH Failure from Company ID: ". $this->wepay_payment_driver->company_gateway->company->id); + throw new PaymentFailed($e->getMessage(), 400); } // display the response diff --git a/app/Services/Invoice/MarkPaid.php b/app/Services/Invoice/MarkPaid.php index 4224b645bc64..5c4a282d5ff3 100644 --- a/app/Services/Invoice/MarkPaid.php +++ b/app/Services/Invoice/MarkPaid.php @@ -103,7 +103,7 @@ class MarkPaid extends AbstractService \DB::connection(config('database.default'))->transaction(function () use($payment){ /* Get the last record for the client and set the current balance*/ - $client = Client::where('id', $this->invoice->client_id)->lockForUpdate()->first(); + $client = Client::withTrashed()->where('id', $this->invoice->client_id)->lockForUpdate()->first(); $client->paid_to_date += $payment->amount; $client->balance -= $payment->amount; $client->save(); diff --git a/app/Services/Invoice/MarkSent.php b/app/Services/Invoice/MarkSent.php index 8f647cb40854..9719057374f9 100644 --- a/app/Services/Invoice/MarkSent.php +++ b/app/Services/Invoice/MarkSent.php @@ -67,7 +67,7 @@ class MarkSent extends AbstractService \DB::connection(config('database.default'))->transaction(function () use($adjustment){ /* Get the last record for the client and set the current balance*/ - $client = Client::where('id', $this->client->id)->lockForUpdate()->first(); + $client = Client::withTrashed()->where('id', $this->client->id)->lockForUpdate()->first(); $client->balance += $adjustment; $client->save(); diff --git a/routes/client.php b/routes/client.php index 47b1a9b7e443..295957d4db35 100644 --- a/routes/client.php +++ b/routes/client.php @@ -8,7 +8,7 @@ Route::get('client/login', 'Auth\ContactLoginController@showLoginForm')->name('c Route::post('client/login', 'Auth\ContactLoginController@login')->name('client.login.submit'); Route::get('client/register/{company_key?}', 'Auth\ContactRegisterController@showRegisterForm')->name('client.register')->middleware(['domain_db', 'contact_account', 'contact_register','locale']); -Route::post('client/register/{company_key?}', 'Auth\ContactRegisterController@register')->middleware(['domain_db', 'contact_account', 'contact_register', 'locale']); +Route::post('client/register/{company_key?}', 'Auth\ContactRegisterController@register')->middleware(['domain_db', 'contact_account', 'contact_register', 'locale','throttle:10,1']); Route::get('client/password/reset', 'Auth\ContactForgotPasswordController@showLinkRequestForm')->name('client.password.request')->middleware(['domain_db', 'contact_account','locale']); Route::post('client/password/email', 'Auth\ContactForgotPasswordController@sendResetLinkEmail')->name('client.password.email')->middleware('locale');