1
0
mirror of https://github.com/bitwarden/browser.git synced 2025-01-04 18:37:45 +01:00

load premium status after pruchase

This commit is contained in:
Kyle Spearrin 2018-06-28 23:05:49 -04:00
parent 04ef16a94b
commit 4a2b3d6293
4 changed files with 34 additions and 8 deletions

2
jslib

@ -1 +1 @@
Subproject commit 3aebe1a09a282fdba1a2b27d42e0c154635b3188 Subproject commit 93edd272dde1d0d5739c29a57668849fb445eee3

View File

@ -1,8 +1,14 @@
import { import {
Component, Component,
EventEmitter,
Output,
ViewChild, ViewChild,
} from '@angular/core'; } from '@angular/core';
import { ToasterService } from 'angular2-toaster';
import { Angulartics2 } from 'angulartics2';
import { ApiService } from 'jslib/abstractions/api.service';
import { I18nService } from 'jslib/abstractions/i18n.service'; import { I18nService } from 'jslib/abstractions/i18n.service';
import { PaymentComponent } from './payment.component'; import { PaymentComponent } from './payment.component';
@ -13,20 +19,29 @@ import { PaymentComponent } from './payment.component';
}) })
export class PremiumComponent { export class PremiumComponent {
@ViewChild(PaymentComponent) paymentComponent: PaymentComponent; @ViewChild(PaymentComponent) paymentComponent: PaymentComponent;
@Output() onPremiumPurchased = new EventEmitter();
premiumPrice = 10; premiumPrice = 10;
storageGbPrice = 4; storageGbPrice = 4;
additionalStorage = 0; additionalStorage = 0;
constructor(private i18nService: I18nService) { } formPromise: Promise<any>;
constructor(private apiService: ApiService, private i18nService: I18nService,
private analytics: Angulartics2, private toasterService: ToasterService) { }
async submit() { async submit() {
try { try {
const token = await this.paymentComponent.createPaymentToken(); this.formPromise = this.paymentComponent.createPaymentToken().then((token) => {
console.log(token); const fd = new FormData();
} catch (e) { fd.append('paymentToken', token);
console.log(e); fd.append('additionalStorageGb', (this.additionalStorage || 0).toString());
} return this.apiService.postPremium(fd);
}).then(() => {
return this.finalizePremium();
});
await this.formPromise;
} catch { }
} }
get additionalStorageTotal(): number { get additionalStorageTotal(): number {
@ -36,4 +51,11 @@ export class PremiumComponent {
get total(): number { get total(): number {
return this.additionalStorageTotal + this.premiumPrice; return this.additionalStorageTotal + this.premiumPrice;
} }
private async finalizePremium() {
await this.apiService.refreshIdentityToken();
this.analytics.eventTrack.next({ action: 'Signed Up Premium' });
this.toasterService.popAsync('success', null, this.i18nService.t('accountUpdated'));
this.onPremiumPurchased.emit();
}
} }

View File

@ -1,4 +1,4 @@
<div class="page-header"> <div class="page-header">
<h1>{{'billingAndLicensing' | i18n}}</h1> <h1>{{'billingAndLicensing' | i18n}}</h1>
</div> </div>
<app-premium *ngIf="!premium"></app-premium> <app-premium *ngIf="!premium" (onPremiumPurchased)="loadPremiumStatus()"></app-premium>

View File

@ -15,6 +15,10 @@ export class UserBillingComponent implements OnInit {
constructor(private tokenService: TokenService) { } constructor(private tokenService: TokenService) { }
async ngOnInit() { async ngOnInit() {
this.loadPremiumStatus();
}
loadPremiumStatus() {
this.premium = this.tokenService.getPremium(); this.premium = this.tokenService.getPremium();
} }
} }