Changeset View
Changeset View
Standalone View
Standalone View
src/app/Wallet.php
Show First 20 Lines • Show All 414 Lines • ▼ Show 20 Lines | class Wallet extends Model | ||||
public function expectedCharges() | public function expectedCharges() | ||||
{ | { | ||||
return $this->chargeEntitlements(false); | return $this->chargeEntitlements(false); | ||||
} | } | ||||
/** | /** | ||||
* Return the exact, numeric version of the discount to be applied. | * Return the exact, numeric version of the discount to be applied. | ||||
* | * | ||||
* Ranges from 0 - 100. | * @return int Discount in percent, ranges from 0 - 100. | ||||
* | |||||
* @return int | |||||
*/ | */ | ||||
public function getDiscount() | public function getDiscount(): int | ||||
{ | { | ||||
return $this->discount ? $this->discount->discount : 0; | return $this->discount ? $this->discount->discount : 0; | ||||
} | } | ||||
/** | /** | ||||
* The actual discount rate for use in multiplication | * The actual discount rate for use in multiplication | ||||
* | * | ||||
* Ranges from 0.00 to 1.00. | * @return float Discount rate, ranges from 0.00 to 1.00. | ||||
*/ | */ | ||||
public function getDiscountRate() | public function getDiscountRate(): float | ||||
{ | { | ||||
return (100 - $this->getDiscount()) / 100; | return (100 - $this->getDiscount()) / 100; | ||||
} | } | ||||
/** | /** | ||||
* The minimum amount of an auto-payment mandate | |||||
* | |||||
* @return int Amount in cents | |||||
*/ | |||||
public function getMinMandateAmount(): int | |||||
{ | |||||
$min = Payment::MIN_AMOUNT; | |||||
if ($plan = $this->plan()) { | |||||
$planCost = (int) ($plan->cost() * $plan->months * $this->getDiscountRate()); | |||||
if ($planCost > $min) { | |||||
$min = $planCost; | |||||
} | |||||
} | |||||
return $min; | |||||
} | |||||
/** | |||||
* Check if the specified user is a controller to this wallet. | * Check if the specified user is a controller to this wallet. | ||||
* | * | ||||
* @param \App\User $user The user object. | * @param \App\User $user The user object. | ||||
* | * | ||||
* @return bool True if the user is one of the wallet controllers (including user), False otherwise | * @return bool True if the user is one of the wallet controllers (including user), False otherwise | ||||
*/ | */ | ||||
public function isController(User $user): bool | public function isController(User $user): bool | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 278 Lines • Show Last 20 Lines |