Completed
Push — master ( 21e228...557ad1 )
by Camilo
03:48 queued 01:51
created

SendInvoice   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 168
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 87.5%

Importance

Changes 0
Metric Value
dl 0
loc 168
ccs 7
cts 8
cp 0.875
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A performSpecialConditions() 0 12 3
A getMandatoryFields() 0 13 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace unreal4u\TelegramAPI\Telegram\Methods;
6
7
use unreal4u\TelegramAPI\Abstracts\TelegramMethods;
8
use unreal4u\TelegramAPI\Telegram\Types\Inline\Keyboard\Markup;
9
use unreal4u\TelegramAPI\Telegram\Types\LabeledPrice;
10
11
/**
12
 * Use this method to send invoices. On success, the sent Message is returned.
13
 *
14
 * Objects defined as-is november 2017
15
 *
16
 * @see https://core.telegram.org/bots/api#sendinvoice
17
 */
18
class SendInvoice extends TelegramMethods
19
{
20
    /**
21
     * Unique identifier for the target private chat
22
     * @var int
23
     */
24
    public $chat_id = 0;
25
26
    /**
27
     * Product name
28
     * @var string
29
     */
30
    public $title = '';
31
32
    /**
33
     * Product description
34
     * @var string
35
     */
36
    public $description = '';
37
38
    /**
39
     * Bot-defined invoice payload, 1-128 bytes. This will not be displayed to the user, use for your internal processes
40
     * @var string
41
     */
42
    public $payload = '';
43
44
    /**
45
     * Payments provider token, obtained via Botfather
46
     * @var string
47
     */
48
    public $provider_token = '';
49
50
    /**
51
     * Unique deep-linking parameter that can be used to generate this invoice when used as a start parameter
52
     * @var string
53
     */
54
    public $start_parameter = '';
55
56
    /**
57
     * Three-letter ISO 4217 currency code, see more on currencies
58
     * @see https://core.telegram.org/bots/payments#supported-currencies
59
     * @var string
60
     */
61
    public $currency = '';
62
63
    /**
64
     * Price breakdown, a list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus,
65
     * etc.)
66
     * @var LabeledPrice[]
67
     */
68
    public $prices = [];
69
70
    /**
71
     * Array data about the invoice, which will be shared with the payment provider. A detailed description of
72
     * required fields should be provided by the payment provider.
73
     *
74
     * The conversion to JSON-encoded string will be handled by the class itself.
75
     * @var array
76
     */
77
    public $provider_data;
78
79
    /**
80
     * Optional. URL of the product photo for the invoice. Can be a photo of the goods or a marketing image for a
81
     * service. People like it better when they see what they are paying for
82
     * @var string
83
     */
84
    public $photo_url = '';
85
86
    /**
87
     * Optional. Photo size
88
     * @var int
89
     */
90
    public $photo_size = 0;
91
92
    /**
93
     * Optional. Photo width
94
     * @var int
95
     */
96
    public $photo_width = 0;
97
98
    /**
99
     * Optional. Photo height
100
     * @var int
101
     */
102
    public $photo_height = 0;
103
104
    /**
105
     * Optional. Pass True, if you require the user's full name to complete the order
106
     * @var bool
107
     */
108
    public $need_name = false;
109
110
    /**
111
     * Optional. Pass True, if you require the user's phone number to complete the order
112
     * @var bool
113
     */
114
    public $need_phone_number = false;
115
116
    /**
117
     * Optional. Pass True, if you require the user's email to complete the order
118
     * @var bool
119
     */
120
    public $need_email = false;
121
122
    /**
123
     * Optional. Pass True, if you require the user's shipping address to complete the order
124
     * @var bool
125
     */
126
    public $need_shipping_address = false;
127
128
    /**
129
     * Optional. Pass True, if the final price depends on the shipping method
130
     * @var bool
131
     */
132
    public $is_flexible = false;
133
134
    /**
135
     * Optional. Sends the message silently. Users will receive a notification with no sound.
136
     * @var bool
137
     */
138
    public $disable_notification = false;
139
140
    /**
141
     * Optional. If the message is a reply, ID of the original message
142
     * @var int
143
     */
144
    public $reply_to_message_id = 0;
145
146
    /**
147
     * Optional. A JSON-serialized object for an inline keyboard. If empty, one 'Pay total price' button will be shown.
148
     * If not empty, the first button must be a Pay button
149
     * @var Markup
150
     */
151
    public $reply_markup;
152
153
    /**
154
     * Prices must be an array of objects, so json_encode() them
155
     *
156
     * @see https://github.com/unreal4u/telegram-api/issues/32
157
     * @return TelegramMethods
158
     */
159 1
    public function performSpecialConditions(): TelegramMethods
160
    {
161 1
        if (!empty($this->prices)) {
162 1
            $this->prices = json_encode($this->prices);
163
        }
164
165 1
        if (!empty($this->provider_data)) {
166
            $this->provider_data = json_encode($this->provider_data);
167
        }
168
169 1
        return parent::performSpecialConditions();
170
    }
171
172 1
    public function getMandatoryFields(): array
173
    {
174
        return [
175 1
            'chat_id',
176
            'title',
177
            'description',
178
            'payload',
179
            'provider_token',
180
            'start_parameter',
181
            'currency',
182
            'prices',
183
        ];
184
    }
185
}
186