|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Goodoneuz\PayUz\Models; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
6
|
|
|
use Goodoneuz\PayUz\Http\Classes\DataFormat; |
|
7
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes; |
|
8
|
|
|
|
|
9
|
|
|
class Transaction extends Model |
|
10
|
|
|
{ |
|
11
|
|
|
use SoftDeletes; |
|
12
|
|
|
|
|
13
|
|
|
protected $dates = [ |
|
14
|
|
|
'deleted_at' |
|
15
|
|
|
]; |
|
16
|
|
|
|
|
17
|
|
|
protected $fillable = [ |
|
18
|
|
|
'payment_system', //varchar 191 |
|
19
|
|
|
'system_transaction_id', // varchar 191 |
|
20
|
|
|
'amount', // double (15,5) |
|
21
|
|
|
'currency_code', // int(11) |
|
22
|
|
|
'state', // int(11) |
|
23
|
|
|
'updated_time', //datetime |
|
24
|
|
|
'comment', // varchar 191 |
|
25
|
|
|
'transactionable_type', |
|
26
|
|
|
'transactionable_id', |
|
27
|
|
|
'detail', // details |
|
28
|
|
|
]; |
|
29
|
|
|
const TIMEOUT = 43200000; |
|
30
|
|
|
|
|
31
|
|
|
const STATE_CREATED = 1; |
|
32
|
|
|
const STATE_COMPLETED = 2; |
|
33
|
|
|
const STATE_CANCELLED = -1; |
|
34
|
|
|
const STATE_CANCELLED_AFTER_COMPLETE = -2; |
|
35
|
|
|
|
|
36
|
|
|
const REASON_RECEIVERS_NOT_FOUND = 1; |
|
37
|
|
|
const REASON_PROCESSING_EXECUTION_FAILED = 2; |
|
38
|
|
|
const REASON_EXECUTION_FAILED = 3; |
|
39
|
|
|
const REASON_CANCELLED_BY_TIMEOUT = 4; |
|
40
|
|
|
const REASON_FUND_RETURNED = 5; |
|
41
|
|
|
const REASON_UNKNOWN = 10; |
|
42
|
|
|
|
|
43
|
|
|
const CURRENCY_CODE_UZS = 860; |
|
44
|
|
|
const CURRENCY_CODE_RUB = 643; |
|
45
|
|
|
const CURRENCY_CODE_USD = 840; |
|
46
|
|
|
const CURRENCY_CODE_EUR = 978; |
|
47
|
|
|
|
|
48
|
|
|
public function cancel($reason) |
|
49
|
|
|
{ |
|
50
|
|
|
$this->updated_time = DataFormat::timestamp(true); |
|
51
|
|
|
|
|
52
|
|
|
if ($this->state == self::STATE_COMPLETED) { |
|
53
|
|
|
// Scenario: CreateTransaction -> PerformTransaction -> CancelTransaction |
|
54
|
|
|
$this->state = self::STATE_CANCELLED_AFTER_COMPLETE; |
|
55
|
|
|
} else { |
|
56
|
|
|
// Scenario: CreateTransaction -> CancelTransaction |
|
57
|
|
|
$this->state = self::STATE_CANCELLED; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
$this->comment = $reason; |
|
61
|
|
|
$detail = json_decode($this->detail,true); |
|
62
|
|
|
$detail['cancel_time'] = $this->updated_time; |
|
63
|
|
|
$detail = json_encode($detail); |
|
64
|
|
|
$this->detail = $detail; |
|
65
|
|
|
|
|
66
|
|
|
|
|
67
|
|
|
|
|
68
|
|
|
$this->update(); |
|
69
|
|
|
} |
|
70
|
|
|
public function isExpired() |
|
71
|
|
|
{ |
|
72
|
|
|
return $this->state == self::STATE_CREATED && DataFormat::datetime2timestamp($this->updated_time) - time() > self::TIMEOUT; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
} |
|
76
|
|
|
|