Completed
Push — draft ( f5c2f2...2c1ae4 )
by Nikolay
02:24
created

AnswerPreCheckoutQueryMethod::createFail()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 6
c 0
b 0
f 0
ccs 0
cts 6
cp 0
rs 10
cc 1
nc 1
nop 2
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Greenplugin\TelegramBot\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
    public static function createSuccess(string $preCheckoutQueryId)
49
    {
50
        $instance = new self();
51
        $instance->preCheckoutQueryId = $preCheckoutQueryId;
52
        $instance->ok = true;
53
    }
54
55
    /**
56
     * @param string $preCheckoutQueryId
57
     * @param string $errorMessage
58
     */
59
    public static function createFail(string $preCheckoutQueryId, string $errorMessage)
60
    {
61
        $instance = new self();
62
        $instance->preCheckoutQueryId = $preCheckoutQueryId;
63
        $instance->ok = false;
64
        $instance->errorMessage = $errorMessage;
65
    }
66
}
67