1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Orkhanahmadov\LaravelGoldenpay\Models; |
4
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Builder; |
6
|
|
|
use Illuminate\Database\Eloquent\Model; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class Payment |
10
|
|
|
* @package Orkhanahmadov\LaravelGoldenpay\Models |
11
|
|
|
* |
12
|
|
|
* @property int $id |
13
|
|
|
* @property string $payment_key |
14
|
|
|
* @property int $amount |
15
|
|
|
* @property string $card_type |
16
|
|
|
* @property string $language |
17
|
|
|
* @property string $description |
18
|
|
|
* @property int $status |
19
|
|
|
* @property string $message |
20
|
|
|
* @property string $reference_number |
21
|
|
|
* @property string $card_number |
22
|
|
|
* @property \Carbon\Carbon $payment_date |
23
|
|
|
* @property int $checks |
24
|
|
|
* @property \Carbon\Carbon $created_at |
25
|
|
|
* @property \Carbon\Carbon $updated_at |
26
|
|
|
* @property-read float|int $formatted_amount |
27
|
|
|
* @property-read bool $successful |
28
|
|
|
* @method static Payment first() |
29
|
|
|
* @method static Builder pending() |
30
|
|
|
*/ |
31
|
|
|
class Payment extends Model |
32
|
|
|
{ |
33
|
|
|
protected $guarded = [ |
34
|
|
|
'status', |
35
|
|
|
]; |
36
|
|
|
|
37
|
|
|
protected $dates = [ |
38
|
|
|
'payment_date', |
39
|
|
|
]; |
40
|
|
|
|
41
|
|
|
protected $hidden = [ |
42
|
|
|
'card_number', |
43
|
|
|
]; |
44
|
|
|
|
45
|
|
|
protected $casts = [ |
46
|
|
|
'amount' => 'int', |
47
|
|
|
'status' => 'int', |
48
|
|
|
'checks' => 'int', |
49
|
|
|
]; |
50
|
|
|
|
51
|
|
|
public function __construct(array $attributes = []) |
52
|
|
|
{ |
53
|
|
|
parent::__construct($attributes); |
54
|
|
|
|
55
|
|
|
$this->setTable(config('goldenpay.table_name')); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function getSuccessfulAttribute(): bool |
59
|
|
|
{ |
60
|
|
|
return $this->status === 1; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function getFormattedAmountAttribute() |
64
|
|
|
{ |
65
|
|
|
return $this->amount / 100; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function scopePending(Builder $builder): Builder |
69
|
|
|
{ |
70
|
|
|
return $builder |
71
|
|
|
->where(function ($query) { |
72
|
|
|
$query->whereNull('status')->orWhereNotIn('status', [1]); |
73
|
|
|
}) |
74
|
|
|
->where('created_at', '>', now()->subMinutes(30)); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|