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