<?xml version="1.0" encoding="utf-8" ?><rss version="2.0" xmlns:tt="http://teletype.in/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:media="http://search.yahoo.com/mrss/"><channel><title>Muxammad Mamajonov</title><generator>teletype.in</generator><description><![CDATA[Muxammad Mamajonov]]></description><image><url>https://img2.teletype.in/files/9c/e7/9ce7b12a-1f39-48dd-9db3-e348d133b26f.png</url><title>Muxammad Mamajonov</title><link>https://teletype.in/@muxammaddev</link></image><link>https://teletype.in/@muxammaddev?utm_source=teletype&amp;utm_medium=feed_rss&amp;utm_campaign=muxammaddev</link><atom:link rel="self" type="application/rss+xml" href="https://teletype.in/rss/muxammaddev?offset=0"></atom:link><atom:link rel="next" type="application/rss+xml" href="https://teletype.in/rss/muxammaddev?offset=10"></atom:link><atom:link rel="search" type="application/opensearchdescription+xml" title="Teletype" href="https://teletype.in/opensearch.xml"></atom:link><pubDate>Tue, 24 Nov 2026 00:36:21 GMT</pubDate><lastBuildDate>Tue, 24 Nov 2026 00:36:21 GMT</lastBuildDate><item><guid isPermaLink="true">https://teletype.in/@muxammaddev/dTqgih5-inF</guid><link>https://teletype.in/@muxammaddev/dTqgih5-inF?utm_source=teletype&amp;utm_medium=feed_rss&amp;utm_campaign=muxammaddev</link><comments>https://teletype.in/@muxammaddev/dTqgih5-inF?utm_source=teletype&amp;utm_medium=feed_rss&amp;utm_campaign=muxammaddev#comments</comments><dc:creator>muxammaddev</dc:creator><title>AIOgram3 18. Connecting payment Telegram Stars</title><pubDate>Wed, 30 Apr 2025 14:18:40 GMT</pubDate><media:content medium="image" url="https://img3.teletype.in/files/28/8d/288de24d-69c4-4419-a869-49d0fc2eec94.png"></media:content><description><![CDATA[<img src="https://habrastorage.org/r/w1560/getpro/habr/upload_files/231/b16/09a/231b1609aeb9dedc359bab4f2404ec7b.png"></img>On June 6, Pavel Durov announced that Telegram was introducing a new currency — Stars. Stars will allow you to purchase digital goods and services, or, in other words, pay for purchases within Telegram, for example, in bots or MiniApps. However, not everything is so rosy. The introduction of a new payment method entails the disabling of all other payment methods. If your bot accepted payments through UKassa, now only &quot;Stars&quot; will be accepted. We will leave the reasons for such changes out of the equation and focus on more important things, namely, how to implement a new payment method — Telegram Stars — into a Telegram bot.]]></description><content:encoded><![CDATA[
  <figure id="UqnJ" class="m_retina">
    <img src="https://habrastorage.org/r/w1560/getpro/habr/upload_files/231/b16/09a/231b1609aeb9dedc359bab4f2404ec7b.png" width="780" />
  </figure>
  <p id="GCMS">On June 6, Pavel Durov announced that Telegram was introducing a new currency — Stars. Stars will allow you to purchase digital goods and services, or, in other words, pay for purchases within Telegram, for example, in bots or MiniApps. However, not everything is so rosy. The introduction of a new payment method entails the disabling of all other payment methods. If your bot accepted payments through UKassa, now only &quot;Stars&quot; will be accepted. We will leave the reasons for such changes out of the equation and focus on more important things, namely, how to implement a new payment method — Telegram Stars — into a Telegram bot.</p>
  <p id="4dp2">You can purchase stars by opening Telegram settings and finding the &quot;Telegram Stars&quot; item.</p>
  <figure id="rNFq" class="m_original">
    <img src="https://img4.teletype.in/files/3b/a2/3ba22317-7dcf-49c6-bd84-f491e1613549.png" width="446" />
  </figure>
  <p id="nF5B"><strong>It is worth noting.</strong> At the time of writing, there was no up-to-date information on how and where to use the stars received from users. The article will be supplemented as information from Telegram is updated. If you know anything, let us know!</p>
  <p id="vkWc">Attention! The post is a continuation of the series &quot; <a href="https://pressanybutton.ru/category/telegram-bot-na-aiogram3/" target="_blank">Telegram bot on AIOgram3</a> &quot;.</p>
  <h3 id="2Iup">Updating dependencies</h3>
  <p id="E8PI">For full support of the new payment method, AIOgram version 3.7.0 is required. To update the library, simply run the command:</p>
  <pre id="ogvn">pip install -U aiogram</pre>
  <p id="SBBF">After that, update the version in the <code>requirements.txt</code>.</p>
  <pre id="YNDY">aiogram==3.7.0</pre>
  <h3 id="TngW">Payment button</h3>
  <p id="Iqq6">Before we start writing the invoice command handler, we need to create a payment button that will open a payment window when clicked.</p>
  <p id="4w2Y">In the package <code>botlogic</code>we will create a new package <code>keyboards</code>, and in it a file <code>payment_keyboard.py</code>.</p>
  <p id="ydY4">Let&#x27;s write a function <code>payment_keyboard</code>that doesn&#x27;t accept anything.</p>
  <p id="7Ux9">In the body of the function, we will create a variable <code>builder</code>in which we will define an instance of the class <code>InlineKeyboardBuilder</code>.</p>
  <p id="KrOf">You can pass a list of lists with objects of the button class to it, but this is not very convenient, it is easier to use class methods. On the next line, we call the method of the class object <code>.button</code>, which adds the button to the keyboard collector. We pass two arguments:</p>
  <ul id="na5k">
    <li id="J40g"><code>text</code>— Defines the text on the button. If the text contains <code>XTR</code>a star emoji ⭐️, it will automatically be replaced with the Telegram Stars icon.</li>
    <li id="OVcz"><code>pay</code>— Defines the button type as a payment button.</li>
  </ul>
  <p id="OIZm">Next, we return the variable <code>builder</code>by applying the method to it <code>.as_markup</code>to get an object ready to be placed in the keyboard message.</p>
  <h4 id="zozu">File code:</h4>
  <pre id="FBb2">from aiogram.utils.keyboard import InlineKeyboardBuilder      

