1
0
mirror of https://github.com/bitwarden/desktop.git synced 2024-11-28 12:35:40 +01:00

manage sub from app store. app store pricing

This commit is contained in:
Kyle Spearrin 2019-09-19 23:04:33 -04:00
parent 30f4c8b949
commit 21e3254219
4 changed files with 39 additions and 5 deletions

2
jslib

@ -1 +1 @@
Subproject commit 575a28e25fd27969d0335f06b1778027f1214c3e Subproject commit 929dd8415dcd69032e545b20f75c1c8abaad0e3a

View File

@ -37,7 +37,12 @@
</li> </li>
</ul> </ul>
<p class="text-center lead no-margin"> <p class="text-center lead no-margin">
{{'premiumPrice' | i18n : (price | currency:'$')}} <span *ngIf="canMakeMacAppStorePayments">
{{'premiumPrice' | i18n : appStoreFormattedPrice}}
</span>
<span *ngIf="!canMakeMacAppStorePayments">
{{'premiumPrice' | i18n : (price | currency:'$')}}
</span>
</p> </p>
</div> </div>
<div *ngIf="isPremium"> <div *ngIf="isPremium">

View File

@ -21,6 +21,8 @@ import { IapCheckRequest } from 'jslib/models/request/iapCheckRequest';
import { Utils } from 'jslib/misc/utils'; import { Utils } from 'jslib/misc/utils';
const AppStorePremiumPlan = 'premium_annually';
@Component({ @Component({
selector: 'app-premium', selector: 'app-premium',
templateUrl: 'premium.component.html', templateUrl: 'premium.component.html',
@ -29,6 +31,7 @@ export class PremiumComponent extends BasePremiumComponent {
purchasePromise: Promise<any>; purchasePromise: Promise<any>;
restorePromise: Promise<any>; restorePromise: Promise<any>;
canMakeMacAppStorePayments = false; canMakeMacAppStorePayments = false;
appStoreFormattedPrice = '$14.99';
canRestorePurchase = false; canRestorePurchase = false;
constructor(i18nService: I18nService, platformUtilsService: PlatformUtilsService, constructor(i18nService: I18nService, platformUtilsService: PlatformUtilsService,
@ -47,10 +50,21 @@ export class PremiumComponent extends BasePremiumComponent {
if (!this.canMakeMacAppStorePayments) { if (!this.canMakeMacAppStorePayments) {
return; 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(); this.setCanRestorePurchase();
remote.inAppPurchase.on('transactions-updated', (event, transactions) => { remote.inAppPurchase.on('transactions-updated', (event, transactions) => {
this.ngZone.run(async () => { this.ngZone.run(async () => {
if (!Array.isArray(transactions)) { if (transactions == null || !Array.isArray(transactions)) {
return; return;
} }
// Check each transaction. // Check each transaction.
@ -64,7 +78,7 @@ export class PremiumComponent extends BasePremiumComponent {
case 'purchased': case 'purchased':
// tslint:disable-next-line // tslint:disable-next-line
console.log(`${payment.productIdentifier} purchased.`); console.log(`${payment.productIdentifier} purchased.`);
if (payment.productIdentifier !== 'premium_annually') { if (payment.productIdentifier !== AppStorePremiumPlan) {
return; return;
} }
await this.makePremium(this.purchasePromise); await this.makePremium(this.purchasePromise);
@ -107,7 +121,7 @@ export class PremiumComponent extends BasePremiumComponent {
request.paymentMethodType = PaymentMethodType.AppleInApp; request.paymentMethodType = PaymentMethodType.AppleInApp;
this.purchasePromise = this.apiService.postIapCheck(request); this.purchasePromise = this.apiService.postIapCheck(request);
await this.purchasePromise; await this.purchasePromise;
remote.inAppPurchase.purchaseProduct('premium_annually', 1, (isValid) => { remote.inAppPurchase.purchaseProduct(AppStorePremiumPlan, 1, (isValid) => {
if (!isValid) { if (!isValid) {
// TODO? // 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<any>) { private async makePremium(promise: Promise<any>) {
const receiptUrl = remote.inAppPurchase.getReceiptURL(); const receiptUrl = remote.inAppPurchase.getReceiptURL();
const receiptBuffer = fs.readFileSync(receiptUrl); const receiptBuffer = fs.readFileSync(receiptUrl);

View File

@ -1254,5 +1254,8 @@
}, },
"restore": { "restore": {
"message": "Restore" "message": "Restore"
},
"premiumManageAlertAppStore": {
"message": "You can manage your subscription from the App Store. Do you want to visit the App Store now?"
} }
} }