From 900cfe2cc25038dd57dd9e28469450a28e5c742d Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Sat, 20 Sep 2025 11:51:19 +0300 Subject: [PATCH] Enhance subscription handling in bot and GraphQL API - Updated the `createOrUpdateSubscription` method in the SubscriptionsService to accept an optional `paymentId` parameter for better tracking of payment transactions. - Modified the bot's subscription feature to pass the `provider_payment_charge_id` when creating or updating subscriptions, improving payment processing accuracy. --- apps/bot/src/bot/features/subscription.ts | 7 ++++++- packages/graphql/api/subscriptions.ts | 6 +++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/apps/bot/src/bot/features/subscription.ts b/apps/bot/src/bot/features/subscription.ts index 545ecb1..0e7b9a0 100644 --- a/apps/bot/src/bot/features/subscription.ts +++ b/apps/bot/src/bot/features/subscription.ts @@ -28,7 +28,12 @@ feature.on(':successful_payment', logHandle('successful-payment'), async (ctx) = const payload = JSON.parse(rawPayload); - const { formattedDate } = await subscriptionsService.createOrUpdateSubscription(payload); + const provider_payment_charge_id = ctx.message?.successful_payment?.provider_payment_charge_id; + + const { formattedDate } = await subscriptionsService.createOrUpdateSubscription( + payload, + provider_payment_charge_id, + ); await ctx.reply(ctx.t('msg-subscribe-success')); await ctx.reply(ctx.t('msg-subscription-active-until', { date: formattedDate })); diff --git a/packages/graphql/api/subscriptions.ts b/packages/graphql/api/subscriptions.ts index cb6d9fe..b86df32 100644 --- a/packages/graphql/api/subscriptions.ts +++ b/packages/graphql/api/subscriptions.ts @@ -20,7 +20,10 @@ export const ERRORS = { }; export class SubscriptionsService extends BaseService { - async createOrUpdateSubscription(payload: { period: GQL.Enum_Subscriptionprice_Period }) { + async createOrUpdateSubscription( + payload: { period: GQL.Enum_Subscriptionprice_Period }, + paymentId?: string, + ) { const { subscriptionPrices } = await this.getSubscriptionPrices({ filters: { period: { eq: payload.period } }, }); @@ -61,6 +64,7 @@ export class SubscriptionsService extends BaseService { amount: subscriptionPrice.amount, currency: 'RUB', description: existingSubscription ? 'Продление Pro доступа' : 'Новая подписка', + paymentId, period: subscriptionPrice.period, source: GQL.Enum_Subscriptionhistory_Source.Payment, state: GQL.Enum_Subscriptionhistory_State.Success,