ProductGateway::getProductsInGroup()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 15
ccs 0
cts 10
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 3
crap 6
1
<?php
2
/*
3
* This file is part of the PayBreak/paybreak-sdk-php 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
13
use PayBreak\Sdk\Entities\GroupEntity;
14
use PayBreak\Sdk\Entities\ProductEntity;
15
16
/**
17
 * Product Gateway
18
 *
19
 * @author EB
20
 * @package PayBreak\Sdk\Gateways
21
 */
22
class ProductGateway extends AbstractGateway
23
{
24
    /**
25
     * @param string $extId
26
     * @param string $token
27
     * @return GroupEntity
28
     */
29 1
    public function getProductGroupsWithProducts($extId, $token)
30
    {
31 1
        $response = $this->fetchDocument(
32 1
            '/v4/installations/' . $extId . '/product-groups?with=products',
33 1
            $token,
34
            'listGroupsWithProducts'
35 1
        );
36
37 1
        foreach ($response as &$group) {
38
            foreach ($group['products'] as &$product) {
39
                $product = ProductEntity::make($product);
40
            }
41
            $group = GroupEntity::make($group);
42 1
        }
43
44 1
        return $response;
45
    }
46
47
    /**
48
     * @author WN
49
     * @param string $installation
50
     * @param string $product
51
     * @param string $token
52
     * @param array $params
53
     * @return array
54
     */
55
    public function getCreditInfo($installation, $product, $token, array $params)
56
    {
57
        return $this->postDocument(
58
            '/v4/installations/' . $installation . '/products/' . $product . '/get-credit-information',
59
            $params,
60
            $token,
61
            'CreditInfo'
62
        );
63
    }
64
65
    /**
66
     * @param string $extId
67
     * @param string $productGroup
68
     * @param string $token
69
     * @return array
70
     * @author SL
71
     */
72
    public function getProductsInGroup($extId, $productGroup, $token)
73
    {
74
        $response = $this->fetchDocument(
75
            '/v4/installations/' . $extId . '/product-groups/' . $productGroup . '/products',
76
            $token,
77
            'getProductsByGroup'
78
        );
79
80
        $products = [];
81
82
        foreach ($response as $product) {
83
            $products[] = ProductEntity::make($product);
84
        }
85
86
        return $products;
87
    }
88
89
    /**
90
     * author EA
91
     * @param string $installation
92
     * @param string $token
93
     * @param array $params
94
     * @return array
95
     */
96
    public function orderProducts($installation, $token, array $params)
97
    {
98
        return $this->postDocument(
99
            '/v4/installations/' . $installation . '/products/set-product-order',
100
            $params,
101
            $token,
102
            'orderProducts'
103
        );
104
    }
105
106
    /**
107
     * author EA
108
     * @param string $installation
109
     * @param string $token
110
     * @return array
111
     */
112
    public function getProducts($installation, $token)
113
    {
114
        $response = $this->fetchDocument(
115
            '/v4/installations/' . $installation . '/products',
116
            $token,
117
            'listProducts'
118
        );
119
120
        $products = [];
121
122
        foreach ($response as $product) {
123
            $products[] = ProductEntity::make($product);
124
        }
125
126
        return $products;
127
    }
128
129
    /**
130
     * author GK
131
     * @param string $installation
132
     * @param string $product
133
     * @param string $token
134
     * @return ProductEntity
135
     */
136 1
    public function getProduct($installation, $product, $token)
137
    {
138 1
        $response = $this->fetchDocument(
139 1
            '/v4/installations/' . $installation . '/products/' . $product,
140 1
            $token,
141
            'getProduct'
142 1
        );
143
144 1
        return ProductEntity::make($response);
145
    }
146
}
147