Completed
Push — master ( 6f9361...424eb0 )
by Evan
11:41
created

ProductGateway::getProductGroupsWithProducts()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3.3332

Importance

Changes 3
Bugs 1 Features 0
Metric Value
c 3
b 1
f 0
dl 0
loc 17
ccs 8
cts 12
cp 0.6667
rs 9.4285
cc 3
eloc 10
nc 3
nop 2
crap 3.3332
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