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:
parent
1f168df095
commit
900cfe2cc2
@ -28,7 +28,12 @@ feature.on(':successful_payment', logHandle('successful-payment'), async (ctx) =
|
|||||||
|
|
||||||
const payload = JSON.parse(rawPayload);
|
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-subscribe-success'));
|
||||||
await ctx.reply(ctx.t('msg-subscription-active-until', { date: formattedDate }));
|
await ctx.reply(ctx.t('msg-subscription-active-until', { date: formattedDate }));
|
||||||
|
|||||||
@ -20,7 +20,10 @@ export const ERRORS = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export class SubscriptionsService extends BaseService {
|
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({
|
const { subscriptionPrices } = await this.getSubscriptionPrices({
|
||||||
filters: { period: { eq: payload.period } },
|
filters: { period: { eq: payload.period } },
|
||||||
});
|
});
|
||||||
@ -61,6 +64,7 @@ export class SubscriptionsService extends BaseService {
|
|||||||
amount: subscriptionPrice.amount,
|
amount: subscriptionPrice.amount,
|
||||||
currency: 'RUB',
|
currency: 'RUB',
|
||||||
description: existingSubscription ? 'Продление Pro доступа' : 'Новая подписка',
|
description: existingSubscription ? 'Продление Pro доступа' : 'Новая подписка',
|
||||||
|
paymentId,
|
||||||
period: subscriptionPrice.period,
|
period: subscriptionPrice.period,
|
||||||
source: GQL.Enum_Subscriptionhistory_Source.Payment,
|
source: GQL.Enum_Subscriptionhistory_Source.Payment,
|
||||||
state: GQL.Enum_Subscriptionhistory_State.Success,
|
state: GQL.Enum_Subscriptionhistory_State.Success,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user