How to offer subscriptions on plentyMarketplace

This tutorial will introduce you to subscription plugins. We will show you how you can offer the plugins you upload on plentyMarketplace on a subscription basis rather than for a fixed price. You can also offer some features of your plugin for free while charging for others, giving both you and your customers even greater flexibility.

Folder structure

TopItems/
    ├-- resources/
    │   ├── lang
    |   |   ├── de
    |   |   |   └── config.properties
    |   |   |
    |   |   └── en
    |   |       └── config.properties
    |   |
    |   └── views/
    │       └── content/
    │           └── hello.twig
    │
    ├── src/
    │   ├── Controllers/
    │   │   └── ContentController.php
    │   │
    │   └── Providers/
    │       ├── HelloSubWorldRouteServiceProvider.php
    │       ├── HelloSubWorldServiceProvider.php
    │       ├── ServiceProviderForFreeComponents.php
    │       └── ServiceProviderForPremiumComponents.php
    |
    ├── config.json
    ├── marketplace.json // subscription information
    └── plugin.json // plugin information

marketplace.json

plugin-hello-subscription-world/marketplace.json
{
    "marketplaceName"   : {"de":"Hallo Subscription Welt","en":"Hello subscription world"},
    "license"           : "GPL",
    "price"             : 0,
    "shortDescription"  : {"de":"plentymarkets plugin subscription example","en":"plentymarkets plugin subscription example"},
    "categories"        : ["3518"],
    "keywords"          : ["plugins", "template"],
    "subscription": [
      {
        "interval": "monthly",
        "price": 10.00
      },
      {
        "interval": "quarterly",
        "price": 30.00
      },
      {
        "interval": "half-yearly",
        "price": 60.00
      },
      {
        "interval": "yearly",
        "price": 120.00
      }
    ]
  }

The marketplace.json provides the core functionality for your subscription plugin. Using the interval properties, you can decide for how long customers can use your plugin at a time. As shown in the above example, you can offer subscriptions on a monthly, quarterly, half-yearly, and yearly basis. While you may want to provide all of these options, it is also possible to only allow monthly subscriptions for example. To do this, remove the other options from your code. Each interval has a price property associated with it. Here, you can enter how much you want to charge in Euro for the respective interval. Only values higher than 10.00 are valid.

Service provider

plugin-hello-subscription-world/src/Providers/HelloSubWorldServiceProvider.php
{
    getApplication()->register(HelloSubWorldRouteServiceProvider::class);
                $this->getApplication()->register(ServiceProviderForFreeComponenents::class);

                // get the Subscription Service
                $this->subscriptionInfoService = pluginApp(SubscriptionInformationServiceContract::class);

            // check if the subscription has been paid
            if ( $this->subscriptionInfoService->isPaid('HelloSubWorld') )
            {
                $this->getApplication()->register(ServiceProviderForPremiumComponenents::class);
            }
        }
    }
}

If the subscription has been paid, the customer has access to the contents of ServiceProviderForPremiumComponenents.php. Be sure to replace the class names in this service provider with the ones you use in your plugin.