The InPlayer SDK for JS allows developers to build libraries and applications that use InPlayer platform services. The JS SDK applies to any frontend project.
You can find the full technical reference of all the SDK methods, here. However, we advise you to read this tutorial thoroughly, before jumping into exploring the SDK.
To find the InPlayer JS SDK refer to NPM, from where you can install the package directly.
Once the SDK is installed, you will find available all the methods in the InPlayer global object. All of the calls return a promise with relevant data, so after each call, you will have to resolve that promise:
Currently, there are two different environments for the SDK - development and production. You can switch between these environments using the
The following section enumerates multiple 'how to' examples about doing specific operations within the InPlayer monetization platform.
The registration process can be carried out using the
Among the parameters,
clientId are always required.
Before you start using the Inplayer SDK, we suggest that you create a new OAUTH application from our Dashboard and obtain your
clinetId. In case you haven’t got an OAUTH application yet, you can use your account UUID as
clientId. To find your UUID navigate to InPlayer Dashboard's 'Account' section, in the top right-hand corner menu.
type parameter can be either
merchant. In case you want to create merchant accounts via the API, you will have to use InPlayer's public UUID for the
There is also a
metadata parameter which can contain additional required and/or optional fields that merchants can choose to require from their end-users to fill in upon registration. If you have required custom registration fields defined by your merchant account, you will have to send those details as well. By default, the metadata parameter is optional.
referrer parameter can be passed in manually for every register request. This parameter represents the URL from which the request has been invoked or the location where the account has been created.
Authentication can be achieved using the
Having the account logged in, you should be able to see an object containing the InPlayer auth token in
If you need to make additional calls, in the name of the authenticated account, you can fetch the token with the
InPlayer.Account.token() call. Additionally, you may call
InPlayer.Account.isSignedIn() to check if someone is logged in or not.
For the account sign out operation use the following call:
Once the customer is authenticated in our system, our SDK enables you to subscribe to listening to notifications via WebSockets. For a complete overview of our notification types, you can refer to this page.
In addition, consider the following sample code that enables you to subscribe and listen for messages:
It should also be noted that you are going to need a code that processes every different notification type when you receive a notification message in the
Our basic use-case here is to have a 'redirect to premium section' handler after the 'successful payment' notification message.
The InPlayer platform enables you to create digital assets to which afterwards you can attach a price with currency and access period, in order to create access fees. The
AccessFee resource holds data of the asset’s price, and the time-frame of the access duration period. The access period resource refers to the access type which might be of the pay-per-view or subscription model. This will be elaborated further on in this tutorial. Once you have created the desired asset with price options (conducted in the Dashboard or via the API), you can fetch and present the fees by invoking the function below.
After the end-user has chosen both the price option and the preferred payment method, depending on the access type, you can either invoke the function for creating one-time purchases (pay-per-view) or the one for subscription (recurring card payment).
The InPlayer Platform supports two methods of carrying out payments – by card and by PayPal. In order to create payment, first you must find and fetch the preferred method.
To make PayPal payments you will need an additional call to fetch the payment details:
After a successful call you will obtain the necessary PayPal data for the external payment. The response will carry the endpoint URL, which will either be a Sandbox PayPal for development, or a standard PayPal URL for a production mode. In order to make a redirect link to PayPal and create your PayPal button use the
In order to check whether a given account can access a certain asset, you should fetch the authorisation token of the logged in account and call the
checkAccessForAsset method with your asset ID.
As a response, you will receive an object with detailed information about the asset access. This way, you can keep the non-premium viewers away from the premium content.
To create the 'My Account' menu for a logged in customer, you need the following segments: account details, ability to update account details, account purchase history, account subscriptions and ability to cancel subscriptions.
By passing in the authorisation token, you can fetch all the account details using the