CompletePurchaseRequest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 23
c 1
b 0
f 1
dl 0
loc 61
rs 10
ccs 0
cts 20
cp 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A updateParametersFromGateway() 0 4 1
A parseNotification() 0 16 2
A isValidNotification() 0 3 1
A getData() 0 9 2
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 Traits\HasKeysTrait;
19
    use \ByTIC\Omnipay\Common\Message\Traits\SendDataRequestTrait;
20
    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...
21
    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...
22
        getData as getDataNotificationTrait;
23
    }
24
    use HasGatewayRequestTrait;
25
26
    /**
27
     * @inheritdoc
28
     */
29
    public function getData(): array
30
    {
31
        $return = $this->getDataNotificationTrait();
32
        // Add model only if has data
33
        if (count($return)) {
34
            $return['model'] = $this->getModel();
35
        }
36
37
        return $return;
38
    }
39
    /**
40
     * @return mixed
41
     */
42
    public function isValidNotification()
43
    {
44
        return $this->hasGet('stpsid');
45
    }
46
47
    /**
48
     * @return bool|mixed
49
     * @throws \Exception
50
     */
51
    protected function parseNotification()
52
    {
53
        if ($this->validateModel()) {
54
            $model = $this->getModel();
55
            $this->updateParametersFromPurchase($model);
56
        }
57
58
        // Retrieve the session that would have been started earlier.
59
        \Stripe\Stripe::setApiKey($this->getApiKey());
60
61
        $session = \Stripe\Checkout\Session::retrieve($this->httpRequest->query->get('stpsid'));
62
        $paymentIntent = \Stripe\PaymentIntent::retrieve($session->payment_intent);
63
64
        return [
65
            'session' => $session,
66
            'paymentIntent' => $paymentIntent
67
        ];
68
    }
69
70
    /**
71
     * @param Gateway $modelGateway
72
     */
73
    protected function updateParametersFromGateway(Gateway $modelGateway)
74
    {
75
        $this->setPublicKey($modelGateway->getPublicKey());
76
        $this->setApiKey($modelGateway->getApiKey());
77
    }
78
}
79