diff --git a/jslib b/jslib index 575a28e2..929dd841 160000 --- a/jslib +++ b/jslib @@ -1 +1 @@ -Subproject commit 575a28e25fd27969d0335f06b1778027f1214c3e +Subproject commit 929dd8415dcd69032e545b20f75c1c8abaad0e3a diff --git a/src/app/accounts/premium.component.html b/src/app/accounts/premium.component.html index fee8f751..515d81a3 100644 --- a/src/app/accounts/premium.component.html +++ b/src/app/accounts/premium.component.html @@ -37,7 +37,12 @@

- {{'premiumPrice' | i18n : (price | currency:'$')}} + + {{'premiumPrice' | i18n : appStoreFormattedPrice}} + + + {{'premiumPrice' | i18n : (price | currency:'$')}} +

diff --git a/src/app/accounts/premium.component.ts b/src/app/accounts/premium.component.ts index 63f1a2dd..062438c6 100644 --- a/src/app/accounts/premium.component.ts +++ b/src/app/accounts/premium.component.ts @@ -21,6 +21,8 @@ import { IapCheckRequest } from 'jslib/models/request/iapCheckRequest'; import { Utils } from 'jslib/misc/utils'; +const AppStorePremiumPlan = 'premium_annually'; + @Component({ selector: 'app-premium', templateUrl: 'premium.component.html', @@ -29,6 +31,7 @@ export class PremiumComponent extends BasePremiumComponent { purchasePromise: Promise; restorePromise: Promise; canMakeMacAppStorePayments = false; + appStoreFormattedPrice = '$14.99'; canRestorePurchase = false; constructor(i18nService: I18nService, platformUtilsService: PlatformUtilsService, @@ -47,10 +50,21 @@ export class PremiumComponent extends BasePremiumComponent { if (!this.canMakeMacAppStorePayments) { return; } + const pricePromise = new Promise((resolve) => { + remote.inAppPurchase.getProducts([AppStorePremiumPlan], (products) => { + this.ngZone.run(async () => { + if (products == null || !Array.isArray(products) || products.length === 0) { + return; + } + this.appStoreFormattedPrice = products[0].formattedPrice; + resolve(); + }); + }); + }); this.setCanRestorePurchase(); remote.inAppPurchase.on('transactions-updated', (event, transactions) => { this.ngZone.run(async () => { - if (!Array.isArray(transactions)) { + if (transactions == null || !Array.isArray(transactions)) { return; } // Check each transaction. @@ -64,7 +78,7 @@ export class PremiumComponent extends BasePremiumComponent { case 'purchased': // tslint:disable-next-line console.log(`${payment.productIdentifier} purchased.`); - if (payment.productIdentifier !== 'premium_annually') { + if (payment.productIdentifier !== AppStorePremiumPlan) { return; } await this.makePremium(this.purchasePromise); @@ -107,7 +121,7 @@ export class PremiumComponent extends BasePremiumComponent { request.paymentMethodType = PaymentMethodType.AppleInApp; this.purchasePromise = this.apiService.postIapCheck(request); await this.purchasePromise; - remote.inAppPurchase.purchaseProduct('premium_annually', 1, (isValid) => { + remote.inAppPurchase.purchaseProduct(AppStorePremiumPlan, 1, (isValid) => { if (!isValid) { // TODO? } @@ -132,6 +146,18 @@ export class PremiumComponent extends BasePremiumComponent { } } + async manage() { + if (!this.canMakeMacAppStorePayments || remote.inAppPurchase.getReceiptURL() == null) { + await super.manage(); + return; + } + const confirmed = await this.platformUtilsService.showDialog(this.i18nService.t('premiumManageAlertAppStore'), + this.i18nService.t('premiumManage'), this.i18nService.t('yes'), this.i18nService.t('cancel')); + if (confirmed) { + this.platformUtilsService.launchUri('itms-apps://apps.apple.com/account/subscriptions'); + } + } + private async makePremium(promise: Promise) { const receiptUrl = remote.inAppPurchase.getReceiptURL(); const receiptBuffer = fs.readFileSync(receiptUrl); diff --git a/src/locales/en/messages.json b/src/locales/en/messages.json index c3d95db1..9bd45c52 100644 --- a/src/locales/en/messages.json +++ b/src/locales/en/messages.json @@ -1254,5 +1254,8 @@ }, "restore": { "message": "Restore" + }, + "premiumManageAlertAppStore": { + "message": "You can manage your subscription from the App Store. Do you want to visit the App Store now?" } }