Moved Payment objects

This commit is contained in:
netkas 2024-10-04 15:09:07 -04:00
parent 0662c64ed6
commit 02dedd3e03
13 changed files with 18 additions and 10 deletions

View file

@ -0,0 +1,123 @@
<?php
namespace TgBotLib\Objects\Payments;
use TgBotLib\Interfaces\ObjectTypeInterface;
class Invoice implements ObjectTypeInterface
{
/**
* @var string
*/
private $title;
/**
* @var string
*/
private $description;
/**
* @var string
*/
private $start_parameter;
/**
* @var string
*/
private $currency;
/**
* @var int
*/
private $total_amount;
/**
* 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;
}
/**
* Returns an array representation of the object.
*
* @return array
*/
public function toArray(): array
{
return [
'title' => $this->title,
'description' => $this->description,
'start_parameter' => $this->start_parameter,
'currency' => $this->currency,
'total_amount' => $this->total_amount,
];
}
/**
* Constructs an object from an array representation.
*
* @param array $data
* @return Invoice
*/
public static function fromArray(array $data): self
{
$object = new self();
$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;
return $object;
}
}

View file

@ -0,0 +1,72 @@
<?php
namespace TgBotLib\Objects\Payments;
use TgBotLib\Interfaces\ObjectTypeInterface;
class LabeledPrice implements ObjectTypeInterface
{
/**
* @var string
*/
private $label;
/**
* @var int
*/
private $amount;
/**
* Portion label
*
* @return string
*/
public function getLabel(): string
{
return $this->label;
}
/**
* Price of the product 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#supported-currencies
* @see https://core.telegram.org/bots/payments/currencies.json
* @return int
*/
public function getAmount(): int
{
return $this->amount;
}
/**
* Returns an array representation of the object
*
* @return array
*/
public function toArray(): array
{
return [
'label' => $this->label,
'amount' => $this->amount,
];
}
/**
* Constructs the object from an array representation
*
* @param array $data
* @return LabeledPrice
*/
public static function fromArray(array $data): self
{
$object = new self();
$object->label = $data['label'] ?? null;
$object->amount = $data['amount'] ?? null;
return $object;
}
}

View file

@ -0,0 +1,102 @@
<?php
namespace TgBotLib\Objects\Payments;
use TgBotLib\Interfaces\ObjectTypeInterface;
class OrderInfo implements ObjectTypeInterface
{
/**
* @var string|null
*/
private $name;
/**
* @var string|null
*/
private $phone_number;
/**
* @var string|null
*/
private $email;
/**
* @var ShippingAddress|null
*/
private $shipping_address;
/**
* Optional. User name
*
* @return string|null
*/
public function getName(): ?string
{
return $this->name;
}
/**
* Optional. User's phone number
*
* @return string|null
*/
public function getPhoneNumber(): ?string
{
return $this->phone_number;
}
/**
* Optional. User email
*
* @return string|null
*/
public function getEmail(): ?string
{
return $this->email;
}
/**
* Optional. User shipping address
*
* @return ShippingAddress|null
*/
public function getShippingAddress(): ?ShippingAddress
{
return $this->shipping_address;
}
/**
* Returns an array representation of the object
*
* @return array
*/
public function toArray(): array
{
return [
'name' => $this->name,
'phone_number' => $this->phone_number,
'email' => $this->email,
'shipping_address' => ($this->shipping_address instanceof ShippingAddress) ? $this->shipping_address->toArray() : null,
];
}
/**
* Constructs object from an array representation
*
* @param array $data
* @return OrderInfo
*/
public static function fromArray(array $data): self
{
$object = new self();
$object->name = $data['name'] ?? null;
$object->phone_number = $data['phone_number'] ?? null;
$object->email = $data['email'] ?? null;
$object->shipping_address = ($data['shipping_address'] ?? null) instanceof ShippingAddress ? $data['shipping_address'] : ShippingAddress::fromArray($data['shipping_address'] ?? []);
return $object;
}
}

View file

