Passed
Push — main ( db3674...c4348d )
by Gabriel
05:36 queued 02:36
created

updateParametersFromGateway()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 2
c 1
b 0
f 1
nc 1
nop 1
dl 0
loc 4
ccs 0
cts 3
cp 0
crap 2
rs 10
1
<?php
2
3
namespace ByTIC\Payments\Stripe\Message;
4
5
use ByTIC\Omnipay\Common\Message\Traits\GatewayNotificationRequestTrait;
6
use ByTIC\Payments\Gateways\Providers\AbstractGateway\Message\Traits\HasGatewayRequestTrait;
7
use ByTIC\Payments\Gateways\Providers\AbstractGateway\Message\Traits\HasModelRequest;
8
use ByTIC\Payments\Stripe\Gateway;
9
10
/**
11
 * Class PurchaseResponse
12
 * @package ByTIC\Payments\Gateways\Providers\Paylike\Message
13
 *
14
 * @method CompletePurchaseResponse send
15
 */
16
class CompletePurchaseRequest extends AbstractCheckoutRequest
17
{
18
    use \ByTIC\Omnipay\Common\Message\Traits\SendDataRequestTrait;
19
    use HasModelRequest;
0 ignored issues
show
introduced by
The trait ByTIC\Payments\Gateways\...\Traits\HasModelRequest requires some properties which are not provided by ByTIC\Payments\Stripe\Me...CompletePurchaseRequest: $query, $id
Loading history...
20
    use GatewayNotificationRequestTrait {
0 ignored issues
show
introduced by
The trait ByTIC\Omnipay\Common\Mes...otificationRequestTrait requires some properties which are not provided by ByTIC\Payments\Stripe\Me...CompletePurchaseRequest: $query, $request
Loading history...
21
        getData as getDataNotificationTrait;
22
    }
23
    use HasGatewayRequestTrait;
24
25
    /**
26
     * @inheritdoc
27
     */
28
    public function getData(): array
29
    {
30
        $return = $this->getDataNotificationTrait();
31
        // Add model only if has data
32
        if (count($return)) {
33
            $return['model'] = $this->getModel();
34
        }
35
36
        return $return;
37
    }
38
    /**
39
     * @return mixed
40
     */
41
    public function isValidNotification()
42
    {
43
        return $this->hasGet('stpsid');
44
    }
45
46
    /**
47
     * @return bool|mixed
48
     * @throws \Exception
49
     */
50
    protected function parseNotification()
51
    {
52
        if ($this->validateModel()) {
53
            $model = $this->getModel();
54
            $this->updateParametersFromPurchase($model);
55
        }
56
57
        // Retrieve the session that would have been started earlier.
58
        \Stripe\Stripe::setApiKey($this->getApiKey());
59
60
        $session = \Stripe\Checkout\Session::retrieve($this->httpRequest->query->get('stpsid'));
61
        $paymentIntent = \Stripe\PaymentIntent::retrieve($session->payment_intent);
62
63
        return [
64
            'session' => $session,
65
            'paymentIntent' => $paymentIntent
66
        ];
67
    }
68
69
    /**
70
     * @param Gateway $modelGateway
71
     */
72
    protected function updateParametersFromGateway(Gateway $modelGateway)
73
    {
74
        $this->setPublicKey($modelGateway->getPublicKey());
75
        $this->setApiKey($modelGateway->getApiKey());
76
    }
77
}
78