forked from wartron/yii2-account-billing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Payment.php
81 lines (70 loc) · 1.85 KB
/
Payment.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
namespace wartron\yii2account\billing\models;
use Exception;
use Yii;
use wartron\yii2account\billing\models\BillableItem;
use wartron\yii2account\billing\models\BillingAccount;
class Payment extends \wartron\yii2uuid\db\ActiveRecord
{
const STATUS_PENDING = 0;
const STATUS_SUCCESSFUL = 1;
const STATUS_FAILED = 2;
/**
* @inheritdoc
*/
public static function tableName()
{
return 'billing_payment';
}
/**
* @inheritdoc
*/
public function behaviors()
{
return [
[
'class' => \yii\behaviors\TimestampBehavior::className(),
'updatedAtAttribute' => false,
],
[
'class' => \yii\behaviors\BlameableBehavior::className(),
'updatedByAttribute' => false,
],
];
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['account_id', 'amount'], 'required'],
[['status', 'amount', 'created_at'], 'integer'],
[['description'], 'string', 'max' => 255],
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getItems()
{
return $this->hasMany(BillableItem::className(), ['id' => 'billing_item_id'])->viaTable('billing_payment_item', ['payment_id' => 'id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getBillingaccount()
{
return $this->hasOne(BillingAccount::className(), ['id' => 'billing_account_id']);
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => Yii::t('app', 'ID'),
'created_at' => Yii::t('app', 'Date'),
];
}
}