@ -0,0 +1,155 @@
<?php
namespace TgBotLib\Objects\Payments;
use TgBotLib\Interfaces\ObjectTypeInterface;
use TgBotLib\Objects\User;
class PreCheckoutQuery implements ObjectTypeInterface
{
/**
* @var string
*/
private $id;
/**
* @var User
*/
private $from;
/**
* @var string
*/
private $currency;
/**
* @var int
*/
private $total_amount;
/**
* @var int
*/
private $invoice_payload;
/**
* @var string|null
*/
private $shipping_option_id;
/**
* @var OrderInfo|null
*/
private $order_info;
/**
* Unique query identifier
*
* @return string
*/
public function getId(): string
{
return $this->id;
}
/**
* User who sent the query
*
* @return User
*/
public function getFrom(): User
{
return $this->from;
}
/**
* 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).
*
* @return int
*/
public function getTotalAmount(): int
{
return $this->total_amount;
}
/**
* Bot specified invoice payload
*
* @return int
*/
public function getInvoicePayload(): int
{
return $this->invoice_payload;
}
/**
* Optional. Identifier of the shipping option chosen by the user
*
* @return string|null
*/
public function getShippingOptionId(): ?string
{
return $this->shipping_option_id;
}
/**
* Optional. Order information provided by the user
*
* @return OrderInfo|null
*/
public function getOrderInfo(): ?OrderInfo
{
return $this->order_info;
}
/**
* Returns an array representation of the object
*
* @return array
*/
public function toArray(): array
{
return [
'id' => $this->id,
'from' => ($this->from instanceof ObjectTypeInterface) ? $this->from->toArray() : null,
'currency' => $this->currency,
'total_amount' => $this->total_amount,
'invoice_payload' => $this->invoice_payload,
'shipping_option_id' => $this->shipping_option_id,
'order_info' => ($this->order_info instanceof ObjectTypeInterface) ? $this->order_info->toArray() : null
];
}
/**
* Constructs object from an array representation
*
* @param array $data
* @return PreCheckoutQuery
*/
public static function fromArray(array $data): self
{
$object = new self();
$object->id = $data['id'] ?? null;
$object->from = isset($data['from']) && is_array($data['from']) ? User::fromArray($data['from']) : null;
$object->currency = $data['currency'] ?? null;
$object->total_amount = $data['total_amount'] ?? null;
$object->invoice_payload = $data['invoice_payload'] ?? null;
$object->shipping_option_id = $data['shipping_option_id'] ?? null;
$object->order_info = isset($data['order_info']) && is_array($data['order_info']) ? OrderInfo::fromArray($data['order_info']) : null;
return $object;
}
}

View file

@ -0,0 +1,96 @@
<?php
namespace TgBotLib\Objects\Payments;
use TgBotLib\Interfaces\ObjectTypeInterface;
class RefundedPayment implements ObjectTypeInterface
{
private string $currency;
private int $total_amount;
private string $invoice_payload;
private string $telegram_payment_charge_id;
private ?string $provider_payment_charge_id;
/**
* Three-letter ISO 4217 currency code, or “XTR” for payments in Telegram Stars. Currently, always “XTR”
*
* @return string
*/
public function getCurrency(): string
{
return $this->currency;
}
/**
* Total refunded price in the smallest units of the currency (integer, not float/double). For example,
* for a price of US$ 1.45, total_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).
*
* @return int
*/
public function getTotalAmount(): int
{
return $this->total_amount;
}
/**
* Bot-specified invoice payload
*
* @return string
*/
public function getInvoicePayload(): string
{
return $this->invoice_payload;
}
/**
* Telegram payment identifier
*
* @return string
*/
public function getTelegramPaymentChargeId(): string
{
return $this->telegram_payment_charge_id;
}
/**
* Optional. Provider payment identifier
*
* @return string
*/
public function getProviderPaymentChargeId(): string
{
return $this->provider_payment_charge_id;
}
/**
* @inheritDoc
*/
public function toArray(): array
{
return [
'currency' => $this->currency,
'total_amount' => $this->total_amount,
'invoice_payload' => $this->invoice_payload,
'telegram_payment_charge_id' => $this->telegram_payment_charge_id,
'provider_payment_charge_id' => $this->provider_payment_charge_id,
];
}
/**
* @inheritDoc
*/
public static function fromArray(array $data): ObjectTypeInterface
{
$object = new self();
$object->currency = $data['currency'];
$object->total_amount = $data['total_amount'];
$object->invoice_payload = $data['invoice_payload'];
$object->telegram_payment_charge_id = $data['telegram_payment_charge_id'];
$object->provider_payment_charge_id = $data['provider_payment_charge_id'] ?? null;
return $object;
}
}

