Skip to content

Commit 065c8eb

Browse files
authored
Merge pull request #34 from tg-bot-api/bugfix/33
Bugfix/33
2 parents a6cda5a + 6cd7432 commit 065c8eb

File tree

4 files changed

+64
-6
lines changed

4 files changed

+64
-6
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip
2222
### Security
2323
- Nothing
2424
--->
25+
26+
## 1.5.1 - 2020-05-28
27+
28+
### Fixed
29+
- fixed SendInvoiceMethod normalization #33.
30+
2531
## 1.5.0 - 2020-04-24
2632

2733
#### April 24, 2020

src/BotApiNormalizer.php

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use TgBotApi\BotApiBase\Normalizer\EditMessageResponseNormalizer;
1717
use TgBotApi\BotApiBase\Normalizer\InputFileNormalizer;
1818
use TgBotApi\BotApiBase\Normalizer\InputMediaNormalizer;
19+
use TgBotApi\BotApiBase\Normalizer\InvoiceNormalizer;
1920
use TgBotApi\BotApiBase\Normalizer\JsonSerializableNormalizer;
2021
use TgBotApi\BotApiBase\Normalizer\LegacyObjectNormalizerWrapper;
2122
use TgBotApi\BotApiBase\Normalizer\MediaGroupNormalizer;
@@ -76,6 +77,7 @@ public function normalize($method): BotApiRequestInterface
7677

7778
$serializer = new Serializer([
7879
new PollNormalizer($objectNormalizer),
80+
new InvoiceNormalizer($objectNormalizer),
7981
new SetMyCommandsNormalizer($objectNormalizer),
8082
new InputFileNormalizer($files),
8183
new MediaGroupNormalizer(new InputMediaNormalizer($objectNormalizer, $files), $objectNormalizer),

src/Normalizer/InvoiceNormalizer.php

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TgBotApi\BotApiBase\Normalizer;
6+
7+
use Symfony\Component\Serializer\Exception\ExceptionInterface;
8+
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
9+
use Symfony\Component\Serializer\Serializer;
10+
use TgBotApi\BotApiBase\Method\SendInvoiceMethod;
11+
12+
class InvoiceNormalizer implements NormalizerInterface
13+
{
14+
/**
15+
* @var NormalizerInterface
16+
*/
17+
private $objectNormalizer;
18+
19+
/**
20+
* JsonSerializableNormalizer constructor.
21+
*/
22+
public function __construct(NormalizerInterface $objectNormalizer)
23+
{
24+
$this->objectNormalizer = $objectNormalizer;
25+
}
26+
27+
/**
28+
* @param SendInvoiceMethod $topic
29+
* @param null $format
30+
*
31+
* @throws ExceptionInterface
32+
*
33+
* @return array|bool|false|float|int|string
34+
*/
35+
public function normalize($topic, $format = null, array $context = [])
36+
{
37+
$serializer = new Serializer([
38+
new JsonSerializableNormalizer($this->objectNormalizer),
39+
$this->objectNormalizer,
40+
]);
41+
42+
$topic->prices = \json_encode($serializer->normalize($topic->prices, null, ['skip_null_values' => true]));
43+
44+
return $serializer->normalize($topic, null, ['skip_null_values' => true]);
45+
}
46+
47+
/**
48+
* @param mixed $data
49+
* @param null $format
50+
*/
51+
public function supportsNormalization($data, $format = null): bool
52+
{
53+
return $data instanceof SendInvoiceMethod;
54+
}
55+
}

tests/Method/SendInvoiceMethodTest.php

+1-6
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ public function testEncode()
2323
$this->getApi()->send($this->getMethod());
2424
}
2525

26-
/**
27-
* @return BotApiComplete
28-
*/
2926
private function getApi(): BotApiComplete
3027
{
3128
return $this->getBot('sendInvoice', [
@@ -52,13 +49,11 @@ private function getApi(): BotApiComplete
5249
'disable_notification' => true,
5350
'reply_to_message_id' => 1,
5451
'reply_markup' => $this->buildInlineMarkupArray(),
55-
], [], ['reply_markup']);
52+
], [], ['reply_markup', 'prices']);
5653
}
5754

5855
/**
5956
* @throws \TgBotApi\BotApiBase\Exception\BadArgumentException
60-
*
61-
* @return SendInvoiceMethod
6257
*/
6358
private function getMethod(): SendInvoiceMethod
6459
{

0 commit comments

Comments
 (0)