From 80afea08826d76302ad80882078846c604d8655d Mon Sep 17 00:00:00 2001 From: Netkas Date: Tue, 14 Feb 2023 15:13:58 -0500 Subject: [PATCH] Added \TgBotLib\Objects > SuccessfulPayment --- src/TgBotLib/Objects/SuccessfulPayment.php | 158 +++++++++++++++++++++ 1 file changed, 158 insertions(+) create mode 100644 src/TgBotLib/Objects/SuccessfulPayment.php diff --git a/src/TgBotLib/Objects/SuccessfulPayment.php b/src/TgBotLib/Objects/SuccessfulPayment.php new file mode 100644 index 0000000..b5dbb20 --- /dev/null +++ b/src/TgBotLib/Objects/SuccessfulPayment.php @@ -0,0 +1,158 @@ +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 OrderInfo) ? $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 ObjectTypeInterface + */ + 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->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']; + $object->provider_payment_charge_id = $data['provider_payment_charge_id']; + + return $object; + } + } \ No newline at end of file