Show actual Play Dew bulk savings and enforce small pack premium
This commit is contained in:
1 parent
b7bf418350
commit
2062597cec
10 files changed
+196
-5
No files matched your search
@@ -0,0 +1,17 @@
|
||||
---
|
||||
description: Google Play Dew pricing and visible bulk savings
|
||||
alwaysApply: true
|
||||
---
|
||||
|
||||
# Google Play Dew pricing
|
||||
|
||||
The owner approved this rule on 2026-10-28:
|
||||
|
||||
- The 10 Dew pack costs the node's current Monero value plus 20%, rounded up
|
||||
to a clean regional price.
|
||||
- Larger packs retain their premiums: 100 Dew at 15%, 500 Dew at 10%,
|
||||
1,000 Dew at 5%, and 5,000 Dew at the base value.
|
||||
- Display savings per Dew against the actual 10 Dew Play price in the same
|
||||
currency. Round percentages down. Show no saving for missing, invalid,
|
||||
mixed-currency or non-discounted prices.
|
||||
- Provisioning only the new 10 Dew product leaves existing prices unchanged.
|
||||
@@ -38,12 +38,21 @@ model-test:
|
||||
|
||||
# Google Play Dew purchases are forgotten only after the node credits them.
|
||||
.PHONY: dew-play-test
|
||||
dew-play-test:
|
||||
dew-play-test: dew-play-savings-test
|
||||
rm -rf build/dew-play-test
|
||||
$(ZIRAN) build --root . $(MODULE_PATHS) --target=c --entry dew_play_test:main -o build/dew-play-test tests/dew_play_test.zi
|
||||
$(CC) -std=c99 -O2 -I$(ZIRAN_ROOT)/include -Ibuild/dew-play-test $$(rg --files build/dew-play-test -g '*.c') -o build/dew-play-test/test
|
||||
env -u DISPLAY -u WAYLAND_DISPLAY build/dew-play-test/test
|
||||
|
||||
.PHONY: dew-play-savings-test
|
||||
dew-play-savings-test:
|
||||
rm -rf build/dew-play-savings-test
|
||||
$(ZIRAN) build --root . $(MODULE_PATHS) --target=c --entry dew_play_savings_test:main -o build/dew-play-savings-test tests/dew_play_savings_test.zi
|
||||
$(CC) -std=c99 -O2 -I$(ZIRAN_ROOT)/include -Ibuild/dew-play-savings-test $$(rg --files build/dew-play-savings-test -g '*.c') -o build/dew-play-savings-test/test
|
||||
env -u DISPLAY -u WAYLAND_DISPLAY build/dew-play-savings-test/test
|
||||
$(ZIRAN) bundle --root . $(MODULE_PATHS) --entry dew_play_savings_test:main -o build/dew-play-savings-test/test.zx tests/dew_play_savings_test.zi
|
||||
env -u DISPLAY -u WAYLAND_DISPLAY $(ZIRAN) run build/dew-play-savings-test/test.zx
|
||||
|
||||
.PHONY: achievement-view-test
|
||||
achievement-view-test:
|
||||
mkdir -p build/achievement-view-test
|
||||
|
||||
@@ -160,6 +160,19 @@ files and the same native Entity account provider; game bundles receive only
|
||||
a navigation service and never see account keys. `scripts/build-web.py` links
|
||||
this provider for browser applications with the locked cryptography packages.
|
||||
|
||||
## Google Play Dew pricing
|
||||
|
||||
The 10 Dew pack uses a 20% premium over the node's current Monero value,
|
||||
rounded up to a clean local price. The larger packs retain their bulk rates:
|
||||
100 Dew at 15%, 500 Dew at 10%, 1,000 Dew at 5%, and 5,000 Dew at the base value.
|
||||
Existing products are changed only when their prices are explicitly provisioned.
|
||||
|
||||
Purchase screens show savings per Dew against the 10 Dew pack, calculated from
|
||||
Google Play's actual prices in the same currency. Whole percentages round down;
|
||||
missing prices, currency mismatches and packs without savings have no badge.
|
||||
Regional rounding can change the displayed percentage. `--pack 10 --apply`
|
||||
provisions only the small pack and leaves the other prices unchanged.
|
||||
|
||||
## Shared game progress
|
||||
|
||||
`entity/game_progress` defines `entity.game-progress.v1` records in the
|
||||
|
||||
+2
-1
@@ -8,6 +8,7 @@
|
||||
#import "std/text_buffer"
|
||||
#import "std/vec"
|
||||
#import "model"
|
||||
#import "dew_play_pricing"
|
||||
#import "kryon/play_billing"
|
||||
|
||||
DEW_PLAY_PRODUCTS :: "dew_10,dew_100,dew_500,dew_1000,dew_5000"
|
||||
@@ -36,7 +37,7 @@ DewPlay :: struct {
|
||||
}
|
||||
|
||||
DewPlayProduct :: (id: string) -> bool {
|
||||
return id == "dew_10" || id == "dew_100" || id == "dew_500" || id == "dew_1000" || id == "dew_5000"
|
||||
return DewPlayPackSize(id) > 0
|
||||
}
|
||||
|
||||
DewPlayToken :: (token: string) -> bool {
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
// Savings use Play's actual local prices, including regional rounding.
|
||||
// They compare the price per Dew with the 10 Dew pack, never with a made-up price.
|
||||
#import "std/json_scan"
|
||||
#import "std/text_buffer"
|
||||
|
||||
DewPlayPackSize :: (id: string) -> s32 {
|
||||
if id == "dew_10" { return 10 }
|
||||
if id == "dew_100" { return 100 }
|
||||
if id == "dew_500" { return 500 }
|
||||
if id == "dew_1000" { return 1000 }
|
||||
if id == "dew_5000" { return 5000 }
|
||||
return 0
|
||||
}
|
||||
|
||||
// Play quotes integral millionths of the local currency. Reject malformed or
|
||||
// implausibly large values before doing integer arithmetic.
|
||||
DewPlayMicros :: (product: string) -> s64 {
|
||||
at := FieldAt(product, 0, "micros")
|
||||
end := ValueEnd(product, at, 0)
|
||||
if at < 0 || end <= at || end - at > 17 { return 0 }
|
||||
amount: s64 = 0
|
||||
for byte: product[at:end] {
|
||||
if byte < #char "0" || byte > #char "9" { return 0 }
|
||||
amount = amount * 10 + cast(s64)(byte - #char "0")
|
||||
}
|
||||
return amount
|
||||
}
|
||||
|
||||
DewPlaySavings :: (state: string, id: string) -> s32 {
|
||||
amount := DewPlayPackSize(id)
|
||||
if amount <= 10 || state.count == 0 || state[0] != #char "{" { return 0 }
|
||||
products := FieldAt(state, 0, "products")
|
||||
small_micros: s64 = 0
|
||||
selected_micros: s64 = 0
|
||||
small_currency: [8]u8
|
||||
selected_currency: [8]u8
|
||||
small_found := false
|
||||
selected_found := false
|
||||
for index: cast(s32)0..7 {
|
||||
at := ElementAt(state, products, index)
|
||||
if at < 0 { break }
|
||||
end := ValueEnd(state, at, 0)
|
||||
if end <= at { return 0 }
|
||||
product := state[at:end]
|
||||
product_id: [64]u8
|
||||
if ReadStringText(product, FieldAt(product, 0, "id"), product_id[:]) <= 0 { continue }
|
||||
name := TextUntilNul(product_id[:])
|
||||
if name != "dew_10" && name != id { continue }
|
||||
price: [64]u8
|
||||
currency: [8]u8
|
||||
if ReadStringText(product, FieldAt(product, 0, "price"), price[:]) <= 0 ||
|
||||
ReadStringText(product, FieldAt(product, 0, "currency"), currency[:]) != 3 { return 0 }
|
||||
for byte: currency[:3] {
|
||||
if byte < #char "A" || byte > #char "Z" { return 0 }
|
||||
}
|
||||
micros := DewPlayMicros(product)
|
||||
if micros <= 0 { return 0 }
|
||||
if name == "dew_10" {
|
||||
if small_found { return 0 }
|
||||
small_found = true
|
||||
small_micros = micros
|
||||
small_currency = currency
|
||||
} else {
|
||||
if selected_found { return 0 }
|
||||
selected_found = true
|
||||
selected_micros = micros
|
||||
selected_currency = currency
|
||||
}
|
||||
}
|
||||
if !small_found || !selected_found ||
|
||||
TextUntilNul(small_currency[:]) != TextUntilNul(selected_currency[:]) { return 0 }
|
||||
multiplier := cast(s64)(amount / 10)
|
||||
// Also leave room for multiplying the difference by 100 below.
|
||||
if small_micros > 92233720368547758 / multiplier { return 0 }
|
||||
reference := small_micros * multiplier
|
||||
if selected_micros >= reference { return 0 }
|
||||
// Whole percentages round down so the label never promises extra savings.
|
||||
return cast(s32)((reference - selected_micros) * 100 / reference)
|
||||
}
|
||||
@@ -6,6 +6,7 @@
|
||||
#import "leaderboard_model"
|
||||
#import "management"
|
||||
#import "dew_model"
|
||||
#import "dew_play_pricing"
|
||||
#import "dew_view"
|
||||
#import "std/json_scan"
|
||||
#import "std/number_text"
|
||||
@@ -1394,6 +1395,7 @@ DrawDew :: () {
|
||||
y += 40.0 * scale
|
||||
products := FieldAt(play, 0, "products")
|
||||
shown: s32 = 0
|
||||
savings_shown := false
|
||||
for index: cast(s32)0..4 {
|
||||
item := ElementAt(play, products, index)
|
||||
if item < 0 { break }
|
||||
@@ -1405,11 +1407,21 @@ DrawDew :: () {
|
||||
if ReadStringText(product, FieldAt(product, 0, "id"), id[:]) <= 4 || ReadStringText(product, FieldAt(product, 0, "price"), price[:]) <= 0 { continue }
|
||||
title: Vec(u8)
|
||||
BuilderPrint(*title, "% Dew · %", TextUntilNul(id[:])[4:], TextUntilNul(price[:]))
|
||||
savings := DewPlaySavings(play, TextUntilNul(id[:]))
|
||||
if savings > 0 {
|
||||
BuilderPrint(*title, " · −%", savings)
|
||||
BuilderPrint(*title, "%%")
|
||||
savings_shown = true
|
||||
}
|
||||
label := BuilderFinish(title)
|
||||
if !busy && Action(45051 + index, label, Rectangle.{x, y, width, 44.0 * scale}) { DewCommand("play", sequence, TextUntilNul(id[:])) }
|
||||
y += 56.0 * scale
|
||||
shown += 1
|
||||
}
|
||||
if savings_shown {
|
||||
Paragraph(45057, Label("profile_dew_play_comparison", "Savings per Dew compared with the 10 Dew pack."), x, y, width, 48.0)
|
||||
y += 56.0 * scale
|
||||
}
|
||||
status: [16]u8
|
||||
unused ReadStringText(json, FieldAt(json, 0, "play_status"), status[:])
|
||||
play_error: [64]u8
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
#import, file "../src/dew_play_pricing.zi";
|
||||
#import "std/text_buffer"
|
||||
#import "std/vec"
|
||||
|
||||
PRICES :: #string JSON
|
||||
{"products":[{"id":"dew_10","price":"$0.72","micros":720000,"currency":"USD"},{"id":"dew_100","price":"$6.90","micros":6900000,"currency":"USD"},{"id":"dew_500","price":"$33.00","micros":33000000,"currency":"USD"},{"id":"dew_1000","price":"$63.00","micros":63000000,"currency":"USD"},{"id":"dew_5000","price":"$300.00","micros":300000000,"currency":"USD"}]}
|
||||
JSON;
|
||||
|
||||
Prices :: (small: string, selected: string, small_currency: string = "USD", currency: string = "USD") -> string {
|
||||
out: Vec(u8)
|
||||
BuilderPrint(*out, "{\"products\":[{\"id\":\"dew_10\",\"price\":\"small\",\"micros\":%,\"currency\":\"%\"},{\"id\":\"dew_100\",\"price\":\"large\",\"micros\":%,\"currency\":\"%\"}]}",
|
||||
small, small_currency, selected, currency)
|
||||
return BuilderFinish(out)
|
||||
}
|
||||
|
||||
#program_export
|
||||
main :: () -> s32 {
|
||||
ids: [5]string = .["dew_10", "dew_100", "dew_500", "dew_1000", "dew_5000"]
|
||||
wanted: [5]s32 = .[0, 4, 8, 12, 16]
|
||||
for id, index: ids {
|
||||
if DewPlaySavings(PRICES, id) != wanted[index] { return 1 + cast(s32)index }
|
||||
}
|
||||
// Regional price endings, rather than the nominal premium, set savings.
|
||||
if DewPlaySavings(Prices("710000", "6990000"), "dew_100") != 1 { return 10 }
|
||||
if DewPlaySavings(Prices("710000", "6790000"), "dew_100") != 4 { return 11 }
|
||||
if DewPlaySavings(Prices("1000000", "9999999"), "dew_100") != 0 { return 12 }
|
||||
if DewPlaySavings(Prices("1000000", "10000000"), "dew_100") != 0 { return 13 }
|
||||
if DewPlaySavings(Prices("1000000", "11000000"), "dew_100") != 0 { return 14 }
|
||||
if DewPlaySavings(Prices("1000000", "9000000", "USD", "EUR"), "dew_100") != 0 { return 15 }
|
||||
if DewPlaySavings(Prices("1000000", "9000000", "", "USD"), "dew_100") != 0 { return 16 }
|
||||
if DewPlaySavings(Prices("1000000", "9000000", "usd", "usd"), "dew_100") != 0 { return 17 }
|
||||
if DewPlaySavings(Prices("1000000", "9000000", "JPY", "JPY"), "dew_100") != 10 { return 18 }
|
||||
invalid: [8]string = .["0", "-1", "1.5", "1e6", "null", "\"1000000\"", "9223372036854775807", "999999999999999999999"]
|
||||
for number: invalid {
|
||||
if DewPlaySavings(Prices(number, "1"), "dew_100") != 0 ||
|
||||
DewPlaySavings(Prices("1000000", number), "dew_100") != 0 { return 20 }
|
||||
}
|
||||
if DewPlaySavings(Prices("92233720368547758", "1"), "dew_100") != 0 { return 21 }
|
||||
if DewPlaySavings("{}", "dew_100") != 0 || DewPlaySavings(PRICES, "dew_42") != 0 { return 22 }
|
||||
duplicate := #string JSON
|
||||
{"products":[{"id":"dew_10","price":"one","micros":1000000,"currency":"USD"},{"id":"dew_10","price":"two","micros":2000000,"currency":"USD"},{"id":"dew_100","price":"large","micros":5000000,"currency":"USD"}]}
|
||||
JSON;
|
||||
if DewPlaySavings(duplicate, "dew_100") != 0 { return 23 }
|
||||
missing := #string JSON
|
||||
{"products":[{"id":"dew_10","micros":1000000,"currency":"USD"},{"id":"dew_100","price":"large","micros":5000000,"currency":"USD"}]}
|
||||
JSON;
|
||||
if DewPlaySavings(missing, "dew_100") != 0 { return 24 }
|
||||
return 0
|
||||
}
|
||||
@@ -64,6 +64,15 @@ class ProvisionTest(unittest.TestCase):
|
||||
self.assertEqual(len(body['purchaseOptions'][0]['regionalPricingAndAvailabilityConfigs']), 2)
|
||||
self.assertFalse(body['purchaseOptions'][0]['buyOption']['multiQuantityEnabled'])
|
||||
|
||||
def test_small_pack_rounding_retains_the_twenty_percent_premium(self):
|
||||
regions = {'US': ('USD', Decimal(1)), 'PY': ('PYG', Decimal(5900)),
|
||||
'JP': ('JPY', Decimal(156))}
|
||||
body, _, _ = products.product('xyz.waozi.inbe', 10, Decimal('0.061'),
|
||||
(regions, {}, '2022/02'))
|
||||
for region in body['purchaseOptions'][0]['regionalPricingAndAvailabilityConfigs']:
|
||||
rate = regions[region['regionCode']][1]
|
||||
self.assertGreaterEqual(products.money(region['price']), Decimal('0.061') * 10 * Decimal('1.20') * rate)
|
||||
|
||||
def test_selected_small_pack_does_not_reprice_existing_products(self):
|
||||
rates = ({'US': ('USD', Decimal(1))}, {}, '2022/02')
|
||||
with patch.object(products, 'Play') as play, \
|
||||
|
||||
@@ -129,16 +129,17 @@ def product(package, dew, usd_per_dew, rates_by_region):
|
||||
regions_rate, other, version = rates_by_region
|
||||
baseline_usd = Decimal(dew) * usd_per_dew
|
||||
play_usd = baseline_usd * PREMIUM[dew]
|
||||
minimum_usd = play_usd if dew == 10 else baseline_usd
|
||||
regions = []
|
||||
for code, (currency, rate) in sorted(regions_rate.items()):
|
||||
regions.append({'regionCode': code, 'availability': 'AVAILABLE',
|
||||
'price': as_price(currency, clean(play_usd * rate, currency, baseline_usd * rate))})
|
||||
'price': as_price(currency, clean(play_usd * rate, currency, minimum_usd * rate))})
|
||||
option = {'purchaseOptionId': 'buy', 'buyOption': {'legacyCompatible': True, 'multiQuantityEnabled': False},
|
||||
'regionalPricingAndAvailabilityConfigs': regions}
|
||||
if other.get('usdPrice') and other.get('eurPrice'):
|
||||
option['newRegionsConfig'] = {'availability': 'AVAILABLE',
|
||||
'usdPrice': as_price('USD', clean(play_usd * money(other['usdPrice']) / REFERENCE, 'USD', baseline_usd * money(other['usdPrice']) / REFERENCE)),
|
||||
'eurPrice': as_price('EUR', clean(play_usd * money(other['eurPrice']) / REFERENCE, 'EUR', baseline_usd * money(other['eurPrice']) / REFERENCE))}
|
||||
'usdPrice': as_price('USD', clean(play_usd * money(other['usdPrice']) / REFERENCE, 'USD', minimum_usd * money(other['usdPrice']) / REFERENCE)),
|
||||
'eurPrice': as_price('EUR', clean(play_usd * money(other['eurPrice']) / REFERENCE, 'EUR', minimum_usd * money(other['eurPrice']) / REFERENCE))}
|
||||
body = {'packageName': package, 'productId': f'dew_{dew}',
|
||||
'listings': [{'languageCode': 'en-US', 'title': f'{dew} Dew',
|
||||
'description': f'{dew} Dew for your Waozi account: the same Dew in every Waozi app and game.'}],
|
||||
|
||||
@@ -27,6 +27,7 @@ publications_read = "src/publications_read.zi"
|
||||
entity_records = "src/entity_records.zi"
|
||||
entity_dew = "src/entity_dew.zi"
|
||||
dew_play = "src/dew_play.zi"
|
||||
dew_play_pricing = "src/dew_play_pricing.zi"
|
||||
game_progress = "src/game_progress.zi"
|
||||
game_shop = "src/game_shop.zi"
|
||||
game_shop_native = "src/game_shop_native.zi"
|
||||
|
||||
Reference in new issue
Block a user