1 | <?php |
||
32 | class PayuTransaction extends Model |
||
33 | { |
||
34 | use SoftDeletes; |
||
35 | |||
36 | const STATUS_PENDING = 'pending'; |
||
37 | const STATUS_FAILED = 'failed'; |
||
38 | const STATUS_SUCCESSFUL = 'successful'; |
||
39 | const STATUS_INVALID = 'invalid'; |
||
40 | |||
41 | protected $fillable = [ |
||
42 | 'transaction_id', 'paid_for_id', 'paid_for_type', 'gateway', 'body', |
||
43 | 'destination', 'hash', 'response', 'status', 'verified_at', |
||
44 | ]; |
||
45 | |||
46 | protected $casts = [ |
||
47 | 'gateway' => Serialized::class, |
||
48 | 'body' => Serialized::class, |
||
49 | 'response' => 'array', |
||
50 | ]; |
||
51 | |||
52 | protected $dates = [ |
||
53 | 'verified_at', |
||
54 | ]; |
||
55 | |||
56 | public function paidFor(): MorphTo |
||
57 | { |
||
58 | return $this->morphTo('paid_for'); |
||
59 | } |
||
60 | |||
61 | public function scopePending(Builder $builder): Builder |
||
62 | { |
||
63 | return $builder->where('status', self::STATUS_PENDING); |
||
64 | } |
||
65 | |||
66 | public function scopeFailed(Builder $builder): Builder |
||
67 | { |
||
68 | return $builder->where('status', self::STATUS_FAILED); |
||
69 | } |
||
70 | |||
71 | public function scopeSuccessful(Builder $builder): Builder |
||
72 | { |
||
73 | return $builder->where('status', self::STATUS_SUCCESSFUL); |
||
74 | } |
||
75 | |||
76 | public function scopeVerifiable(Builder $builder): Builder |
||
77 | { |
||
78 | return $builder->whereIn('status', config('payu.verify', []))->whereNull('verified_at'); |
||
79 | } |
||
80 | |||
81 | public function scopeLocate(Builder $builder, string $id): ?self |
||
88 | |||
89 | public function successful() |
||
93 | |||
94 | public function failed() |
||
98 | |||
99 | public function pending() |
||
103 | |||
104 | public function invalid() |
||
108 | |||
109 | public function verified() |
||
110 | { |
||
111 | return ! empty($this->verified_at); |
||
112 | } |
||
113 | |||
114 | public function shouldVerify() |
||
121 | |||
122 | public function verify(): ?self |
||
130 | |||
131 | public function verifyAsync() |
||
135 | |||
136 | public function response($key) |
||
140 | } |
||
141 |