Within the code itself, Inside the menu are other menusNot sure how you're putting your functions behind a pay wall so they can't use them again without paying. That's normally why I use the apis and handle everything in a service such as lambda or on my server.
Example of how I am handling menu based on tier.
Code:
// Add the following code in your Google Apps Script project
// Constants for subscription tiers
const TIER_FREE = 'Free';
const TIER_BASIC = 'Basic';
const TIER_PRO = 'Pro';
// Add an onOpen trigger to create the menu
function onOpen() {
var ui = SpreadsheetApp.getUi();
// Create the top-level menu
var topLevelMenu = ui.createMenu('Subscription');
// Add submenus for each tier
var freeMenu = ui.createMenu(TIER_FREE).addItem('Access Free Features', 'accessFreeFeatures');
var basicMenu = ui.createMenu(TIER_BASIC).addItem('Access Basic Features', 'accessBasicFeatures');
var proMenu = ui.createMenu(TIER_PRO).addItem('Access Pro Features', 'accessProFeatures');
// Add the submenus to the top-level menu
topLevelMenu.addSubMenu(freeMenu).addSubMenu(basicMenu).addSubMenu(proMenu);
// Add the top-level menu to the spreadsheet UI
topLevelMenu.addToUi();
}
// Functions to be called when accessing each tier
function accessFreeFeatures() {
if (checkSubscriptionTier(TIER_FREE)) {
// Code to execute for Free tier features
SpreadsheetApp.getUi().alert('You are accessing Free features.');
}
}
function accessBasicFeatures() {
if (checkSubscriptionTier(TIER_BASIC)) {
// Code to execute for Basic tier features
SpreadsheetApp.getUi().alert('You are accessing Basic features.');
}
}
function accessProFeatures() {
if (checkSubscriptionTier(TIER_PRO)) {
// Code to execute for Pro tier features
SpreadsheetApp.getUi().alert('You are accessing Pro features.');
}
}
// Function to check the user's subscription tier using Google OAuth and Stripe verification
function checkSubscriptionTier(tier) {
// Implement your OAuth and Stripe verification logic here
// Return true if the user is subscribed to the specified tier, otherwise return false
// You can use the user's Google account information or stored subscription data for verification
// You'll need to integrate with Google OAuth and Stripe API for authentication and subscription management
// Example implementation:
var currentUser = Session.getActiveUser().getEmail();
var userSubscriptions = getStripeSubscriptions(currentUser);
return userSubscriptions.includes(tier);
}
// Function to retrieve the user's subscriptions from Stripe
function getStripeSubscriptions(email) {
// Implement your logic to retrieve the user's subscriptions from Stripe using the email as identifier
// This function should communicate with the Stripe API and return the user's subscription tiers
// Example implementation:
var stripeSubscriptions = ['Free', 'Basic']; // Dummy data, replace with actual implementation
return stripeSubscriptions;
}
This part I am confused on, need a good starting point to educate myself on Oauth and using them in the cloud services to authenticate. it really is my last hurdle.
// Implement your OAuth and Stripe verification logic here
// Return true if the user is subscribed to the specified tier, otherwise return false
// You can use the user's Google account information or stored subscription data for verification
// You'll need to integrate with Google OAuth and Stripe API for authentication and subscription management
