To have accesstype JS working on any web page, ensure pre-requisites are met and follow the below steps.
Step 1. : Load AccessTypeJS
<script src="https://accesstype.com/frontend/v2/accesstype.js?key=[YOUR_ACCOUNT_KEY]"></script>
You can get your Account key from Settings
> General
on Accesstype Dashboard.
For staging environments where you have configured the payment gateways to use test or sandbox modes, pass an additional query parameter env=sandbox
so that the script configures the payment provider scripts accordingly.
<script src="https://accesstype.com/frontend/v2/accesstype.js?key=[YOUR_ACCOUNT_KEY]&env=sandbox"></script>
Step 2: Set User
setUser method needs to be used to set the user context.
Call with below attributes:
- accesstypeJwt optional
- It is used to authorize user and is required for a logged-in user.
User will be considered as non logged-in if its value is null or invalid. - accesstypeJwtUrl optional
- If `accesstypeJwt` is not passed, then this GET endpoint is called to get the `accesstypeJwt`. It takes the value of `x-integration-token` from response headers as `accesstypeJwt`. If `x-integration-token` response header is not present then it takes the value of `accesstypeJwt` key in json response body.
If `accesstypeJwt` is not found due to any reason, its value defaults to null. - readerId optional
- For identifying unique user when Metered Paywall feature is toggled on. When this is not explicitly set, ATJS looks for the availablility of `at-meter` cookie for using as readerId.
- readerIdUrl optional
- If `readerId` is not passed, then this POST URL endpoint is called. This url is expected to set a cookie called `at-meter`. If this URL is not passed, then a POST call to `/api/access/v1/set-reader-id` publisher endpoint is made which is expected to set `at-meter` cookie.
- isLoggedIn optional
- Its value defaults to true if a valid `accesstypeJwt` is passed, else it defaults to false.
Can be set to false explicitely when a logged in user is to be considered as non-loggedin, for eg in case of accepting donations by email address. - emailAddress optional
- Email address of the user
- mobileNumber optional
- Phone number of the user. Required by some payment providers, like Simpl
Some examples with code snippets are available here.
Step 3: Call any other method
Now call the method depending on your usecase. Some popular use cases are explained here