From dff1bb8144e6b1b9134b6b6e2d9aeb0ce8cf9e7c Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Mon, 23 Sep 2019 22:59:40 -0400 Subject: [PATCH] getReceiptUrl only when receipt available --- src/app/accounts/premium.component.ts | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/app/accounts/premium.component.ts b/src/app/accounts/premium.component.ts index ba94ac8d34..9b9ee0415b 100644 --- a/src/app/accounts/premium.component.ts +++ b/src/app/accounts/premium.component.ts @@ -43,11 +43,11 @@ export class PremiumComponent extends BasePremiumComponent { async ngOnInit() { await super.ngOnInit(); - if (this.isPremium || !this.platformUtilsService.isMacAppStore()) { - return; + const isMacAppStore = this.platformUtilsService.isMacAppStore(); + if (isMacAppStore) { + this.canMakeMacAppStorePayments = remote.inAppPurchase.canMakePayments(); } - this.canMakeMacAppStorePayments = remote.inAppPurchase.canMakePayments(); - if (!this.canMakeMacAppStorePayments) { + if (this.isPremium || !isMacAppStore || !this.canMakeMacAppStorePayments) { return; } const pricePromise = new Promise((resolve) => { @@ -147,7 +147,7 @@ export class PremiumComponent extends BasePremiumComponent { } async manage() { - if (!this.canMakeMacAppStorePayments || remote.inAppPurchase.getReceiptURL() == null) { + if (!this.canMakeMacAppStorePayments || this.getReceiptUrl() == null) { await super.manage(); return; } @@ -159,7 +159,7 @@ export class PremiumComponent extends BasePremiumComponent { } private async makePremium(restore: boolean) { - const receiptUrl = remote.inAppPurchase.getReceiptURL(); + const receiptUrl = this.getReceiptUrl(); const receiptBuffer = fs.readFileSync(receiptUrl); const receiptB64 = Utils.fromBufferToB64(receiptBuffer); const fd = new FormData(); @@ -193,10 +193,18 @@ export class PremiumComponent extends BasePremiumComponent { private setCanRestorePurchase() { if (!this.isPremium && this.canMakeMacAppStorePayments) { - const receiptUrl = remote.inAppPurchase.getReceiptURL(); + const receiptUrl = this.getReceiptUrl(); this.canRestorePurchase = receiptUrl != null; } else { this.canRestorePurchase = false; } } + + private getReceiptUrl(): string { + const receiptUrl = remote.inAppPurchase.getReceiptURL(); + if (receiptUrl != null) { + return fs.existsSync(receiptUrl) ? receiptUrl : null; + } + return null; + } }