Skip to content

Commit

Permalink
Merge pull request #11 from NikitaKharkov/supporting-pre_checkout_query
Browse files Browse the repository at this point in the history
Completed supporting pre checkout query API object
  • Loading branch information
makasim authored Feb 1, 2019
2 parents 7696ef6 + 76b4012 commit 03ab028
Show file tree
Hide file tree
Showing 6 changed files with 197 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/AnswerPreCheckoutQuery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
namespace Formapro\TelegramBot;

use function Makasim\Values\get_value;
use function Makasim\Values\set_value;

class AnswerPreCheckoutQuery
{
private $values = [];

public function __construct(string $preCheckoutQueryId, bool $ok)
{
set_value($this, 'pre_checkout_query_id', $preCheckoutQueryId);
set_value($this, 'ok', $ok);
}

public function getOk(): bool
{
return get_value($this, 'ok');
}

public function getErrorMessage(): ?string
{
return get_value($this, 'error_message');
}

public function setErrorMessage(?string $errorMessage): void
{
set_value($this, 'error_message', $errorMessage);
}
}
7 changes: 7 additions & 0 deletions src/Bot.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ public function answerCallbackQuery(AnswerCallbackQuery $answerCallbackQuery): R
]);
}

public function answerPreCheckoutQuery(AnswerPreCheckoutQuery $answerPreCheckoutQuery): ResponseInterface
{
return $this->httpClient->post($this->getMethodUrl('answerPreCheckoutQuery'), [
'json' => get_values($answerPreCheckoutQuery),
]);
}

private function getMethodUrl(string $method): string
{
return sprintf('https://api.telegram.org/bot%s/%s', $this->token, $method);
Expand Down
53 changes: 53 additions & 0 deletions src/OrderInfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace Formapro\TelegramBot;

use function Makasim\Values\get_object;
use function Makasim\Values\get_value;

class OrderInfo
{
private $values = [];

private $objects = [];

public function getName(): ?string
{
return get_value($this, 'name');
}

public function setName(?string $name): void
{
set_value($this, 'name', $name);
}

public function getPhoneNumber(): ?string
{
return get_value($this, 'phone_number');
}

public function setPhoneNumber(?string $phoneNumber): void
{
set_value($this, 'phone_number', $phoneNumber);
}

public function getEmail(): ?string
{
return get_value($this, 'email');
}

public function setEmail(?string $email): void
{
set_value($this, 'email', $email);
}

public function getShippingAddress(): ?ShippingAddress
{
return get_object($this, 'shipping_address', ShippingAddress::class);
}

public function setShippingAddress(?ShippingAddress $shippingAddress): ?ShippingAddress
{
set_object($this, 'shipping_address', $shippingAddress);
}
}
58 changes: 58 additions & 0 deletions src/PreCheckoutQuery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php
namespace Formapro\TelegramBot;

use function Makasim\Values\get_object;
use function Makasim\Values\get_value;
use function Makasim\Values\set_value;

class PreCheckoutQuery
{
private $values = [];

private $objects = [];

public function getId(): string
{
return get_value($this, 'id');
}

public function getFrom(): User
{
return get_object($this, 'from', User::class);
}

public function getCurrency(): string
{
return get_value($this, 'currency');
}

public function getTotalAmount(): int
{
return get_value($this, 'total_amount');
}

public function getInvoicePayload(): string
{
return get_value($this, 'invoice_payload');
}

public function getShippingOptionId(): ?string
{
return get_value($this, 'shipping_option_id');
}

public function setShippingOptionId(?string $shippingOptionId): void
{
set_value($this, 'shipping_option_id', $shippingOptionId);
}

public function getOrderInfo(): ?OrderInfo
{
return get_object($this, 'order_info', OrderInfo::class);
}

public function setOrderInfo(?OrderInfo $orderInfo): void
{
set_object($this, 'order_info', $orderInfo);
}
}
43 changes: 43 additions & 0 deletions src/ShippingAddress.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace Formapro\TelegramBot;

use function Makasim\Values\get_object;
use function Makasim\Values\get_value;

class ShippingAddress
{
private $values = [];

private $objects = [];

public function getCountryCode(): string
{
return get_value($this, 'country_code');
}

public function getState(): string
{
return get_value($this, 'state');
}

public function getCity(): string
{
return get_value($this, 'city');
}

public function getStreetLine1(): string
{
return get_object($this, 'street_line1');
}

public function getStreetLine2(): string
{
return get_object($this, 'street_line2');
}

public function getPostCode(): string
{
return get_object($this, 'post_code');
}
}
5 changes: 5 additions & 0 deletions src/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ public function getCallbackQuery(): ?CallbackQuery
return get_object($this, 'callback_query', CallbackQuery::class);
}

public function getPreCheckoutQuery(): ?PreCheckoutQuery
{
return get_object($this, 'pre_checkout_query', PreCheckoutQuery::class);
}

public static function create(array $data): self
{
$update = new self();
Expand Down

0 comments on commit 03ab028

Please sign in to comment.