@aepstore-dev/contracts 1.39.0 → 1.41.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,407 +1,407 @@
1
- syntax = "proto3";
2
-
3
- package payments.v1;
4
-
5
- // Commerce + double-entry wallet/ledger (D9 / D9.2). See payments-service/docs/FINANCE.md.
6
- // Money = Decimal-as-string (D7). Statuses/enums as strings (avoid proto enum
7
- // value-name clashes within one package).
8
- service PaymentsService {
9
- // ----- buyer -----
10
- rpc Topup(TopupRequest) returns (CheckoutResponse);
11
- rpc CreateCheckout(CreateCheckoutRequest) returns (CheckoutResponse);
12
- rpc GetMyPurchases(GetMyPurchasesRequest) returns (PurchasesListResponse);
13
- rpc GetPurchase(GetPurchaseRequest) returns (Purchase);
14
- rpc RefundPurchase(RefundPurchaseRequest) returns (Purchase);
15
-
16
- // ----- wallet -----
17
- rpc GetWallet(GetWalletRequest) returns (WalletResponse);
18
- rpc ListTransactions(ListTransactionsRequest) returns (TransactionsListResponse);
19
- rpc GetTransactionMonths(GetTransactionMonthsRequest) returns (GetTransactionMonthsResponse);
20
-
21
- // ----- withdrawals -----
22
- rpc RequestWithdrawal(RequestWithdrawalRequest) returns (Withdrawal);
23
- rpc ListWithdrawals(ListWithdrawalsRequest) returns (WithdrawalsListResponse);
24
- rpc ProcessWithdrawal(ProcessWithdrawalRequest) returns (Withdrawal);
25
-
26
- // ----- provider webhook (gateway forwards a verified event) -----
27
- rpc HandlePaymentEvent(PaymentEventRequest) returns (Ok);
28
-
29
- // ----- premium -----
30
- rpc GetPremiumPlans(GetPremiumPlansRequest) returns (PremiumPlansResponse);
31
- rpc PurchasePremium(PurchasePremiumRequest) returns (PurchasePremiumResponse);
32
- // 7-day refund window from completedAt. Reverses ledger, calls YooKassa for
33
- // card purchases, rolls back the subscription's expiresAt by the period.
34
- rpc RefundPremium(RefundPremiumRequest) returns (RefundPremiumResponse);
35
- rpc GetMyPremiumPayments(GetMyPremiumPaymentsRequest) returns (PremiumPaymentsListResponse);
36
- // Internal — InternalServiceGuard. tasks-service cron triggers due renewals;
37
- // payments-service iterates ACTIVE subscriptions with autoRenew+savedCard.
38
- rpc RunPremiumRenewals(RunPremiumRenewalsRequest) returns (RunPremiumRenewalsResponse);
39
-
40
- // ----- saved cards -----
41
- rpc ListSavedCards(ListSavedCardsRequest) returns (ListSavedCardsResponse);
42
- rpc DeleteSavedCard(DeleteSavedCardRequest) returns (Ok);
43
- rpc SetDefaultSavedCard(SetDefaultSavedCardRequest) returns (SavedCard);
44
- rpc UpdateSavedCard(UpdateSavedCardRequest) returns (SavedCard);
45
-
46
- // ----- payout details -----
47
- rpc UpdatePayoutDetails(UpdatePayoutDetailsRequest) returns (UpdatePayoutDetailsResponse);
48
- rpc GetPayoutDetails(GetPayoutDetailsRequest) returns (UpdatePayoutDetailsResponse);
49
-
50
- // ----- admin -----
51
- rpc GetAdminOverview(AdminOverviewRequest) returns (AdminOverviewResponse);
52
- rpc AdminListTransactions(AdminListTransactionsRequest) returns (AdminTransactionsListResponse);
53
- rpc GetUserFinance(GetUserFinanceRequest) returns (UserFinanceResponse);
54
- rpc CreateAdjustment(CreateAdjustmentRequest) returns (Ok);
55
- rpc GetSalesAnalytics(SalesAnalyticsRequest) returns (SalesAnalyticsResponse);
56
- }
57
-
58
- message Ok { bool ok = 1; }
59
-
60
- // ---------------------------------------------------------------------------
61
- // Purchase / checkout / topup
62
- // ---------------------------------------------------------------------------
63
- message Purchase {
64
- string id = 1;
65
- string product_id = 2;
66
- string product_name = 3;
67
- string user_id = 4;
68
- string price = 5;
69
- string status = 6; // PENDING | COMPLETED | FAILED | REFUNDED
70
- string payment_id = 7;
71
- string payment_method = 8; // BALANCE | YOOKASSA
72
- string commission_percent = 9;
73
- string seller_amount = 10;
74
- string created_at = 11;
75
- string completed_at = 12;
76
- }
77
-
78
- message TopupRequest {
79
- string user_id = 1;
80
- string amount = 2; // >= 10.00
81
- string return_url = 3;
82
- }
83
-
84
- message CreateCheckoutRequest {
85
- string user_id = 1;
86
- string product_id = 2;
87
- string payment_method = 3; // BALANCE | YOOKASSA (default YOOKASSA)
88
- string return_url = 4;
89
- }
90
-
91
- message CheckoutResponse {
92
- string purchase_id = 1;
93
- string payment_id = 2;
94
- string confirmation_url = 3; // empty when paid from balance (instant)
95
- string status = 4; // PENDING (redirect) | COMPLETED (balance)
96
- }
97
-
98
- message GetMyPurchasesRequest { string user_id = 1; int32 page = 2; int32 limit = 3; }
99
- message PurchasesListResponse { repeated Purchase items = 1; int32 total = 2; int32 page = 3; int32 limit = 4; }
100
- message GetPurchaseRequest { string id = 1; string user_id = 2; }
101
- message RefundPurchaseRequest { string purchase_id = 1; string actor_user_id = 2; bool is_admin = 3; string reason = 4; }
102
-
103
- // ---------------------------------------------------------------------------
104
- // Wallet & statement
105
- // ---------------------------------------------------------------------------
106
- message GetWalletRequest { string user_id = 1; }
107
- message WalletResponse {
108
- string spending = 1;
109
- string pending = 2;
110
- string payout = 3;
111
- string spendable = 4; // spending + payout
112
- string withdrawable = 5; // payout
113
- string currency = 6;
114
- int32 lifetime_sales = 7;
115
- string current_commission_percent = 8;
116
- }
117
-
118
- message ListTransactionsRequest {
119
- string user_id = 1;
120
- // Legacy low-level filter (one of LedgerTxType). Kept for backward
121
- // compatibility — admin tooling still uses it directly.
122
- string type = 2;
123
- int32 page = 3;
124
- int32 limit = 4;
125
- // ↓ added for the wallet statement page (Round 3)
126
- // UI-semantic filter mapped onto displayKind:
127
- // ALL | SALES | INCOME | OUTCOME | REFUND | WITHDRAWAL | PREMIUM
128
- // SALES = the seller's earnings on this account (USER_PENDING credits from
129
- // PURCHASE transactions); these stay separate from INCOME (TOPUP).
130
- string flow = 5;
131
- // Period selection. `month` is the convenience form (YYYY-MM) used by the
132
- // month dropdown; from/to override it for an arbitrary range.
133
- string month = 6;
134
- string from = 7;
135
- string to = 8;
136
- // Filter wallet to purchases/refunds of a specific Product category. Has
137
- // no effect on TOPUP/WITHDRAWAL/PREMIUM/ADJUSTMENT entries (they have no
138
- // product).
139
- string product_category_id = 9;
140
- // sort_by ∈ { date | amount | type }. Default: date.
141
- string sort_by = 10;
142
- // order ∈ { asc | desc }. Default: desc.
143
- string order = 11;
144
- }
145
- message StatementEntry {
146
- string id = 1;
147
- string tx_id = 2;
148
- string type = 3; // raw tx type (TOPUP|PURCHASE|...)
149
- string account_kind = 4;
150
- string direction = 5; // DEBIT | CREDIT
151
- string amount = 6;
152
- string description = 7;
153
- string created_at = 8;
154
- // ↓ added for the wallet statement page (Round 3)
155
- // UI-friendly classification computed server-side:
156
- // TOPUP | PURCHASE | SALE | REFUND | PREMIUM | WITHDRAWAL | ADJUSTMENT
157
- // SALE is the seller's view of someone else's PURCHASE (CREDIT to their
158
- // USER_PENDING) — distinct from PURCHASE which is the buyer's DEBIT.
159
- // PREMIUM is split out of PURCHASE/REFUND so the UI can show
160
- // "Продление Premium" / refund-of-premium in their own filter bucket.
161
- // SALE_CLEAR transactions are excluded from the wallet view — the maturity
162
- // event is surfaced via sale_status on the original SALE row instead.
163
- string display_kind = 9;
164
- string balance_after = 10; // affected-account running balance, Decimal-as-string
165
- string product_id = 11; // empty for non-product entries
166
- string product_name = 12;
167
- string product_category = 13; // "Assets" | "Project File" | "Templates"
168
- string product_preview = 14; // optional thumbnail URL for richer rows
169
- // Sale lifecycle. Populated only when display_kind=SALE.
170
- // PENDING — held in USER_PENDING, not yet withdrawable.
171
- // MATURED — SALE_CLEAR has fired; money is in USER_PAYOUT.
172
- string sale_status = 15;
173
- // ISO 8601 when the sale becomes withdrawable (sale_completed_at +
174
- // GRACE_DAYS). Empty for non-sale rows.
175
- string matures_at = 16;
176
- }
177
- message TransactionsListResponse { repeated StatementEntry items = 1; int32 total = 2; int32 page = 3; int32 limit = 4; }
178
-
179
- message GetTransactionMonthsRequest { string user_id = 1; }
180
- message GetTransactionMonthsResponse {
181
- // Newest first. "YYYY-MM" strings; the dropdown renders them
182
- // localized client-side.
183
- repeated string months = 1;
184
- }
185
-
186
- // ---------------------------------------------------------------------------
187
- // Withdrawals
188
- // ---------------------------------------------------------------------------
189
- message Withdrawal {
190
- string id = 1;
191
- string seller_id = 2;
192
- string amount = 3;
193
- string status = 4; // PENDING | PROCESSING | COMPLETED | REJECTED
194
- string method = 5;
195
- string details = 6;
196
- string comment = 7;
197
- string processed_by = 8;
198
- string processed_at = 9;
199
- string created_at = 10;
200
- }
201
- message RequestWithdrawalRequest { string seller_id = 1; string amount = 2; string method = 3; string details = 4; }
202
- message ListWithdrawalsRequest { string seller_id = 1; string status = 2; int32 page = 3; int32 limit = 4; }
203
- message WithdrawalsListResponse { repeated Withdrawal items = 1; int32 total = 2; int32 page = 3; int32 limit = 4; }
204
- message ProcessWithdrawalRequest { string withdrawal_id = 1; string admin_id = 2; string action = 3; string comment = 4; }
205
-
206
- // ---------------------------------------------------------------------------
207
- // Webhook
208
- // ---------------------------------------------------------------------------
209
- message PaymentEventRequest { string event = 1; string payment_id = 2; }
210
-
211
- // ---------------------------------------------------------------------------
212
- // Admin
213
- // ---------------------------------------------------------------------------
214
- message AdminOverviewRequest { string from = 1; string to = 2; }
215
- message AdminOverviewResponse {
216
- string revenue = 1; // platform commission earned (period)
217
- string gmv = 2; // gross merchandise value (period)
218
- string liabilities = 3; // Σ all users' (pending+payout+spending) — what we owe
219
- string psp_clearing = 4; // money in transit at PSP
220
- string payouts_payable = 5; // reserved for approved withdrawals
221
- string refunds_total = 6;
222
- string topups_total = 7;
223
- string withdrawals_total = 8;
224
- int32 sales_count = 9;
225
- string currency = 10;
226
- }
227
-
228
- message AdminListTransactionsRequest {
229
- string type = 1;
230
- string user_id = 2;
231
- string account_kind = 3;
232
- string from = 4;
233
- string to = 5;
234
- int32 page = 6;
235
- int32 limit = 7;
236
- }
237
- message AdminEntry { string account_id = 1; string account_kind = 2; string owner_id = 3; string direction = 4; string amount = 5; }
238
- message AdminLedgerTx {
239
- string id = 1;
240
- string type = 2;
241
- string status = 3;
242
- string ref_type = 4;
243
- string ref_id = 5;
244
- string description = 6;
245
- string created_by = 7;
246
- string created_at = 8;
247
- repeated AdminEntry entries = 9;
248
- }
249
- message AdminTransactionsListResponse { repeated AdminLedgerTx items = 1; int32 total = 2; int32 page = 3; int32 limit = 4; }
250
-
251
- message GetUserFinanceRequest { string user_id = 1; }
252
- message AccountBalance { string kind = 1; string balance = 2; string currency = 3; }
253
- message UserFinanceResponse {
254
- WalletResponse wallet = 1;
255
- repeated AccountBalance accounts = 2;
256
- repeated StatementEntry recent = 3;
257
- }
258
-
259
- message CreateAdjustmentRequest {
260
- string admin_id = 1;
261
- string user_id = 2;
262
- string account_kind = 3; // USER_SPENDING | USER_PAYOUT | USER_PENDING
263
- string direction = 4; // CREDIT (give) | DEBIT (take)
264
- string amount = 5;
265
- string reason = 6;
266
- }
267
-
268
- message SalesAnalyticsRequest { string from = 1; string to = 2; string granularity = 3; } // day|week|month
269
- message SalesPoint { string date = 1; int32 sales_count = 2; string gmv = 3; string revenue = 4; }
270
- message SellerStat { string seller_id = 1; string username = 2; int32 sales = 3; string gmv = 4; }
271
- message SalesAnalyticsResponse {
272
- repeated SalesPoint points = 1;
273
- repeated SellerStat top_sellers = 2;
274
- string refund_rate = 3; // % refunded purchases
275
- }
276
-
277
- // ---------------------------------------------------------------------------
278
- // Premium
279
- // ---------------------------------------------------------------------------
280
- message GetPremiumPlansRequest {}
281
-
282
- // One plan per (period). Prices are computed server-side from BASE_PRICE × months
283
- // × (1 − discount); kept here as canonical strings so the gateway has no math.
284
- message PremiumPlan {
285
- string period = 1; // MONTH_1 | MONTH_3 | MONTH_6 | MONTH_12
286
- int32 months = 2;
287
- string price = 3; // total to charge, Decimal-as-string
288
- string monthly_price = 4; // for UI "≈ X ₽/month"
289
- string discount_percent = 5;
290
- string currency = 6;
291
- }
292
-
293
- message PremiumPlansResponse {
294
- repeated PremiumPlan plans = 1;
295
- string base_monthly_price = 2;
296
- }
297
-
298
- message PurchasePremiumRequest {
299
- string user_id = 1;
300
- string period = 2; // MONTH_1 | MONTH_3 | MONTH_6 | MONTH_12
301
- string payment_method = 3; // BALANCE | YOOKASSA
302
- string return_url = 4; // YooKassa only
303
- // Save the YooKassa payment_method for future auto-renewals. Ignored for
304
- // BALANCE. Default true — the UI surfaces a checkbox.
305
- bool save_payment_method = 5;
306
- }
307
-
308
- message PurchasePremiumResponse {
309
- string payment_id = 1; // PremiumPayment.id
310
- string confirmation_url = 2; // empty for BALANCE (instant) or YooKassa-issued
311
- string status = 3; // PENDING (redirect) | COMPLETED (balance)
312
- }
313
-
314
- message RunPremiumRenewalsRequest {
315
- int32 max_batch = 1; // safety cap; default 100
316
- }
317
-
318
- message RunPremiumRenewalsResponse {
319
- int32 attempted = 1;
320
- int32 succeeded = 2;
321
- int32 failed = 3;
322
- }
323
-
324
- message PremiumPaymentRow {
325
- string id = 1;
326
- string user_id = 2;
327
- string amount = 3;
328
- string period = 4; // MONTH_1 | MONTH_3 | MONTH_6 | MONTH_12
329
- string method = 5; // BALANCE | YOOKASSA
330
- string status = 6; // PENDING | COMPLETED | FAILED | REFUNDED
331
- bool is_renewal = 7;
332
- string created_at = 8;
333
- string completed_at = 9;
334
- string refunded_at = 10;
335
- string refunded_amount = 11;
336
- // Convenience: true if this payment is currently inside the 7-day refund
337
- // window AND status == COMPLETED AND not already refunded.
338
- bool refundable = 12;
339
- }
340
-
341
- message RefundPremiumRequest {
342
- string user_id = 1;
343
- string payment_id = 2;
344
- string reason = 3; // optional
345
- }
346
-
347
- message RefundPremiumResponse {
348
- PremiumPaymentRow payment = 1;
349
- string new_expires_at = 2; // ISO 8601 after rollback
350
- bool subscription_revoked = 3; // true when rollback put expiresAt <= now
351
- }
352
-
353
- message GetMyPremiumPaymentsRequest {
354
- string user_id = 1;
355
- int32 page = 2;
356
- int32 limit = 3;
357
- }
358
-
359
- message PremiumPaymentsListResponse {
360
- repeated PremiumPaymentRow items = 1;
361
- int32 total = 2;
362
- int32 page = 3;
363
- int32 limit = 4;
364
- }
365
-
366
- // ---------------------------------------------------------------------------
367
- // Saved cards (YooKassa payment_method tokens; we never see PAN)
368
- // ---------------------------------------------------------------------------
369
- message SavedCard {
370
- string id = 1;
371
- string brand = 2; // "MIR" | "VISA" | "MASTERCARD" | ""
372
- string last4 = 3; // "0000" etc, display-only
373
- int32 exp_month = 4;
374
- int32 exp_year = 5;
375
- bool is_default = 6;
376
- string nickname = 7; // user-set label
377
- string created_at = 8;
378
- }
379
-
380
- message ListSavedCardsRequest { string user_id = 1; }
381
- message ListSavedCardsResponse { repeated SavedCard items = 1; }
382
-
383
- message DeleteSavedCardRequest { string user_id = 1; string id = 2; }
384
-
385
- message SetDefaultSavedCardRequest { string user_id = 1; string id = 2; }
386
-
387
- message UpdateSavedCardRequest {
388
- string user_id = 1;
389
- string id = 2;
390
- string nickname = 3; // empty = clear
391
- }
392
-
393
- // ---------------------------------------------------------------------------
394
- // Payout details (persistent default; per-withdrawal override still allowed)
395
- // ---------------------------------------------------------------------------
396
- message UpdatePayoutDetailsRequest {
397
- string user_id = 1;
398
- string method = 2; // "card" | "sbp" | "bank" | "" (clear)
399
- string details = 3; // JSON string — payments-service treats opaquely
400
- }
401
-
402
- message UpdatePayoutDetailsResponse {
403
- string method = 1;
404
- string details = 2;
405
- }
406
-
407
- message GetPayoutDetailsRequest { string user_id = 1; }
1
+ syntax = "proto3";
2
+
3
+ package payments.v1;
4
+
5
+ // Commerce + double-entry wallet/ledger (D9 / D9.2). See payments-service/docs/FINANCE.md.
6
+ // Money = Decimal-as-string (D7). Statuses/enums as strings (avoid proto enum
7
+ // value-name clashes within one package).
8
+ service PaymentsService {
9
+ // ----- buyer -----
10
+ rpc Topup(TopupRequest) returns (CheckoutResponse);
11
+ rpc CreateCheckout(CreateCheckoutRequest) returns (CheckoutResponse);
12
+ rpc GetMyPurchases(GetMyPurchasesRequest) returns (PurchasesListResponse);
13
+ rpc GetPurchase(GetPurchaseRequest) returns (Purchase);
14
+ rpc RefundPurchase(RefundPurchaseRequest) returns (Purchase);
15
+
16
+ // ----- wallet -----
17
+ rpc GetWallet(GetWalletRequest) returns (WalletResponse);
18
+ rpc ListTransactions(ListTransactionsRequest) returns (TransactionsListResponse);
19
+ rpc GetTransactionMonths(GetTransactionMonthsRequest) returns (GetTransactionMonthsResponse);
20
+
21
+ // ----- withdrawals -----
22
+ rpc RequestWithdrawal(RequestWithdrawalRequest) returns (Withdrawal);
23
+ rpc ListWithdrawals(ListWithdrawalsRequest) returns (WithdrawalsListResponse);
24
+ rpc ProcessWithdrawal(ProcessWithdrawalRequest) returns (Withdrawal);
25
+
26
+ // ----- provider webhook (gateway forwards a verified event) -----
27
+ rpc HandlePaymentEvent(PaymentEventRequest) returns (Ok);
28
+
29
+ // ----- premium -----
30
+ rpc GetPremiumPlans(GetPremiumPlansRequest) returns (PremiumPlansResponse);
31
+ rpc PurchasePremium(PurchasePremiumRequest) returns (PurchasePremiumResponse);
32
+ // 7-day refund window from completedAt. Reverses ledger, calls YooKassa for
33
+ // card purchases, rolls back the subscription's expiresAt by the period.
34
+ rpc RefundPremium(RefundPremiumRequest) returns (RefundPremiumResponse);
35
+ rpc GetMyPremiumPayments(GetMyPremiumPaymentsRequest) returns (PremiumPaymentsListResponse);
36
+ // Internal — InternalServiceGuard. tasks-service cron triggers due renewals;
37
+ // payments-service iterates ACTIVE subscriptions with autoRenew+savedCard.
38
+ rpc RunPremiumRenewals(RunPremiumRenewalsRequest) returns (RunPremiumRenewalsResponse);
39
+
40
+ // ----- saved cards -----
41
+ rpc ListSavedCards(ListSavedCardsRequest) returns (ListSavedCardsResponse);
42
+ rpc DeleteSavedCard(DeleteSavedCardRequest) returns (Ok);
43
+ rpc SetDefaultSavedCard(SetDefaultSavedCardRequest) returns (SavedCard);
44
+ rpc UpdateSavedCard(UpdateSavedCardRequest) returns (SavedCard);
45
+
46
+ // ----- payout details -----
47
+ rpc UpdatePayoutDetails(UpdatePayoutDetailsRequest) returns (UpdatePayoutDetailsResponse);
48
+ rpc GetPayoutDetails(GetPayoutDetailsRequest) returns (UpdatePayoutDetailsResponse);
49
+
50
+ // ----- admin -----
51
+ rpc GetAdminOverview(AdminOverviewRequest) returns (AdminOverviewResponse);
52
+ rpc AdminListTransactions(AdminListTransactionsRequest) returns (AdminTransactionsListResponse);
53
+ rpc GetUserFinance(GetUserFinanceRequest) returns (UserFinanceResponse);
54
+ rpc CreateAdjustment(CreateAdjustmentRequest) returns (Ok);
55
+ rpc GetSalesAnalytics(SalesAnalyticsRequest) returns (SalesAnalyticsResponse);
56
+ }
57
+
58
+ message Ok { bool ok = 1; }
59
+
60
+ // ---------------------------------------------------------------------------
61
+ // Purchase / checkout / topup
62
+ // ---------------------------------------------------------------------------
63
+ message Purchase {
64
+ string id = 1;
65
+ string product_id = 2;
66
+ string product_name = 3;
67
+ string user_id = 4;
68
+ string price = 5;
69
+ string status = 6; // PENDING | COMPLETED | FAILED | REFUNDED
70
+ string payment_id = 7;
71
+ string payment_method = 8; // BALANCE | YOOKASSA
72
+ string commission_percent = 9;
73
+ string seller_amount = 10;
74
+ string created_at = 11;
75
+ string completed_at = 12;
76
+ }
77
+
78
+ message TopupRequest {
79
+ string user_id = 1;
80
+ string amount = 2; // >= 10.00
81
+ string return_url = 3;
82
+ }
83
+
84
+ message CreateCheckoutRequest {
85
+ string user_id = 1;
86
+ string product_id = 2;
87
+ string payment_method = 3; // BALANCE | YOOKASSA (default YOOKASSA)
88
+ string return_url = 4;
89
+ }
90
+
91
+ message CheckoutResponse {
92
+ string purchase_id = 1;
93
+ string payment_id = 2;
94
+ string confirmation_url = 3; // empty when paid from balance (instant)
95
+ string status = 4; // PENDING (redirect) | COMPLETED (balance)
96
+ }
97
+
98
+ message GetMyPurchasesRequest { string user_id = 1; int32 page = 2; int32 limit = 3; }
99
+ message PurchasesListResponse { repeated Purchase items = 1; int32 total = 2; int32 page = 3; int32 limit = 4; }
100
+ message GetPurchaseRequest { string id = 1; string user_id = 2; }
101
+ message RefundPurchaseRequest { string purchase_id = 1; string actor_user_id = 2; bool is_admin = 3; string reason = 4; }
102
+
103
+ // ---------------------------------------------------------------------------
104
+ // Wallet & statement
105
+ // ---------------------------------------------------------------------------
106
+ message GetWalletRequest { string user_id = 1; }
107
+ message WalletResponse {
108
+ string spending = 1;
109
+ string pending = 2;
110
+ string payout = 3;
111
+ string spendable = 4; // spending + payout
112
+ string withdrawable = 5; // payout
113
+ string currency = 6;
114
+ int32 lifetime_sales = 7;
115
+ string current_commission_percent = 8;
116
+ }
117
+
118
+ message ListTransactionsRequest {
119
+ string user_id = 1;
120
+ // Legacy low-level filter (one of LedgerTxType). Kept for backward
121
+ // compatibility — admin tooling still uses it directly.
122
+ string type = 2;
123
+ int32 page = 3;
124
+ int32 limit = 4;
125
+ // ↓ added for the wallet statement page (Round 3)
126
+ // UI-semantic filter mapped onto displayKind:
127
+ // ALL | SALES | INCOME | OUTCOME | REFUND | WITHDRAWAL | PREMIUM
128
+ // SALES = the seller's earnings on this account (USER_PENDING credits from
129
+ // PURCHASE transactions); these stay separate from INCOME (TOPUP).
130
+ string flow = 5;
131
+ // Period selection. `month` is the convenience form (YYYY-MM) used by the
132
+ // month dropdown; from/to override it for an arbitrary range.
133
+ string month = 6;
134
+ string from = 7;
135
+ string to = 8;
136
+ // Filter wallet to purchases/refunds of a specific Product category. Has
137
+ // no effect on TOPUP/WITHDRAWAL/PREMIUM/ADJUSTMENT entries (they have no
138
+ // product).
139
+ string product_category_id = 9;
140
+ // sort_by ∈ { date | amount | type }. Default: date.
141
+ string sort_by = 10;
142
+ // order ∈ { asc | desc }. Default: desc.
143
+ string order = 11;
144
+ }
145
+ message StatementEntry {
146
+ string id = 1;
147
+ string tx_id = 2;
148
+ string type = 3; // raw tx type (TOPUP|PURCHASE|...)
149
+ string account_kind = 4;
150
+ string direction = 5; // DEBIT | CREDIT
151
+ string amount = 6;
152
+ string description = 7;
153
+ string created_at = 8;
154
+ // ↓ added for the wallet statement page (Round 3)
155
+ // UI-friendly classification computed server-side:
156
+ // TOPUP | PURCHASE | SALE | REFUND | PREMIUM | WITHDRAWAL | ADJUSTMENT
157
+ // SALE is the seller's view of someone else's PURCHASE (CREDIT to their
158
+ // USER_PENDING) — distinct from PURCHASE which is the buyer's DEBIT.
159
+ // PREMIUM is split out of PURCHASE/REFUND so the UI can show
160
+ // "Продление Premium" / refund-of-premium in their own filter bucket.
161
+ // SALE_CLEAR transactions are excluded from the wallet view — the maturity
162
+ // event is surfaced via sale_status on the original SALE row instead.
163
+ string display_kind = 9;
164
+ string balance_after = 10; // affected-account running balance, Decimal-as-string
165
+ string product_id = 11; // empty for non-product entries
166
+ string product_name = 12;
167
+ string product_category = 13; // "Assets" | "Project File" | "Templates"
168
+ string product_preview = 14; // optional thumbnail URL for richer rows
169
+ // Sale lifecycle. Populated only when display_kind=SALE.
170
+ // PENDING — held in USER_PENDING, not yet withdrawable.
171
+ // MATURED — SALE_CLEAR has fired; money is in USER_PAYOUT.
172
+ string sale_status = 15;
173
+ // ISO 8601 when the sale becomes withdrawable (sale_completed_at +
174
+ // GRACE_DAYS). Empty for non-sale rows.
175
+ string matures_at = 16;
176
+ }
177
+ message TransactionsListResponse { repeated StatementEntry items = 1; int32 total = 2; int32 page = 3; int32 limit = 4; }
178
+
179
+ message GetTransactionMonthsRequest { string user_id = 1; }
180
+ message GetTransactionMonthsResponse {
181
+ // Newest first. "YYYY-MM" strings; the dropdown renders them
182
+ // localized client-side.
183
+ repeated string months = 1;
184
+ }
185
+
186
+ // ---------------------------------------------------------------------------
187
+ // Withdrawals
188
+ // ---------------------------------------------------------------------------
189
+ message Withdrawal {
190
+ string id = 1;
191
+ string seller_id = 2;
192
+ string amount = 3;
193
+ string status = 4; // PENDING | PROCESSING | COMPLETED | REJECTED
194
+ string method = 5;
195
+ string details = 6;
196
+ string comment = 7;
197
+ string processed_by = 8;
198
+ string processed_at = 9;
199
+ string created_at = 10;
200
+ }
201
+ message RequestWithdrawalRequest { string seller_id = 1; string amount = 2; string method = 3; string details = 4; }
202
+ message ListWithdrawalsRequest { string seller_id = 1; string status = 2; int32 page = 3; int32 limit = 4; }
203
+ message WithdrawalsListResponse { repeated Withdrawal items = 1; int32 total = 2; int32 page = 3; int32 limit = 4; }
204
+ message ProcessWithdrawalRequest { string withdrawal_id = 1; string admin_id = 2; string action = 3; string comment = 4; }
205
+
206
+ // ---------------------------------------------------------------------------
207
+ // Webhook
208
+ // ---------------------------------------------------------------------------
209
+ message PaymentEventRequest { string event = 1; string payment_id = 2; }
210
+
211
+ // ---------------------------------------------------------------------------
212
+ // Admin
213
+ // ---------------------------------------------------------------------------
214
+ message AdminOverviewRequest { string from = 1; string to = 2; }
215
+ message AdminOverviewResponse {
216
+ string revenue = 1; // platform commission earned (period)
217
+ string gmv = 2; // gross merchandise value (period)
218
+ string liabilities = 3; // Σ all users' (pending+payout+spending) — what we owe
219
+ string psp_clearing = 4; // money in transit at PSP
220
+ string payouts_payable = 5; // reserved for approved withdrawals
221
+ string refunds_total = 6;
222
+ string topups_total = 7;
223
+ string withdrawals_total = 8;
224
+ int32 sales_count = 9;
225
+ string currency = 10;
226
+ }
227
+
228
+ message AdminListTransactionsRequest {
229
+ string type = 1;
230
+ string user_id = 2;
231
+ string account_kind = 3;
232
+ string from = 4;
233
+ string to = 5;
234
+ int32 page = 6;
235
+ int32 limit = 7;
236
+ }
237
+ message AdminEntry { string account_id = 1; string account_kind = 2; string owner_id = 3; string direction = 4; string amount = 5; }
238
+ message AdminLedgerTx {
239
+ string id = 1;
240
+ string type = 2;
241
+ string status = 3;
242
+ string ref_type = 4;
243
+ string ref_id = 5;
244
+ string description = 6;
245
+ string created_by = 7;
246
+ string created_at = 8;
247
+ repeated AdminEntry entries = 9;
248
+ }
249
+ message AdminTransactionsListResponse { repeated AdminLedgerTx items = 1; int32 total = 2; int32 page = 3; int32 limit = 4; }
250
+
251
+ message GetUserFinanceRequest { string user_id = 1; }
252
+ message AccountBalance { string kind = 1; string balance = 2; string currency = 3; }
253
+ message UserFinanceResponse {
254
+ WalletResponse wallet = 1;
255
+ repeated AccountBalance accounts = 2;
256
+ repeated StatementEntry recent = 3;
257
+ }
258
+
259
+ message CreateAdjustmentRequest {
260
+ string admin_id = 1;
261
+ string user_id = 2;
262
+ string account_kind = 3; // USER_SPENDING | USER_PAYOUT | USER_PENDING
263
+ string direction = 4; // CREDIT (give) | DEBIT (take)
264
+ string amount = 5;
265
+ string reason = 6;
266
+ }
267
+
268
+ message SalesAnalyticsRequest { string from = 1; string to = 2; string granularity = 3; } // day|week|month
269
+ message SalesPoint { string date = 1; int32 sales_count = 2; string gmv = 3; string revenue = 4; }
270
+ message SellerStat { string seller_id = 1; string username = 2; int32 sales = 3; string gmv = 4; }
271
+ message SalesAnalyticsResponse {
272
+ repeated SalesPoint points = 1;
273
+ repeated SellerStat top_sellers = 2;
274
+ string refund_rate = 3; // % refunded purchases
275
+ }
276
+
277
+ // ---------------------------------------------------------------------------
278
+ // Premium
279
+ // ---------------------------------------------------------------------------
280
+ message GetPremiumPlansRequest {}
281
+
282
+ // One plan per (period). Prices are computed server-side from BASE_PRICE × months
283
+ // × (1 − discount); kept here as canonical strings so the gateway has no math.
284
+ message PremiumPlan {
285
+ string period = 1; // MONTH_1 | MONTH_3 | MONTH_6 | MONTH_12
286
+ int32 months = 2;
287
+ string price = 3; // total to charge, Decimal-as-string
288
+ string monthly_price = 4; // for UI "≈ X ₽/month"
289
+ string discount_percent = 5;
290
+ string currency = 6;
291
+ }
292
+
293
+ message PremiumPlansResponse {
294
+ repeated PremiumPlan plans = 1;
295
+ string base_monthly_price = 2;
296
+ }
297
+
298
+ message PurchasePremiumRequest {
299
+ string user_id = 1;
300
+ string period = 2; // MONTH_1 | MONTH_3 | MONTH_6 | MONTH_12
301
+ string payment_method = 3; // BALANCE | YOOKASSA
302
+ string return_url = 4; // YooKassa only
303
+ // Save the YooKassa payment_method for future auto-renewals. Ignored for
304
+ // BALANCE. Default true — the UI surfaces a checkbox.
305
+ bool save_payment_method = 5;
306
+ }
307
+
308
+ message PurchasePremiumResponse {
309
+ string payment_id = 1; // PremiumPayment.id
310
+ string confirmation_url = 2; // empty for BALANCE (instant) or YooKassa-issued
311
+ string status = 3; // PENDING (redirect) | COMPLETED (balance)
312
+ }
313
+
314
+ message RunPremiumRenewalsRequest {
315
+ int32 max_batch = 1; // safety cap; default 100
316
+ }
317
+
318
+ message RunPremiumRenewalsResponse {
319
+ int32 attempted = 1;
320
+ int32 succeeded = 2;
321
+ int32 failed = 3;
322
+ }
323
+
324
+ message PremiumPaymentRow {
325
+ string id = 1;
326
+ string user_id = 2;
327
+ string amount = 3;
328
+ string period = 4; // MONTH_1 | MONTH_3 | MONTH_6 | MONTH_12
329
+ string method = 5; // BALANCE | YOOKASSA
330
+ string status = 6; // PENDING | COMPLETED | FAILED | REFUNDED
331
+ bool is_renewal = 7;
332
+ string created_at = 8;
333
+ string completed_at = 9;
334
+ string refunded_at = 10;
335
+ string refunded_amount = 11;
336
+ // Convenience: true if this payment is currently inside the 7-day refund
337
+ // window AND status == COMPLETED AND not already refunded.
338
+ bool refundable = 12;
339
+ }
340
+
341
+ message RefundPremiumRequest {
342
+ string user_id = 1;
343
+ string payment_id = 2;
344
+ string reason = 3; // optional
345
+ }
346
+
347
+ message RefundPremiumResponse {
348
+ PremiumPaymentRow payment = 1;
349
+ string new_expires_at = 2; // ISO 8601 after rollback
350
+ bool subscription_revoked = 3; // true when rollback put expiresAt <= now
351
+ }
352
+
353
+ message GetMyPremiumPaymentsRequest {
354
+ string user_id = 1;
355
+ int32 page = 2;
356
+ int32 limit = 3;
357
+ }
358
+
359
+ message PremiumPaymentsListResponse {
360
+ repeated PremiumPaymentRow items = 1;
361
+ int32 total = 2;
362
+ int32 page = 3;
363
+ int32 limit = 4;
364
+ }
365
+
366
+ // ---------------------------------------------------------------------------
367
+ // Saved cards (YooKassa payment_method tokens; we never see PAN)
368
+ // ---------------------------------------------------------------------------
369
+ message SavedCard {
370
+ string id = 1;
371
+ string brand = 2; // "MIR" | "VISA" | "MASTERCARD" | ""
372
+ string last4 = 3; // "0000" etc, display-only
373
+ int32 exp_month = 4;
374
+ int32 exp_year = 5;
375
+ bool is_default = 6;
376
+ string nickname = 7; // user-set label
377
+ string created_at = 8;
378
+ }
379
+
380
+ message ListSavedCardsRequest { string user_id = 1; }
381
+ message ListSavedCardsResponse { repeated SavedCard items = 1; }
382
+
383
+ message DeleteSavedCardRequest { string user_id = 1; string id = 2; }
384
+
385
+ message SetDefaultSavedCardRequest { string user_id = 1; string id = 2; }
386
+
387
+ message UpdateSavedCardRequest {
388
+ string user_id = 1;
389
+ string id = 2;
390
+ string nickname = 3; // empty = clear
391
+ }
392
+
393
+ // ---------------------------------------------------------------------------
394
+ // Payout details (persistent default; per-withdrawal override still allowed)
395
+ // ---------------------------------------------------------------------------
396
+ message UpdatePayoutDetailsRequest {
397
+ string user_id = 1;
398
+ string method = 2; // "card" | "sbp" | "bank" | "" (clear)
399
+ string details = 3; // JSON string — payments-service treats opaquely
400
+ }
401
+
402
+ message UpdatePayoutDetailsResponse {
403
+ string method = 1;
404
+ string details = 2;
405
+ }
406
+
407
+ message GetPayoutDetailsRequest { string user_id = 1; }