ptgb
A complete Telegram Bot API client for Dart

Payments & Telegram Stars

Part of the API Reference.

sendInvoice

Future<Json> sendInvoice(
    Object chatId,
    String title,
    String description,
    String payload,
    String currency,
    List<Json> prices, {
    int? messageThreadId,
    String? providerToken,
    int? maxTipAmount,
    List<int>? suggestedTipAmounts,
    String? startParameter,
    String? providerData,
    String? photoUrl,
    int? photoSize,
    int? photoWidth,
    int? photoHeight,
    bool? needName,
    bool? needPhoneNumber,
    bool? needEmail,
    bool? needShippingAddress,
    bool? sendPhoneNumberToProvider,
    bool? sendEmailToProvider,
    bool? isFlexible,
    bool? disableNotification,
    bool? protectContent,
    bool? allowPaidBroadcast,
    String? messageEffectId,
    ReplyParameters? replyParameters,
    InlineKeyboardMarkup? replyMarkup,
  }) async =>

Sends an invoice for a payment (physical goods, digital goods, or Telegram Stars). Use [providerToken] for a payment provider, or leave it empty when charging in Telegram Stars (currency: 'XTR').

Future<String> createInvoiceLink(
    String title,
    String description,
    String payload,
    String currency,
    List<Json> prices, {
    String? businessConnectionId,
    String? providerToken,
    int? subscriptionPeriod,
    int? maxTipAmount,
    List<int>? suggestedTipAmounts,
    String? providerData,
    String? photoUrl,
    int? photoSize,
    int? photoWidth,
    int? photoHeight,
    bool? needName,
    bool? needPhoneNumber,
    bool? needEmail,
    bool? needShippingAddress,
    bool? sendPhoneNumberToProvider,
    bool? sendEmailToProvider,
    bool? isFlexible,
  }) async =>

Creates a standalone payment link for an invoice, without sending it to a chat.

answerShippingQuery

Future<bool> answerShippingQuery(
    String shippingQueryId,
    bool ok, {
    List<Json>? shippingOptions,
    String? errorMessage,
  }) async =>

Responds to a shipping query raised for an invoice with flexible shipping options.

answerPreCheckoutQuery

Future<bool> answerPreCheckoutQuery(
    String preCheckoutQueryId,
    bool ok, {
    String? errorMessage,
  }) async =>

Responds to the final pre-checkout confirmation before payment is captured. Must be answered within 10 seconds or the payment is cancelled.

getStarTransactions

Future<Json> getStarTransactions({int? offset, int? limit}) async =>

Lists the bot’s incoming and outgoing Telegram Stars transactions.

refundStarPayment

Future<bool> refundStarPayment(int userId, String telegramPaymentChargeId) async =>

Refunds a successful payment that was made in Telegram Stars.

editUserStarSubscription

Future<bool> editUserStarSubscription(
    int userId,
    String telegramPaymentChargeId,
    bool isCanceled,
  ) async =>

Cancels or reactivates a user’s recurring Telegram Stars subscription payment.

getMyStarBalance

Future<Json> getMyStarBalance() async => _o(await call('getMyStarBalance'));

Returns the bot's current balance of Telegram Stars as a StarAmount object (raw JSON).