def payment_keyboard():
      builder = InlineKeyboardBuilder()
      builder.button(text=f&quot;Оплатить 20 ⭐️&quot;, pay=True)        
      return builder.as_markup()</pre>
  <p id="A2kw">Creating a keyboard is not necessary, you can send an invoice without it. However, it allows you to customize the button text, as well as add additional functional buttons, such as cancel payment, select another product, etc.</p>
  <h3 id="y04U">Invoice Processor</h3>
  <p id="GcHM">Let&#x27;s start writing the command handler.</p>
  <p id="NIJ4">In the package <code>handlers</code>we will create a file <code>payment.py</code>.</p>
  <p id="9SCN">In this file we will write an asynchronous function <code>send_invoice_handler</code>that accepts <code>message</code>an object of the class <code>Message</code>.</p>
  <p id="yq3F">Let&#x27;s create a variable <code>prices</code>in which we&#x27;ll place a list with objects of the class <code>LabeledPrice</code>, or rather, with one object, since for payment via Telegram Stars this list must consist of one element. We pass the following arguments to the class object:</p>
  <ul id="4gSJ">
    <li id="alxG"><code>label</code>— Definition of currency. In our case it is <code>XTR</code>.</li>
    <li id="FoCK"><code>amount</code>— Cost in stars.</li>
  </ul>
  <p id="fXRp">Next, <code>message</code>we call the method on the variable <code>.answer_invoice</code>so that the bot responds to the user&#x27;s message with a button with an invoice for payment. We pass the following arguments to the method:</p>
  <ul id="ULrJ">
    <li id="TEff"><code>title</code>— Name of payment, product or service.</li>
    <li id="2ILY"><code>description</code>— Description of payment, product or service.</li>
    <li id="uZYZ"><code>prices</code>— A list of objects <code>LabeledPrice</code>previously defined in the variable of the same name.</li>
    <li id="SH2N"><code>provider_token</code>— Payment system token, for Telegram Stars we simply send an empty string.</li>
    <li id="EqCu"><code>payload</code>— Payment label. It is not displayed to the user, but can be used to separate payments by their types, etc. Maximum 128 bytes of data (in Python, one character takes up one byte, but keep in mind that special characters or emojis may take up more space).</li>
    <li id="NSnA"><code>currency</code>— Payment currency, for Telegram Stars it is <code>XTR</code>.</li>
    <li id="F816"><code>reply_markup</code>— Keyboard object.</li>
  </ul>
  <h4 id="Iwa8">Handler code:</h4>
  <pre id="JM8C">from aiogram.types import LabeledPrice, Message    
from botlogic.keyboards.payment_keyboard import payment_keyboard      

