TransactionTrait::isSubscription()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
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');
0 ignored issues
show
Bug introduced by
It seems like addCast() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

58
        $this->/** @scrutinizer ignore-call */ 
59
               addCast('metadata', AsMetadataObject::class . ':json');
Loading history...
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