Passed
Push — master ( b2ca99...77b7f1 )
by Gabriel
05:51 queued 13s
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
eloc 2
c 0
b 0
f 0
dl 0
loc 5
ccs 0
cts 3
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
7
/**
8
 * Trait PurchaseSessionTrait
9
 * @package ByTIC\Payments\Models\PurchaseSessions
10
 *
11
 * @property string $type
12
 * @property string $new_status
13
 * @property string $gateway
14
 * @property string $post
15
 * @property string $get
16
 * @property string $debug
17
 * @property string $created
18
 */
19
trait PurchaseSessionTrait
20
{
21
    /**
22
     * @param $payment
23
     * @return $this
24
     */
25
    public function populateFromPayment($payment)
26
    {
27
        $this->{$this->getPurchaseFk()} = $payment->id;
28
        $this->new_status = $payment->status;
29
30
        return $this;
31
    }
32
33
    /**
34
     * @param $response
35
     */
36
    public function populateFromResponse($response)
37
    {
38
        if (method_exists($response,'getSessionDebug')) {
39
            $this->debug = $response->getSessionDebug();
40
        }
41
    }
42
43
    /**
44
     * @param AbstractGateway $gateway
45
     */
46
    public function populateFromGateway($gateway)
47
    {
48
        $this->gateway = $gateway->getName();
49
    }
50
51
    /**
52
     *
53
     */
54
    public function populateFromRequest()
55
    {
56
        $this->post = base64_encode(gzcompress(serialize($_POST)));
57
        $this->get = base64_encode(gzcompress(serialize($_GET)));
58
    }
59
60
    /**
61
     * @inheritdoc
62
     */
63
    public function insert()
64
    {
65
        $this->created = date('Y-m-d H:i:s');
66
67
        return parent::insert();
68
    }
69
70
    /**
71
     * @return string
72
     */
73
    protected function getPurchaseFk()
74
    {
75
        return 'id_purchase';
76
    }
77
}
78