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.
This commit is contained in:
parent
4d40230864
commit
ee4e70f43d
@ -5,6 +5,7 @@ import { formatMoney } from '@/utils/format';
|
|||||||
import { combine } from '@/utils/messages';
|
import { combine } from '@/utils/messages';
|
||||||
import { type Conversation } from '@grammyjs/conversations';
|
import { type Conversation } from '@grammyjs/conversations';
|
||||||
import { fmt, i } from '@grammyjs/parse-mode';
|
import { fmt, i } from '@grammyjs/parse-mode';
|
||||||
|
import { CustomersService } from '@repo/graphql/api/customers';
|
||||||
import { SubscriptionsService } from '@repo/graphql/api/subscriptions';
|
import { SubscriptionsService } from '@repo/graphql/api/subscriptions';
|
||||||
import * as GQL from '@repo/graphql/types';
|
import * as GQL from '@repo/graphql/types';
|
||||||
import { InlineKeyboard } from 'grammy';
|
import { InlineKeyboard } from 'grammy';
|
||||||
@ -107,6 +108,9 @@ export async function subscription(conversation: Conversation<Context, Context>,
|
|||||||
parse_mode: 'HTML',
|
parse_mode: 'HTML',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const customerService = new CustomersService({ telegramId });
|
||||||
|
const { customer } = await customerService.getCustomer({ telegramId });
|
||||||
|
|
||||||
return ctx.replyWithInvoice(
|
return ctx.replyWithInvoice(
|
||||||
'Оплата Pro доступа',
|
'Оплата Pro доступа',
|
||||||
combine(
|
combine(
|
||||||
@ -123,6 +127,27 @@ export async function subscription(conversation: Conversation<Context, Context>,
|
|||||||
],
|
],
|
||||||
{
|
{
|
||||||
protect_content: true,
|
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,
|
provider_token: env.BOT_PROVIDER_TOKEN,
|
||||||
start_parameter: 'get_access',
|
start_parameter: 'get_access',
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user