SendInvoiceMethod   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 183
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
eloc 35
dl 0
loc 183
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A create() 0 26 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace TgBotApi\BotApiBase\Method;
6
7
use TgBotApi\BotApiBase\Method\Interfaces\SendMethodAliasInterface;
8
use TgBotApi\BotApiBase\Method\Traits\FillFromArrayTrait;
9
use TgBotApi\BotApiBase\Method\Traits\SendToChatVariablesTrait;
10
use TgBotApi\BotApiBase\Type\InlineKeyboardMarkupType;
11
use TgBotApi\BotApiBase\Type\LabeledPriceType;
12
13
/**
14
 * Class SendInvoiceMethod.
15
 *
16
 * @see https://core.telegram.org/bots/api#sendinvoice
17
 */
18
class SendInvoiceMethod implements SendMethodAliasInterface
19
{
20
    use FillFromArrayTrait;
21
    use SendToChatVariablesTrait;
22
23
    /**
24
     * Product name, 1-32 characters.
25
     *
26
     * @var string
27
     */
28
    public $title;
29
30
    /**
31
     * Product description, 1-255 characters.
32
     *
33
     * @var string
34
     */
35
    public $description;
36
37
    /**
38
     * Bot-defined invoice payload, 1-128 bytes.
39
     * This will not be displayed to the user, use for your internal processes.
40
     *
41
     * @var string
42
     */
43
    public $payload;
44
45
    /**
46
     * Payments provider token, obtained via Botfather.
47
     *
48
     * @var string
49
     */
50
    public $providerToken;
51
52
    /**
53
     * Unique deep-linking parameter that can be used to generate this invoice when used as a start parameter.
54
     *
55
     * @var string
56
     */
57
    public $startParameter;
58
59
    /**
60
     * Three-letter ISO 4217 currency code, see more on currencies.
61
     *
62
     * @var string
63
     */
64
    public $currency;
65
66
    /**
67
     * Price breakdown, a list of components
68
     * (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.).
69
     *
70
     * @var LabeledPriceType[]
71
     */
72
    public $prices;
73
74
    /**
75
     * Optional. JSON-encoded data about the invoice, which will be shared with the payment provider.
76
     * A detailed description of required fields should be provided by the payment provider.
77
     *
78
     * @var string|null
79
     */
80
    public $providerData;
81
82
    /**
83
     * Optional. URL of the product photo for the invoice.
84
     * Can be a photo of the goods or a marketing image for a service.
85
     * People like it better when they see what they are paying for.
86
     *
87
     * @var string|null
88
     */
89
    public $photoUrl;
90
91
    /**
92
     * Optional. Photo size.
93
     *
94
     * @var int|null
95
     */
96
    public $photoSize;
97
98
    /**
99
     * Optional. Photo width.
100
     *
101
     * @var int|null
102
     */
103
    public $photoWidth;
104
105
    /**
106
     * Optional. Photo height.
107
     *
108
     * @var int|null
109
     */
110
    public $photoHeight;
111
112
    /**
113
     * Optional. Pass True, if you require the user's full name to complete the order.
114
     *
115
     * @var bool|null
116
     */
117
    public $needName;
118
119
    /**
120
     * Optional. Pass True, if you require the user's phone number to complete the order.
121
     *
122
     * @var bool|null
123
     */
124
    public $needPhoneNumber;
125
126
    /**
127
     * Optional. Pass True, if you require the user's email address to complete the order.
128
     *
129
     * @var bool|null
130
     */
131
    public $needEmail;
132
133
    /**
134
     * Optional. Pass True, if you require the user's shipping address to complete the order.
135
     *
136
     * @var bool|null
137
     */
138
    public $needShippingAddress;
139
140
    /**
141
     * Optional. Pass True, if user's phone number should be sent to provider.
142
     *
143
     * @var bool|null
144
     */
145
    public $sendPhoneNumberToProvider;
146
147
    /**
148
     * Optional. Pass True, if user's email address should be sent to provider.
149
     *
150
     * @var bool|null
151
     */
152
    public $sendEmailToProvider;
153
154
    /**
155
     * Optional. Pass True, if the final price depends on the shipping method.
156
     *
157
     * @var bool|null
158
     */
159
    public $isFlexible;
160
161
    /**
162
     * Optional. A JSON-serialized object for an inline keyboard. If empty, one 'Pay total price' button will be shown.
163
     * If not empty, the first button must be a Pay button.
164
     *
165
     * @var InlineKeyboardMarkupType|null
166
     */
167
    public $replyMarkup;
168
169
    /**
170
     * @param int|string         $chatId
171
     * @param LabeledPriceType[] $prices
172
     *
173
     * @throws \TgBotApi\BotApiBase\Exception\BadArgumentException
174
     */
175 1
    public static function create(
176
        $chatId,
177
        string $title,
178
        string $description,
179
        string $payload,
180
        string $providerToken,
181
        string $startParameter,
182
        string $currency,
183
        array $prices,
184
        array $data = null
185
    ): SendInvoiceMethod {
186 1
        $instance = new static();
187 1
        $instance->chatId = $chatId;
188 1
        $instance->title = $title;
189 1
        $instance->description = $description;
190 1
        $instance->payload = $payload;
191 1
        $instance->providerToken = $providerToken;
192 1
        $instance->startParameter = $startParameter;
193 1
        $instance->currency = $currency;
194 1
        $instance->prices = $prices;
195
196 1
        if ($data) {
197 1
            $instance->fill($data);
198
        }
199
200 1
        return $instance;
201
    }
202
}
203