SDK for JavaScript
#
Full Technical ReferenceThe 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.
#
Installing the SDKTo find the InPlayer JS SDK refer to NPM, from where you can install the package directly.
#
Setting up the SDKOnce 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 setConfig
method:
#
'How to' ExamplesThe following section enumerates multiple 'how to' examples about doing specific operations within the InPlayer monetization platform.
#
How to Register an AccountThe registration process can be carried out using the InPlayer.Account.signUp()
method.
Among the parameters, fullName
, email
, password
, passwordConfirmation
, type
, and 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 clientId
. 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.
The type
parameter can be either consumer
or merchant
. In case you want to create merchant accounts via the API, you will have to use InPlayer's public UUID for the clientId
parameter.
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.
Lastly, the 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.
#
How to Authenticate an AccountAuthentication can be achieved using the InPlayer.Account.signIn()
method.
Having the account logged in, you should be able to see an object containing the InPlayer auth token in localStorage
.
If you need to make additional calls, in the name of the authenticated account, you can use the account details provided by the InPlayer.Account.getAccountInfo()
method.
This method returns a Promise
which containst the following information:
You can find more information about the usage of this method on the following link.
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:
#
Real-time NotificationsOnce 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 OnMessage
callback.
Our basic use-case here is to have a 'redirect to premium section' handler after the 'successful payment' notification message.
For example:
The uuid
value should be fetched from the InPlayer.Account.getAccountInfo()
method.
#
How to Create Payments#
Creating an Access FeeThe 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).
#
Creating PaymentsThe 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.
#
Creating One-time Card Payments#
Creating Recurring Card Subscriptions#
Creating PayPal PaymentsTo 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 data.endpoint
value.
#
How to Validate Content AccessIn 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.
#
How to Create the 'My Account' MenuTo 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.
#
Fetching Account DetailsBy passing in the authorisation token, you can fetch all the account details using the getAccountInfo
method.