Passed
Push — master ( 96d33b...43186b )
by Gabriel
13:27
created

PurchaseSessionTrait::insert()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 5
rs 10
ccs 0
cts 1
cp 0
crap 2
1
<?php
2
3
namespace ByTIC\Payments\Models\PurchaseSessions;
4
5
use ByTIC\DataObjects\Behaviors\Timestampable\TimestampableTrait;
6
use ByTIC\Payments\Models\AbstractModels\HasGateway\HasGatewayRecordTrait;
7
use ByTIC\Payments\Models\AbstractModels\HasPurchaseParent;
8
9
/**
10
 * Trait PurchaseSessionTrait
11
 * @package ByTIC\Payments\Models\PurchaseSessions
12
 *
13
 * @property string $type
14
 * @property string $new_status
15
 * @property string $gateway
16
 * @property string $post
17
 * @property string $get
18
 * @property string $debug
19
 * @property string $created
20
 *
21
 * @method PurchaseSessionsTrait getManager
22
 */
23
trait PurchaseSessionTrait
24
{
25
    use HasPurchaseParent {
26
        populateFromPayment as populateFromPaymentTrait;
27
    }
28
    use HasGatewayRecordTrait;
29
    use TimestampableTrait;
30
31
    /**
32
     * @var string
33
     */
34
    static protected $createTimestamps = ['created'];
35
36
    /**
37
     * @var string
38
     */
39
    static protected $updateTimestamps = [];
40
41
    /**
42
     * @param $payment
43
     * @return $this
44
     */
45
    public function populateFromPayment($payment)
46
    {
47
        $this->populateFromPaymentTrait($payment);
48
        $this->new_status = (string) $payment->status;
49
50
        return $this;
51
    }
52
53
    /**
54
     * @param $response
55
     */
56
    public function populateFromResponse($response)
57
    {
58
        if (method_exists($response, 'getSessionDebug')) {
59
            $this->debug = $this->getManager()::encodeParams($response->getSessionDebug());
60
        }
61
    }
62
63
    public function populateFromRequest()
64
    {
65
        $this->post = $this->getManager()::encodeParams($_POST);
66
        $this->get = $this->getManager()::encodeParams($_GET);
67
    }
68
}
69