async def send_invoice_handler(message: Message):
      prices = [LabeledPrice(label=&quot;XTR&quot;, amount=20)]      
      await message.answer_invoice(          
            title=&quot;Поддержка канала&quot;,          
            description=&quot;Поддержать канал на 20 звёзд!&quot;,          
            prices=prices,          
            provider_token=&quot;&quot;,          
            payload=&quot;channel_support&quot;,          
            currency=&quot;XTR&quot;,          
            reply_markup=payment_keyboard(),      
      )</pre>
  <h3 id="zMp0">Pre-sale inspection</h3>
  <p id="WcF2">The invoice is issued, the user clicks &quot;Pay&quot;. If he does not have enough stars, the system will offer to buy them. If he has enough stars, he will make the payment, and at that moment Telegram will send a request to the bot &quot;is everything really okay?&quot; We will have exactly 10 seconds to respond. If for some reason we do not want to accept payments from this user or the bot logic is set to cancel the payment, in this case it is necessary to give a response signaling the cancellation of the payment, accompanying it with the reason for the cancellation. Otherwise, we confirm that everything is &quot;OK&quot;.</p>
  <p id="vYDy">In the same file, we will create an asynchronous function <code>pre_checkout_handler</code>that takes an argument <code>pre_checkout_query</code>- an object of the class <code>PreCheckoutQuery</code>.</p>
  <p id="QItO">In the body of the function, <code>pre_checkout_query</code>we call the method on the variable <code>.answer</code>, passing an argument <code>ok</code>with the value to it <code>True</code>.</p>
  <h4 id="t4vq">Function code:</h4>
  <pre id="QA86">from aiogram.types import PreCheckoutQueryasync 

def pre_checkout_handler(pre_checkout_query: PreCheckoutQuery):
      await pre_checkout_query.answer(ok=True)</pre>
  <h3 id="bOwZ">Informing about purchase</h3>
  <p id="tkWx">The bureaucracy is behind us, all that&#x27;s left is to congratulate the user on their purchase!</p>
  <p id="eYcY">In the same file, we will create an asynchronous function <code>success_payment_handler</code>that takes an argument <code>message</code>- an object of the class <code>Message</code>.</p>
  <p id="F6Ag">The class object <code>Message</code>stores various information about the current message, and the field <code>successful_payment</code>contains information about the payment, such as the payment identifier, amount, currency, information received from the user. Ideally, all this should be saved to avoid possible questions about payments in the future.</p>
  <p id="MNIp">In the body of the function, we make a normal response, reporting that the purchase was successful.</p>
  <h4 id="s6vW">Function code:</h4>
  <pre id="QRGW">async def success_payment_handler(message: Message):
      await message.answer(text=&quot;🥳Спасибо за вашу поддержку!🤗&quot;)</pre>
  <h3 id="QuE9">Paysupport team and a little about refunds</h3>
  <p id="496b">Telegram also has conditions for refunding users. Not all products and services are eligible for refunds, but the user should still be able to request a refund or be informed about it.</p>
  <p id="aA8H">To inform the user, there must be a command <code>/paysupport</code>. It can contain return conditions, contact information, etc. Let&#x27;s make this command.</p>
  <p id="HvWV">Let&#x27;s create an asynchronous function <code>pay_support_handler</code>that accepts <code>message</code>an object of class <code>Message</code>. In the body of the function, we&#x27;ll write a response to the message with text describing the conditions for returning funds.</p>
  <h4 id="lkb4">Function code:</h4>
  <pre id="CstU">async def pay_support_handler(message: Message):
      await message.answer(
           text=&quot;Добровольные пожертвования не подразумевают возврат средств, &quot;          
           &quot;однако, если вы очень хотите вернуть средства - свяжитесь с нами.&quot;    )</pre>
  <p id="VxLz">The refund itself can be made available to the user. To do this, you need to create a handler for the refund command, in which, when accessing the method <code>.refund_star_payment</code>of the object <code>Bot</code>, pass <code>user_id</code>and to it <code>telegram_payment_charge_id</code>.</p>
  <ul id="24pP">
    <li id="SR41"><code>user_id</code>— Telegram ID of the user requesting a refund.</li>
    <li id="vxf5"><code>telegram_payment_charge_id</code>— Identifier of the payment made by the user.</li>
  </ul>
  <h3 id="VnvA">Registering handlers</h3>
  <p id="87XG">Everything is ready, all that remains is to register the handlers in <code>main.py</code>.</p>
  <p id="kXTn">Let&#x27;s open the file <code>main.py</code>and add four registrations to the function <code>start</code>:</p>
  <ol id="b3Tq">
    <li id="caUf"><code>send_invoice_handler</code>— We register it as a regular message, specifying the command filter <code>donate</code>.</li>
    <li id="lrvt"><code>pre_checkout_handler</code>— We register it as an event <code>pre_checkout_query</code>.</li>
    <li id="7H68"><code>success_payment_handler</code>— We register it as a normal message. As a filter we use the so-called &quot;Magic filter <code>F</code>&quot;, which is an object <code>Message</code>. In the filter we access the field <code>successful_payment</code>. If it is not empty (successful payment), the handler will be called.</li>
    <li id="joLC"><code>pay_support_handler</code>— We register it as a normal message with a filter for the command <code>paysupport</code>.</li>
  </ol>
  <pre id="dxM7">from aiogram import F

