# Payments

{% tabs %}
{% tab title="TypeScript" %}

```typescript
import { Keyboard } from 'degreet-telegram'
import { Payment } from 'degreet-telegram/src/creators'
import { IContext } from 'degreet-telegram/src/types'

bot.command('start', async (ctx: IContext): Promise<any> => {
  try {
    await ctx.answer.send(
      new Payment()
        .setTitle('Title') // required
        .setDescription('Description') // required
        .setToken('Payment token from botFather') // required
        .setCurrency('USD') // required
        .addItem('First item', 20) // required
        .addItem('Second item', 25)
        .addDiscount('Discount', 10)
        .allowTips(5, [1, 3, 5]) // 1 - max tip amount, 2 - suggested tip amounts
        .needUserData(['email']) // email, phone_number, name or shipping_query
        .setPhotoUrl(IMAGE_URL), // you can add photo also, but url only
      new Keyboard('under_the_message') // optional, if you didn't add keyboard, it will be added automatically with  pay button
        .btn('pay', ctx.i18n?.get('pay_btn')!).row()
        .useLayout('go_menu_btn')
    )
  } catch (e: any) {
    console.error(e)
  }
})

bot.on('payment_answer', async (ctx: IContext): Promise<any> => {
  try {
    await ctx.answer.payment(true) // 1 - isSuccess, 2 - error message
  } catch (e: any) {
    console.error(e)
  }
})

bot.on('successful_payment', async (ctx: IContext): Promise<any> => {
  try {
    await ctx.answer.send('Thank you for payment!')
  } catch (e: any) {
    console.error(e)
  }
})
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const { Keyboard } = require('degreet-telegram')
const { Payment } = require('degreet-telegram/src/creators')

bot.command('start', async (ctx) => {
  try {
    await ctx.answer.send(
      new Payment()
        .setTitle('Title') // required
        .setDescription('Description') // required
        .setToken('Payment token from botFather') // required
        .setCurrency('USD') // required
        .addItem('First item', 20) // required
        .addItem('Second item', 25)
        .addDiscount('Discount', 10)
        .allowTips(5, [1, 3, 5]) // 1 - max tip amount, 2 - suggested tip amounts
        .needUserData(['email']) // email, phone_number, name or shipping_query
        .setPhotoUrl(IMAGE_URL), // you can add photo also, but url only
      new Keyboard('under_the_message') // optional, if you didn't add keyboard, it will be added automatically with  pay button
        .btn('pay', ctx.i18n?.get('pay_btn')).row()
        .useLayout('go_menu_btn')
    )
  } catch (e) {
    console.error(e)
  }
})

bot.on('payment_answer', async (ctx) => {
  try {
    await ctx.answer.payment(true) // 1 - isSuccess, 2 - error message
  } catch (e) {
    console.error(e)
  }
})

bot.on('successful_payment', async (ctx) => {
  try {
    await ctx.answer.send('Thank you for payment!')
  } catch (e) {
    console.error(e)
  }
})
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://degreetpro.gitbook.io/degreet-telegram/advanced/payments.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
