Bc::advertiserBalanceGet()   A
last analyzed

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