1 | <?php |
||||||||
2 | |||||||||
3 | namespace ByTIC\Payments\Models\PurchaseSessions; |
||||||||
4 | |||||||||
5 | use ByTIC\Payments\Actions\GatewayNotifications\CreateSessionFromResponse; |
||||||||
6 | use ByTIC\Payments\Gateways\Providers\AbstractGateway\Message\Traits\CompletePurchaseResponseTrait; |
||||||||
7 | use ByTIC\Payments\Models\Purchase\Traits\IsPurchasableModelTrait; |
||||||||
8 | use ByTIC\Payments\Models\PurchaseSessions\Traits\Cleanup\RecordsTrait as CleanupRecordsTrait; |
||||||||
9 | use ByTIC\Payments\Utility\PaymentsModels; |
||||||||
10 | use Omnipay\Common\Message\ResponseInterface; |
||||||||
11 | |||||||||
12 | /** |
||||||||
13 | * Trait PurchaseSessionsTrait |
||||||||
14 | * @package ByTIC\Payments\Models\PurchaseSessions |
||||||||
15 | * |
||||||||
16 | * @method PurchaseSessionTrait getNew |
||||||||
17 | */ |
||||||||
18 | trait PurchaseSessionsTrait |
||||||||
19 | { |
||||||||
20 | use CleanupRecordsTrait; |
||||||||
21 | |||||||||
22 | /** |
||||||||
23 | * @param string $type |
||||||||
24 | * @param CompletePurchaseResponseTrait|ResponseInterface $response |
||||||||
25 | * @return PurchaseSessionTrait |
||||||||
26 | */ |
||||||||
27 | public function createFromResponse($response, $type) |
||||||||
28 | { |
||||||||
29 | return CreateSessionFromResponse::handle($response, $response->getModel(), $type); |
||||||||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() The method
getModel() does not exist on Omnipay\Common\Message\ResponseInterface . Did you maybe mean getCode() ?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() The call to
ByTIC\Payments\Actions\G...nFromResponse::handle() has too many arguments starting with $response->getModel() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above. ![]() $response of type ByTIC\Payments\Gateways\...ssage\ResponseInterface is incompatible with the type ByTIC\Payments\Actions\G...ations\NotificationData expected by parameter $notification of ByTIC\Payments\Actions\G...nFromResponse::handle() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
30 | } |
||||||||
31 | |||||||||
32 | /** |
||||||||
33 | * @param string $type |
||||||||
34 | * @param IsPurchasableModelTrait $payment |
||||||||
35 | * @return PurchaseSessionTrait |
||||||||
36 | */ |
||||||||
37 | public function createFromPurchase($payment, $type) |
||||||||
38 | { |
||||||||
39 | $session = $this->generateFromPurchaseType($payment, $type); |
||||||||
40 | $session->insert(); |
||||||||
0 ignored issues
–
show
It seems like
insert() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
41 | |||||||||
42 | return $session; |
||||||||
43 | } |
||||||||
44 | |||||||||
45 | /** |
||||||||
46 | * @param $params |
||||||||
47 | * @return mixed |
||||||||
48 | */ |
||||||||
49 | public static function decodeParams($params) |
||||||||
50 | { |
||||||||
51 | if (empty($params)) { |
||||||||
52 | return $params; |
||||||||
53 | } |
||||||||
54 | return unserialize(gzuncompress(base64_decode($params))); |
||||||||
55 | } |
||||||||
56 | |||||||||
57 | public static function encodeParams($params) |
||||||||
58 | { |
||||||||
59 | return base64_encode(gzcompress(serialize($params))); |
||||||||
60 | } |
||||||||
61 | |||||||||
62 | protected function initRelations() |
||||||||
63 | { |
||||||||
64 | parent::initRelations(); |
||||||||
65 | } |
||||||||
66 | |||||||||
67 | protected function initRelationsCommon() |
||||||||
68 | { |
||||||||
69 | $this->initRelationsPurchase(); |
||||||||
70 | } |
||||||||
71 | |||||||||
72 | protected function initRelationsPurchase() |
||||||||
73 | { |
||||||||
74 | $this->belongsTo('Purchase', ['class' => get_class(PaymentsModels::purchases())]); |
||||||||
0 ignored issues
–
show
It seems like
belongsTo() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
75 | } |
||||||||
76 | |||||||||
77 | /** |
||||||||
78 | * @param array $params |
||||||||
79 | */ |
||||||||
80 | protected function injectParams(&$params = []) |
||||||||
81 | { |
||||||||
82 | $params['order'][] = ['created', 'desc']; |
||||||||
83 | |||||||||
84 | parent::injectParams($params); |
||||||||
85 | } |
||||||||
86 | |||||||||
87 | /** |
||||||||
88 | * @param IsPurchasableModelTrait $payment |
||||||||
89 | * @param string $type |
||||||||
90 | * @return PurchaseSessionTrait |
||||||||
91 | */ |
||||||||
92 | public function generateFromPurchaseType($payment, $type) |
||||||||
93 | { |
||||||||
94 | $session = $this->generateFromPurchase($payment); |
||||||||
95 | $session->type = $type; |
||||||||
96 | return $session; |
||||||||
97 | } |
||||||||
98 | |||||||||
99 | /** |
||||||||
100 | * @param IsPurchasableModelTrait $payment |
||||||||
101 | * @return PurchaseSessionTrait |
||||||||
102 | */ |
||||||||
103 | protected function generateFromPurchase($payment) |
||||||||
104 | { |
||||||||
105 | $session = $this->getNew(); |
||||||||
106 | $session->populateFromPayment($payment); |
||||||||
107 | $session->populateFromGateway($payment->getPaymentMethod()->getType()->getGateway()); |
||||||||
108 | $session->populateFromRequest(); |
||||||||
109 | |||||||||
110 | return $session; |
||||||||
111 | } |
||||||||
112 | |||||||||
113 | /** |
||||||||
114 | * @return mixed|\Nip\Config\Config |
||||||||
115 | * @throws \Exception |
||||||||
116 | */ |
||||||||
117 | protected function generateTable() |
||||||||
118 | { |
||||||||
119 | return config('payments.tables.purchases_sessions', 'purchases_sessions'); |
||||||||
120 | } |
||||||||
121 | } |
||||||||
122 |