Skip to content

Commit 76b4012

Browse files
committed
Completed supporting pre checkout query API object
1 parent 7696ef6 commit 76b4012

File tree

6 files changed

+197
-0
lines changed

6 files changed

+197
-0
lines changed

src/AnswerPreCheckoutQuery.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
namespace Formapro\TelegramBot;
3+
4+
use function Makasim\Values\get_value;
5+
use function Makasim\Values\set_value;
6+
7+
class AnswerPreCheckoutQuery
8+
{
9+
private $values = [];
10+
11+
public function __construct(string $preCheckoutQueryId, bool $ok)
12+
{
13+
set_value($this, 'pre_checkout_query_id', $preCheckoutQueryId);
14+
set_value($this, 'ok', $ok);
15+
}
16+
17+
public function getOk(): bool
18+
{
19+
return get_value($this, 'ok');
20+
}
21+
22+
public function getErrorMessage(): ?string
23+
{
24+
return get_value($this, 'error_message');
25+
}
26+
27+
public function setErrorMessage(?string $errorMessage): void
28+
{
29+
set_value($this, 'error_message', $errorMessage);
30+
}
31+
}

src/Bot.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,13 @@ public function answerCallbackQuery(AnswerCallbackQuery $answerCallbackQuery): R
122122
]);
123123
}
124124

125+
public function answerPreCheckoutQuery(AnswerPreCheckoutQuery $answerPreCheckoutQuery): ResponseInterface
126+
{
127+
return $this->httpClient->post($this->getMethodUrl('answerPreCheckoutQuery'), [
128+
'json' => get_values($answerPreCheckoutQuery),
129+
]);
130+
}
131+
125132
private function getMethodUrl(string $method): string
126133
{
127134
return sprintf('https://api.telegram.org/bot%s/%s', $this->token, $method);

src/OrderInfo.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
namespace Formapro\TelegramBot;
4+
5+
use function Makasim\Values\get_object;
6+
use function Makasim\Values\get_value;
7+
8+
class OrderInfo
9+
{
10+
private $values = [];
11+
12+
private $objects = [];
13+
14+
public function getName(): ?string
15+
{
16+
return get_value($this, 'name');
17+
}
18+
19+
public function setName(?string $name): void
20+
{
21+
set_value($this, 'name', $name);
22+
}
23+
24+
public function getPhoneNumber(): ?string
25+
{
26+
return get_value($this, 'phone_number');
27+
}
28+
29+
public function setPhoneNumber(?string $phoneNumber): void
30+
{
31+
set_value($this, 'phone_number', $phoneNumber);
32+
}
33+
34+
public function getEmail(): ?string
35+
{
36+
return get_value($this, 'email');
37+
}
38+
39+
public function setEmail(?string $email): void
40+
{
41+
set_value($this, 'email', $email);
42+
}
43+
44+
public function getShippingAddress(): ?ShippingAddress
45+
{
46+
return get_object($this, 'shipping_address', ShippingAddress::class);
47+
}
48+
49+
public function setShippingAddress(?ShippingAddress $shippingAddress): ?ShippingAddress
50+
{
51+
set_object($this, 'shipping_address', $shippingAddress);
52+
}
53+
}

src/PreCheckoutQuery.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
namespace Formapro\TelegramBot;
3+
4+
use function Makasim\Values\get_object;
5+
use function Makasim\Values\get_value;
6+
use function Makasim\Values\set_value;
7+
8+
class PreCheckoutQuery
9+
{
10+
private $values = [];
11+
12+
private $objects = [];
13+
14+
public function getId(): string
15+
{
16+
return get_value($this, 'id');
17+
}
18+
19+
public function getFrom(): User
20+
{
21+
return get_object($this, 'from', User::class);
22+
}
23+
24+
public function getCurrency(): string
25+
{
26+
return get_value($this, 'currency');
27+
}
28+
29+
public function getTotalAmount(): int
30+
{
31+
return get_value($this, 'total_amount');
32+
}
33+
34+
public function getInvoicePayload(): string
35+
{
36+
return get_value($this, 'invoice_payload');
37+
}
38+
39+
public function getShippingOptionId(): ?string
40+
{
41+
return get_value($this, 'shipping_option_id');
42+
}
43+
44+
public function setShippingOptionId(?string $shippingOptionId): void
45+
{
46+
set_value($this, 'shipping_option_id', $shippingOptionId);
47+
}
48+
49+
public function getOrderInfo(): ?OrderInfo
50+
{
51+
return get_object($this, 'order_info', OrderInfo::class);
52+
}
53+
54+
public function setOrderInfo(?OrderInfo $orderInfo): void
55+
{
56+
set_object($this, 'order_info', $orderInfo);
57+
}
58+
}

src/ShippingAddress.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
namespace Formapro\TelegramBot;
4+
5+
use function Makasim\Values\get_object;
6+
use function Makasim\Values\get_value;
7+
8+
class ShippingAddress
9+
{
10+
private $values = [];
11+
12+
private $objects = [];
13+
14+
public function getCountryCode(): string
15+
{
16+
return get_value($this, 'country_code');
17+
}
18+
19+
public function getState(): string
20+
{
21+
return get_value($this, 'state');
22+
}
23+
24+
public function getCity(): string
25+
{
26+
return get_value($this, 'city');
27+
}
28+
29+
public function getStreetLine1(): string
30+
{
31+
return get_object($this, 'street_line1');
32+
}
33+
34+
public function getStreetLine2(): string
35+
{
36+
return get_object($this, 'street_line2');
37+
}
38+
39+
public function getPostCode(): string
40+
{
41+
return get_object($this, 'post_code');
42+
}
43+
}

src/Update.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ public function getCallbackQuery(): ?CallbackQuery
2727
return get_object($this, 'callback_query', CallbackQuery::class);
2828
}
2929

30+
public function getPreCheckoutQuery(): ?PreCheckoutQuery
31+
{
32+
return get_object($this, 'pre_checkout_query', PreCheckoutQuery::class);
33+
}
34+
3035
public static function create(array $data): self
3136
{
3237
$update = new self();

0 commit comments

Comments
 (0)