59e26b28 by Jonille Arreglo

31466_limited_usage_chatbot+

1 parent 80f3ea39
Showing 1 changed file with 36 additions and 33 deletions
...@@ -430,43 +430,46 @@ async function validation (aiwp_app_id, req, res) { ...@@ -430,43 +430,46 @@ async function validation (aiwp_app_id, req, res) {
430 let auth = await authenticate({ "aiwp_logged_in": aiwp_logged_in, "user_event_data": {}, "user_event": "endpoint" }); 430 let auth = await authenticate({ "aiwp_logged_in": aiwp_logged_in, "user_event_data": {}, "user_event": "endpoint" });
431 431
432 if (!auth.success) { 432 if (!auth.success) {
433 IS_FREE_USER = true; 433 IS_FREE_USER = true;
434 if (auth.is_restrict) { 434 if (auth.is_restrict) {
435 res.json({ status: "invalid", restrict: true, redirect: auth.redirect }); 435 res.json({ status: "invalid", restrict: true, redirect: auth.redirect });
436 res.end(); 436 res.end();
437 return false; 437 return false;
438 } else if (typeof auth.has_pro_access === "undefined" && !auth.has_pro_access) { 438 } else if (auth.subscription_type &&
439 res.json({ status: "invalid", restrict: true }); 439 typeof auth.has_pro_access === "undefined" && !auth.has_pro_access) {
440 res.end(); 440 res.json({ status: "invalid", restrict: true });
441 return false; 441 res.end();
442 return false;
443 }
444 } else {
445 let data = await getUsage({
446 aiwp_logged_in, app: 'chatbot+'
447 });
448
449 if (!(data.success === 1 && data.status === 'valid')) {
450 res.json({ status: "invalid", data });
451 res.status(200);
452 return false;
442 } 453 }
443 } 454 }
444 let data = await getUsage({ 455 } else {
445 aiwp_logged_in, app: 'chatbot+' 456 IS_FREE_USER = true;
446 });
447
448 if (!(data.success === 1 && data.status === 'valid')) {
449 res.json({ status: "invalid", data });
450 res.status(200);
451 return false;
452 }
453 } else {
454 IS_FREE_USER = true;
455 let data = await getLimitedUsage({
456 "aiwp_app_id": aiwp_app_id
457 });
458
459 if (data.usage !== null) {
460 TRIED_USAGE = parseInt(data.usage);
461 }
462
463 } 457 }
464 if (IS_FREE_USER && TRIED_USAGE >= limit) { 458 if(IS_FREE_USER) {
465 res.json({ status: "invalid", limited: true }); 459 let data = await getLimitedUsage({
466 res.end(); 460 "aiwp_app_id": aiwp_app_id
467 return false; 461 });
462
463 if (data.usage !== null) {
464 TRIED_USAGE = parseInt(data.usage);
465 }
466 if (TRIED_USAGE >= limit) {
467 res.json({ status: "invalid", limited: true });
468 res.end();
469 return false;
470 }
471 TRIED_USAGE++;
468 } 472 }
469 if (IS_FREE_USER) TRIED_USAGE++;
470 473
471 return { IS_FREE_USER, aiwp_logged_in, TRIED_USAGE }; 474 return { IS_FREE_USER, aiwp_logged_in, TRIED_USAGE };
472 }; 475 };
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!