Changeset View
Changeset View
Standalone View
Standalone View
src/app/Entitlement.php
Show All 23 Lines | |||||
* @property \App\Wallet $wallet The wallet to which this entitlement is charged. | * @property \App\Wallet $wallet The wallet to which this entitlement is charged. | ||||
* @property string $wallet_id | * @property string $wallet_id | ||||
*/ | */ | ||||
class Entitlement extends Model | class Entitlement extends Model | ||||
{ | { | ||||
use SoftDeletes; | use SoftDeletes; | ||||
use UuidStrKeyTrait; | use UuidStrKeyTrait; | ||||
/** | /** @var array<int, string> The attributes that are mass assignable */ | ||||
* The fillable columns for this Entitlement | |||||
* | |||||
* @var array | |||||
*/ | |||||
protected $fillable = [ | protected $fillable = [ | ||||
'sku_id', | 'sku_id', | ||||
'wallet_id', | 'wallet_id', | ||||
'entitleable_id', | 'entitleable_id', | ||||
'entitleable_type', | 'entitleable_type', | ||||
'cost', | 'cost', | ||||
'description', | 'description', | ||||
'fee', | 'fee', | ||||
]; | ]; | ||||
/** @var array<string, string> The attributes that should be cast */ | |||||
protected $casts = [ | protected $casts = [ | ||||
'cost' => 'integer', | 'cost' => 'integer', | ||||
'fee' => 'integer' | 'fee' => 'integer' | ||||
]; | ]; | ||||
/** | /** | ||||
* Return the costs per day for this entitlement. | * Return the costs per day for this entitlement. | ||||
* | * | ||||
Show All 20 Lines | class Entitlement extends Model | ||||
* @param string $type The type of transaction ('created', 'billed', 'deleted'), but use the | * @param string $type The type of transaction ('created', 'billed', 'deleted'), but use the | ||||
* \App\Transaction constants. | * \App\Transaction constants. | ||||
* @param int $amount The amount involved in cents | * @param int $amount The amount involved in cents | ||||
* | * | ||||
* @return string The transaction ID | * @return string The transaction ID | ||||
*/ | */ | ||||
public function createTransaction($type, $amount = null) | public function createTransaction($type, $amount = null) | ||||
{ | { | ||||
$transaction = \App\Transaction::create( | $transaction = Transaction::create( | ||||
[ | [ | ||||
'object_id' => $this->id, | 'object_id' => $this->id, | ||||
'object_type' => \App\Entitlement::class, | 'object_type' => Entitlement::class, | ||||
'type' => $type, | 'type' => $type, | ||||
'amount' => $amount | 'amount' => $amount | ||||
] | ] | ||||
); | ); | ||||
return $transaction->id; | return $transaction->id; | ||||
} | } | ||||
Show All 10 Lines | class Entitlement extends Model | ||||
/** | /** | ||||
* Returns entitleable object title (e.g. email or domain name). | * Returns entitleable object title (e.g. email or domain name). | ||||
* | * | ||||
* @return string|null An object title/name | * @return string|null An object title/name | ||||
*/ | */ | ||||
public function entitleableTitle(): ?string | public function entitleableTitle(): ?string | ||||
{ | { | ||||
if ($this->entitleable instanceof \App\Domain) { | if ($this->entitleable instanceof Domain) { | ||||
return $this->entitleable->namespace; | return $this->entitleable->namespace; | ||||
} | } | ||||
return $this->entitleable->email; | return $this->entitleable->email; | ||||
} | } | ||||
/** | /** | ||||
* Simplified Entitlement/SKU information for a specified entitleable object | * Simplified Entitlement/SKU information for a specified entitleable object | ||||
▲ Show 20 Lines • Show All 53 Lines • Show Last 20 Lines |