View file

@ -0,0 +1,136 @@
<?php
namespace TgBotLib\Objects\Payments;
use TgBotLib\Interfaces\ObjectTypeInterface;
class ShippingAddress implements ObjectTypeInterface
{
/**
* @var string|null
*/
private $country_code;
/**
* @var string|null
*/
private $state;
/**
* @var string|null
*/
private $city;
/**
* @var string|null
*/
private $street_line1;
/**
* @var string|null
*/
private $street_line2;
/**
* @var string|null
*/
private $post_code;
/**
* Two-letter ISO 3166-1 alpha-2 country code
*
* @return string|null
*/
public function getCountryCode(): ?string
{
return $this->country_code;
}
/**
* State, if applicable
*
* @return string|null
*/
public function getState(): ?string
{
return $this->state;
}
/**
* City
*
* @return string|null
*/
public function getCity(): ?string
{
return $this->city;
}
/**
* First line for the address
*
* @return string|null
*/
public function getStreetLine1(): ?string
{
return $this->street_line1;
}
/**
* Second line for the address
*
* @return string|null
*/
public function getStreetLine2(): ?string
{
return $this->street_line2;
}
/**
* Address post code
*
* @return string|null
*/
public function getPostCode(): ?string
{
return $this->post_code;
}
/**
* Returns an array representation of the object.
*
* @return array
*/
public function toArray(): array
{
return [
'country_code' => $this->country_code,
'state' => $this->state,
'city' => $this->city,
'street_line1' => $this->street_line1,
'street_line2' => $this->street_line2,
'post_code' => $this->post_code,
];
}
/**
* Constructs object from an array representation.
*
* @param array $data
* @return ShippingAddress
*/
public static function fromArray(array $data): self
{
$object = new self();
$object->country_code = $data['country_code'] ?? null;
$object->state = $data['state'] ?? null;
$object->city = $data['city'] ?? null;
$object->street_line1 = $data['street_line1'] ?? null;
$object->street_line2 = $data['street_line2'] ?? null;
$object->post_code = $data['post_code'] ?? null;
return $object;
}
}

View file

@ -0,0 +1,88 @@
<?php
namespace TgBotLib\Objects\Payments;
use TgBotLib\Interfaces\ObjectTypeInterface;
class ShippingOption implements ObjectTypeInterface
{
/**
* @var string
*/
private $id;
/**
* @var string
*/
private $title;
/**
* @var LabeledPrice[]
*/
private $prices;
/**
* Shipping option identifier
*
* @return string
*/
public function getId(): string
{
return $this->id;
}
/**
* Option title
*
* @return string
*/
public function getTitle(): string
{
return $this->title;
}
/**
* List of price portions
*
* @return LabeledPrice[]
*/
public function getPrices(): array
{
return $this->prices;
}
/**
* Returns an array representation of the object
*
* @return array
*/
public function toArray(): array
{
return [
'id' => $this->id,
'title' => $this->title,
'prices' => array_map(function (LabeledPrice $price) {
return $price->toArray();
}, $this->prices)
];
}
/**
* Constructs object from an array representation
*
* @param array $data
* @return ShippingOption
*/
public static function fromArray(array $data): self
{
$object = new self();
$object->id = $data['id'];
$object->title = $data['title'];
$object->prices = array_map(function (array $price) {
return LabeledPrice::fromArray($price);
}, $data['prices']);
return $object;
}
}

View file

