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