Changeset View
Changeset View
Standalone View
Standalone View
src/app/Entitlement.php
Show First 20 Lines • Show All 78 Lines • ▼ Show 20 Lines | class Entitlement extends Model | ||||
* \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 = \App\Transaction::create( | ||||
[ | [ | ||||
'user_email' => \App\Utils::userEmailOrNull(), | |||||
'object_id' => $this->id, | 'object_id' => $this->id, | ||||
vanmeeuwen: Why would we not include the whodunnit here? | |||||
'object_type' => \App\Entitlement::class, | 'object_type' => \App\Entitlement::class, | ||||
'type' => $type, | 'type' => $type, | ||||
'amount' => $amount | 'amount' => $amount | ||||
] | ] | ||||
); | ); | ||||
return $transaction->id; | return $transaction->id; | ||||
} | } | ||||
/** | /** | ||||
* Principally entitleable objects such as 'Domain' or 'User'. | * Principally entitleable objects such as 'Domain' or 'User'. | ||||
* | * | ||||
* @return mixed | * @return mixed | ||||
*/ | */ | ||||
public function entitleable() | public function entitleable() | ||||
{ | { | ||||
return $this->morphTo(); | return $this->morphTo(); | ||||
} | } | ||||
/** | /** | ||||
* Returns entitleable object title (e.g. email or domain name). | |||||
* | |||||
* @return string|null An object title/name | |||||
*/ | |||||
public function entitleableTitle(): ?string | |||||
{ | |||||
if ($this->entitleable instanceof \App\User) { | |||||
return $this->entitleable->email; | |||||
} | |||||
if ($this->entitleable instanceof \App\Domain) { | |||||
return $this->entitleable->namespace; | |||||
} | |||||
} | |||||
/** | |||||
* The SKU concerned. | * The SKU concerned. | ||||
* | * | ||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo | ||||
*/ | */ | ||||
public function sku() | public function sku() | ||||
{ | { | ||||
return $this->belongsTo('App\Sku'); | return $this->belongsTo('App\Sku'); | ||||
} | } | ||||
Show All 19 Lines |
Why would we not include the whodunnit here?