dp.message.register(payment.send_invoice_handler, Command(commands=&quot;donate&quot;))
dp.pre_checkout_query.register(payment.pre_checkout_handler)
dp.message.register(payment.success_payment_handler, F.successful_payment)
dp.message.register(payment.pay_support_handler, Command(commands=&quot;paysupport&quot;))</pre>
  <h3 id="MgNZ">Testing</h3>
  <p id="yGnP">Let&#x27;s launch the bot and execute the command <code>/donate</code>.</p>
  <figure id="teOf" class="m_custom">
    <img src="https://habrastorage.org/r/w1560/getpro/habr/upload_files/84c/62b/c1c/84c62bc1ce7e5962d69432d588c9ca05.png" width="738" />
  </figure>
  <p id="cl22">We will receive a message with payment information and a bill button. We will click on the button.</p>
  <p id="CDSc">A window will open with payment confirmation (if you don&#x27;t have stars, a purchase window will open, as in the first screenshot at the beginning of the post). Click &quot;Confirm and pay&quot;.</p>
  <figure id="l4uV" class="m_custom">
    <img src="https://habrastorage.org/r/w1560/getpro/habr/upload_files/2d6/60f/2e4/2d660f2e4a7017fb0202cbb2a062c02d.png" width="366" />
  </figure>
  <p id="XAvT">Confetti will shoot out in the chat and we will see a message about a successful payment.</p>
  <figure id="D25E" class="m_original">
    <img src="https://img2.teletype.in/files/15/78/157806f0-207e-45ea-b681-eedefa201df1.png" width="731" />
  </figure>
  <figure id="mqZ0" class="m_custom">
    <img src="https://habrastorage.org/r/w1560/getpro/habr/upload_files/1fc/743/c5d/1fc743c5d70c0fcffcd485a2f4e861c1.png" width="630" />
  </figure>
  <h3 id="P471">Conclusion</h3>
  <p id="kfeC">The innovation, of course, surprised everyone and took them a little by surprise. They gave little time for the transition, and probably not everyone even knew about it. It will be interesting to see where all this leads.</p>

]]></content:encoded></item><item><guid isPermaLink="true">https://teletype.in/@muxammaddev/g_fDIAXLWyk</guid><link>https://teletype.in/@muxammaddev/g_fDIAXLWyk?utm_source=teletype&amp;utm_medium=feed_rss&amp;utm_campaign=muxammaddev</link><comments>https://teletype.in/@muxammaddev/g_fDIAXLWyk?utm_source=teletype&amp;utm_medium=feed_rss&amp;utm_campaign=muxammaddev#comments</comments><dc:creator>muxammaddev</dc:creator><title>Aiogram 3x da Telegram Stars ulash</title><pubDate>Wed, 30 Apr 2025 14:11:59 GMT</pubDate><media:content medium="image" url="https://img3.teletype.in/files/28/8d/288de24d-69c4-4419-a869-49d0fc2eec94.png"></media:content><description><![CDATA[<img src="https://habrastorage.org/r/w1560/getpro/habr/upload_files/231/b16/09a/231b1609aeb9dedc359bab4f2404ec7b.png"></img>6-iyun kuni Pavel Durov Telegram yangi pul birligi — Yulduzlarni muomalaga kiritayotganini ma’lum qildi. Yulduzlar sizga raqamli tovarlar va xizmatlarni xarid qilish yoki boshqacha qilib aytganda Telegram’da xaridlar uchun to‘lovni amalga oshirish imkonini beradi, masalan, botlar yoki MiniApps. Biroq, hamma narsa juda qizg'ish emas. Yangi to'lov usulini joriy etish barcha boshqa to'lov usullarini o'chirib qo'yishga olib keladi. Agar sizning botingiz Ukassa orqali to'lovlarni qabul qilgan bo'lsa, endi faqat &quot;Yulduzlar&quot;. Biz bunday o‘zgarishlarning sabablarini chetga surib, muhimroq narsalarga, xususan, Telegram botiga yangi to‘lov usuli – Telegram Starsni qanday joriy etishga e’tibor qaratamiz.]]></description><content:encoded><![CDATA[
  <figure id="NkvK" class="m_retina">
    <img src="https://habrastorage.org/r/w1560/getpro/habr/upload_files/231/b16/09a/231b1609aeb9dedc359bab4f2404ec7b.png" width="780" />
  </figure>
  <p id="JcYK">6-iyun kuni Pavel Durov Telegram yangi pul birligi — Yulduzlarni muomalaga kiritayotganini ma’lum qildi. Yulduzlar sizga raqamli tovarlar va xizmatlarni xarid qilish yoki boshqacha qilib aytganda Telegram’da xaridlar uchun to‘lovni amalga oshirish imkonini beradi, masalan, botlar yoki MiniApps. Biroq, hamma narsa juda qizg&#x27;ish emas. Yangi to&#x27;lov usulini joriy etish barcha boshqa to&#x27;lov usullarini o&#x27;chirib qo&#x27;yishga olib keladi. Agar sizning botingiz Ukassa orqali to&#x27;lovlarni qabul qilgan bo&#x27;lsa, endi faqat &quot;Yulduzlar&quot;. Biz bunday o‘zgarishlarning sabablarini chetga surib, muhimroq narsalarga, xususan, Telegram botiga yangi to‘lov usuli – Telegram Starsni qanday joriy etishga e’tibor qaratamiz.</p>
  <p id="oehY">Telegram sozlamalarini ochib, “Telegram yulduzlari” bandini topib, yulduzlarni xarid qilishingiz mumkin.</p>
  <p id="n86g"></p>
  <figure id="ZLbb" class="m_original">
    <img src="https://habrastorage.org/r/w1560/getpro/habr/upload_files/629/d3e/03b/629d3e03b4d28add5072adbcfb973511.png" width="446" />
  </figure>
  <p id="5b1O"><strong>Shuni ta&#x27;kidlash kerak.</strong> Yozish vaqtida foydalanuvchilardan olingan yulduzlardan qanday va qayerda foydalanish haqida so‘nggi ma’lumotlar yo‘q edi. Maqola Telegram’dagi ma’lumotlarning yangilanishi bilan yangilanadi. Agar biror narsa bilsangiz, iltimos, bizga xabar bering!</p>
  <p id="zAAc">Yangi toʻlov usulini toʻliq qoʻllab-quvvatlash uchun minimum AIOgram 3.7.0 versiyasi talab qilinadi. Kutubxonani yangilash uchun buyruqni bajaring:</p>
  <pre id="WD1z">pip install -U aiogram</pre>
  <p id="IJJE">Shundan so&#x27;ng, versiyani yangilang <code>requirements.txt</code>.</p>
  <pre id="d3Cb">aiogram==3.7.0</pre>
  <h3 id="Xu3G">To&#x27;lov tugmasi</h3>
  <p id="Iz5I">Hisob-faktura buyrug&#x27;i ishlovchisini yozishni boshlashdan oldin, biz bosilganda to&#x27;lov oynasini ochadigan to&#x27;lov tugmachasini yaratishimiz kerak.</p>
  <p id="y9ft">Paketda <code>botlogic</code>biz yangi paket yaratamiz <code>keyboards</code>va unda fayl <code>payment_keyboard.py</code>.</p>
  <p id="Npph"><code>payment_keyboard</code>Hech narsani qabul qilmaydigan funksiya yozamiz .</p>
  <p id="jHcG">Funktsiya tanasida biz o&#x27;zgaruvchi yaratamiz, <code>builder</code>unda biz sinfning namunasini aniqlaymiz <code>InlineKeyboardBuilder</code>.</p>
  <p id="Ncz5">Siz unga tugmalar sinfi ob&#x27;ektlari bilan ro&#x27;yxatlar ro&#x27;yxatini o&#x27;tkazishingiz mumkin, ammo bu juda qulay emas; sinf usullaridan foydalanish osonroq. Keyingi qatorda biz sinf ob&#x27;ektining usulini chaqiramiz <code>.button</code>, bu klaviatura yaratuvchisiga tugma qo&#x27;shadi. Biz ikkita dalil keltiramiz:</p>
  <ul id="MDSg">
    <li id="IWNH"><code>text</code>— Tugmadagi matnni belgilaydi. Agar matnda <code>XTR</code>yulduzcha kulgich ⭐️ bo‘lsa, u avtomatik ravishda Telegram yulduzlari belgisi bilan almashtiriladi.</li>
    <li id="QcqL"><code>pay</code>— Tugma turini toʻlov tugmasi sifatida belgilaydi.</li>
  </ul>
  <p id="JE0Q">Keyinchalik, ob&#x27;ektni klaviatura xabariga joylashtirishga tayyor bo&#x27;lish uchun <code>builder</code>usulni qo&#x27;llash orqali o&#x27;zgaruvchini qaytaramiz .<code>.as_markup</code></p>
  <h4 id="2Xmk">Fayl kodi:</h4>
  <pre id="t1Yh">from aiogram.utils.keyboard import InlineKeyboardBuilder

