1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of the PayBreak/basket package. |
4
|
|
|
* |
5
|
|
|
* (c) PayBreak <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace PayBreak\Sdk\Gateways; |
12
|
|
|
use PayBreak\Sdk\Entities\GroupEntity; |
13
|
|
|
use PayBreak\Sdk\Entities\ProductEntity; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Product Gateway |
17
|
|
|
* |
18
|
|
|
* @author EB |
19
|
|
|
* @package PayBreak\Sdk\Gateways |
20
|
|
|
*/ |
21
|
|
|
class ProductGateway extends AbstractGateway |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @param string $extId |
25
|
|
|
* @param string $token |
26
|
|
|
* @return GroupEntity |
27
|
|
|
*/ |
28
|
2 |
|
public function getProductGroupsWithProducts($extId, $token) |
29
|
|
|
{ |
30
|
2 |
|
$response = $this->fetchDocument( |
31
|
2 |
|
'/v4/installations/' . $extId . '/product-groups?with=products', |
32
|
2 |
|
$token, |
33
|
|
|
'listGroupsWithProducts' |
34
|
2 |
|
); |
35
|
|
|
|
36
|
2 |
|
foreach($response as &$group) { |
37
|
|
|
foreach($group['products'] as &$product) { |
38
|
|
|
$product = ProductEntity::make($product); |
39
|
|
|
} |
40
|
|
|
$group = GroupEntity::make($group); |
41
|
2 |
|
} |
42
|
|
|
|
43
|
2 |
|
return $response; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @author WN |
48
|
|
|
* @param string $installation |
49
|
|
|
* @param string $product |
50
|
|
|
* @param string $token |
51
|
|
|
* @param array $params |
52
|
|
|
* @return array |
53
|
|
|
*/ |
54
|
|
|
public function getCreditInfo($installation, $product, $token, array $params) |
55
|
|
|
{ |
56
|
|
|
return $this->postDocument( |
57
|
|
|
'/v4/installations/' . $installation . '/products/' . $product . '/get-credit-information', |
58
|
|
|
$params, |
59
|
|
|
$token, |
60
|
|
|
'CreditInfo' |
61
|
|
|
); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @param string $extId |
66
|
|
|
* @param string $productGroup |
67
|
|
|
* @param string $token |
68
|
|
|
* @return array |
69
|
|
|
* @author SL |
70
|
|
|
*/ |
71
|
|
View Code Duplication |
public function getProductsInGroup($extId, $productGroup, $token) |
|
|
|
|
72
|
|
|
{ |
73
|
|
|
$response = $this->fetchDocument( |
74
|
|
|
'/v4/installations/' . $extId . '/product-groups/' . $productGroup . '/products', |
75
|
|
|
$token, |
76
|
|
|
'getProductsByGroup' |
77
|
|
|
); |
78
|
|
|
|
79
|
|
|
$products = []; |
80
|
|
|
|
81
|
|
|
foreach($response as $product) { |
82
|
|
|
$products[] = ProductEntity::make($product); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
return $products; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* author EA |
90
|
|
|
* @param string $installation |
91
|
|
|
* @param string $token |
92
|
|
|
* @param array $params |
93
|
|
|
* @return array |
94
|
|
|
*/ |
95
|
|
|
public function orderProducts($installation, $token, array $params) |
96
|
|
|
{ |
97
|
|
|
return $this->postDocument( |
98
|
|
|
'/v4/installations/' . $installation . '/products/set-product-order', |
99
|
|
|
$params, |
100
|
|
|
$token, |
101
|
|
|
'orderProducts' |
102
|
|
|
); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* author EA |
107
|
|
|
* @param string $installation |
108
|
|
|
* @param string $token |
109
|
|
|
* @return array |
110
|
|
|
*/ |
111
|
|
View Code Duplication |
public function getProducts($installation, $token) |
|
|
|
|
112
|
|
|
{ |
113
|
|
|
$response = $this->fetchDocument( |
114
|
|
|
'/v4/installations/' . $installation . '/products', |
115
|
|
|
$token, |
116
|
|
|
'listProducts' |
117
|
|
|
); |
118
|
|
|
|
119
|
|
|
$products = []; |
120
|
|
|
|
121
|
|
|
foreach($response as $product) { |
122
|
|
|
$products[] = ProductEntity::make($product); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
return $products; |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.