Class CommerceManager
Client facade for the Codename One Commerce service. It does not replace
the Purchase API -- it wraps it: purchases still go through the
platform store, and this class adds server-side validation and a
store-agnostic entitlement check ("does this user have pro?")
instead of per-SKU receipt juggling.
Typical use:
CommerceManager cm = CommerceManager.getInstance();
cm.setAppUserId(myAccountId); // optional; stable per user
cm.subscribe("pro_monthly"); // delegates to Purchase
// later, off the EDT:
cm.refresh(); // validate receipts with the cloud
if (cm.isEntitled("pro")) { ... } // entitlement, not SKU
Graceful degradation. When the cloud is unreachable, or the
developer's account is over its monthly validated-volume cap, the cloud
stops validating and isDegraded() becomes true. Entitlement checks
then fall back to the store-direct signal (the platform's own receipt), so
a paying user is never locked out -- exactly the server-side behaviour,
mirrored on the device.
The cloud endpoint, build key and package are stamped into the build by
the Codename One build server when commerce is enabled
(codename1.arg.commerce.cloud.enabled=true); when they are absent
this class is inert and every call is a safe no-op that defers to
Purchase.
-
Method Summary
Modifier and TypeMethodDescriptionSnapshot of the entitlement ids currently considered active.The current (explicit or generated-anonymous) app user id.static CommerceManagerThe shared instance.booleanWhether cloud commerce is active in this build.booleanTrue after arefresh()that could not get a server-validated answer -- the cloud was unreachable or the account is over its monthly cap.booleanisEntitled(String entitlementId) Whether the user currently holdsentitlementId.voidvoidrefresh()Validates the device's current receipts with the cloud and updates the entitlement cache.voidsetAppUserId(String id) Sets the stable per-user id the cloud keys entitlements on.voidvoidunsubscribe(String sku)
-
Method Details
-
getInstance
The shared instance. -
isCloudEnabled
public boolean isCloudEnabled()Whether cloud commerce is active in this build. True for any cloud build (one that carries abuild_key) unless the developer explicitly disabled it withcodename1.commerce.cloud.enabled=false. In the simulator / a local build there is no build key, so this is false and every call safely defers toPurchase. -
isDegraded
public boolean isDegraded()True after arefresh()that could not get a server-validated answer -- the cloud was unreachable or the account is over its monthly cap. Entitlement checks fall back to the store-direct signal while this is true. -
setAppUserId
Sets the stable per-user id the cloud keys entitlements on. Pass your own account id once the user signs in; if never set, an anonymous id is generated and persisted so entitlements survive restarts on the device. -
getAppUserId
The current (explicit or generated-anonymous) app user id. -
purchase
-
subscribe
-
unsubscribe
-
isEntitled
Whether the user currently holdsentitlementId. Uses the last cloud-validated answer when available; otherwise (cloud disabled or degraded) falls back to the store-direct signal, treating the entitlement id as a subscription SKU so a paying user keeps access. -
getActiveEntitlements
Snapshot of the entitlement ids currently considered active. -
refresh
public void refresh()Validates the device's current receipts with the cloud and updates the entitlement cache. Blocking network call -- invoke off the EDT. Safe no-op when the cloud is not enabled in this build. On any failure the manager flips todegradedand leaves the previous (or store-direct) answers in place.
-