def payment_keyboard():
    builder = InlineKeyboardBuilder()
    builder.button(text=f&quot;Оплатить 20 ⭐️&quot;, pay=True)
    return builder.as_markup()</pre>
  <p id="QPa4">Klaviatura yaratish shart emas; hisob-fakturani usiz yuborishingiz mumkin. Biroq, bu sizga tugma matnini sozlash imkonini beradi, shuningdek, to&#x27;lovni bekor qilish, boshqa mahsulotni tanlash va hokazo kabi qo&#x27;shimcha funktsional tugmalarni qo&#x27;shish imkonini beradi.</p>
  <h3 id="eBhk">Hisob-faktura protsessor</h3>
  <p id="UVqx">Buyruqlar ishlovchisini yozishni boshlaylik.</p>
  <p id="OETg">Paketda <code>handlers</code>biz fayl yaratamiz <code>payment.py</code>.</p>
  <p id="2h1a">Ushbu faylda biz sinf ob&#x27;ektini <code>send_invoice_handler</code>qabul qiladigan asinxron funksiyani yozamiz .<code>messageMessage</code></p>
  <p id="RKoO">Keling, sinf ob&#x27;ektlari ro&#x27;yxatini , aniqrog&#x27;i, bitta ob&#x27;ekt bilan <code>prices</code>joylashadigan o&#x27;zgaruvchi yarataylik , chunki Telegram Stars orqali to&#x27;lash uchun bu ro&#x27;yxat bitta elementdan iborat bo&#x27;lishi kerak. <code>LabeledPrice</code>Biz quyidagi argumentlarni sinf ob&#x27;ektiga o&#x27;tkazamiz:</p>
  <ul id="GbZ1">
    <li id="79RG"><code>label</code>- Valyuta ta&#x27;rifi. Bizning holatimizda shunday <code>XTR</code>.</li>
    <li id="SUTJ"><code>amount</code>- Yulduzlarda narx.</li>
  </ul>
  <p id="EHIU">Keyinchalik, <code>message</code>biz o&#x27;zgaruvchi bo&#x27;yicha usulni chaqiramiz <code>.answer_invoice</code>, shunda bot foydalanuvchining xabariga to&#x27;lov uchun hisob-faktura bilan tugma bilan javob beradi. Usulga quyidagi argumentlarni beramiz:</p>
  <ul id="B2Ns">
    <li id="wVct"><code>title</code>— Toʻlov, mahsulot yoki xizmat nomi.</li>
    <li id="LFEi"><code>description</code>— Toʻlov, mahsulot yoki xizmat tavsifi.</li>
    <li id="MHr4"><code>pricesLabeledPrice</code>— Oldin bir xil nomdagi oʻzgaruvchida aniqlangan obyektlar roʻyxati .</li>
    <li id="Ze8V"><code>provider_token</code>— To‘lov tizimi tokeni, Telegram Stars uchun biz shunchaki bo‘sh qator yuboramiz.</li>
    <li id="vKXF"><code>payload</code>- To&#x27;lov belgisi. U foydalanuvchiga ko&#x27;rsatilmaydi, lekin to&#x27;lovlarni turlari bo&#x27;yicha ajratish uchun ishlatilishi mumkin va hokazo. Maksimal 128 bayt ma&#x27;lumot (Pythonda bir belgi bir baytni egallaydi, lekin esda tutingki, maxsus belgilar yoki emoji ko&#x27;proq joy egallashi mumkin).</li>
    <li id="PEhx"><code>currency</code>— Toʻlov valyutasi, Telegram yulduzlari uchun bu <code>XTR</code>.</li>
    <li id="Ml9u"><code>reply_markup</code>— Klaviatura obyekti.</li>
  </ul>
  <h4 id="NRAh">Ishlovchi kodi:</h4>
  <pre id="ooTZ">from aiogram.types import LabeledPrice, Message    
