Passed
Push — master ( c0f464...9c6e80 )
by Gabriel
11:21
created

PurchaseSessionTrait::getPurchaseFk()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace ByTIC\Payments\Models\PurchaseSessions;
4
5
use ByTIC\Payments\Gateways\Providers\AbstractGateway\Traits\GatewayTrait as AbstractGateway;
6
use ByTIC\Payments\Models\AbstractModels\HasPurchaseParent;
7
8
/**
9
 * Trait PurchaseSessionTrait
10
 * @package ByTIC\Payments\Models\PurchaseSessions
11
 *
12
 * @property string $type
13
 * @property string $new_status
14
 * @property string $gateway
15
 * @property string $post
16
 * @property string $get
17
 * @property string $debug
18
 * @property string $created
19
 *
20
 * @method PurchaseSessionsTrait getManager
21
 */
22
trait PurchaseSessionTrait
23
{
24
    use HasPurchaseParent {
25
        populateFromPayment as populateFromPaymentTrait;
26
    }
27
28
    /**
29
     * @param $payment
30
     * @return $this
31
     */
32
    public function populateFromPayment($payment)
33
    {
34
        $this->populateFromPaymentTrait($payment);
35
        $this->new_status = (string) $payment->status;
36
37
        return $this;
38
    }
39
40
    /**
41
     * @param $response
42
     */
43
    public function populateFromResponse($response)
44
    {
45
        if (method_exists($response, 'getSessionDebug')) {
46
            $this->debug = $this->getManager()::encodeParams($response->getSessionDebug());
47
        }
48
    }
49
50
    /**
51
     * @param AbstractGateway $gateway
52
     */
53
    public function populateFromGateway($gateway)
54
    {
55
        $this->gateway = $gateway->getName();
56
    }
57
58
    /**
59
     *
60
     */
61
    public function populateFromRequest()
62
    {
63
        $this->post = $this->getManager()::encodeParams($_POST);
64
        $this->get = $this->getManager()::encodeParams($_GET);
65
    }
66
67
    /**
68
     * @inheritdoc
69
     */
70
    public function insert()
71
    {
72
        $this->created = date('Y-m-d H:i:s');
73
74
        return parent::insert();
75
    }
76
}
77