Completed
Push — master ( 989005...ce143f )
by Camilo
04:43
created

AnswerPreCheckoutQuery   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 1
dl 0
loc 39
ccs 0
cts 5
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getMandatoryFields() 0 14 2
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace unreal4u\TelegramAPI\Telegram\Methods;
6
7
use unreal4u\TelegramAPI\Abstracts\TelegramMethods;
8
9
/**
10
 * Once the user has confirmed their payment and shipping details, the Bot API sends the final confirmation in the form
11
 * of an Update with the field pre_checkout_query. Use this method to respond to such pre-checkout queries. On success,
12
 * True is returned. Note: The Bot API must receive an answer within 10 seconds after the pre-checkout query was sent
13
 *
14
 * Objects defined as-is May 2017
15
 *
16
 * @see https://core.telegram.org/bots/api#answerprecheckoutquery
17
 */
18
class AnswerPreCheckoutQuery extends TelegramMethods
19
{
20
    /**
21
     * Unique identifier for the query to be answered
22
     * @var string
23
     */
24
    public $pre_checkout_query_id = '';
25
26
    /**
27
     * Specify True if everything is alright (goods are available, etc.) and the bot is ready to proceed with the order.
28
     * Use False if there are any problems
29
     * @var bool
30
     */
31
    public $ok;
32
33
    /**
34
     * Required if ok is False. Error message in human readable form that explains the reason for failure to proceed
35
     * with the checkout (e.g. "Sorry, somebody just bought the last of our amazing black T-shirts while you were busy
36
     * filling out your payment details. Please choose a different color or garment!"). Telegram will display this
37
     * message to the user
38
     * @var string
39
     */
40
    public $error_message = '';
41
42
    public function getMandatoryFields(): array
43
    {
44
        $return = [
45
            'pre_checkout_query_id',
46
            'ok',
47
        ];
48
49
        // Shipping options are mandatory if ok is set to true, otherwise, error_message is
50
        if ($this->ok === false) {
51
            $return[] = 'error_message';
52
        }
53
54
        return $return;
55
    }
56
}
57