from botlogic.keyboards.payment_keyboard import payment_keyboard
      
async def send_invoice_handler(message: Message):      
    prices = [LabeledPrice(label=&quot;XTR&quot;, amount=20)]      
    await message.answer_invoice(
        title=&quot;Поддержка канала&quot;,
        description=&quot;Поддержать канал на 20 звёзд!&quot;,
        prices=prices,
        provider_token=&quot;&quot;,
        payload=&quot;channel_support&quot;,
        currency=&quot;XTR&quot;,          
        reply_markup=payment_keyboard()
    )</pre>
  <h3 id="mqlK">Sotishdan oldin tekshirish</h3>
  <p id="nBYx">Hisob-faktura beriladi, foydalanuvchi &quot;To&#x27;lash&quot; tugmasini bosing. Agar uning yulduzlari etarli bo&#x27;lmasa, tizim ularni sotib olishni taklif qiladi. Agar uning yulduzlari yetarli bo‘lsa, u to‘lovni amalga oshiradi va shu daqiqada Telegram botga “hammasi yaxshimi?” degan so‘rov yuboradi. Javob berish uchun roppa-rosa 10 soniya vaqtimiz bor. Agar biron sababga ko&#x27;ra biz ushbu foydalanuvchidan to&#x27;lovlarni qabul qilishni xohlamasak yoki bot mantig&#x27;i to&#x27;lovni bekor qilish uchun o&#x27;rnatilgan bo&#x27;lsa, bu holda to&#x27;lovni bekor qilish to&#x27;g&#x27;risida signal beruvchi javobni bekor qilish sababi bilan birga berish kerak. Aks holda, biz hamma narsa &quot;OK&quot; ekanligini tasdiqlaymiz.</p>
  <p id="yWrv">Xuddi shu faylda biz <code>pre_checkout_handler</code>argumentni qabul qiladigan asinxron funktsiyani yaratamiz <code>pre_checkout_query</code>- sinf ob&#x27;ekti <code>PreCheckoutQuery</code>.</p>
  <p id="igv4">Funktsiyaning tanasida biz o&#x27;zgaruvchiga argumentni o&#x27;tkazib, o&#x27;zgaruvchidagi <code>pre_checkout_query</code>usulni chaqiramiz .<code>.answerokTrue</code></p>
  <h4 id="G4n1">Funktsiya kodi:</h4>
  <pre id="Na9w">from aiogram.types import PreCheckoutQueryasync 

