|
|
@ -3,8 +3,9 @@ import { DataService } from '@ghostfolio/client/services/data.service';
|
|
|
|
import { UserService } from '@ghostfolio/client/services/user/user.service';
|
|
|
|
import { UserService } from '@ghostfolio/client/services/user/user.service';
|
|
|
|
import { User } from '@ghostfolio/common/interfaces';
|
|
|
|
import { User } from '@ghostfolio/common/interfaces';
|
|
|
|
import { translate } from '@ghostfolio/ui/i18n';
|
|
|
|
import { translate } from '@ghostfolio/ui/i18n';
|
|
|
|
|
|
|
|
import { StripeService } from 'ngx-stripe';
|
|
|
|
import { Subject } from 'rxjs';
|
|
|
|
import { Subject } from 'rxjs';
|
|
|
|
import { takeUntil } from 'rxjs/operators';
|
|
|
|
import { catchError, switchMap, takeUntil } from 'rxjs/operators';
|
|
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
@Component({
|
|
|
|
host: { class: 'page' },
|
|
|
|
host: { class: 'page' },
|
|
|
@ -15,6 +16,7 @@ import { takeUntil } from 'rxjs/operators';
|
|
|
|
export class PricingPageComponent implements OnDestroy, OnInit {
|
|
|
|
export class PricingPageComponent implements OnDestroy, OnInit {
|
|
|
|
public baseCurrency: string;
|
|
|
|
public baseCurrency: string;
|
|
|
|
public coupon: number;
|
|
|
|
public coupon: number;
|
|
|
|
|
|
|
|
public couponId: string;
|
|
|
|
public importAndExportTooltipBasic = translate(
|
|
|
|
public importAndExportTooltipBasic = translate(
|
|
|
|
'DATA_IMPORT_AND_EXPORT_TOOLTIP_BASIC'
|
|
|
|
'DATA_IMPORT_AND_EXPORT_TOOLTIP_BASIC'
|
|
|
|
);
|
|
|
|
);
|
|
|
@ -26,6 +28,7 @@ export class PricingPageComponent implements OnDestroy, OnInit {
|
|
|
|
);
|
|
|
|
);
|
|
|
|
public isLoggedIn: boolean;
|
|
|
|
public isLoggedIn: boolean;
|
|
|
|
public price: number;
|
|
|
|
public price: number;
|
|
|
|
|
|
|
|
public priceId: string;
|
|
|
|
public user: User;
|
|
|
|
public user: User;
|
|
|
|
|
|
|
|
|
|
|
|
private unsubscribeSubject = new Subject<void>();
|
|
|
|
private unsubscribeSubject = new Subject<void>();
|
|
|
@ -33,6 +36,7 @@ export class PricingPageComponent implements OnDestroy, OnInit {
|
|
|
|
public constructor(
|
|
|
|
public constructor(
|
|
|
|
private changeDetectorRef: ChangeDetectorRef,
|
|
|
|
private changeDetectorRef: ChangeDetectorRef,
|
|
|
|
private dataService: DataService,
|
|
|
|
private dataService: DataService,
|
|
|
|
|
|
|
|
private stripeService: StripeService,
|
|
|
|
private userService: UserService
|
|
|
|
private userService: UserService
|
|
|
|
) {}
|
|
|
|
) {}
|
|
|
|
|
|
|
|
|
|
|
@ -50,13 +54,35 @@ export class PricingPageComponent implements OnDestroy, OnInit {
|
|
|
|
this.user = state.user;
|
|
|
|
this.user = state.user;
|
|
|
|
|
|
|
|
|
|
|
|
this.coupon = subscriptions?.[this.user?.subscription?.offer]?.coupon;
|
|
|
|
this.coupon = subscriptions?.[this.user?.subscription?.offer]?.coupon;
|
|
|
|
|
|
|
|
this.couponId =
|
|
|
|
|
|
|
|
subscriptions?.[this.user.subscription.offer]?.couponId;
|
|
|
|
this.price = subscriptions?.[this.user?.subscription?.offer]?.price;
|
|
|
|
this.price = subscriptions?.[this.user?.subscription?.offer]?.price;
|
|
|
|
|
|
|
|
this.priceId = subscriptions?.[this.user.subscription.offer]?.priceId;
|
|
|
|
|
|
|
|
|
|
|
|
this.changeDetectorRef.markForCheck();
|
|
|
|
this.changeDetectorRef.markForCheck();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public onCheckout() {
|
|
|
|
|
|
|
|
this.dataService
|
|
|
|
|
|
|
|
.createCheckoutSession({ couponId: this.couponId, priceId: this.priceId })
|
|
|
|
|
|
|
|
.pipe(
|
|
|
|
|
|
|
|
switchMap(({ sessionId }: { sessionId: string }) => {
|
|
|
|
|
|
|
|
return this.stripeService.redirectToCheckout({ sessionId });
|
|
|
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
catchError((error) => {
|
|
|
|
|
|
|
|
alert(error.message);
|
|
|
|
|
|
|
|
throw error;
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
.subscribe((result) => {
|
|
|
|
|
|
|
|
if (result.error) {
|
|
|
|
|
|
|
|
alert(result.error.message);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public ngOnDestroy() {
|
|
|
|
public ngOnDestroy() {
|
|
|
|
this.unsubscribeSubject.next();
|
|
|
|
this.unsubscribeSubject.next();
|
|
|
|
this.unsubscribeSubject.complete();
|
|
|
|
this.unsubscribeSubject.complete();
|
|
|
|