Changeset View
Changeset View
Standalone View
Standalone View
src/app/Payment.php
Show First 20 Lines • Show All 100 Lines • ▼ Show 20 Lines | class Payment extends Model | ||||
/** | /** | ||||
* Apply the successful payment's pecunia to the wallet | * Apply the successful payment's pecunia to the wallet | ||||
* | * | ||||
* @param string $method Payment method name | * @param string $method Payment method name | ||||
*/ | */ | ||||
public function credit($method): void | public function credit($method): void | ||||
{ | { | ||||
// TODO: Possibly we should sanity check that payment is paid, and not negative? | if (empty($this->wallet)) { | ||||
throw new \Exception("Cannot credit a payment not assigned to a wallet"); | |||||
} | |||||
if ($this->credit_amount < 0) { | |||||
throw new \Exception("Cannot credit a payment with negative amount"); | |||||
} | |||||
// TODO: Possibly we should sanity check that payment is paid? | |||||
// TODO: Localization? | // TODO: Localization? | ||||
$description = $this->type == self::TYPE_RECURRING ? 'Auto-payment' : 'Payment'; | $description = $this->type == self::TYPE_RECURRING ? 'Auto-payment' : 'Payment'; | ||||
$description .= " transaction {$this->id} using {$method}"; | $description .= " transaction {$this->id} using {$method}"; | ||||
$this->wallet->credit($this, $description); | $this->wallet->credit($this, $description); | ||||
// Unlock the disabled auto-payment mandate | // Unlock the disabled auto-payment mandate | ||||
if ($this->wallet->balance >= 0) { | if ($this->wallet->balance >= 0) { | ||||
$this->wallet->setSetting('mandate_disabled', null); | $this->wallet->setSetting('mandate_disabled', null); | ||||
} | } | ||||
// Remove RESTRICTED flag from the wallet owner and all users in the wallet | |||||
if ($this->wallet->owner && $this->wallet->owner->isRestricted()) { | |||||
$this->wallet->owner->unrestrict(true); | |||||
} | |||||
} | } | ||||
/** | /** | ||||
* Creates a payment and transaction records for the refund/chargeback operation. | * Creates a payment and transaction records for the refund/chargeback operation. | ||||
* Deducts an amount of pecunia from the wallet. | * Deducts an amount of pecunia from the wallet. | ||||
* | * | ||||
* @param array $refund A refund or chargeback data (id, type, amount, currency, description) | * @param array $refund A refund or chargeback data (id, type, amount, currency, description) | ||||
* | * | ||||
▲ Show 20 Lines • Show All 65 Lines • Show Last 20 Lines |