def pre_checkout_handler(pre_checkout_query: PreCheckoutQuery):
    await pre_checkout_query.answer(ok=True)</pre>
  <h3 id="fkX5">Sotib olish haqida ma&#x27;lumot</h3>
  <p id="d5OZ">Byurokratiya ortda qoldi, foydalanuvchini xaridi bilan tabriklashgina qoldi!</p>
  <p id="ovAS">Xuddi shu faylda biz <code>success_payment_handler</code>argumentni qabul qiladigan asinxron funktsiyani yaratamiz <code>message</code>- sinf ob&#x27;ekti <code>Message</code>.</p>
  <p id="urYi">Sinf ob&#x27;ekti <code>Message</code>joriy xabar haqida turli ma&#x27;lumotlarni saqlaydi va maydonda <code>successful_payment</code>to&#x27;lov identifikatori, summa, valyuta, foydalanuvchidan olingan ma&#x27;lumotlar kabi to&#x27;lov haqidagi ma&#x27;lumotlar mavjud. Ideal holda, bularning barchasi kelajakda yuzaga kelishi mumkin bo&#x27;lgan to&#x27;lov muammolarini oldini olish uchun saqlanishi kerak.</p>
  <p id="rVbB">Funktsiyaning tanasida biz xarid muvaffaqiyatli bo&#x27;lganligi haqida xabar berib, oddiy javob beramiz.</p>
  <h4 id="y0JM">Funktsiya kodi:</h4>
  <pre id="tCCb">async def success_payment_handler(message: Message):
      await message.answer(text=&quot;🥳Спасибо за вашу поддержку!🤗&quot;)</pre>
  <h3 id="PtF0">Paysupport jamoasi va pulni qaytarish haqida bir oz</h3>
  <p id="KGik">Telegram’da foydalanuvchilarning mablag‘larini qaytarish shartlari ham mavjud. Hamma mahsulot va xizmatlar pulni qaytarishga haqli emas, lekin foydalanuvchi hali ham pulni qaytarishni talab qilishi yoki bu haqda xabardor bo‘lishi kerak.</p>
  <p id="SrBS">Foydalanuvchini xabardor qilish uchun buyruq bo&#x27;lishi kerak <code>/paysupport</code>. Qaytish shartlarini, aloqa ma&#x27;lumotlarini va hokazolarni belgilashingiz mumkin. Keling, ushbu buyruqni bajaramiz.</p>
  <p id="LeQi">Keling, sinf ob&#x27;ektini <code>pay_support_handler</code>qabul qiladigan asinxron funksiya yarataylik . Funktsiyaning asosiy qismida biz pul mablag&#x27;larini qaytarish shartlarini tavsiflovchi matn bilan xabarga javob yozamiz.<code>messageMessage</code></p>
  <h4 id="5ULg">Funktsiya kodi:</h4>
  <pre id="qoQZ">async def pay_support_handler(message: Message):
    await message.answer(
        text=&quot;Добровольные пожертвования не подразумевают возврат средств, &quot;
        &quot;однако, если вы очень хотите вернуть средства - свяжитесь с нами.&quot;)</pre>
  <p id="lfJy">To&#x27;lovning o&#x27;zi foydalanuvchiga taqdim etilishi mumkin. Buni amalga oshirish uchun siz <code>.refund_star_payment</code>ob&#x27;ekt usuliga kirishda <code>Bot</code>siz <code>user_id</code>va unga o&#x27;tadigan qaytish buyrug&#x27;i ishlovchisini yaratishingiz kerak <code>telegram_payment_charge_id</code>.</p>
  <ul id="ic8A">
    <li id="rcgk"><code>user_id</code>— Pulni qaytarishni talab qilayotgan foydalanuvchining Telegram identifikatori.</li>
    <li id="rMZL"><code>telegram_payment_charge_id</code>— Foydalanuvchi tomonidan amalga oshirilgan to‘lov identifikatori.</li>
  </ul>
  <h3 id="VJJQ">Ishlovchilarni ro&#x27;yxatdan o&#x27;tkazish</h3>
  <p id="o6EV">Hammasi tayyor, ishlovchilarni ro&#x27;yxatdan o&#x27;tkazish qoladi <code>main.py</code>.</p>
  <p id="RBOa">Keling, faylni ochamiz <code>main.py</code>va funktsiyaga to&#x27;rtta ro&#x27;yxatga olish qo&#x27;shamiz <code>start</code>:</p>
  <ol id="w8Nm">
    <li id="yHuM"><code>send_invoice_handler</code>— Biz uni oddiy xabar sifatida ro&#x27;yxatdan o&#x27;tkazamiz, buyruq filtrini ko&#x27;rsatamiz <code>donate</code>.</li>
    <li id="nJQE"><code>pre_checkout_handler</code>- Biz buni voqea sifatida ro&#x27;yxatdan o&#x27;tkazamiz <code>pre_checkout_query</code>.</li>
    <li id="4Z0N"><code>success_payment_handler</code>— Biz buni oddiy xabar sifatida ro&#x27;yxatdan o&#x27;tkazamiz. Filtr sifatida biz <code>F</code>ob&#x27;ekt bo&#x27;lgan &quot;Sehrli filtr&quot; dan foydalanamiz <code>Message</code>. Filtrda biz maydonga murojaat qilamiz <code>successful_payment</code>. Agar u bo&#x27;sh bo&#x27;lmasa (muvaffaqiyatli to&#x27;lov), ishlov beruvchi chaqiriladi.</li>
    <li id="Aepi"><code>pay_support_handler</code>— Biz uni oddiy xabar sifatida buyruq uchun filtr bilan ro&#x27;yxatdan o&#x27;tkazamiz <code>paysupport</code>.</li>
  </ol>
  <pre id="lyeZ">from aiogram import F
