Completed
Push — master ( b0359c...aafcb0 )
by Camilo
02:48
created

SendInvoice::performSpecialConditions()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

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