From ee4e70f43d424b7fe24acf9081558ec619e69edd Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Thu, 9 Oct 2025 18:04:38 +0300 Subject: [PATCH] feat: integrate customer data into subscription invoice - Added CustomersService to retrieve customer information based on telegramId. - Enhanced invoice provider data to include customer phone and item details for improved payment processing. - Updated the subscription function to utilize the new customer data in the invoice generation. --- .../bot/src/bot/conversations/subscription.ts | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/apps/bot/src/bot/conversations/subscription.ts b/apps/bot/src/bot/conversations/subscription.ts index 6b7e8c3..701474d 100644 --- a/apps/bot/src/bot/conversations/subscription.ts +++ b/apps/bot/src/bot/conversations/subscription.ts @@ -5,6 +5,7 @@ import { formatMoney } from '@/utils/format'; import { combine } from '@/utils/messages'; import { type Conversation } from '@grammyjs/conversations'; import { fmt, i } from '@grammyjs/parse-mode'; +import { CustomersService } from '@repo/graphql/api/customers'; import { SubscriptionsService } from '@repo/graphql/api/subscriptions'; import * as GQL from '@repo/graphql/types'; import { InlineKeyboard } from 'grammy'; @@ -107,6 +108,9 @@ export async function subscription(conversation: Conversation, parse_mode: 'HTML', }); + const customerService = new CustomersService({ telegramId }); + const { customer } = await customerService.getCustomer({ telegramId }); + return ctx.replyWithInvoice( 'Оплата Pro доступа', combine( @@ -123,6 +127,27 @@ export async function subscription(conversation: Conversation, ], { protect_content: true, + provider_data: JSON.stringify({ + receipt: { + customer: { + phone: customer?.phone.replaceAll(/\D/gu, ''), + }, + items: [ + { + amount: { + currency: 'RUB', + value: selectedPrice.amount, + }, + description: selectedPrice.description || 'Pro доступ', + payment_mode: 'full_payment', + payment_subject: 'payment', + quantity: 1, + vat_code: 1, + }, + ], + tax_system_code: 1, + }, + }), provider_token: env.BOT_PROVIDER_TOKEN, start_parameter: 'get_access', },