From 2f84e2fd821a9049bed58f2d96539bea88329873 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Thu, 19 Sep 2019 09:09:25 -0400 Subject: [PATCH] purchase promise --- src/app/accounts/premium.component.html | 3 ++- src/app/accounts/premium.component.ts | 10 ++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/app/accounts/premium.component.html b/src/app/accounts/premium.component.html index 3760ca56..1327efa8 100644 --- a/src/app/accounts/premium.component.html +++ b/src/app/accounts/premium.component.html @@ -51,7 +51,8 @@ - diff --git a/src/app/accounts/premium.component.ts b/src/app/accounts/premium.component.ts index d5f36b8e..c55c22d1 100644 --- a/src/app/accounts/premium.component.ts +++ b/src/app/accounts/premium.component.ts @@ -26,7 +26,7 @@ import { Utils } from 'jslib/misc/utils'; templateUrl: 'premium.component.html', }) export class PremiumComponent extends BasePremiumComponent { - formPromise: Promise; + purchasePromise: Promise; canMakeMacAppStorePayments = false; constructor(i18nService: I18nService, platformUtilsService: PlatformUtilsService, @@ -51,7 +51,7 @@ export class PremiumComponent extends BasePremiumComponent { return; } // Check each transaction. - transactions.forEach((transaction) => { + transactions.forEach(async (transaction) => { const payment = transaction.payment; switch (transaction.transactionState) { case 'purchasing': @@ -72,11 +72,12 @@ export class PremiumComponent extends BasePremiumComponent { fd.append('paymentToken', receiptB64); fd.append('additionalStorageGb', '0'); try { - this.formPromise = this.apiService.postPremium(fd).then((paymentResponse) => { + this.purchasePromise = this.apiService.postPremium(fd).then((paymentResponse) => { if (paymentResponse.success) { return this.finalizePremium(); } }); + await this.purchasePromise; } catch { } // Finish the transaction. remote.inAppPurchase.finishTransactionByDate(transaction.transactionDate); @@ -111,7 +112,8 @@ export class PremiumComponent extends BasePremiumComponent { try { const request = new IapCheckRequest(); request.paymentMethodType = PaymentMethodType.AppleInApp; - await this.apiService.postIapCheck(request); + this.purchasePromise = this.apiService.postIapCheck(request); + await this.purchasePromise; remote.inAppPurchase.purchaseProduct('premium_annually', 1, (isValid) => { if (!isValid) { // TODO?