@aepstore-dev/contracts 1.59.0 → 1.61.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,31 +1,35 @@
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
-
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
+ // Generalized per-provider callback (POST /payments/webhook/:provider).
29
+ // Carries the EXACT raw JSON body: signed providers (Heleket) hash the
30
+ // byte-exact payload, so re-serializing a parsed body would break the sign.
31
+ rpc HandleProviderCallback(ProviderCallbackRequest) returns (Ok);
32
+
29
33
  // ----- premium -----
30
34
  rpc GetPremiumPlans(GetPremiumPlansRequest) returns (PremiumPlansResponse);
31
35
  rpc PurchasePremium(PurchasePremiumRequest) returns (PurchasePremiumResponse);
@@ -33,307 +37,313 @@ service PaymentsService {
33
37
  // 7-day refund window from completedAt. Reverses ledger, calls YooKassa for
34
38
  // card purchases, rolls back the subscription's expiresAt by the period.
35
39
  rpc RefundPremium(RefundPremiumRequest) returns (RefundPremiumResponse);
36
- rpc GetMyPremiumPayments(GetMyPremiumPaymentsRequest) returns (PremiumPaymentsListResponse);
37
- // Internal InternalServiceGuard. tasks-service cron triggers due renewals;
38
- // payments-service iterates ACTIVE subscriptions with autoRenew+savedCard.
39
- rpc RunPremiumRenewals(RunPremiumRenewalsRequest) returns (RunPremiumRenewalsResponse);
40
-
41
- // ----- saved cards -----
42
- rpc ListSavedCards(ListSavedCardsRequest) returns (ListSavedCardsResponse);
43
- rpc DeleteSavedCard(DeleteSavedCardRequest) returns (Ok);
44
- rpc SetDefaultSavedCard(SetDefaultSavedCardRequest) returns (SavedCard);
45
- rpc UpdateSavedCard(UpdateSavedCardRequest) returns (SavedCard);
46
- // Standalone "bind card" flow: creates a 1₽ YooKassa charge with
47
- // save_payment_method=true; after the webhook the SavedCard row is
48
- // persisted and the 1₽ credits USER_SPENDING so the user keeps it.
49
- rpc BindCard(BindCardRequest) returns (CheckoutResponse);
50
- // Poll an intent after returnUrl redirect: TOPUP/PREMIUM completion, bind-card
51
- // completion. Ownership-checked by user_id.
52
- rpc GetPaymentIntent(GetPaymentIntentRequest) returns (PaymentIntentStatus);
53
-
54
- // ----- payout details -----
55
- rpc UpdatePayoutDetails(UpdatePayoutDetailsRequest) returns (UpdatePayoutDetailsResponse);
56
- rpc GetPayoutDetails(GetPayoutDetailsRequest) returns (UpdatePayoutDetailsResponse);
57
-
58
- // ----- admin -----
59
- rpc GetAdminOverview(AdminOverviewRequest) returns (AdminOverviewResponse);
60
- rpc AdminListTransactions(AdminListTransactionsRequest) returns (AdminTransactionsListResponse);
61
- rpc GetUserFinance(GetUserFinanceRequest) returns (UserFinanceResponse);
62
- rpc CreateAdjustment(CreateAdjustmentRequest) returns (Ok);
63
- rpc GetSalesAnalytics(SalesAnalyticsRequest) returns (SalesAnalyticsResponse);
64
- }
65
-
66
- message Ok { bool ok = 1; }
67
-
68
- // ---------------------------------------------------------------------------
69
- // Purchase / checkout / topup
70
- // ---------------------------------------------------------------------------
71
- message Purchase {
72
- string id = 1;
73
- string product_id = 2;
74
- string product_name = 3;
75
- string user_id = 4;
76
- string price = 5;
77
- string status = 6; // PENDING | COMPLETED | FAILED | REFUNDED
78
- string payment_id = 7;
79
- string payment_method = 8; // BALANCE | YOOKASSA
80
- string commission_percent = 9;
81
- string seller_amount = 10;
82
- string created_at = 11;
83
- string completed_at = 12;
84
- }
85
-
86
- message TopupRequest {
87
- string user_id = 1;
88
- string amount = 2; // >= 10.00
89
- string return_url = 3;
90
- string payment_method = 4; // YOOKASSA | SAVED_CARD (default YOOKASSA)
91
- string saved_card_id = 5; // required when payment_method=SAVED_CARD
92
- }
93
-
94
- message CreateCheckoutRequest {
95
- string user_id = 1;
96
- string product_id = 2;
97
- string payment_method = 3; // BALANCE | YOOKASSA | SAVED_CARD (default YOOKASSA)
98
- string return_url = 4;
99
- // When payment_method=SAVED_CARD — required. ID of a SavedCard row owned
100
- // by user_id. Ignored otherwise.
101
- string saved_card_id = 5;
102
- // When payment_method=YOOKASSA — optional. If true, save the card token
103
- // after success; the bound card becomes available in /account/cards.
104
- bool save_payment_method = 6;
105
- }
106
-
107
- message BindCardRequest {
108
- string user_id = 1;
109
- string return_url = 2;
110
- }
111
-
112
- message GetPaymentIntentRequest {
113
- string intent_id = 1;
114
- string user_id = 2; // ownership check
115
- }
116
-
117
- message PaymentIntentStatus {
118
- string id = 1;
119
- string user_id = 2;
120
- string purpose = 3; // TOPUP | PREMIUM
121
- string status = 4; // PENDING | COMPLETED | FAILED | CANCELED
122
- string amount = 5;
123
- string currency = 6;
124
- string purchase_id = 7; // set when purpose=PREMIUM (else empty)
125
- string created_at = 8;
126
- string updated_at = 9;
127
- }
128
-
129
- message CheckoutResponse {
130
- string purchase_id = 1;
131
- string payment_id = 2;
132
- string confirmation_url = 3; // empty when paid from balance (instant)
133
- string status = 4; // PENDING (redirect) | COMPLETED (balance)
134
- string intent_id = 5; // poll via GetPaymentIntent for TOPUP / bind-card flows
135
- }
136
-
137
- message GetMyPurchasesRequest { string user_id = 1; int32 page = 2; int32 limit = 3; }
138
- message PurchasesListResponse { repeated Purchase items = 1; int32 total = 2; int32 page = 3; int32 limit = 4; }
139
- message GetPurchaseRequest { string id = 1; string user_id = 2; }
140
- message RefundPurchaseRequest { string purchase_id = 1; string actor_user_id = 2; bool is_admin = 3; string reason = 4; }
141
-
142
- // ---------------------------------------------------------------------------
143
- // Wallet & statement
144
- // ---------------------------------------------------------------------------
145
- message GetWalletRequest { string user_id = 1; }
146
- message WalletResponse {
147
- string spending = 1;
148
- string pending = 2;
149
- string payout = 3;
150
- string spendable = 4; // spending + payout
151
- string withdrawable = 5; // payout
152
- string currency = 6;
153
- int32 lifetime_sales = 7;
154
- string current_commission_percent = 8;
155
- }
156
-
157
- message ListTransactionsRequest {
158
- string user_id = 1;
159
- // Legacy low-level filter (one of LedgerTxType). Kept for backward
160
- // compatibility admin tooling still uses it directly.
161
- string type = 2;
162
- int32 page = 3;
163
- int32 limit = 4;
164
- // added for the wallet statement page (Round 3)
165
- // UI-semantic filter mapped onto displayKind:
166
- // ALL | SALES | INCOME | OUTCOME | REFUND | WITHDRAWAL | PREMIUM
167
- // SALES = the seller's earnings on this account (USER_PENDING credits from
168
- // PURCHASE transactions); these stay separate from INCOME (TOPUP).
169
- string flow = 5;
170
- // Period selection. `month` is the convenience form (YYYY-MM) used by the
171
- // month dropdown; from/to override it for an arbitrary range.
172
- string month = 6;
173
- string from = 7;
174
- string to = 8;
175
- // Filter wallet to purchases/refunds of a specific Product category. Has
176
- // no effect on TOPUP/WITHDRAWAL/PREMIUM/ADJUSTMENT entries (they have no
177
- // product).
178
- string product_category_id = 9;
179
- // sort_by { date | amount | type }. Default: date.
180
- string sort_by = 10;
181
- // order { asc | desc }. Default: desc.
182
- string order = 11;
183
- }
184
- message StatementEntry {
185
- string id = 1;
186
- string tx_id = 2;
187
- string type = 3; // raw tx type (TOPUP|PURCHASE|...)
188
- string account_kind = 4;
189
- string direction = 5; // DEBIT | CREDIT
190
- string amount = 6;
191
- string description = 7;
192
- string created_at = 8;
193
- // added for the wallet statement page (Round 3)
194
- // UI-friendly classification computed server-side:
195
- // TOPUP | PURCHASE | SALE | REFUND | PREMIUM | WITHDRAWAL | ADJUSTMENT
196
- // SALE is the seller's view of someone else's PURCHASE (CREDIT to their
197
- // USER_PENDING) distinct from PURCHASE which is the buyer's DEBIT.
198
- // PREMIUM is split out of PURCHASE/REFUND so the UI can show
199
- // "Продление Premium" / refund-of-premium in their own filter bucket.
200
- // SALE_CLEAR transactions are excluded from the wallet view — the maturity
201
- // event is surfaced via sale_status on the original SALE row instead.
202
- string display_kind = 9;
203
- string balance_after = 10; // affected-account running balance, Decimal-as-string
204
- string product_id = 11; // empty for non-product entries
205
- string product_name = 12;
206
- string product_category = 13; // "Assets" | "Project File" | "Templates"
207
- string product_preview = 14; // optional thumbnail URL for richer rows
208
- // Sale lifecycle. Populated only when display_kind=SALE.
209
- // PENDING held in USER_PENDING, not yet withdrawable.
210
- // MATUREDSALE_CLEAR has fired; money is in USER_PAYOUT.
211
- string sale_status = 15;
212
- // ISO 8601 when the sale becomes withdrawable (sale_completed_at +
213
- // GRACE_DAYS). Empty for non-sale rows.
214
- string matures_at = 16;
215
- }
216
- message TransactionsListResponse { repeated StatementEntry items = 1; int32 total = 2; int32 page = 3; int32 limit = 4; }
217
-
218
- message GetTransactionMonthsRequest { string user_id = 1; }
219
- message GetTransactionMonthsResponse {
220
- // Newest first. "YYYY-MM" strings; the dropdown renders them
221
- // localized client-side.
222
- repeated string months = 1;
223
- }
224
-
225
- // ---------------------------------------------------------------------------
226
- // Withdrawals
227
- // ---------------------------------------------------------------------------
228
- message Withdrawal {
229
- string id = 1;
230
- string seller_id = 2;
231
- string amount = 3;
232
- string status = 4; // PENDING | PROCESSING | COMPLETED | REJECTED
233
- string method = 5;
234
- string details = 6;
235
- string comment = 7;
236
- string processed_by = 8;
237
- string processed_at = 9;
238
- string created_at = 10;
239
- }
240
- message RequestWithdrawalRequest { string seller_id = 1; string amount = 2; string method = 3; string details = 4; }
241
- message ListWithdrawalsRequest { string seller_id = 1; string status = 2; int32 page = 3; int32 limit = 4; }
242
- message WithdrawalsListResponse { repeated Withdrawal items = 1; int32 total = 2; int32 page = 3; int32 limit = 4; }
243
- message ProcessWithdrawalRequest { string withdrawal_id = 1; string admin_id = 2; string action = 3; string comment = 4; }
244
-
245
- // ---------------------------------------------------------------------------
246
- // Webhook
247
- // ---------------------------------------------------------------------------
248
- message PaymentEventRequest { string event = 1; string payment_id = 2; }
249
-
250
- // ---------------------------------------------------------------------------
251
- // Admin
252
- // ---------------------------------------------------------------------------
253
- message AdminOverviewRequest { string from = 1; string to = 2; }
254
- message AdminOverviewResponse {
255
- string revenue = 1; // platform commission earned (period)
256
- string gmv = 2; // gross merchandise value (period)
257
- string liabilities = 3; // Σ all users' (pending+payout+spending) — what we owe
258
- string psp_clearing = 4; // money in transit at PSP
259
- string payouts_payable = 5; // reserved for approved withdrawals
260
- string refunds_total = 6;
261
- string topups_total = 7;
262
- string withdrawals_total = 8;
263
- int32 sales_count = 9;
264
- string currency = 10;
265
- }
266
-
267
- message AdminListTransactionsRequest {
268
- string type = 1;
269
- string user_id = 2;
270
- string account_kind = 3;
271
- string from = 4;
272
- string to = 5;
273
- int32 page = 6;
274
- int32 limit = 7;
275
- }
276
- message AdminEntry { string account_id = 1; string account_kind = 2; string owner_id = 3; string direction = 4; string amount = 5; }
277
- message AdminLedgerTx {
278
- string id = 1;
279
- string type = 2;
280
- string status = 3;
281
- string ref_type = 4;
282
- string ref_id = 5;
283
- string description = 6;
284
- string created_by = 7;
285
- string created_at = 8;
286
- repeated AdminEntry entries = 9;
287
- }
288
- message AdminTransactionsListResponse { repeated AdminLedgerTx items = 1; int32 total = 2; int32 page = 3; int32 limit = 4; }
289
-
290
- message GetUserFinanceRequest { string user_id = 1; }
291
- message AccountBalance { string kind = 1; string balance = 2; string currency = 3; }
292
- message UserFinanceResponse {
293
- WalletResponse wallet = 1;
294
- repeated AccountBalance accounts = 2;
295
- repeated StatementEntry recent = 3;
296
- }
297
-
298
- message CreateAdjustmentRequest {
299
- string admin_id = 1;
300
- string user_id = 2;
301
- string account_kind = 3; // USER_SPENDING | USER_PAYOUT | USER_PENDING
302
- string direction = 4; // CREDIT (give) | DEBIT (take)
303
- string amount = 5;
304
- string reason = 6;
305
- }
306
-
307
- message SalesAnalyticsRequest { string from = 1; string to = 2; string granularity = 3; } // day|week|month
308
- message SalesPoint { string date = 1; int32 sales_count = 2; string gmv = 3; string revenue = 4; }
309
- message SellerStat { string seller_id = 1; string username = 2; int32 sales = 3; string gmv = 4; }
310
- message SalesAnalyticsResponse {
311
- repeated SalesPoint points = 1;
312
- repeated SellerStat top_sellers = 2;
313
- string refund_rate = 3; // % refunded purchases
314
- }
315
-
316
- // ---------------------------------------------------------------------------
317
- // Premium
318
- // ---------------------------------------------------------------------------
319
- message GetPremiumPlansRequest {}
320
-
321
- // One plan per (period). Prices are computed server-side from BASE_PRICE × months
322
- // × (1 − discount); kept here as canonical strings so the gateway has no math.
323
- message PremiumPlan {
324
- string period = 1; // MONTH_1 | MONTH_3 | MONTH_6 | MONTH_12
325
- int32 months = 2;
326
- string price = 3; // total to charge, Decimal-as-string
327
- string monthly_price = 4; // for UI "≈ X ₽/month"
328
- string discount_percent = 5;
329
- string currency = 6;
330
- }
331
-
332
- message PremiumPlansResponse {
333
- repeated PremiumPlan plans = 1;
334
- string base_monthly_price = 2;
335
- }
336
-
40
+ rpc GetMyPremiumPayments(GetMyPremiumPaymentsRequest) returns (PremiumPaymentsListResponse);
41
+ rpc GetPremiumPayment(GetPremiumPaymentRequest) returns (PremiumPaymentRow);
42
+ // Internal — InternalServiceGuard. tasks-service cron triggers due renewals;
43
+ // payments-service iterates ACTIVE subscriptions with autoRenew+savedCard.
44
+ rpc RunPremiumRenewals(RunPremiumRenewalsRequest) returns (RunPremiumRenewalsResponse);
45
+
46
+ // ----- saved cards -----
47
+ rpc ListSavedCards(ListSavedCardsRequest) returns (ListSavedCardsResponse);
48
+ rpc DeleteSavedCard(DeleteSavedCardRequest) returns (Ok);
49
+ rpc SetDefaultSavedCard(SetDefaultSavedCardRequest) returns (SavedCard);
50
+ rpc UpdateSavedCard(UpdateSavedCardRequest) returns (SavedCard);
51
+ // Standalone "bind card" flow: creates a 1₽ YooKassa charge with
52
+ // save_payment_method=true; after the webhook the SavedCard row is
53
+ // persisted and the 1₽ credits USER_SPENDING so the user keeps it.
54
+ rpc BindCard(BindCardRequest) returns (CheckoutResponse);
55
+ // Poll an intent after returnUrl redirect: TOPUP/PREMIUM completion, bind-card
56
+ // completion. Ownership-checked by user_id.
57
+ rpc GetPaymentIntent(GetPaymentIntentRequest) returns (PaymentIntentStatus);
58
+
59
+ // ----- payout details -----
60
+ rpc UpdatePayoutDetails(UpdatePayoutDetailsRequest) returns (UpdatePayoutDetailsResponse);
61
+ rpc GetPayoutDetails(GetPayoutDetailsRequest) returns (UpdatePayoutDetailsResponse);
62
+
63
+ // ----- admin -----
64
+ rpc GetAdminOverview(AdminOverviewRequest) returns (AdminOverviewResponse);
65
+ rpc AdminListTransactions(AdminListTransactionsRequest) returns (AdminTransactionsListResponse);
66
+ rpc GetUserFinance(GetUserFinanceRequest) returns (UserFinanceResponse);
67
+ rpc CreateAdjustment(CreateAdjustmentRequest) returns (Ok);
68
+ rpc GetSalesAnalytics(SalesAnalyticsRequest) returns (SalesAnalyticsResponse);
69
+ }
70
+
71
+ message Ok { bool ok = 1; }
72
+
73
+ // ---------------------------------------------------------------------------
74
+ // Purchase / checkout / topup
75
+ // ---------------------------------------------------------------------------
76
+ message Purchase {
77
+ string id = 1;
78
+ string product_id = 2;
79
+ string product_name = 3;
80
+ string user_id = 4;
81
+ string price = 5;
82
+ string status = 6; // PENDING | COMPLETED | FAILED | REFUNDED
83
+ string payment_id = 7;
84
+ string payment_method = 8; // BALANCE | YOOKASSA
85
+ string commission_percent = 9;
86
+ string seller_amount = 10;
87
+ string created_at = 11;
88
+ string completed_at = 12;
89
+ }
90
+
91
+ message TopupRequest {
92
+ string user_id = 1;
93
+ string amount = 2; // >= 10.00
94
+ string return_url = 3;
95
+ string payment_method = 4; // YOOKASSA | SAVED_CARD | CRYPTO (default YOOKASSA)
96
+ string saved_card_id = 5; // required when payment_method=SAVED_CARD
97
+ }
98
+
99
+ message CreateCheckoutRequest {
100
+ string user_id = 1;
101
+ string product_id = 2;
102
+ string payment_method = 3; // BALANCE | YOOKASSA | SAVED_CARD (default YOOKASSA)
103
+ string return_url = 4;
104
+ // When payment_method=SAVED_CARD — required. ID of a SavedCard row owned
105
+ // by user_id. Ignored otherwise.
106
+ string saved_card_id = 5;
107
+ // When payment_method=YOOKASSA optional. If true, save the card token
108
+ // after success; the bound card becomes available in /account/cards.
109
+ bool save_payment_method = 6;
110
+ }
111
+
112
+ message BindCardRequest {
113
+ string user_id = 1;
114
+ string return_url = 2;
115
+ }
116
+
117
+ message GetPaymentIntentRequest {
118
+ string intent_id = 1;
119
+ string user_id = 2; // ownership check
120
+ }
121
+
122
+ message PaymentIntentStatus {
123
+ string id = 1;
124
+ string user_id = 2;
125
+ string purpose = 3; // TOPUP | PREMIUM
126
+ string status = 4; // PENDING | COMPLETED | FAILED | CANCELED
127
+ string amount = 5;
128
+ string currency = 6;
129
+ string purchase_id = 7; // set when purpose=PREMIUM (else empty)
130
+ string created_at = 8;
131
+ string updated_at = 9;
132
+ }
133
+
134
+ message CheckoutResponse {
135
+ string purchase_id = 1;
136
+ string payment_id = 2;
137
+ string confirmation_url = 3; // empty when paid from balance (instant)
138
+ string status = 4; // PENDING (redirect) | COMPLETED (balance)
139
+ string intent_id = 5; // poll via GetPaymentIntent for TOPUP / bind-card flows
140
+ }
141
+
142
+ message GetMyPurchasesRequest { string user_id = 1; int32 page = 2; int32 limit = 3; }
143
+ message PurchasesListResponse { repeated Purchase items = 1; int32 total = 2; int32 page = 3; int32 limit = 4; }
144
+ message GetPurchaseRequest { string id = 1; string user_id = 2; }
145
+ message RefundPurchaseRequest { string purchase_id = 1; string actor_user_id = 2; bool is_admin = 3; string reason = 4; }
146
+
147
+ // ---------------------------------------------------------------------------
148
+ // Wallet & statement
149
+ // ---------------------------------------------------------------------------
150
+ message GetWalletRequest { string user_id = 1; }
151
+ message WalletResponse {
152
+ string spending = 1;
153
+ string pending = 2;
154
+ string payout = 3;
155
+ string spendable = 4; // spending + payout
156
+ string withdrawable = 5; // payout
157
+ string currency = 6;
158
+ int32 lifetime_sales = 7;
159
+ string current_commission_percent = 8;
160
+ }
161
+
162
+ message ListTransactionsRequest {
163
+ string user_id = 1;
164
+ // Legacy low-level filter (one of LedgerTxType). Kept for backward
165
+ // compatibility admin tooling still uses it directly.
166
+ string type = 2;
167
+ int32 page = 3;
168
+ int32 limit = 4;
169
+ // added for the wallet statement page (Round 3)
170
+ // UI-semantic filter mapped onto displayKind:
171
+ // ALL | SALES | INCOME | OUTCOME | REFUND | WITHDRAWAL | PREMIUM
172
+ // SALES = the seller's earnings on this account (USER_PENDING credits from
173
+ // PURCHASE transactions); these stay separate from INCOME (TOPUP).
174
+ string flow = 5;
175
+ // Period selection. `month` is the convenience form (YYYY-MM) used by the
176
+ // month dropdown; from/to override it for an arbitrary range.
177
+ string month = 6;
178
+ string from = 7;
179
+ string to = 8;
180
+ // Filter wallet to purchases/refunds of a specific Product category. Has
181
+ // no effect on TOPUP/WITHDRAWAL/PREMIUM/ADJUSTMENT entries (they have no
182
+ // product).
183
+ string product_category_id = 9;
184
+ // sort_by { date | amount | type }. Default: date.
185
+ string sort_by = 10;
186
+ // order { asc | desc }. Default: desc.
187
+ string order = 11;
188
+ }
189
+ message StatementEntry {
190
+ string id = 1;
191
+ string tx_id = 2;
192
+ string type = 3; // raw tx type (TOPUP|PURCHASE|...)
193
+ string account_kind = 4;
194
+ string direction = 5; // DEBIT | CREDIT
195
+ string amount = 6;
196
+ string description = 7;
197
+ string created_at = 8;
198
+ // added for the wallet statement page (Round 3)
199
+ // UI-friendly classification computed server-side:
200
+ // TOPUP | PURCHASE | SALE | REFUND | PREMIUM | WITHDRAWAL | ADJUSTMENT
201
+ // SALE is the seller's view of someone else's PURCHASE (CREDIT to their
202
+ // USER_PENDING) distinct from PURCHASE which is the buyer's DEBIT.
203
+ // PREMIUM is split out of PURCHASE/REFUND so the UI can show
204
+ // "Продление Premium" / refund-of-premium in their own filter bucket.
205
+ // SALE_CLEAR transactions are excluded from the wallet view the maturity
206
+ // event is surfaced via sale_status on the original SALE row instead.
207
+ string display_kind = 9;
208
+ string balance_after = 10; // affected-account running balance, Decimal-as-string
209
+ string product_id = 11; // empty for non-product entries
210
+ string product_name = 12;
211
+ string product_category = 13; // "Assets" | "Project File" | "Templates"
212
+ string product_preview = 14; // optional thumbnail URL for richer rows
213
+ // Sale lifecycle. Populated only when display_kind=SALE.
214
+ // PENDINGheld in USER_PENDING, not yet withdrawable.
215
+ // MATURED SALE_CLEAR has fired; money is in USER_PAYOUT.
216
+ string sale_status = 15;
217
+ // ISO 8601 when the sale becomes withdrawable (sale_completed_at +
218
+ // GRACE_DAYS). Empty for non-sale rows.
219
+ string matures_at = 16;
220
+ }
221
+ message TransactionsListResponse { repeated StatementEntry items = 1; int32 total = 2; int32 page = 3; int32 limit = 4; }
222
+
223
+ message GetTransactionMonthsRequest { string user_id = 1; }
224
+ message GetTransactionMonthsResponse {
225
+ // Newest first. "YYYY-MM" strings; the dropdown renders them
226
+ // localized client-side.
227
+ repeated string months = 1;
228
+ }
229
+
230
+ // ---------------------------------------------------------------------------
231
+ // Withdrawals
232
+ // ---------------------------------------------------------------------------
233
+ message Withdrawal {
234
+ string id = 1;
235
+ string seller_id = 2;
236
+ string amount = 3;
237
+ string status = 4; // PENDING | PROCESSING | COMPLETED | REJECTED
238
+ string method = 5;
239
+ string details = 6;
240
+ string comment = 7;
241
+ string processed_by = 8;
242
+ string processed_at = 9;
243
+ string created_at = 10;
244
+ }
245
+ message RequestWithdrawalRequest { string seller_id = 1; string amount = 2; string method = 3; string details = 4; }
246
+ message ListWithdrawalsRequest { string seller_id = 1; string status = 2; int32 page = 3; int32 limit = 4; }
247
+ message WithdrawalsListResponse { repeated Withdrawal items = 1; int32 total = 2; int32 page = 3; int32 limit = 4; }
248
+ message ProcessWithdrawalRequest { string withdrawal_id = 1; string admin_id = 2; string action = 3; string comment = 4; }
249
+
250
+ // ---------------------------------------------------------------------------
251
+ // Webhook
252
+ // ---------------------------------------------------------------------------
253
+ message PaymentEventRequest { string event = 1; string payment_id = 2; }
254
+
255
+ message ProviderCallbackRequest {
256
+ string provider = 1; // yookassa | heleket | …
257
+ string raw_body = 2; // exact raw JSON body as received (signature input)
258
+ }
259
+
260
+ // ---------------------------------------------------------------------------
261
+ // Admin
262
+ // ---------------------------------------------------------------------------
263
+ message AdminOverviewRequest { string from = 1; string to = 2; }
264
+ message AdminOverviewResponse {
265
+ string revenue = 1; // platform commission earned (period)
266
+ string gmv = 2; // gross merchandise value (period)
267
+ string liabilities = 3; // Σ all users' (pending+payout+spending) — what we owe
268
+ string psp_clearing = 4; // money in transit at PSP
269
+ string payouts_payable = 5; // reserved for approved withdrawals
270
+ string refunds_total = 6;
271
+ string topups_total = 7;
272
+ string withdrawals_total = 8;
273
+ int32 sales_count = 9;
274
+ string currency = 10;
275
+ }
276
+
277
+ message AdminListTransactionsRequest {
278
+ string type = 1;
279
+ string user_id = 2;
280
+ string account_kind = 3;
281
+ string from = 4;
282
+ string to = 5;
283
+ int32 page = 6;
284
+ int32 limit = 7;
285
+ }
286
+ message AdminEntry { string account_id = 1; string account_kind = 2; string owner_id = 3; string direction = 4; string amount = 5; }
287
+ message AdminLedgerTx {
288
+ string id = 1;
289
+ string type = 2;
290
+ string status = 3;
291
+ string ref_type = 4;
292
+ string ref_id = 5;
293
+ string description = 6;
294
+ string created_by = 7;
295
+ string created_at = 8;
296
+ repeated AdminEntry entries = 9;
297
+ }
298
+ message AdminTransactionsListResponse { repeated AdminLedgerTx items = 1; int32 total = 2; int32 page = 3; int32 limit = 4; }
299
+
300
+ message GetUserFinanceRequest { string user_id = 1; }
301
+ message AccountBalance { string kind = 1; string balance = 2; string currency = 3; }
302
+ message UserFinanceResponse {
303
+ WalletResponse wallet = 1;
304
+ repeated AccountBalance accounts = 2;
305
+ repeated StatementEntry recent = 3;
306
+ }
307
+
308
+ message CreateAdjustmentRequest {
309
+ string admin_id = 1;
310
+ string user_id = 2;
311
+ string account_kind = 3; // USER_SPENDING | USER_PAYOUT | USER_PENDING
312
+ string direction = 4; // CREDIT (give) | DEBIT (take)
313
+ string amount = 5;
314
+ string reason = 6;
315
+ }
316
+
317
+ message SalesAnalyticsRequest { string from = 1; string to = 2; string granularity = 3; } // day|week|month
318
+ message SalesPoint { string date = 1; int32 sales_count = 2; string gmv = 3; string revenue = 4; }
319
+ message SellerStat { string seller_id = 1; string username = 2; int32 sales = 3; string gmv = 4; }
320
+ message SalesAnalyticsResponse {
321
+ repeated SalesPoint points = 1;
322
+ repeated SellerStat top_sellers = 2;
323
+ string refund_rate = 3; // % refunded purchases
324
+ }
325
+
326
+ // ---------------------------------------------------------------------------
327
+ // Premium
328
+ // ---------------------------------------------------------------------------
329
+ message GetPremiumPlansRequest {}
330
+
331
+ // One plan per (period). Prices are computed server-side from BASE_PRICE × months
332
+ // × (1 − discount); kept here as canonical strings so the gateway has no math.
333
+ message PremiumPlan {
334
+ string period = 1; // MONTH_1 | MONTH_3 | MONTH_6 | MONTH_12
335
+ int32 months = 2;
336
+ string price = 3; // total to charge, Decimal-as-string
337
+ string monthly_price = 4; // for UI "≈ X ₽/month"
338
+ string discount_percent = 5;
339
+ string currency = 6;
340
+ }
341
+
342
+ message PremiumPlansResponse {
343
+ repeated PremiumPlan plans = 1;
344
+ string base_monthly_price = 2;
345
+ }
346
+
337
347
  message PurchasePremiumRequest {
338
348
  string user_id = 1;
339
349
  string period = 2; // MONTH_1 | MONTH_3 | MONTH_6 | MONTH_12
@@ -345,17 +355,17 @@ message PurchasePremiumRequest {
345
355
  bool auto_renew = 6; // default false; requires off-session-capable method
346
356
  string saved_card_id = 7; // optional for SAVED_CARD; empty = default card
347
357
  }
348
-
349
- message PurchasePremiumResponse {
350
- string payment_id = 1; // PremiumPayment.id
351
- string confirmation_url = 2; // empty for BALANCE (instant) or YooKassa-issued
352
- string status = 3; // PENDING (redirect) | COMPLETED (balance)
353
- }
354
-
355
- message RunPremiumRenewalsRequest {
356
- int32 max_batch = 1; // safety cap; default 100
357
- }
358
-
358
+
359
+ message PurchasePremiumResponse {
360
+ string payment_id = 1; // PremiumPayment.id
361
+ string confirmation_url = 2; // empty for BALANCE (instant) or YooKassa-issued
362
+ string status = 3; // PENDING (redirect) | COMPLETED (balance)
363
+ }
364
+
365
+ message RunPremiumRenewalsRequest {
366
+ int32 max_batch = 1; // safety cap; default 100
367
+ }
368
+
359
369
  message RunPremiumRenewalsResponse {
360
370
  int32 attempted = 1;
361
371
  int32 succeeded = 2;
@@ -375,86 +385,91 @@ message PremiumPaymentMethodResponse {
375
385
  }
376
386
 
377
387
  message PremiumPaymentRow {
378
- string id = 1;
379
- string user_id = 2;
380
- string amount = 3;
381
- string period = 4; // MONTH_1 | MONTH_3 | MONTH_6 | MONTH_12
382
- string method = 5; // BALANCE | YOOKASSA
383
- string status = 6; // PENDING | COMPLETED | FAILED | REFUNDED
384
- bool is_renewal = 7;
385
- string created_at = 8;
386
- string completed_at = 9;
387
- string refunded_at = 10;
388
- string refunded_amount = 11;
389
- // Convenience: true if this payment is currently inside the 7-day refund
390
- // window AND status == COMPLETED AND not already refunded.
391
- bool refundable = 12;
392
- }
393
-
394
- message RefundPremiumRequest {
395
- string user_id = 1;
396
- string payment_id = 2;
397
- string reason = 3; // optional
398
- }
399
-
400
- message RefundPremiumResponse {
401
- PremiumPaymentRow payment = 1;
402
- string new_expires_at = 2; // ISO 8601 after rollback
403
- bool subscription_revoked = 3; // true when rollback put expiresAt <= now
404
- }
405
-
406
- message GetMyPremiumPaymentsRequest {
407
- string user_id = 1;
408
- int32 page = 2;
409
- int32 limit = 3;
410
- }
411
-
412
- message PremiumPaymentsListResponse {
413
- repeated PremiumPaymentRow items = 1;
414
- int32 total = 2;
415
- int32 page = 3;
416
- int32 limit = 4;
417
- }
418
-
419
- // ---------------------------------------------------------------------------
420
- // Saved cards (YooKassa payment_method tokens; we never see PAN)
421
- // ---------------------------------------------------------------------------
422
- message SavedCard {
423
- string id = 1;
424
- string brand = 2; // "MIR" | "VISA" | "MASTERCARD" | ""
425
- string last4 = 3; // "0000" etc, display-only
426
- int32 exp_month = 4;
427
- int32 exp_year = 5;
428
- bool is_default = 6;
429
- string nickname = 7; // user-set label
430
- string created_at = 8;
431
- }
432
-
433
- message ListSavedCardsRequest { string user_id = 1; }
434
- message ListSavedCardsResponse { repeated SavedCard items = 1; }
435
-
436
- message DeleteSavedCardRequest { string user_id = 1; string id = 2; }
437
-
438
- message SetDefaultSavedCardRequest { string user_id = 1; string id = 2; }
439
-
440
- message UpdateSavedCardRequest {
441
- string user_id = 1;
442
- string id = 2;
443
- string nickname = 3; // empty = clear
444
- }
445
-
446
- // ---------------------------------------------------------------------------
447
- // Payout details (persistent default; per-withdrawal override still allowed)
448
- // ---------------------------------------------------------------------------
449
- message UpdatePayoutDetailsRequest {
450
- string user_id = 1;
451
- string method = 2; // "card" | "sbp" | "bank" | "" (clear)
452
- string details = 3; // JSON string — payments-service treats opaquely
453
- }
454
-
455
- message UpdatePayoutDetailsResponse {
456
- string method = 1;
457
- string details = 2;
458
- }
459
-
460
- message GetPayoutDetailsRequest { string user_id = 1; }
388
+ string id = 1;
389
+ string user_id = 2;
390
+ string amount = 3;
391
+ string period = 4; // MONTH_1 | MONTH_3 | MONTH_6 | MONTH_12
392
+ string method = 5; // BALANCE | YOOKASSA
393
+ string status = 6; // PENDING | COMPLETED | FAILED | REFUNDED
394
+ bool is_renewal = 7;
395
+ string created_at = 8;
396
+ string completed_at = 9;
397
+ string refunded_at = 10;
398
+ string refunded_amount = 11;
399
+ // Convenience: true if this payment is currently inside the 7-day refund
400
+ // window AND status == COMPLETED AND not already refunded.
401
+ bool refundable = 12;
402
+ }
403
+
404
+ message RefundPremiumRequest {
405
+ string user_id = 1;
406
+ string payment_id = 2;
407
+ string reason = 3; // optional
408
+ }
409
+
410
+ message RefundPremiumResponse {
411
+ PremiumPaymentRow payment = 1;
412
+ string new_expires_at = 2; // ISO 8601 after rollback
413
+ bool subscription_revoked = 3; // true when rollback put expiresAt <= now
414
+ }
415
+
416
+ message GetMyPremiumPaymentsRequest {
417
+ string user_id = 1;
418
+ int32 page = 2;
419
+ int32 limit = 3;
420
+ }
421
+
422
+ message GetPremiumPaymentRequest {
423
+ string user_id = 1;
424
+ string payment_id = 2;
425
+ }
426
+
427
+ message PremiumPaymentsListResponse {
428
+ repeated PremiumPaymentRow items = 1;
429
+ int32 total = 2;
430
+ int32 page = 3;
431
+ int32 limit = 4;
432
+ }
433
+
434
+ // ---------------------------------------------------------------------------
435
+ // Saved cards (YooKassa payment_method tokens; we never see PAN)
436
+ // ---------------------------------------------------------------------------
437
+ message SavedCard {
438
+ string id = 1;
439
+ string brand = 2; // "MIR" | "VISA" | "MASTERCARD" | ""
440
+ string last4 = 3; // "0000" etc, display-only
441
+ int32 exp_month = 4;
442
+ int32 exp_year = 5;
443
+ bool is_default = 6;
444
+ string nickname = 7; // user-set label
445
+ string created_at = 8;
446
+ }
447
+
448
+ message ListSavedCardsRequest { string user_id = 1; }
449
+ message ListSavedCardsResponse { repeated SavedCard items = 1; }
450
+
451
+ message DeleteSavedCardRequest { string user_id = 1; string id = 2; }
452
+
453
+ message SetDefaultSavedCardRequest { string user_id = 1; string id = 2; }
454
+
455
+ message UpdateSavedCardRequest {
456
+ string user_id = 1;
457
+ string id = 2;
458
+ string nickname = 3; // empty = clear
459
+ }
460
+
461
+ // ---------------------------------------------------------------------------
462
+ // Payout details (persistent default; per-withdrawal override still allowed)
463
+ // ---------------------------------------------------------------------------
464
+ message UpdatePayoutDetailsRequest {
465
+ string user_id = 1;
466
+ string method = 2; // "card" | "sbp" | "bank" | "" (clear)
467
+ string details = 3; // JSON string — payments-service treats opaquely
468
+ }
469
+
470
+ message UpdatePayoutDetailsResponse {
471
+ string method = 1;
472
+ string details = 2;
473
+ }
474
+
475
+ message GetPayoutDetailsRequest { string user_id = 1; }