dp.message.register(payment.send_invoice_handler, Command(commands=&quot;donate&quot;))
dp.pre_checkout_query.register(payment.pre_checkout_handler)
dp.message.register(payment.success_payment_handler, F.successful_payment)
dp.message.register(payment.pay_support_handler, Command(commands=&quot;paysupport&quot;))</pre>
  <h3 id="SIXH">Sinov</h3>
  <p id="xOza">Keling, botni ishga tushiramiz va buyruqni bajaramiz <code>/donate</code>.</p>
  <figure id="qJag" class="m_original">
    <img src="https://img3.teletype.in/files/68/a4/68a4e975-b66d-4c1f-9e17-c8c82b35e26d.png" width="738" />
  </figure>
  <p id="Qp5L">Biz to&#x27;lov ma&#x27;lumotlari va hisob-kitob tugmasi bilan xabar olamiz. Keling, tugmani bosamiz.</p>
  <p id="nZ8x">To&#x27;lovni tasdiqlovchi oyna ochiladi (agar sizda yulduzcha bo&#x27;lmasa, xabarning boshida birinchi skrinshotda bo&#x27;lgani kabi xarid oynasi ochiladi). &quot;Tasdiqlash va to&#x27;lash&quot; tugmasini bosing.</p>
  <figure id="ENof" class="m_original">
    <img src="https://img1.teletype.in/files/02/02/02028354-6371-42d7-9678-e0b95fc64d02.png" width="366" />
  </figure>
  <p id="nzZj">Confetti chatda chiqadi va biz muvaffaqiyatli to&#x27;lov haqida xabarni ko&#x27;ramiz.</p>
  <figure id="VZPF" class="m_original">
    <img src="https://img2.teletype.in/files/15/78/157806f0-207e-45ea-b681-eedefa201df1.png" width="731" />
  </figure>
  <figure id="AnI3" class="m_original">
    <img src="https://img4.teletype.in/files/f2/51/f251dbaa-d497-4e2e-92ff-ab45e34960f6.png" width="630" />
  </figure>
  <h3 id="2F8X">Xulosa</h3>
  <p id="vpTM">Yangilik, albatta, barchani hayratda qoldirdi va ularni biroz hayratda qoldirdi. Ular o&#x27;tish uchun oz vaqt berishdi va ehtimol bu haqda hamma ham bilmas edi. Bularning barchasi qayerga olib kelishini ko&#x27;rish qiziq bo&#x27;ladi.</p>

]]></content:encoded></item></channel></rss>