Skip to content

Commit

Permalink
Merge pull request #34 from tg-bot-api/bugfix/33
Browse files Browse the repository at this point in the history
Bugfix/33
  • Loading branch information
greenplugin authored May 27, 2020
2 parents a6cda5a + 6cd7432 commit 065c8eb
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip
### Security
- Nothing
--->

## 1.5.1 - 2020-05-28

### Fixed
- fixed SendInvoiceMethod normalization #33.

## 1.5.0 - 2020-04-24

#### April 24, 2020
Expand Down
2 changes: 2 additions & 0 deletions src/BotApiNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use TgBotApi\BotApiBase\Normalizer\EditMessageResponseNormalizer;
use TgBotApi\BotApiBase\Normalizer\InputFileNormalizer;
use TgBotApi\BotApiBase\Normalizer\InputMediaNormalizer;
use TgBotApi\BotApiBase\Normalizer\InvoiceNormalizer;
use TgBotApi\BotApiBase\Normalizer\JsonSerializableNormalizer;
use TgBotApi\BotApiBase\Normalizer\LegacyObjectNormalizerWrapper;
use TgBotApi\BotApiBase\Normalizer\MediaGroupNormalizer;
Expand Down Expand Up @@ -76,6 +77,7 @@ public function normalize($method): BotApiRequestInterface

$serializer = new Serializer([
new PollNormalizer($objectNormalizer),
new InvoiceNormalizer($objectNormalizer),
new SetMyCommandsNormalizer($objectNormalizer),
new InputFileNormalizer($files),
new MediaGroupNormalizer(new InputMediaNormalizer($objectNormalizer, $files), $objectNormalizer),
Expand Down
55 changes: 55 additions & 0 deletions src/Normalizer/InvoiceNormalizer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

declare(strict_types=1);

namespace TgBotApi\BotApiBase\Normalizer;

use Symfony\Component\Serializer\Exception\ExceptionInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
use Symfony\Component\Serializer\Serializer;
use TgBotApi\BotApiBase\Method\SendInvoiceMethod;

class InvoiceNormalizer implements NormalizerInterface
{
/**
* @var NormalizerInterface
*/
private $objectNormalizer;

/**
* JsonSerializableNormalizer constructor.
*/
public function __construct(NormalizerInterface $objectNormalizer)
{
$this->objectNormalizer = $objectNormalizer;
}

/**
* @param SendInvoiceMethod $topic
* @param null $format
*
* @throws ExceptionInterface
*
* @return array|bool|false|float|int|string
*/
public function normalize($topic, $format = null, array $context = [])
{
$serializer = new Serializer([
new JsonSerializableNormalizer($this->objectNormalizer),
$this->objectNormalizer,
]);

$topic->prices = \json_encode($serializer->normalize($topic->prices, null, ['skip_null_values' => true]));

return $serializer->normalize($topic, null, ['skip_null_values' => true]);
}

/**
* @param mixed $data
* @param null $format
*/
public function supportsNormalization($data, $format = null): bool
{
return $data instanceof SendInvoiceMethod;
}
}
7 changes: 1 addition & 6 deletions tests/Method/SendInvoiceMethodTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ public function testEncode()
$this->getApi()->send($this->getMethod());
}

/**
* @return BotApiComplete
*/
private function getApi(): BotApiComplete
{
return $this->getBot('sendInvoice', [
Expand All @@ -52,13 +49,11 @@ private function getApi(): BotApiComplete
'disable_notification' => true,
'reply_to_message_id' => 1,
'reply_markup' => $this->buildInlineMarkupArray(),
], [], ['reply_markup']);
], [], ['reply_markup', 'prices']);
}

/**
* @throws \TgBotApi\BotApiBase\Exception\BadArgumentException
*
* @return SendInvoiceMethod
*/
private function getMethod(): SendInvoiceMethod
{
Expand Down

0 comments on commit 065c8eb

Please sign in to comment.