web-manager 3.2.13 → 3.2.16
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/account.js +38 -11
- package/package.json +2 -2
package/lib/account.js
CHANGED
@@ -11,7 +11,9 @@ function Account(init) {
|
|
11
11
|
self.dom = init.dom || self.Manager.dom();
|
12
12
|
self.utilities = init.utilities || self.Manager.utilities();
|
13
13
|
|
14
|
-
|
14
|
+
var url = new URL(window.location.href);
|
15
|
+
|
16
|
+
if (url.pathname.startsWith('/account')) {
|
15
17
|
self.initializeAccountPage();
|
16
18
|
}
|
17
19
|
} catch (e) {
|
@@ -102,9 +104,10 @@ Account.prototype.resolve = function (account, options) {
|
|
102
104
|
|
103
105
|
account = account || {};
|
104
106
|
options = options || {};
|
107
|
+
options.fetchNewAccount = typeof options.fetchNewAccount === 'undefined' ? true : options.fetchNewAccount;
|
105
108
|
|
106
109
|
// If there is no user logged in or we choose not to fetch the account, resolve a default account
|
107
|
-
if (!currentUser || !currentUser.uid || options.fetchNewAccount
|
110
|
+
if (!currentUser || !currentUser.uid || !options.fetchNewAccount) {
|
108
111
|
return resolve(
|
109
112
|
self.handleAccount(
|
110
113
|
self._resolveAccount(currentUser, account, options)
|
@@ -273,11 +276,11 @@ Account.prototype._resolveAccount = function (firebaseUser, account, options) {
|
|
273
276
|
currentURL = new URL(window.location.href);
|
274
277
|
isDevelopment = self.utilities.get(self.Manager, 'properties.meta.environment', '') === 'development';
|
275
278
|
|
276
|
-
if (
|
279
|
+
if (isDevelopment) {
|
277
280
|
currentURL.searchParams
|
278
281
|
.forEach(function(value, key) {
|
279
282
|
var accountValue = self.utilities.get(account, key, undefined)
|
280
|
-
if (typeof accountValue !== undefined) {
|
283
|
+
if (typeof accountValue !== 'undefined') {
|
281
284
|
if (value === 'true') { value = true }
|
282
285
|
if (value === 'false') { value = false }
|
283
286
|
|
@@ -291,12 +294,15 @@ Account.prototype._resolveAccount = function (firebaseUser, account, options) {
|
|
291
294
|
}
|
292
295
|
}
|
293
296
|
|
294
|
-
var planExpireDate = new Date(account.plan.expires.timestamp);
|
295
297
|
var now = new Date();
|
298
|
+
var planExpireDate = new Date(account.plan.expires.timestamp);
|
296
299
|
var daysTillExpire = Math.floor((planExpireDate - now) / 86400000);
|
297
300
|
var difference = (planExpireDate.getTime() - now.getTime()) / (24 * 3600 * 1000);
|
301
|
+
var trialExpireDate = new Date(account.plan.trial.expires.timestamp);
|
302
|
+
var daysTillTrialExpire = Math.floor((trialExpireDate - now) / 86400000);
|
298
303
|
var startDate = new Date(account.plan.payment.startDate.timestamp);
|
299
304
|
var planIsActive = difference > -1 && account.plan.id !== defaultPlanId;
|
305
|
+
var planIsSuspended = account.plan.status === 'suspended';
|
300
306
|
|
301
307
|
if (planIsActive) {
|
302
308
|
account.plan.id = account.plan.id;
|
@@ -379,7 +385,7 @@ Account.prototype._resolveAccount = function (firebaseUser, account, options) {
|
|
379
385
|
// Set UI elements
|
380
386
|
// In a try/catch because this lib is used in node sometimes
|
381
387
|
try {
|
382
|
-
var cancelURL = isDevelopment ? 'http://localhost:4001/cancel
|
388
|
+
var cancelURL = isDevelopment ? 'http://localhost:4001/cancel' : 'https://itwcreativeworks.com/portal/account/manage';
|
383
389
|
|
384
390
|
var billingSubscribeBtn = self.dom.select('.auth-billing-subscribe-btn');
|
385
391
|
var billingUpdateBtn = self.dom.select('.auth-billing-update-btn');
|
@@ -387,6 +393,8 @@ Account.prototype._resolveAccount = function (firebaseUser, account, options) {
|
|
387
393
|
var billingFrequencyEl = self.dom.select('.auth-billing-frequency-element');
|
388
394
|
var billingStartDateEl = self.dom.select('.auth-billing-start-date-element');
|
389
395
|
var billingExpirationDateEl = self.dom.select('.auth-billing-expiration-date-element');
|
396
|
+
var billingSuspendedMessageEl = self.dom.select('.auth-billing-suspended-message-element');
|
397
|
+
var billingTrialExpirationDateEl = self.dom.select('.auth-billing-trial-expiration-date-element');
|
390
398
|
|
391
399
|
var $referralCount = self.dom.select('.auth-referral-count-element');
|
392
400
|
var $referralCode = self.dom.select('.auth-referral-code-element');
|
@@ -420,18 +428,37 @@ Account.prototype._resolveAccount = function (firebaseUser, account, options) {
|
|
420
428
|
)
|
421
429
|
authPhoneInput.setInnerHTML(firebaseUser.phoneNumber).setValue(firebaseUser.phoneNumber)
|
422
430
|
|
431
|
+
updateURL.searchParams.set('orderId', account.plan.payment.orderId);
|
432
|
+
updateURL.searchParams.set('resourceId', account.plan.payment.resourceId);
|
433
|
+
|
434
|
+
billingUpdateBtn.setAttribute('hidden', true).setAttribute('href', updateURL.toString());
|
423
435
|
billingSubscribeBtn.setAttribute('hidden', true);
|
424
|
-
|
436
|
+
billingSuspendedMessageEl.setAttribute('hidden');
|
437
|
+
billingTrialExpirationDateEl.setAttribute('hidden');
|
425
438
|
|
439
|
+
// Update active UI
|
426
440
|
if (planIsActive) {
|
427
|
-
|
428
|
-
updateURL.searchParams.set('resourceId', account.plan.payment.resourceId);
|
429
|
-
|
430
|
-
billingUpdateBtn.removeAttribute('hidden').setAttribute('href', updateURL.toString());
|
441
|
+
billingUpdateBtn.removeAttribute('hidden');
|
431
442
|
} else {
|
432
443
|
billingSubscribeBtn.removeAttribute('hidden');
|
433
444
|
}
|
434
445
|
|
446
|
+
// Update suspended UI
|
447
|
+
if (planIsSuspended) {
|
448
|
+
billingUpdateBtn.removeAttribute('hidden');
|
449
|
+
billingSubscribeBtn.setAttribute('hidden', true);
|
450
|
+
|
451
|
+
billingSuspendedMessageEl.removeAttribute('hidden');
|
452
|
+
}
|
453
|
+
|
454
|
+
// Update trial UI
|
455
|
+
if (account.plan.trial.activated) {
|
456
|
+
billingTrialExpirationDateEl
|
457
|
+
.removeAttribute('hidden')
|
458
|
+
.setInnerHTML('<i class="fas fa-gift mr-1"></i> Your free trial expires in ' + daysTillTrialExpire + ' days');
|
459
|
+
}
|
460
|
+
|
461
|
+
// Update billing UI
|
435
462
|
billingPlanId.setInnerHTML(uppercase(account.plan.id));
|
436
463
|
billingFrequencyEl.setInnerHTML(account.plan.id !== defaultPlanId ? ' (billed ' + uppercase(account.plan.payment.frequency) + ')' : '');
|
437
464
|
billingStartDateEl.setInnerHTML(account.plan.id !== defaultPlanId ? ' - Purchased ' + getMonth(startDate) + ' ' + startDate.getDate() + ', ' + startDate.getFullYear() : '');
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "web-manager",
|
3
|
-
"version": "3.2.
|
3
|
+
"version": "3.2.16",
|
4
4
|
"description": "Easily access important variables such as the query string, current domain, and current page in a single object.",
|
5
5
|
"main": "index.js",
|
6
6
|
"scripts": {
|
@@ -36,4 +36,4 @@
|
|
36
36
|
"firebase": "^9.23.0",
|
37
37
|
"lazysizes": "^5.3.2"
|
38
38
|
}
|
39
|
-
}
|
39
|
+
}
|