Open 0xrpj opened 1 day ago
I generated the invoice in the backend as such:
async function generateLink() { const payload = { title: "TG Game", description: "TG Game is a fun game", uuid: randomUUID(), provider_token: '', currency: 'XTR', prices: [{ label: "TGGame", amount: 1 }] } console.log(payload) try { const url = `https://api.telegram.org/bot${process.env.BOT_TOKEN}/createInvoiceLink`; const response = await axios.get(url, { params: { title: payload.title, description: payload.description, payload: payload.uuid, provider_token: '', currency: 'XTR', prices: JSON.stringify(payload.prices), photo_url: "https://upload.wikimedia.org/wikipedia/en/thumb/5/5f/Original_Doge_meme.jpg/220px-Original_Doge_meme.jpg", photo_width: 500, photo_height: 500, }, }); return response.data.result; } catch (e) { console.log({ e }) return '' } }
In the frontend, I am using this package and here is the code:
import { useLayoutEffect } from 'react'; import WebApp from "@twa-dev/sdk"; function App() { useLayoutEffect(() => { const initWebApp = async () => { if (typeof window !== "undefined") { WebApp.ready(); } }; initWebApp(); }, []); function openInvoice() { WebApp.openInvoice("https://t.me/$KUjyOab64FUKAQAAVP4zD7wA1QU", (data) => { console.log({ data }) }) } return ( <> <h1>TG Stars Demo</h1> <div className="card"> <button onClick={() => { openInvoice() }}> Buy Stars </button> </div> </> ) } export default App
But, I keep getting "An error occured". And the callback function says failed and for the love of god, I don't know why.
Its not a problem with my account. I have tried paying in other apps and it did work.
I generated the invoice in the backend as such:
In the frontend, I am using this package and here is the code:
But, I keep getting "An error occured". And the callback function says failed and for the love of god, I don't know why.
Its not a problem with my account. I have tried paying in other apps and it did work.