@ -0,0 +1,103 @@
<?php
namespace TgBotLib\Objects\Payments;
use TgBotLib\Interfaces\ObjectTypeInterface;
use TgBotLib\Objects\User;
class ShippingQuery implements ObjectTypeInterface
{
/**
* @var string
*/
private $id;
/**
* @var User
*/
private $from;
/**
* @var string
*/
private $invoice_payload;
/**
* @var ShippingAddress
*/
private $shipping_address;
/**
* Unique query identifier
*
* @return string
*/
public function getId(): string
{
return $this->id;
}
/**
* User who sent the query
*
* @return User
*/
public function getFrom(): User
{
return $this->from;
}
/**
* Bot specified invoice payload
*
* @return string
*/
public function getInvoicePayload(): string
{
return $this->invoice_payload;
}
/**
* User specified shipping address
*
* @return ShippingAddress
*/
public function getShippingAddress(): ShippingAddress
{
return $this->shipping_address;
}
/**
* Returns an array representation of the object
*
* @return array
*/
public function toArray(): array
{
return [
'id' => $this->id,
'from' => ($this->from instanceof User) ? $this->from->toArray() : $this->from,
'invoice_payload' => $this->invoice_payload,
'shipping_address' => ($this->shipping_address instanceof ShippingAddress) ? $this->shipping_address->toArray() : $this->shipping_address,
];
}
/**
* Constructs object from an array representation
*
* @param array $data
* @return ShippingQuery
*/
public static function fromArray(array $data): self
{
$object = new self();
$object->id = $data['id'] ?? null;
$object->from = isset($data['from']) && is_array($data['from']) ? User::fromArray($data['from']) : $data['from'];
$object->invoice_payload = $data['invoice_payload'] ?? null;
$object->shipping_address = isset($data['shipping_address']) && is_array($data['shipping_address']) ? ShippingAddress::fromArray($data['shipping_address']) : $data['shipping_address'];
return $object;
}
}

View file

@ -0,0 +1,157 @@
<?php
namespace TgBotLib\Objects\Payments;
use TgBotLib\Interfaces\ObjectTypeInterface;
class SuccessfulPayment implements ObjectTypeInterface
{
/**
* @var string
*/
private $currency;
/**
* @var string
*/
private $total_amount;
/**
* @var string
*/
private $invoice_payload;
/**
* @var string|null
*/
private $shipping_option_id;
/**
* @var OrderInfo|null
*/
private $order_info;
/**
* @var string
*/
private $telegram_payment_charge_id;
/**
* @var string
*/
private $provider_payment_charge_id;
/**
* 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 string
*/
public function getTotalAmount(): string
{
return $this->total_amount;
}
/**
* Bot specified invoice payload
*
* @return string
*/
public function getInvoicePayload(): string
{
return $this->invoice_payload;
}
/**
* Optional. Identifier of the shipping option chosen by the user
*
* @return string|null
*/
public function getShippingOptionId(): ?string
{
return $this->shipping_option_id;
}
/**
* Optional. Order information provided by the user
*
* @return OrderInfo|null
*/
public function getOrderInfo(): ?OrderInfo
{
return $this->order_info;
}
/**
* Telegram payment identifier
*
* @return string
*/
public function getTelegramPaymentChargeId(): string
{
return $this->telegram_payment_charge_id;
}
/**
* Provider payment identifier
*
* @return string
*/
public function getProviderPaymentChargeId(): string
{
return $this->provider_payment_charge_id;
}
/**
* Returns an array representation of the object
*
* @return array
*/
public function toArray(): array
{
return [
'currency' => $this->currency,
'total_amount' => $this->total_amount,
'invoice_payload' => $this->invoice_payload,
'shipping_option_id' => $this->shipping_option_id,
'order_info' => ($this->order_info instanceof ObjectTypeInterface) ? $this->order_info->toArray() : null,
'telegram_payment_charge_id' => $this->telegram_payment_charge_id,
'provider_payment_charge_id' => $this->provider_payment_charge_id,
];
}
/**
* Constructs object from an array representation
*
* @param array $data
* @return SuccessfulPayment
*/
public static function fromArray(array $data): self
{
$object = new self();
$object->currency = $data['currency'] ?? null;
$object->total_amount = $data['total_amount'] ?? null;
$object->invoice_payload = $data['invoice_payload'] ?? null;
$object->shipping_option_id = $data['shipping_option_id'] ?? null;
$object->order_info = isset($data['order_info']) ? OrderInfo::fromArray($data['order_info']) : null;
$object->telegram_payment_charge_id = $data['telegram_payment_charge_id'] ?? null;
$object->provider_payment_charge_id = $data['provider_payment_charge_id'] ?? null;
return $object;
}
}