Changeset View
Changeset View
Standalone View
Standalone View
src/app/Payment.php
<?php | <?php | ||||
namespace App; | namespace App; | ||||
use Dyrynda\Database\Support\NullableFields; | use Dyrynda\Database\Support\NullableFields; | ||||
use Illuminate\Database\Eloquent\Model; | use Illuminate\Database\Eloquent\Model; | ||||
/** | /** | ||||
* A payment operation on a wallet. | * A payment operation on a wallet. | ||||
* | * | ||||
* @property int $amount Amount of money in cents of system currency (payment provider) | * @property int $amount Amount of money in cents of system currency (payment provider) | ||||
* @property int $credit_amount Amount of money in cents of system currency (wallet balance) | * @property int $credit_amount Amount of money in cents of system currency (wallet balance) | ||||
* @property string $description Payment description | * @property string $description Payment description | ||||
* @property string $id Mollie's Payment ID | * @property string $id Mollie's Payment ID | ||||
* @property string $status Payment status (Payment::STATUS_*) | |||||
* @property string $type Payment type (Payment::TYPE_*) | |||||
* @property ?string $vat_rate_id VAT rate identifier | * @property ?string $vat_rate_id VAT rate identifier | ||||
* @property \App\Wallet $wallet The wallet | * @property \App\Wallet $wallet The wallet | ||||
* @property string $wallet_id The ID of the wallet | * @property string $wallet_id The ID of the wallet | ||||
* @property string $currency Currency of this payment | * @property string $currency Currency of this payment | ||||
* @property int $currency_amount Amount of money in cents of $currency | * @property int $currency_amount Amount of money in cents of $currency | ||||
*/ | */ | ||||
class Payment extends Model | class Payment extends Model | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 98 Lines • ▼ Show 20 Lines | public function credit($method): void | ||||
$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); | ||||
} | } | ||||
if ($owner = $this->wallet->owner) { | |||||
// Remove RESTRICTED flag from the wallet owner and all users in the wallet | // Remove RESTRICTED flag from the wallet owner and all users in the wallet | ||||
if ($this->wallet->owner && $this->wallet->owner->isRestricted()) { | if ($owner->isRestricted()) { | ||||
$this->wallet->owner->unrestrict(true); | $owner->unrestrict(true); | ||||
} | |||||
// Activate the inactive user | |||||
if (!$owner->isActive()) { | |||||
$owner->status |= User::STATUS_ACTIVE; | |||||
$owner->save(); | |||||
} | |||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* 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 66 Lines • Show Last 20 Lines |