Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk4 min

How to Handle Telegram Stars Payments in PHP, From Invoice to Fulfillment

A safe PHP workflow for Telegram Stars: send an XTR invoice, verify the pending order in pre-checkout, and deliver only after successful_payment.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To accept Telegram Stars for digital goods or services sold inside Telegram, send an invoice in currency XTR, validate and answer each pre_checkout_query within 10 seconds, then fulfill the order only after receiving successful_payment. Save Telegram’s payment charge ID with the order so you can identify it if a refund is needed. The Bot API workflow is language-neutral; the available PHP example covers provider-based payments, not a confirmed Stars implementation.

Check that Stars is the right payment flow

Telegram requires Stars for digital goods and services sold inside Telegram apps, even if the seller also operates a website or accepts other payment methods elsewhere. This guide is for those in-app digital purchases. Telegram directs physical-goods sellers to its separate payments documentation. See Telegram’s Bot Payments API for Digital Goods and Services.

As an Amazon Associate I earn from qualifying purchases.

For a digital-goods invoice, use currency XTR. Telegram’s Stars guide says provider_token is needed only for physical goods and services, so it can be left empty for digital sales. The Bot API changelog says to omit it for Stars in the relevant methods. Since PHP wrappers may serialize optional parameters differently, check the current method definition and the behavior of your exact library rather than assuming that an empty string and an omitted parameter are equivalent. See the Bot API changelog.

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

Stars payments were added in Bot API 7.4 on May 28, 2024, alongside the refundStarPayment method. That is historical release context, not a claim that Bot API 7.4 is the current version.

Prepare an order record before sending the invoice

Create a pending order in your own system before the customer can check out. Include an invoice payload that identifies the order, along with the expected product, currency, and amount. Use the payload to associate later Telegram updates with the correct internal order.

Telegram documents the payload, currency, and total amount in the pre-checkout update. The amount is an integer in the currency’s smallest unit; for an XTR invoice, it is expressed in Stars. Your PHP handler should compare those reported values with the pending order before approving checkout. See Telegram’s pre-checkout query update definition.

Send the Stars invoice

Build the invoice using the Bot API method exposed by your PHP library, with XTR as the currency and the order-specific payload. Follow the method’s current parameter definition for provider_token; do not copy a provider-token setup from a conventional card-payment example and assume it applies to Stars.

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

Telegram’s API documentation does not prescribe PHP syntax or endorse a particular PHP package. Confirm that your chosen package supports Stars-specific invoice parameters and that it sends the payload in a form your update handler can read. Keep the pending order available before sending the invoice so that a quick checkout can be validated.

Validate and answer the pre-checkout query

When the user proceeds with payment, Telegram sends a pre_checkout_query. Match its payload to a pending order and verify that the order is still eligible, and that the reported currency and integer amount agree with what you stored. Approve only a valid match.

  1. Receive the update. Route pre_checkout_query updates to a handler in your bot.
  2. Validate the order. Look up the pending order by its payload; check its status, expected product, currency, and amount against the update.
  3. Respond within 10 seconds. Call answerPreCheckoutQuery promptly. If you cannot process the order, reject it with a human-readable reason; Telegram displays that reason to the user.

Telegram cancels a checkout that is not answered in time. Keep this handler short enough to meet the deadline; do not wait for slow work that is unnecessary to decide whether to approve the order. See Telegram’s step-by-step Stars payment process.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Fulfill only after Telegram confirms payment

An approved pre-checkout query is not proof that the payment succeeded. Wait for the successful_payment update before delivering the digital item or enabling the service. Telegram explicitly warns: “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.”

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

When processing the successful-payment update, associate it with the order and record Telegram’s telegram_payment_charge_id. Telegram says this identifier may be required for a future refund; its Stars guide points to refundStarPayment for digital-goods refunds. See Telegram’s Stars refund guidance.

What to verify in a PHP library

The API rules above apply regardless of implementation language, but package support and update parsing are library-specific. A PHP example repository separates payment and pre-checkout commands and describes generic post-payment messaging, yet its setup uses a payment-provider token and covers traditional payments; it does not establish a Stars-ready implementation. Review its payment example README as an example of that distinction, not as a Stars recipe.

  • Confirm the library version supports Stars invoices with XTR and handles the optional provider_token as Telegram currently specifies.
  • Check how it parses and dispatches pre_checkout_query and successful_payment updates.
  • Verify that the invoice payload is available to your handler and can be mapped to your pending order.
  • Confirm that the successful-payment data exposes telegram_payment_charge_id and that your integration can call the refund method if needed.

Do not treat a provider-based PHP example as evidence that Stars support works in a particular package. The Telegram documentation defines the required API behavior; the package’s current version and serialization determine how to implement it in PHP.

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
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

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.