tgbotlib/src/TgBotLib/Objects/Payments/Invoice.php

103 lines
2.8 KiB
PHP
Raw Normal View History

2023-02-13 23:19:30 -05:00
<?php
2024-10-04 15:09:07 -04:00
namespace TgBotLib\Objects\Payments;
2023-02-13 23:19:30 -05:00
use TgBotLib\Interfaces\ObjectTypeInterface;
class Invoice implements ObjectTypeInterface
{
2024-10-04 15:15:00 -04:00
private string $title;
private string $description;
private string $start_parameter;
private string $currency;
private int $total_amount;
2023-02-13 23:19:30 -05:00
/**
* Product name
*
* @return string
*/
public function getTitle(): string
{
return $this->title;
}
/**
* Product description
*
* @return string
*/
public function getDescription(): string
{
return $this->description;
}
/**
* Unique bot deep-linking parameter that can be used to generate this invoice
*
* @return string
*/
public function getStartParameter(): string
{
return $this->start_parameter;
}
/**
* Three-letter ISO 4217 currency code
*
* @see https://core.telegram.org/bots/payments#supported-currencies
* @return string
*/
public function getCurrency(): string
{
return $this->currency;
}
/**
* Total price in the smallest units of the currency (integer, not float/double). For example, for a price of
* US$ 1.45 pass amount = 145. See the exp parameter in currencies.json, it shows the number of digits past the
* decimal point for each currency (2 for the majority of currencies).
*
* @see https://core.telegram.org/bots/payments/currencies.json
* @return int
*/
public function getTotalAmount(): int
{
return $this->total_amount;
}
/**
2024-10-04 15:15:00 -04:00
* @inheritDoc
2023-02-13 23:19:30 -05:00
*/
public function toArray(): array
{
return [
'title' => $this->title,
'description' => $this->description,
'start_parameter' => $this->start_parameter,
'currency' => $this->currency,
'total_amount' => $this->total_amount,
];
}
/**
2024-10-04 15:15:00 -04:00
* @inheritDoc
2023-02-13 23:19:30 -05:00
*/
2024-10-04 15:15:00 -04:00
public static function fromArray(?array $data): ?Invoice
2023-02-13 23:19:30 -05:00
{
2024-10-04 15:15:00 -04:00
if($data === null)
{
return null;
}
2023-02-13 23:19:30 -05:00
2024-10-04 15:15:00 -04:00
$object = new self();
2023-02-14 17:35:16 -05:00
$object->title = $data['title'] ?? null;
$object->description = $data['description'] ?? null;
$object->start_parameter = $data['start_parameter'] ?? null;
$object->currency = $data['currency'] ?? null;
$object->total_amount = $data['total_amount'] ?? null;
2023-02-13 23:19:30 -05:00
return $object;
}
}