Passed
Push — master ( c05883...1d5c29 )
by Nikolay
02:30
created

AnswerPreCheckoutQueryMethod   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
eloc 13
dl 0
loc 56
ccs 0
cts 14
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createFail() 0 8 1
A createSuccess() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace TgBotApi\BotApiBase\Method;
6
7
/**
8
 * Class AnswerPreCheckoutQueryMethod.
9
 *
10
 * Once the user has confirmed their payment and shipping details,
11
 * the Bot API sends the final confirmation in the form of an Update with the field pre_checkout_query.
12
 * Use this method to respond to such pre-checkout queries. On success, True is returned.
13
 * Note: The Bot API must receive an answer within 10 seconds after the pre-checkout query was sent.
14
 *
15
 * @see https://core.telegram.org/bots/api#answerprecheckoutquery
16
 */
17
class AnswerPreCheckoutQueryMethod
18
{
19
    /**
20
     * Unique identifier for the query to be answered.
21
     *
22
     * @var string
23
     */
24
    public $preCheckoutQueryId;
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
     *
30
     * @var bool
31
     */
32
    public $ok;
33
34
    /**
35
     * Optional. Required if ok is False.
36
     * Error message in human readable form that explains the reason for failure to proceed with the checkout
37
     * (e.g. "Sorry, somebody just bought the last of our amazing black T-shirts while you
38
     * were busy filling out your payment details. Please choose a different color or garment!").
39
     * Telegram will display this message to the user.
40
     *
41
     * @var string|null
42
     */
43
    public $errorMessage;
44
45
    /**
46
     * @param string $preCheckoutQueryId
47
     *
48
     * @return AnswerPreCheckoutQueryMethod
49
     */
50
    public static function createSuccess(string $preCheckoutQueryId): AnswerPreCheckoutQueryMethod
51
    {
52
        $instance = new static();
53
        $instance->preCheckoutQueryId = $preCheckoutQueryId;
54
        $instance->ok = true;
55
56
        return $instance;
57
    }
58
59
    /**
60
     * @param string $preCheckoutQueryId
61
     * @param string $errorMessage
62
     *
63
     * @return AnswerPreCheckoutQueryMethod
64
     */
65
    public static function createFail(string $preCheckoutQueryId, string $errorMessage): AnswerPreCheckoutQueryMethod
66
    {
67
        $instance = new static();
68
        $instance->preCheckoutQueryId = $preCheckoutQueryId;
69
        $instance->ok = false;
70
        $instance->errorMessage = $errorMessage;
71
72
        return $instance;
73
    }
74
}
75