Completed
Push — master ( 7f94ed...cf1f16 )
by Dmitry
01:56
created

Bc::advertiserBalanceGet()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 14
rs 10
cc 1
nc 1
nop 4
1
<?php
2
declare(strict_types=1);
3
4
namespace Promopult\TikTokMarketingApi\Service;
5
6
/**
7
 * Class Bc
8
 *
9
 * Business Center is a central hub that allows organizations and agencies to efficiently manage multiple TikTok ad
10
 * accounts, users, assets, and finances in a secure environment. It is an essential tool for anyone who needs to run,
11
 * place, and oversee multiple TikTok For Business accounts.
12
 *
13
 * @see https://ads.tiktok.com/marketing_api/docs?id=1690849685291009
14
 */
15
final class Bc extends \Promopult\TikTokMarketingApi\AbstractService
16
{
17
    /**
18
     *
19
     * Get a List of Business Center Accounts
20
     *
21
     * @param ?int $bcId        The Business Center ID, when not passed, returns the user's entire list of
22
     *                          Business Centers by default, and returns the specified Business Center account when
23
     *                          passed in.
24
     *
25
     * @param ?int $page        Current number of pages, default value: 1, the value range : ≥ 1
26
     *
27
     * @param ?int $pageSize    Page size, default value: 10, value range: 1-50
28
     *
29
     * @return array
30
     *
31
     * @throws \Throwable
32
     *
33
     * @see https://ads.tiktok.com/marketing_api/docs?id=1690122235145217
34
     */
35
    public function get(?int $bcId = null, ?int $page = null, ?int $pageSize = null): array
36
    {
37
        return $this->requestApi(
38
            'GET',
39
            '/open_api/v1.2/bc/get/',
40
            [
41
                'bc_id' => $bcId,
42
                'page' => $page,
43
                'page_size' => $pageSize
44
            ]
45
        );
46
    }
47
48
    /**
49
     * Get a Business Center Balance
50
     *
51
     * Used to obtain the balance of a Business Center account
52
     *
53
     * @param int $bcId         Business Center ID
54
     *
55
     * @return array
56
     *
57
     * @throws \Throwable
58
     *
59
     * @see https://ads.tiktok.com/marketing_api/docs?id=1690131519696898
60
     */
61
    public function balanceGet(int $bcId): array
62
    {
63
        return $this->requestApi(
64
            'GET',
65
            '/open_api/v1.2/bc/balance/get/',
66
            [
67
                'bc_id' => $bcId,
68
            ]
69
        );
70
    }
71
72
    /**
73
     * Get the Balance on an Ad Account
74
     *
75
     * Note: This interface only returns the Ad Account that the business center has administrator rights to the Ad
76
     * Account.
77
     *
78
     * @param int $bcId         Business Center ID
79
     * @param ?array $filtering Filtering conditions
80
     * @param ?int $page        Current number of pages, default value: 1, the value range : ≥ 1
81
     * @param ?int $pageSize    Page size, default value: 10, value range: 1-50
82
     *
83
     * @return array
84
     *
85
     * @throws \Throwable
86
     *
87
     * @see https://ads.tiktok.com/marketing_api/docs?id=1690131519696898
88
     */
89
    public function advertiserBalanceGet(
90
        int $bcId,
91
        ?array $filtering = null,
92
        ?int $page = null,
93
        ?int $pageSize = null
94
    ): array {
95
        return $this->requestApi(
96
            'GET',
97
            '/open_api/v1.2/advertiser/balance/get/',
98
            [
99
                'bc_id' => $bcId,
100
                'filtering' => $filtering,
101
                'page' => $page,
102
                'page_size' => $pageSize
103
            ]
104
        );
105
    }
106
107
    /**
108
     * Ad Account Creation
109
     *
110
     * @param int $bcId                 Business Center ID
111
     * @param array $advertiserInfo     Ad Account information
112
     * @param array $customerInfo       Business Information
113
     * @param array $qualificationInfo  Qualification information
114
     * @param ?array $contactInfo       Contact Information
115
     * @param ?array $billingInfo       Billing information. Required if the place of registration of the ad account
116
     *                                  is France or Brazil.
117
     *
118
     * @return array
119
     *
120
     * @throws \Throwable
121
     *
122
     * @see https://ads.tiktok.com/marketing_api/docs?id=1690131505474562
123
     */
124
    public function advertiserCreate(
125
        int $bcId,
126
        array $advertiserInfo,
127
        array $customerInfo,
128
        array $qualificationInfo,
129
        ?array $contactInfo = null,
130
        ?array $billingInfo = null
131
    ): array {
132
        return $this->requestApi(
133
            'POST',
134
            '/open_api/v1.2/bc/advertiser/create/',
135
            [
136
                'bc_id' => $bcId,
137
                'advertiser_info' => $advertiserInfo,
138
                'customer_info' => $customerInfo,
139
                'qualification_info' => $qualificationInfo,
140
                'contact_info' => $contactInfo,
141
                'billing_info' => $billingInfo
142
            ]
143
        );
144
    }
145
146
    /**
147
     * Charge Money to or Deduct Money from Ad Account
148
     *
149
     * You can use this endpoint to charge money to or deduct money from an ad account in a Business Center account.
150
     *
151
     * @param int $bcId             Business Center ID
152
     * @param int $advertiserId     Ad Account ID
153
     * @param string $transferType  The transfer type. Enum values:RECHARGE(transfer), REFUND(deduction)
154
     * @param ?float $cashAmount    The amount to process. Rounded to two decimal places. Value range: > 0
155
     * @param ?float $grantAmount   Coupon/voucher amount. Rounded to two decimal places. Value range: > 0
156
     *
157
     * @return array
158
     *
159
     * @throws \Throwable
160
     */
161
    public function transfer(
162
        int $bcId,
163
        int $advertiserId,
164
        string $transferType,
165
        ?float $cashAmount,
166
        ?float $grantAmount = null
167
    ): array {
168
        return $this->requestApi(
169
            'POST',
170
            '/open_api/v1.2/bc/transfer/',
171
            [
172
                'bc_id' => $bcId,
173
                'advertiser_id' => $advertiserId,
174
                'transfer_type' => $transferType,
175
                'cash_amount' => $cashAmount,
176
                'grant_amount' => $grantAmount
177
            ]
178
        );
179
    }
180
181
    /**
182
     * Get the Transaction Record of an Ad Account
183
     * Note: This interface only returns the Ad Account that the business center has administrator rights to the Ad
184
     * Account.
185
     *
186
     * @param int $bcId             Business Center ID
187
     * @param ?array $filtering     Filtering conditions
188
     * @param ?string $start_date   Transaction record search start time, (UTC+0) format:2020-10-12,default is 90 days ago
189
     * @param ?string $end_date     Transaction record search end time, (UTC+0) format:2020-11-12,default is the same day
190
     * @param ?int $page            Current number of pages, default value: 1, the value range : ≥ 1
191
     * @param ?int $pageSize        Page size, default value: 10, value range: 1-50
192
     *
193
     * @return array
194
     *
195
     * @throws \Throwable
196
     *
197
     * @see https://ads.tiktok.com/marketing_api/docs?id=1690131519696898
198
     */
199
    public function transactionGet(
200
        int $bcId,
201
        ?array $filtering = null,
202
        ?string $start_date = null,
203
        ?string $end_date = null,
204
        ?int $page = null,
205
        ?int $pageSize = null
206
    ): array {
207
        return $this->requestApi(
208
            'GET',
209
            '/open_api/v1.2/advertiser/transaction/get/',
210
            [
211
                'bc_id' => $bcId,
212
                'filtering' => $filtering,
213
                'start_date' => $start_date,
214
                'end_date' => $end_date,
215
                'page' => $page,
216
                'page_size' => $pageSize
217
            ]
218
        );
219
    }
220
}
221