Simply put; I want customers to pay for being allowed to visit a video page during a restricted time. So is it possible in Wix to set a page access time limit for a specific customer and if so, do I have to fix this with code or in another way?
You can do it with code.
Create a database collection with member Id and expiration date fields.
On the page, make the video hidden on load.
Query the collection and if it’s not expired - show the video.
(P.S. this video can still be accessed from the browser dev tools. But most of the users don’t know how to access it. If you don’t wan it to be available there as well, there’re other ways to do that)
Thank you very much for the positive answer but do you also know how to write a code for this?
Create a collection (‘MembersVideoPermissions’) with the following fields:
member - reference filed to the Members/PrivateMembersData collection
videoId - string that you set for each video (if you currently have only one video, use the same ID for all).
expirationDate - Date & Time
Fill-out the values (manually or by code).
Make the video hidden on load (through the element Property Panel).
Then:
// page code:
import {checkExpiration} from 'backend/expiration-check.jsw
const VIDEO_ID = '1';//for example'
Promise.all([
checkExpiration(VIDEO_ID),
new Promise(resolve => $w.onReady(() => resolve()))
])
.then(r => r[0] ? $w('#video1').hide() : $w('#video1').show());
// backend/expiration-check.jsw
import wixData from 'wix-data';
import { currentMember } from 'wix-members-backend';
export function checkExpiration(videoId){
return currentMember.getMember()
.then(member => {
return wixData.query('MembersVideoPermissions').eq('member', member._id).eq('videoId', videoId).gt('expirationDate', new Date()).limit(1).find();
})
.then(r => r.items.length ? false : true);
})
Thank you very much J.D.!
You’re welcome.
I made a small change in the code. Please have a look.
About the collection fields, do you mean that “videoId” is the Text type of field or shall I set it as a Video field?
Then next question: One thing that makes this complicated is that I use a dynamic page for several videos. So the video that is played up on the actual page depends on what video link the customer has clicked on at another page. Can I handle this matter in some clever way?
I guess that it is better then to put your code on a landing page with links to all my videos which the customer have to go through to get on to the actual video page? If the time limit is out for the video he have paid for the link for that video will not work. What do you think about that solution?
I assumed you might have more than one video, and you wished to set an expiration date per each video, so the videoId is a text field with the video identifier. If you don’t have more than one video or if all the videos always have the same expiration date (per member), you can omit it from the collection schema and from the query & function argument.
I don’t think I fully understand your description, but you can either query the expiration date on each page you need, or query it on the first page, and save it in memory for the next pages (it’ll save the query run time). See docs for ‘wix-storage’.
What I mean is that if I would write #video1 in your “time expire” code on the page that I use for showing all my videos but with the same screen (which of the videos that will be seen depends on what link the customer have clicked on an earlier page) then just video1 will be shown, right? With other words, the fact that it is a dynamic page makes it a problem. Shall I instead write a check list over all my videos in the “time expire” code (#video1, #video2, #video3 etc.)?
Yes
Okay, I will try to make it work but I am no coder
If it doesn’t work, post your code.
When I write more than one video in your code I get a message that it expected 1 arguments but got 2 so how can I write to make it accept more videos that shall be automatically checked for time limits when a customer visits the page? On the other hand, the code itself stops a video effect from working and I don´t know how to fix that? Can you make the code snippet independent in some way so that it doesn´t affect other functions?
//....
.then(r => r[0] ? $w('#video1, #video2, #video3').hide() : $w('#video1, #video2, #video3').show());
Thanks, I will try and hope it works.
Would you please tell me what text I should write in the expiration-check.jsw?
I already posted it. See above.
Sorry but I don´t understand how you mean because I only see what you have written as code för the main page. What do you mean is the text for the expiration-check.jsw page??
Please read my second comment above (from Oct 23).
There’re 2 code blocks there. The second one is for the expiration-check.jsw.
Okay he he, I had put both your blocks in the main pages code but now I have fixed that. Thanks!