Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk6 min

Process Telegram Stars Payments in PHP: Invoices, Pre-Checkout, and Webhooks

A Stars sale in a PHP bot runs on four steps: send an XTR invoice, answer pre-checkout within 10 seconds, deliver only after successful_payment, and store the charge ID for refunds.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A Stars sale in a PHP bot is a four-part loop. Your bot sends an invoice with currency XTR, answers the pre_checkout_query within 10 seconds, delivers the goods only after a successful_payment update arrives, and stores the telegram_payment_charge_id so you can handle support requests and refunds later.

Know the rules before writing code

Telegram’s Stars guide says digital goods and services sold inside Telegram apps must be paid for with Stars. The Bot API changelog records that Bot API 7.4 added Stars support, using the XTR currency code, and introduced the refundStarPayment method on May 28, 2024. Those are the two anchors for everything below.

As an Amazon Associate I earn from qualifying purchases.

Telegram’s public documentation describes the Bot API payment lifecycle. It does not provide PHP code, name a preferred PHP library, or describe how a particular framework dispatches webhook updates. Treat the examples in this guide as a map of the flow. Check method names, parameter types, and webhook setup against the Bot API method reference and against the current documentation of the PHP client you use.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Step 1: Create the Stars invoice

Call sendInvoice with the parameters below. The table shows what a Stars invoice needs; your client may wrap these in its own method signature.

Parameter Value for a Stars invoice Notes
chat_id The buyer’s chat ID Identifies where the invoice is sent.
title and description Short product name and a sentence about what the buyer gets Shown to the buyer on the invoice.
payload Your internal order reference Telegram returns this value in the pre-checkout query. Use it to look up the order on your server. Do not put the price in it.
currency XTR Stars currency code, introduced with Bot API 7.4.
prices One labeled price whose amount is the Star count The amount is set on your server from your own price list.
provider_token Follow your client’s signature Sources differ on this field. The Stars guide says to leave it empty, while the Bot API changelog says it must be omitted for Stars invoices. Check the current changelog and your client’s signature, and do not send a token for a Stars invoice unless your client requires the field.

Create the order record on your server before you send the invoice, with the product, the Star amount, and a status such as pending. Build the price from server-side data. Never accept a price from the client, and do not treat the invoice message in the chat as proof of purchase.

Step 2: Validate the pre-checkout query

When the buyer taps Pay, Telegram sends a pre_checkout_query update. It contains the query ID, the buyer, the currency, the total amount, and the invoice payload. Use these fields to check the order:

  • The invoice_payload matches an order that is still pending.
  • The currency is XTR.
  • The total_amount equals the price stored for that order.
  • The item is still available and the buyer is not already entitled to it.

Call answerPreCheckoutQuery with the query ID and ok=true if all checks pass. The Bot Payments API documentation sets a deadline of 10 seconds for this answer, and the method reference repeats that deadline. Keep the handler fast. Do not call slow external services from inside it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

If the order cannot be fulfilled, send ok=false with an error_message that a buyer can read, such as “This item is sold out.” Telegram displays that text to the buyer.

Telegram’s payment guide also warns that multi-use and forwarded invoices require the merchant to decide whether to accept each payment. If your bot sells one-time items, your pre-checkout check should reject a second payment for the same order.

Step 3: Wait for successful_payment before delivering

Approving pre-checkout does not prove the money moved. Telegram’s Stars guide puts it directly: “You must always check that you received a successful_payment update before delivering the goods or services purchased by the user – simply answering a pre_checkout_query does not guarantee a successful order or payment.” That warning is part of Telegram’s official documentation and is not attributed to a named person.

The successful_payment field arrives inside a message update. Before you deliver anything, check that:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. The currency is XTR.
  2. The total amount matches the order.
  3. The invoice payload matches an order that is pending or paid.
  4. No other order already uses the same telegram_payment_charge_id.

Then mark the order as paid and deliver the goods. Make this step idempotent. Your webhook or polling loop may receive the same update more than once, and a retry must not grant the item twice. A unique database index on the charge ID is the simplest protection. Confirm your client’s behavior on duplicate delivery before you rely on it.

Step 4: Store the charge ID, then handle support and refunds

Save telegram_payment_charge_id with the order at the moment you mark it paid. The Stars guide says you may need it for a later refund, so a record without it cannot be refunded through the documented method.

Customer support with /paysupport

Telegram assigns the handling of legitimate payment disputes to the merchant, and your bot must respond to the /paysupport command. Build a reply that tells the buyer how to reach you, what information to include, and what the usual timeline is. Your handler should look up the buyer’s orders so you can answer quickly.

Refunds with refundStarPayment

Use refundStarPayment when a refund is appropriate. It was added in Bot API 7.4 and needs the stored charge ID. Decide your refund policy before you need it, and record the refund on the order so the item cannot be delivered again after a refund.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Webhooks, long polling, and your PHP client

Whether you receive updates by webhook or long polling depends on the client you choose and how you deploy the bot. The payment sources do not settle that choice, and they do not describe retry behavior, update parsing, or how duplicate deliveries are handled. Check these points in your client’s documentation before you ship:

  • How the client sets the webhook, and whether it lets you list the update types you want, including pre_checkout_query and message, which carries successful_payment.
  • How it turns the incoming JSON into update objects, and whether it exposes pre_checkout_query and successful_payment as typed fields.
  • Whether Telegram retries a failed webhook delivery, and how the client reports a failed handler.
  • Which method signature it uses for sendInvoice and whether it sends or omits provider_token for Stars.

Name the client and version in your own code and tests. Client APIs change, and the Stars parameters changed with Bot API 7.4.

Troubleshooting checklist

  • The buyer sees an error after tapping Pay. Your pre-checkout handler did not answer in time or returned ok=false. Time the handler, and check the order payload and amount.
  • The buyer paid but received nothing. The bot did not process successful_payment. Confirm that your webhook includes the message update type and that your handler delivers the item on that event.
  • The item was delivered twice. Your fulfillment step is not idempotent. Add a unique constraint on the charge ID and check it before delivery.
  • A refund cannot be issued. The charge ID was not stored with the order. Recover it from your logs or from the stored update payload, if you kept one.
  • A buyer asks for help with /paysupport and gets no reply. The command handler is not registered or your webhook does not receive messages. Test the command on a live bot.

Test the full path on a test bot with a small Stars price before you open the bot to buyers. Confirm each event in order: invoice, pre-checkout, successful_payment, stored charge ID, and delivery.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.