|
@@ -2,6 +2,7 @@
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
+use App\ApiSDK\PhyreApiSDK;
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
@@ -10,6 +11,7 @@ class Customer extends Model
|
|
|
use HasFactory;
|
|
|
|
|
|
protected $fillable = [
|
|
|
+ 'phyre_server_id',
|
|
|
'name',
|
|
|
'username',
|
|
|
'password',
|
|
@@ -23,6 +25,37 @@ class Customer extends Model
|
|
|
'company',
|
|
|
];
|
|
|
|
|
|
+ public static function boot()
|
|
|
+ {
|
|
|
+ parent::boot();
|
|
|
+
|
|
|
+ static::creating(function ($model) {
|
|
|
+ if ($model->phyre_server_id > 0) {
|
|
|
+ $phyreServer = PhyreServer::where('id', $model->phyre_server_id)->first();
|
|
|
+ if ($phyreServer) {
|
|
|
+ $phyreApiSDK = new PhyreApiSDK($phyreServer->ip, 8443, $phyreServer->username, $phyreServer->password);
|
|
|
+ $createCustomer = $phyreApiSDK->createCustomer([
|
|
|
+ 'name' => $model->name,
|
|
|
+ 'email' => $model->email
|
|
|
+ ]);
|
|
|
+ if (isset($createCustomer['data']['customer']['id'])) {
|
|
|
+ $model->external_id = $createCustomer['data']['customer']['id'];
|
|
|
+ } else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ static::deleting(function ($model) {
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
public function hostingSubscriptions()
|
|
|
{
|
|
|
return $this->hasMany(HostingSubscription::class);
|