feat(payments): wallet screen with balances, benefits and storefront
CI / changes (pull_request) Successful in 3s
CI / unit (pull_request) Successful in 11s
CI / integration (pull_request) Successful in 19s
CI / ui (pull_request) Successful in 1m8s
CI / conformance (pull_request) Successful in 9s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 1m39s
CI / changes (pull_request) Successful in 3s
CI / unit (pull_request) Successful in 11s
CI / integration (pull_request) Successful in 19s
CI / ui (pull_request) Successful in 1m8s
CI / conformance (pull_request) Successful in 9s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 1m39s
Add the "Кошелёк" section to the settings hub: context-visible chip balances, active benefits (no-ads term/forever, hints) and a storefront of chip-priced values and money-priced chip packs. Guests have no wallet; the Google Play build hides the money purchases behind a RuStore stub; a web purchase that would draw VK/Telegram chips warns first. Add the catalog read path the storefront needs — a context-projected GET /api/v1/user/wallet/catalog (payments service + store, gateway op wallet.catalog, FBS Catalog/CatalogProduct/CatalogAtom, client decode) — plus the client leg for the existing wallet.get/buy ops. Value spends reuse the existing spend path; the chip-pack purchase (money order flow) arrives with payment intake, so its action is a disabled placeholder for now. Covered by Go unit (catalog projection) + integration (/wallet/catalog over Postgres), vitest (formatting, spendable selection, web-spend warning, GP flag, codec + gateway encode round-trips) and Playwright mock e2e (render, guest-hidden, GP stub, warning) on Chromium + WebKit.
This commit is contained in:
@@ -107,6 +107,52 @@ func encodeWallet(w backendclient.WalletResp) []byte {
|
||||
return b.FinishedBytes()
|
||||
}
|
||||
|
||||
// encodeCatalog builds a Catalog payload: the storefront products for the caller's context, each
|
||||
// with its atom composition (built bottom-up — every product's atoms vector is finished before
|
||||
// its product table, and every product before the products vector).
|
||||
func encodeCatalog(cat backendclient.CatalogResp) []byte {
|
||||
b := flatbuffers.NewBuilder(256)
|
||||
prods := make([]flatbuffers.UOffsetT, len(cat.Products))
|
||||
for i, p := range cat.Products {
|
||||
atoms := make([]flatbuffers.UOffsetT, len(p.Atoms))
|
||||
for j, a := range p.Atoms {
|
||||
at := b.CreateString(a.AtomType)
|
||||
fb.CatalogAtomStart(b)
|
||||
fb.CatalogAtomAddAtomType(b, at)
|
||||
fb.CatalogAtomAddQuantity(b, int32(a.Quantity))
|
||||
atoms[j] = fb.CatalogAtomEnd(b)
|
||||
}
|
||||
fb.CatalogProductStartAtomsVector(b, len(atoms))
|
||||
for j := len(atoms) - 1; j >= 0; j-- {
|
||||
b.PrependUOffsetT(atoms[j])
|
||||
}
|
||||
atomsVec := b.EndVector(len(atoms))
|
||||
|
||||
kind := b.CreateString(p.Kind)
|
||||
pid := b.CreateString(p.ProductID)
|
||||
title := b.CreateString(p.Title)
|
||||
cur := b.CreateString(p.MoneyCurrency)
|
||||
fb.CatalogProductStart(b)
|
||||
fb.CatalogProductAddKind(b, kind)
|
||||
fb.CatalogProductAddProductId(b, pid)
|
||||
fb.CatalogProductAddTitle(b, title)
|
||||
fb.CatalogProductAddChips(b, int32(p.Chips))
|
||||
fb.CatalogProductAddMoneyAmount(b, p.MoneyAmount)
|
||||
fb.CatalogProductAddMoneyCurrency(b, cur)
|
||||
fb.CatalogProductAddAtoms(b, atomsVec)
|
||||
prods[i] = fb.CatalogProductEnd(b)
|
||||
}
|
||||
fb.CatalogStartProductsVector(b, len(prods))
|
||||
for i := len(prods) - 1; i >= 0; i-- {
|
||||
b.PrependUOffsetT(prods[i])
|
||||
}
|
||||
prodVec := b.EndVector(len(prods))
|
||||
fb.CatalogStart(b)
|
||||
fb.CatalogAddProducts(b, prodVec)
|
||||
b.Finish(fb.CatalogEnd(b))
|
||||
return b.FinishedBytes()
|
||||
}
|
||||
|
||||
func encodeProfile(p backendclient.ProfileResp) []byte {
|
||||
b := flatbuffers.NewBuilder(192)
|
||||
uid := b.CreateString(p.UserID)
|
||||
|
||||
@@ -53,6 +53,7 @@ const (
|
||||
MsgFeedbackGet = "feedback.get"
|
||||
MsgFeedbackUnread = "feedback.unread"
|
||||
MsgWalletGet = "wallet.get"
|
||||
MsgWalletCatalog = "wallet.catalog"
|
||||
MsgWalletBuy = "wallet.buy"
|
||||
)
|
||||
|
||||
@@ -108,6 +109,7 @@ func NewRegistry(backend *backendclient.Client, tg TelegramValidator, opts ...Op
|
||||
r.ops[MsgAuthEmailConfirmLink] = Op{Handler: authEmailConfirmLinkHandler(backend)}
|
||||
r.ops[MsgProfileGet] = Op{Handler: profileHandler(backend), Auth: true}
|
||||
r.ops[MsgWalletGet] = Op{Handler: walletHandler(backend), Auth: true}
|
||||
r.ops[MsgWalletCatalog] = Op{Handler: walletCatalogHandler(backend), Auth: true}
|
||||
r.ops[MsgWalletBuy] = Op{Handler: walletBuyHandler(backend), Auth: true}
|
||||
r.ops[MsgBlockStatus] = Op{Handler: blockStatusHandler(backend), Auth: true}
|
||||
r.ops[MsgGameSubmitPlay] = Op{Handler: submitPlayHandler(backend), Auth: true}
|
||||
@@ -308,6 +310,16 @@ func walletHandler(backend *backendclient.Client) Handler {
|
||||
}
|
||||
}
|
||||
|
||||
func walletCatalogHandler(backend *backendclient.Client) Handler {
|
||||
return func(ctx context.Context, req Request) ([]byte, error) {
|
||||
cat, err := backend.Catalog(ctx, req.UserID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return encodeCatalog(cat), nil
|
||||
}
|
||||
}
|
||||
|
||||
func walletBuyHandler(backend *backendclient.Client) Handler {
|
||||
return func(ctx context.Context, req Request) ([]byte, error) {
|
||||
in := fb.GetRootAsWalletBuyRequest(req.Payload, 0)
|
||||
|
||||
@@ -86,6 +86,52 @@ func TestGameStateRoundTripForwardsUserID(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestWalletCatalogRoundTrip(t *testing.T) {
|
||||
backend, cleanup := fakeBackend(t, func(w http.ResponseWriter, r *http.Request) {
|
||||
if got := r.Header.Get("X-User-ID"); got != "u-9" {
|
||||
t.Errorf("X-User-ID = %q, want u-9", got)
|
||||
}
|
||||
if r.URL.Path != "/api/v1/user/wallet/catalog" {
|
||||
t.Errorf("unexpected path %q", r.URL.Path)
|
||||
}
|
||||
_, _ = w.Write([]byte(`{"products":[` +
|
||||
`{"kind":"value","product_id":"val-1","title":"50 hints","chips":100,"money_amount":0,"money_currency":"","atoms":[{"atom_type":"hints","quantity":50}]},` +
|
||||
`{"kind":"pack","product_id":"pack-1","title":"100 chips","chips":0,"money_amount":14900,"money_currency":"RUB","atoms":[{"atom_type":"chips","quantity":100}]}` +
|
||||
`]}`))
|
||||
})
|
||||
defer cleanup()
|
||||
|
||||
reg := transcode.NewRegistry(backend, nil)
|
||||
op, ok := reg.Lookup(transcode.MsgWalletCatalog)
|
||||
if !ok {
|
||||
t.Fatal("wallet.catalog not registered")
|
||||
}
|
||||
payload, err := op.Handler(context.Background(), transcode.Request{UserID: "u-9"})
|
||||
if err != nil {
|
||||
t.Fatalf("handler: %v", err)
|
||||
}
|
||||
|
||||
cat := fb.GetRootAsCatalog(payload, 0)
|
||||
if cat.ProductsLength() != 2 {
|
||||
t.Fatalf("products = %d, want 2", cat.ProductsLength())
|
||||
}
|
||||
var value fb.CatalogProduct
|
||||
cat.Products(&value, 0)
|
||||
if string(value.Kind()) != "value" || string(value.ProductId()) != "val-1" || value.Chips() != 100 || value.AtomsLength() != 1 {
|
||||
t.Fatalf("value decoded wrong: kind=%q id=%q chips=%d atoms=%d", value.Kind(), value.ProductId(), value.Chips(), value.AtomsLength())
|
||||
}
|
||||
var atom fb.CatalogAtom
|
||||
value.Atoms(&atom, 0)
|
||||
if string(atom.AtomType()) != "hints" || atom.Quantity() != 50 {
|
||||
t.Fatalf("atom decoded wrong: type=%q qty=%d", atom.AtomType(), atom.Quantity())
|
||||
}
|
||||
var pack fb.CatalogProduct
|
||||
cat.Products(&pack, 1)
|
||||
if string(pack.Kind()) != "pack" || pack.Chips() != 0 || pack.MoneyAmount() != 14900 || string(pack.MoneyCurrency()) != "RUB" {
|
||||
t.Fatalf("pack decoded wrong: kind=%q chips=%d money=%d cur=%q", pack.Kind(), pack.Chips(), pack.MoneyAmount(), pack.MoneyCurrency())
|
||||
}
|
||||
}
|
||||
|
||||
func TestEnqueueRoundTripEncodesMatch(t *testing.T) {
|
||||
backend, cleanup := fakeBackend(t, func(w http.ResponseWriter, r *http.Request) {
|
||||
_, _ = w.Write([]byte(`{"matched":true,"game":{"id":"g-9","variant":"scrabble_en","status":"active","players":2,"to_move":0,"seats":[]}}`))
|
||||
|
||||
Reference in New Issue
Block a user