53 lines
1.5 KiB
PHP
53 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace humhub\modules\donations\models;
|
|
|
|
use humhub\components\ActiveRecord;
|
|
|
|
class DonationTransaction extends ActiveRecord
|
|
{
|
|
public const STATUS_PENDING = 'pending';
|
|
public const STATUS_SUCCEEDED = 'succeeded';
|
|
public const STATUS_FAILED = 'failed';
|
|
public const STATUS_CANCELLED = 'cancelled';
|
|
public const STATUS_REFUNDED = 'refunded';
|
|
|
|
public static function tableName()
|
|
{
|
|
return 'rescue_donation_transaction';
|
|
}
|
|
|
|
public function rules()
|
|
{
|
|
return [
|
|
[['contentcontainer_id', 'provider', 'mode', 'status', 'amount'], 'required'],
|
|
[['contentcontainer_id', 'donor_user_id', 'is_anonymous', 'goal_id', 'target_animal_id'], 'integer'],
|
|
[['amount'], 'number', 'min' => 0.01],
|
|
[['metadata_json'], 'string'],
|
|
[['provider', 'status', 'goal_type'], 'string', 'max' => 32],
|
|
[['mode'], 'string', 'max' => 16],
|
|
[['currency'], 'string', 'max' => 8],
|
|
[['provider_payment_id', 'provider_checkout_id', 'provider_subscription_id', 'provider_customer_id'], 'string', 'max' => 190],
|
|
];
|
|
}
|
|
|
|
public function beforeSave($insert)
|
|
{
|
|
if (!parent::beforeSave($insert)) {
|
|
return false;
|
|
}
|
|
|
|
$now = date('Y-m-d H:i:s');
|
|
if ($insert && empty($this->created_at)) {
|
|
$this->created_at = $now;
|
|
}
|
|
$this->updated_at = $now;
|
|
|
|
if (empty($this->currency)) {
|
|
$this->currency = 'USD';
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|