|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Greenplugin\TelegramBot\Method; |
|
6
|
|
|
|
|
7
|
|
|
use Greenplugin\TelegramBot\Type\ShippingOption; |
|
8
|
|
|
use phpDocumentor\Reflection\Types\This; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Class AnswerShippingQueryMethod. |
|
12
|
|
|
* |
|
13
|
|
|
* @see https://core.telegram.org/bots/api#answershippingquery |
|
14
|
|
|
*/ |
|
15
|
|
|
class AnswerShippingQueryMethod |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* Unique identifier for the query to be answered. |
|
19
|
|
|
* |
|
20
|
|
|
* @var string |
|
21
|
|
|
*/ |
|
22
|
|
|
public $shippingQueryId; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Specify True if delivery to the specified address is possible and False if there are any problems |
|
26
|
|
|
* (for example, if delivery to the specified address is not possible). |
|
27
|
|
|
* |
|
28
|
|
|
* @var bool |
|
29
|
|
|
*/ |
|
30
|
|
|
public $ok; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Optional. Required if ok is True. A JSON-serialized array of available shipping options. |
|
34
|
|
|
* |
|
35
|
|
|
* @var ShippingOption[]|null |
|
36
|
|
|
*/ |
|
37
|
|
|
public $shippingOptions; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Optional. Required if ok is False. |
|
41
|
|
|
* Error message in human readable form that explains why it is impossible to complete the order |
|
42
|
|
|
* (e.g. "Sorry, delivery to your desired address is unavailable'). |
|
43
|
|
|
* Telegram will display this message to the user. |
|
44
|
|
|
* |
|
45
|
|
|
* @var string|null |
|
46
|
|
|
*/ |
|
47
|
|
|
public $errorMessage; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @param string $shippingQueryId |
|
51
|
|
|
* @param array $shippingOptions |
|
52
|
|
|
*/ |
|
53
|
|
|
public static function createSuccess(string $shippingQueryId, array $shippingOptions) |
|
54
|
|
|
{ |
|
55
|
|
|
$instance = new self(); |
|
56
|
|
|
$instance->shippingQueryId = $shippingQueryId; |
|
57
|
|
|
$instance->ok = true; |
|
58
|
|
|
$instance->shippingOptions = $shippingOptions; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @param string $shippingQueryId |
|
63
|
|
|
* @param string $errorMessage |
|
64
|
|
|
*/ |
|
65
|
|
|
public static function createFail(string $shippingQueryId, string $errorMessage) |
|
66
|
|
|
{ |
|
67
|
|
|
$instance = new self(); |
|
68
|
|
|
$instance->shippingQueryId = $shippingQueryId; |
|
69
|
|
|
$instance->ok = false; |
|
70
|
|
|
$instance->errorMessage = $errorMessage; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @param ShippingOption $shippingOption |
|
75
|
|
|
*/ |
|
76
|
|
|
public function addShippingOption(ShippingOption $shippingOption) |
|
77
|
|
|
{ |
|
78
|
|
|
$this->shippingOptions[] = $shippingOption; |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|