Class PaywallView

All Implemented Interfaces:
Animation, Editable, StyleListener, Iterable<Component>

public class PaywallView extends Container

A paywall built from a paywall document and the offering it sells.

The document is a tree of nodes, each a JSON object with a type: stack, text, image, icon, features, packages, purchaseButton, restoreButton, closeButton, carousel, footer and spacer. A node of any other type is skipped, so a document made for a newer client still shows. Sizes in the document are millimetres.

A text is first looked up in the document's strings, by the device's locale and then the document's default locale, and used as written when it is not a key there. Then {{price}}, {{period}}, {{trialPeriod}}, {{introPrice}}, {{productName}} and {{packageId}} are replaced from the selected package, again whenever the selection changes. The price is the store's localized one when the store listed the product.

Styling

Every element has a UIID, so a theme can restyle the paywall. The colors the document names -- its dark set when the device is in dark mode, its light set otherwise -- are applied on top of the theme.

  • Paywall: the view itself
  • PaywallStack: a stack node
  • PaywallTitle, PaywallHeadline, PaywallBody, PaywallCaption: the text of a text node, by its style
  • PaywallImage, PaywallIcon: an image and an icon node
  • PaywallFeatures, PaywallFeature, PaywallFeatureIcon, PaywallFeatureText: a features node, one of its rows and the row's parts
  • PaywallPackages: a packages node
  • PaywallPackage, PaywallPackageTitle, PaywallPackagePrice: a package and its two lines
  • PaywallPackageSelected, PaywallPackageTitleSelected, PaywallPackagePriceSelected: the same for the selected package
  • PaywallPurchaseButton, PaywallRestoreButton, PaywallCloseButton
  • PaywallCloseBar: the row holding the close button
  • PaywallCarousel: a carousel node
  • PaywallFooter, PaywallFooterLink: a footer node and its links
  • PaywallSpacer: a spacer node, and the gap between a stack's children
Events

The view reports IMPRESSION when it is first shown, PURCHASE_START, PURCHASE and CLOSE through CommerceManager.logEvent(String, String, String, String).

  • Constructor Details

    • PaywallView

      public PaywallView(Offering offering)

      Builds the paywall of an offering from the offering's own document, or from the built-in one when it has none.

      Parameters
      • offering: the offering to sell
    • PaywallView

      public PaywallView(Offering offering, Map paywallDocument)

      Builds a paywall from a document.

      Parameters
      • offering: the offering to sell

      • paywallDocument: the parsed paywall document; null uses the built-in one

  • Method Details

    • setPaywallListener

      public void setPaywallListener(PaywallListener listener)

      Sets the listener that is told what happens on this paywall.

      Parameters
      • listener: the listener, or null for none
    • getOffering

      public Offering getOffering()
      The offering this paywall sells.
    • getPaywallId

      public String getPaywallId()
      The id of the paywall document, or null when it has none.
    • getSelectedPackage

      public CommercePackage getSelectedPackage()

      The package that is selected, which the purchase button buys.

      Returns

      the package, or null when the offering has no package

    • selectPackage

      public void selectPackage(String packageId)

      Selects a package, as tapping it does.

      Parameters
      • packageId: the id of a package of the offering; any other value is ignored
    • purchase

      public void purchase()
      Buys the selected package, as the purchase button does. The listener hears purchaseStarted now and purchaseCompleted once the cloud reports the customer as owning the product.
    • restore

      public void restore()
      Restores the purchases of the store account, as the restore button does. The listener hears restoreCompleted when the customer information changes afterwards.
    • close

      public void close()
      Closes the paywall, as the close button does. A purchase that was started and not confirmed yet is reported as cancelled.
    • setCloseHandler

      public void setCloseHandler(Runnable closeHandler)

      Sets what closing the paywall does to the screen, after the listener was told. Paywall.show(Offering, PaywallListener) sets it to return to the previous form; an application that embeds the view in a form of its own sets it to whatever removes the view.

      Parameters
      • closeHandler: run on the EDT when the paywall closes, or null
    • initComponent

      protected void initComponent()
      Description copied from class: Component
      Allows subclasses to bind functionality that relies on fully initialized and "ready for action" component state
      Overrides:
      initComponent in class Component