When you publish your Blocks app in the Wix App Market, you can choose to provide different app behaviors for site-creators with different pricing. For example, people who download a free version of your app may get several services, while those who pay for it, get more. This requires creating and managing a system that identifies the user, determines their pricing plan and impacts the app's behavior.
Before you begin adjusting your app to different pricing plans, define your business model in your App Dashboard.
Note:
Configuring the pricing settings in the App Dashboard is only a first step. Now, you need to adjust your app to handle these pricing plans with your own logic and user interface (UI). This includes two main steps:
More optional steps can include:
Here is an example application that uses pricing plans. You can click Build in Blocks, to create your own copy of this application.
This example application gives you:
The template does not give you the following (define them on your own):
Since your app needs to behave differently to users according to their different pricing plans, the first thing you should understand is what the different users see. You can do this through a multi-state box, which gives you different user inteface with no code at all. Alternatively, you can delete and restore elements with the delete()
and restore()
functions.
Should I use a mutli-state box or delete() and restore() ?
Use the following in your widget code to impact your widget's behavior.
Your app's JWT
When your Blocks app is installed on a site, it generates a JSON Web Token (JWT) for that app instance. The JWT has two fields that are important for this process:
appDefId
: Your app's IDvendorProductId
: The ID of the pricing plan in use, as you configured in the App Dashboard. If there is no plan, this ID is null
.getDecodedAppInstance()
This function is part of the wix-application module and is used for parsing your app's JWT.
First, import the wix-application
module in order to process this information.
Then, use getDecodedAppInstance()
to save the vendorProductId
and use it in your app's logic:
wix-application-backend
You can also import wix-application-backend in your app's backend files. To do this, use the following syntax:
Now, you might want to make some changes in the Configuration tab in Blocks.
You can define certain elements of your widget, such as a grid that helped you layout the elements, as non-selectable. You can also change display names. Make sure to think about all your pricing plans when making these changes.
Note: Once you define a pricing plan for your app, your widget automatically gets an Upgrade button in its action bar.
Learn more about configuring widget and element display names and behavior.
You can get the vendorProductId
of the app and show or hide panel elements according to the plan, just as you did in the widget code.
This is done in the code section of your panel in the Panels tab.
Your app installation settings allow you to control what widgets are seen in a site's Add Elements panel, and more options. Make sure to think about all your pricing plans when you go over your installation settings.
Learn more about app and widget installation settings.