/** * Refund flow — user-initiated request, admin-approved, executed via * `refundStarPayment` on Telegram's side, reversed in our cache via * `derive.ts`'s incremental + full-rebuild helpers. * * The flow mirrors `access-control.ts`'s admin-DM approval pattern: * * user opens /settings → 💎 VIP → 📜 History → tap a charge * │ * "💸 Request refund" → confirm overlay → tap "✅" * │ * pay:charge.paysupportState = 'opened' * DM admin with charge details + [✅ Approve] [❌ Deny] * │ * admin taps * │ * Approve → refundStarPayment → pay:refund + revert state * Deny → paysupportState = 'none' * │ * user gets DM with the outcome * * Callback data carries the chargeId only — everything else is read * from the persisted record. Telegram's `telegram_payment_charge_id` is * a moderately long string (~40 chars in practice); with our short * `payRf*` schema names this stays under the 64-byte callback_data cap. */ import type { Storage } from "@gramio/storage"; import type { BotCallbackCtx } from "../ctx.js"; import type { PaymentsStores } from "./stores.js"; import type { BotPaymentsConfig, RefundEvent, SessionLike } from "./types.js"; /** User tap on a charge entry — opens confirmation overlay then admin DM. */ export declare const refundRequestCb: import("gramio").CallbackData<{ cid: string; } & {}, { cid: string; } & {}>; /** Admin tap on the DM notification — approve. */ export declare const refundApproveCb: import("gramio").CallbackData<{ cid: string; } & {}, { cid: string; } & {}>; /** Admin tap on the DM notification — deny. */ export declare const refundDenyCb: import("gramio").CallbackData<{ cid: string; } & {}, { cid: string; } & {}>; /** Admin tap on the DM notification — close (no action). */ export declare const refundCloseCb: import("gramio").CallbackData<{} & {}, {} & {}>; /** Strict bot.api surface this module exercises. */ type RefundBotApi = { refundStarPayment: (params: { user_id: number; telegram_payment_charge_id: string; }) => Promise; editUserStarSubscription: (params: { user_id: number; telegram_payment_charge_id: string; is_canceled: boolean; }) => Promise; sendMessage: (params: { chat_id: number; message_thread_id?: number; text: string; reply_markup?: unknown; }) => Promise; }; /** * Callback-query ctx shape this module's handlers receive. Composed * from the canonical `BotCallbackCtx` with `{ cid: string }` queryData, * intersected with the admin-context derives (`adminId`, `isAdmin`) * the handlers depend on for the approve/deny/close paths. */ type CommonCtx = BotCallbackCtx & { adminId: number; isAdmin: boolean; }; export type RefundHandlersOptions = { stores: PaymentsStores; /** * Raw storage for cross-user session record reads/writes (the * `@gramio/session` keyspace, outside our `pay:*` stores). Used by * `applyRefundToUser` + `loadFullRecord` to reach a target user's * full session record (preserving fields owned by other plugins). */ storage: Storage; cfg: BotPaymentsConfig; /** * `onRefunded` registrations, keyed by productKey (plus the `"*"` * catch-all). Fired fire-and-forget after an approved refund — the * mirror of `onFulfilled`. */ onRefunded: ReadonlyMap void>>; }; /** * User taps "💸 Request refund" on a charge entry inside the menu's * History view. The menu plugin's `confirm:` overlay already handled * the "Are you sure?" step; this fires on the confirmed tap and: * * 1. Marks the charge `paysupportState = 'opened'` * 2. DMs the admin with [Approve][Deny] buttons * 3. Returns a toast acknowledging the request was sent * * The user's menu remains on the History view (menu's * `confirm`-confirmed action returns to root, but the toast confirms * the action so the user knows what happened). */ export declare const buildRefundRequestHandler: (opts: RefundHandlersOptions) => (ctx: CommonCtx & { queryData: { cid: string; }; }) => Promise; /** * Admin taps "✅ Approve". Calls Telegram's `refundStarPayment`, * persists the refund record + flips charge state, applies the refund * to the target user's session (cross-user write), and notifies the * user. */ export declare const buildRefundApproveHandler: (opts: RefundHandlersOptions) => (ctx: CommonCtx & { queryData: { cid: string; }; }) => Promise; /** * Admin taps "❌ Deny". Reverts `paysupportState` to `'none'` so the * user can try again or the admin can reconsider later. Notifies the * user with the configured paysupport contact for further escalation. */ export declare const buildRefundDenyHandler: (opts: RefundHandlersOptions) => (ctx: CommonCtx & { queryData: { cid: string; }; }) => Promise; export {}; //# sourceMappingURL=refund.d.ts.map