Skip to content

Commit

Permalink
Merge pull request #59 from Sodiqmirzo/master
Browse files Browse the repository at this point in the history
added transactionable morph in transaction model
  • Loading branch information
shaxzodbek-uzb authored Apr 12, 2023
2 parents 2daeb08 + 3db6bef commit 3f43622
Showing 1 changed file with 25 additions and 21 deletions.
46 changes: 25 additions & 21 deletions src/Models/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,31 @@

namespace Goodoneuz\PayUz\Models;

use Illuminate\Database\Eloquent\Model;
use Goodoneuz\PayUz\Http\Classes\DataFormat;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphTo;
use Illuminate\Database\Eloquent\SoftDeletes;

class Transaction extends Model
{
use SoftDeletes;

protected $dates = [
const TIMEOUT = 43200000;
const STATE_CREATED = 1;
const STATE_COMPLETED = 2;
const STATE_CANCELLED = -1;
const STATE_CANCELLED_AFTER_COMPLETE = -2;
const REASON_RECEIVERS_NOT_FOUND = 1;
const REASON_PROCESSING_EXECUTION_FAILED = 2;
const REASON_EXECUTION_FAILED = 3;
const REASON_CANCELLED_BY_TIMEOUT = 4;
const REASON_FUND_RETURNED = 5;
const REASON_UNKNOWN = 10;
const CURRENCY_CODE_UZS = 860;
const CURRENCY_CODE_RUB = 643;
const CURRENCY_CODE_USD = 840;
const CURRENCY_CODE_EUR = 978;
protected $dates = [
'deleted_at'
];
protected $casts = [
Expand All @@ -28,24 +44,6 @@ class Transaction extends Model
'transactionable_id',
'detail', // details
];
const TIMEOUT = 43200000;

const STATE_CREATED = 1;
const STATE_COMPLETED = 2;
const STATE_CANCELLED = -1;
const STATE_CANCELLED_AFTER_COMPLETE = -2;

const REASON_RECEIVERS_NOT_FOUND = 1;
const REASON_PROCESSING_EXECUTION_FAILED = 2;
const REASON_EXECUTION_FAILED = 3;
const REASON_CANCELLED_BY_TIMEOUT = 4;
const REASON_FUND_RETURNED = 5;
const REASON_UNKNOWN = 10;

const CURRENCY_CODE_UZS = 860;
const CURRENCY_CODE_RUB = 643;
const CURRENCY_CODE_USD = 840;
const CURRENCY_CODE_EUR = 978;

public function cancel($reason)
{
Expand All @@ -66,8 +64,14 @@ public function cancel($reason)

$this->update();
}

public function isExpired()
{
return $this->state == self::STATE_CREATED && DataFormat::datetime2timestamp($this->updated_time) - time() > self::TIMEOUT;
}
}

public function transactionable(): MorphTo
{
return $this->morphTo();
}
}

0 comments on commit 3f43622

Please sign in to comment.