vipertecpro / game3d-economy
Wallet, lives, entitlements and a store interface for game3d games, with a clearly labelled demo store and simulated rewarded ads.
Requires
- php: ^8.5
- vipertecpro/game3d: ^2.1
- vipertecpro/game3d-save: 0.1.0
Requires (Dev)
- pestphp/pest: ^3.0|^4.0
Suggests
- vipertecpro/purchases: Real store purchases through Paywalls & Purchases for NativePHP (its adapter comes with the demo app)
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-28 20:03:28 UTC
README
An add-on for game3d, a paid plugin for NativePHP Mobile sold at https://vipertecpro.com/products/game3d-engine (Android only). This add-on is free and MIT, and needs game3d to run. It is an independent project, not made or endorsed by NativePHP.
A game's economy for games made with game3d: a wallet, lives that refill on the clock, things owned (earned or bought), a store interface and rewarded ads. PHP only, MIT. It saves through game3d-save, in its own slot.
use Vipertecpro\Game3dEconomy\{Economy, GrantSource}; $economy = app(Economy::class); $economy->wallet()->spend('coins', 120); $economy->lives()->configure(5, 1800)->lose(); $economy->entitlements()->grant('hero.ninja', GrantSource::Earned); $result = $economy->store()->purchase('coins_500'); // Pending: show $result->sheet $economy->complete($economy->store()->confirm($result->sheet->token));
Products come from config('game3d-economy.products'): consumable products give coins, entitlement products give a flag, and subscription products give a flag for a number of days.
Install
This add-on needs a game3d licence. From your dashboard at vipertecpro.com, add the game3d Composer repository and key (the two composer config commands shown there), then:
composer require vipertecpro/game3d-economy
game3d-save is installed with it.
- Demo store:
FakeStorecharges nothing. Every sheet it opens is labelled "Demo store, no money is charged". - Demo ads:
SimulatedAdsstands in for rewarded ads, labelled "Simulated ad". - Release builds:
game3d:doctor --releasewarns while either demo is active. - Real stores and ads: bind your own
StoreandAdProvider. - Lives: they refill on wall-clock time, so a refill goes on while the game is closed. A clock set back gains nothing; a clock set forward does gain lives (check against a server where that matters).
- Owned flags: a flag both earned and bought stays owned after a refund.
- Lost saves: if the economy's save is damaged, or loaded from its backup (perhaps one change behind),
wasLost()says so, so the game can offer a restore. A save from a newer version of the game is read and never written over. - Purchases: each completed transaction is granted once. A subscription's flag lasts until the subscription ends. Open store and ad sheets are saved, so they can be finished in a later request.
- Events:
purchasedandrewardedgo to whateveronEvent()is given.
Testing
The tests need game3d ^2.1, which is not public, so they run where a licensed copy is
installed: add the game3d repository as in Install, then run composer install and
vendor/bin/pest.