Telegram-Mini-Apps / telegram-apps

Made from scratch TypeScript packages, examples and documentation you will surely need to start developing on Telegram Mini Apps.
https://docs.telegram-mini-apps.com/
MIT License
691 stars 191 forks source link

[Bug]: Error with openInvoice #534

Closed tlbvkhamzin closed 6 days ago

tlbvkhamzin commented 2 weeks ago

Telegram Application

Telegram for macOS

Describe the Bug

Whenever I complete a TG Stars payment, I receive a following error:

TypeError: undefined is not an object (evaluating 'window.TelegramGameProxy.receiveEvent')

I am testing that on the MacOS, and indeed TelegramGameProxy seems not to have been defined in TG for MacOS:

image

To Reproduce

This snippet works well on mobile, but fails on macOS:

// ...
const status = await openInvoice(invoice_url, 'url');
if (status === 'paid') {
  alert('Successfully paid.');
}
// ...

Expected Behavior

Payment notification shouldn't throw an error

heyqbnk commented 2 weeks ago

You probably forgot to initialize the SDK.

https://docs.telegram-mini-apps.com/packages/telegram-apps-sdk/2-x/initializing

tlbvkhamzin commented 2 weeks ago

Hi @heyqbnk. I'm doing the following on the app start:

import { init } from '@telegram-apps/sdk-react';

// ...
init();
// ...

Without the initialization, it indeed didn't work on any device. But like the above it works well on iOS for example, and breaks on macOS.

Let me create a minimal reproducible case and share it with you.

tlbvkhamzin commented 6 days ago

Sorry, you were right. I was only initializing the app for mobile devices.