2020-08-22 02:42:12 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Observers;
|
|
|
|
|
2021-01-26 23:17:27 +01:00
|
|
|
use App\Models\ClientGatewayToken;
|
2020-08-22 05:34:41 +02:00
|
|
|
use App\Models\CompanyGateway;
|
2020-08-22 02:42:12 +02:00
|
|
|
|
|
|
|
class CompanyGatewayObserver
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Handle the company gateway "created" event.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param CompanyGateway $company_gateway
|
2020-08-22 02:42:12 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function created(CompanyGateway $company_gateway)
|
|
|
|
{
|
2020-08-27 23:34:15 +02:00
|
|
|
|
|
|
|
/* Set company gateway if not exists*/
|
2020-09-06 11:38:10 +02:00
|
|
|
if (! $company_gateway->label) {
|
2020-08-22 02:42:12 +02:00
|
|
|
$company_gateway->label = $company_gateway->gateway->name;
|
|
|
|
$company_gateway->save();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the company gateway "updated" event.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param CompanyGateway $company_gateway
|
2020-08-22 02:42:12 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function updated(CompanyGateway $company_gateway)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the company gateway "deleted" event.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param CompanyGateway $company_gateway
|
2020-08-22 02:42:12 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function deleted(CompanyGateway $company_gateway)
|
|
|
|
{
|
2021-01-26 23:17:27 +01:00
|
|
|
//when we soft delete a gateway - we also soft delete the tokens
|
|
|
|
$company_gateway->client_gateway_tokens()->delete();
|
2020-08-22 02:42:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the company gateway "restored" event.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param CompanyGateway $company_gateway
|
2020-08-22 02:42:12 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function restored(CompanyGateway $company_gateway)
|
|
|
|
{
|
2021-01-26 23:17:27 +01:00
|
|
|
//When we restore the gateway, bring back the tokens!
|
2021-09-21 23:45:06 +02:00
|
|
|
ClientGatewayToken::where('company_gateway_id', $company_gateway->id)
|
2022-06-21 11:57:17 +02:00
|
|
|
->withTrashed()->cursor()->each(function ($cgt) {
|
|
|
|
$cgt->restore();
|
2021-09-21 23:45:06 +02:00
|
|
|
});
|
2020-08-22 02:42:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the company gateway "force deleted" event.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param CompanyGateway $company_gateway
|
2020-08-22 02:42:12 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function forceDeleted(CompanyGateway $company_gateway)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
}
|