ContractTier::listContractTiers()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Fenerum\API;
6
7
class ContractTier extends Base
8
{
9
    /**
10
     * @param string $accountCode
11
     * @param string $contract
12
     * @return array|null
13
     * @throws \Fenerum\API\Exceptions\FenerumApiException
14
     */
15
    public function listContractTiers(string $accountCode, string $contract): ?array
16
    {
17
        return $this->client->get('accounts/'.$accountCode.'/contracts/'.$contract.'/tiers/');
18
    }
19
20
    /**
21
     * @param string $accountCode
22
     * @param string $contract
23
     * @param string $id
24
     * @return array|null
25
     * @throws \Fenerum\API\Exceptions\FenerumApiException
26
     */
27
    public function getContract(string $accountCode, string $contract, string $id): ?array
28
    {
29
        return $this->client->get('accounts/'.$accountCode.'/contracts/'.$contract.'/tiers/'.$id.'/');
30
    }
31
32
    /**
33
     * @param array $data
34
     * @param string $accountCode
35
     * @param string $contract
36
     * @return array|null
37
     * @throws \Fenerum\API\Exceptions\FenerumApiException
38
     * @throws \Fenerum\API\Exceptions\FenerumValidationException
39
     */
40
    public function createContractTier(array $data, string $accountCode, string $contract): ?array
41
    {
42
        $this->validate($data, [
43
            'minimum_quantity' => 'required|integer',
44
            'maximum_quantity' => 'integer',
45
            'discount' => 'string',
46
            'discount_type' => 'required|string',
47
            'overall_flat_discount' => 'string',
48
            'only_apply_to_quantity_above_minimal' => 'boolean',
49
        ]);
50
51
        return $this->client->post('accounts/'.$accountCode.'/contracts/'.$contract.'/tiers/', $data);
52
    }
53
54
    /**
55
     * @param array $data
56
     * @param string $accountCode
57
     * @param string $contract
58
     * @param string $id
59
     * @return array|null
60
     * @throws \Fenerum\API\Exceptions\FenerumApiException
61
     * @throws \Fenerum\API\Exceptions\FenerumValidationException
62
     */
63
    public function updateContractTier(array $data, string $accountCode, string $contract, string $id): ?array
64
    {
65
        $this->validate($data, [
66
            'minimum_quantity' => 'required|integer',
67
            'maximum_quantity' => 'integer',
68
            'discount' => 'string',
69
            'discount_type' => 'required|string',
70
            'overall_flat_discount' => 'string',
71
            'only_apply_to_quantity_above_minimal' => 'boolean',
72
        ]);
73
74
        return $this->client->put('accounts/'.$accountCode.'/contracts/'.$contract.'/tiers/'.$id.'/', $data);
75
    }
76
77
    /**
78
     * @param string $accountCode
79
     * @param string $contract
80
     * @param string $id
81
     * @return array|null
82
     * @throws \Fenerum\API\Exceptions\FenerumApiException
83
     */
84
    public function deleteContractTier(string $accountCode, string $contract, string $id): ?array
85
    {
86
        return $this->client->delete('accounts/'.$accountCode.'/contracts/'.$contract.'/tiers/'.$id.'/');
87
    }
88
}
89