mirror of
https://github.com/bitwarden/browser
synced 2025-12-15 15:53:27 +00:00
purchase promise
This commit is contained in:
@@ -51,7 +51,8 @@
|
|||||||
<button type="button" class="primary" appBlurClick (click)="manage()" *ngIf="isPremium">
|
<button type="button" class="primary" appBlurClick (click)="manage()" *ngIf="isPremium">
|
||||||
<b>{{'premiumManage' | i18n}}</b>
|
<b>{{'premiumManage' | i18n}}</b>
|
||||||
</button>
|
</button>
|
||||||
<button type="button" class="primary" appBlurClick (click)="purchase()" *ngIf="!isPremium">
|
<button #purchaseBtn type="button" class="primary" appBlurClick (click)="purchase()" *ngIf="!isPremium"
|
||||||
|
[disabled]="purchaseBtn.loading" [appApiAction]="purchasePromise">
|
||||||
<b>{{'premiumPurchase' | i18n}}</b>
|
<b>{{'premiumPurchase' | i18n}}</b>
|
||||||
</button>
|
</button>
|
||||||
<button type="button" data-dismiss="modal">{{'close' | i18n}}</button>
|
<button type="button" data-dismiss="modal">{{'close' | i18n}}</button>
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import { Utils } from 'jslib/misc/utils';
|
|||||||
templateUrl: 'premium.component.html',
|
templateUrl: 'premium.component.html',
|
||||||
})
|
})
|
||||||
export class PremiumComponent extends BasePremiumComponent {
|
export class PremiumComponent extends BasePremiumComponent {
|
||||||
formPromise: Promise<any>;
|
purchasePromise: Promise<any>;
|
||||||
canMakeMacAppStorePayments = false;
|
canMakeMacAppStorePayments = false;
|
||||||
|
|
||||||
constructor(i18nService: I18nService, platformUtilsService: PlatformUtilsService,
|
constructor(i18nService: I18nService, platformUtilsService: PlatformUtilsService,
|
||||||
@@ -51,7 +51,7 @@ export class PremiumComponent extends BasePremiumComponent {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Check each transaction.
|
// Check each transaction.
|
||||||
transactions.forEach((transaction) => {
|
transactions.forEach(async (transaction) => {
|
||||||
const payment = transaction.payment;
|
const payment = transaction.payment;
|
||||||
switch (transaction.transactionState) {
|
switch (transaction.transactionState) {
|
||||||
case 'purchasing':
|
case 'purchasing':
|
||||||
@@ -72,11 +72,12 @@ export class PremiumComponent extends BasePremiumComponent {
|
|||||||
fd.append('paymentToken', receiptB64);
|
fd.append('paymentToken', receiptB64);
|
||||||
fd.append('additionalStorageGb', '0');
|
fd.append('additionalStorageGb', '0');
|
||||||
try {
|
try {
|
||||||
this.formPromise = this.apiService.postPremium(fd).then((paymentResponse) => {
|
this.purchasePromise = this.apiService.postPremium(fd).then((paymentResponse) => {
|
||||||
if (paymentResponse.success) {
|
if (paymentResponse.success) {
|
||||||
return this.finalizePremium();
|
return this.finalizePremium();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
await this.purchasePromise;
|
||||||
} catch { }
|
} catch { }
|
||||||
// Finish the transaction.
|
// Finish the transaction.
|
||||||
remote.inAppPurchase.finishTransactionByDate(transaction.transactionDate);
|
remote.inAppPurchase.finishTransactionByDate(transaction.transactionDate);
|
||||||
@@ -111,7 +112,8 @@ export class PremiumComponent extends BasePremiumComponent {
|
|||||||
try {
|
try {
|
||||||
const request = new IapCheckRequest();
|
const request = new IapCheckRequest();
|
||||||
request.paymentMethodType = PaymentMethodType.AppleInApp;
|
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) => {
|
remote.inAppPurchase.purchaseProduct('premium_annually', 1, (isValid) => {
|
||||||
if (!isValid) {
|
if (!isValid) {
|
||||||
// TODO?
|
// TODO?
|
||||||
|
|||||||
Reference in New Issue
Block a user