1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ByTIC\Payments\Models\Transactions; |
4
|
|
|
|
5
|
|
|
use ByTIC\DataObjects\Behaviors\Timestampable\TimestampableTrait; |
6
|
|
|
use ByTIC\DataObjects\Casts\Metadata\AsMetadataObject; |
7
|
|
|
use ByTIC\Payments\Models\AbstractModels\HasGateway\HasGatewayRecordTrait; |
8
|
|
|
use ByTIC\Payments\Models\AbstractModels\HasPaymentMethod\HasPaymentMethodRecord; |
9
|
|
|
use ByTIC\Payments\Models\AbstractModels\HasPurchaseParent; |
10
|
|
|
use ByTIC\Payments\Models\AbstractModels\HasToken\HasTokenRecord; |
11
|
|
|
use ByTIC\Payments\Models\Purchases\PurchaseTrait; |
12
|
|
|
use ByTIC\Payments\Models\Subscriptions\Subscription; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Trait TransactionTrait |
16
|
|
|
* @package ByTIC\Payments\Models\Transactions |
17
|
|
|
* |
18
|
|
|
* @property int $id_purchase |
19
|
|
|
* @property int $id_subscription |
20
|
|
|
* @property int $id_token |
21
|
|
|
* @property string $gateway |
22
|
|
|
* @property int $amount |
23
|
|
|
* @property string $currency |
24
|
|
|
* |
25
|
|
|
* @property string $card |
26
|
|
|
* @property string $code A response code from the payment gateway |
27
|
|
|
* @property string $reference A reference provided by the gateway to represent this transaction |
28
|
|
|
* @property string $metadata |
29
|
|
|
* |
30
|
|
|
* @property string $modified |
31
|
|
|
* @property string $created |
32
|
|
|
* |
33
|
|
|
* @method TransactionsTrait getManager |
34
|
|
|
* @method PurchaseTrait getPurchase |
35
|
|
|
* @method Subscription getSubscription |
36
|
|
|
*/ |
37
|
|
|
trait TransactionTrait |
38
|
|
|
{ |
39
|
|
|
use HasPurchaseParent; |
40
|
|
|
use HasTokenRecord; |
41
|
|
|
use HasPaymentMethodRecord; |
42
|
|
|
use HasGatewayRecordTrait; |
43
|
|
|
use TimestampableTrait; |
44
|
|
|
use \ByTIC\Models\SmartProperties\RecordsTraits\HasStatus\RecordTrait; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var string |
48
|
|
|
*/ |
49
|
|
|
protected static $createTimestamps = ['created']; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @var string |
53
|
|
|
*/ |
54
|
|
|
protected static $updateTimestamps = ['modified']; |
55
|
|
|
|
56
|
|
|
public function bootTransactionTrait() |
57
|
|
|
{ |
58
|
|
|
$this->addCast('metadata', AsMetadataObject::class . ':json'); |
|
|
|
|
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param Subscription $method |
63
|
|
|
*/ |
64
|
|
|
public function populateFromSubscription($subscription) |
65
|
|
|
{ |
66
|
|
|
$this->id_subscription = is_object($subscription) ? $subscription->id : $subscription; |
67
|
|
|
} |
68
|
|
|
/** |
69
|
|
|
* @param $key |
70
|
|
|
* @param $value |
71
|
|
|
*/ |
72
|
|
|
public function addMedata($key, $value) |
73
|
|
|
{ |
74
|
|
|
$this->metadata->set($key, $value); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function isSubscription(): bool |
78
|
|
|
{ |
79
|
|
|
return $this->id_subscription > 0; |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|