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.
This commit is contained in:
vchikalkin 2025-09-20 11:51:19 +03:00
parent 1f168df095
commit 900cfe2cc2
2 changed files with 11 additions and 2 deletions

View File

@ -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 }));

View File

@ -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,