Feature/add stripe checkout to pricing page (#1942)
* Add Stripe checkout directly to pricing page * Update changelog
This commit is contained in:
parent
27d9b075ce
commit
7140ed8512
@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Added support for the _Stripe_ checkout to the pricing page
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- Improved the management of platforms in the admin control panel
|
- Improved the management of platforms in the admin control panel
|
||||||
|
@ -189,9 +189,11 @@ export class AccountPageComponent implements OnDestroy, OnInit {
|
|||||||
.createCheckoutSession({ couponId: this.couponId, priceId: this.priceId })
|
.createCheckoutSession({ couponId: this.couponId, priceId: this.priceId })
|
||||||
.pipe(
|
.pipe(
|
||||||
switchMap(({ sessionId }: { sessionId: string }) => {
|
switchMap(({ sessionId }: { sessionId: string }) => {
|
||||||
return this.stripeService.redirectToCheckout({
|
return this.stripeService.redirectToCheckout({ sessionId });
|
||||||
sessionId
|
}),
|
||||||
});
|
catchError((error) => {
|
||||||
|
alert(error.message);
|
||||||
|
throw error;
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
.subscribe((result) => {
|
.subscribe((result) => {
|
||||||
|
@ -32,7 +32,7 @@
|
|||||||
<button
|
<button
|
||||||
color="primary"
|
color="primary"
|
||||||
mat-flat-button
|
mat-flat-button
|
||||||
(click)="onCheckout(priceId)"
|
(click)="onCheckout()"
|
||||||
>
|
>
|
||||||
<ng-container
|
<ng-container
|
||||||
*ngIf="user.subscription.offer === 'default'"
|
*ngIf="user.subscription.offer === 'default'"
|
||||||
|
@ -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();
|
||||||
|
@ -336,7 +336,7 @@
|
|||||||
*ngIf="user?.subscription?.type === 'Basic'"
|
*ngIf="user?.subscription?.type === 'Basic'"
|
||||||
class="mt-3 text-center"
|
class="mt-3 text-center"
|
||||||
>
|
>
|
||||||
<a color="primary" mat-flat-button [routerLink]="['/account']">
|
<button color="primary" mat-flat-button (click)="onCheckout()">
|
||||||
<ng-container
|
<ng-container
|
||||||
*ngIf="user.subscription.offer === 'default'"
|
*ngIf="user.subscription.offer === 'default'"
|
||||||
i18n
|
i18n
|
||||||
@ -347,7 +347,7 @@
|
|||||||
i18n
|
i18n
|
||||||
>Renew Plan</ng-container
|
>Renew Plan</ng-container
|
||||||
>
|
>
|
||||||
</a>
|
</button>
|
||||||
<p class="m-0 text-muted">
|
<p class="m-0 text-muted">
|
||||||
<small i18n>One-time payment, no auto-renewal.</small>
|
<small i18n>One-time payment, no auto-renewal.</small>
|
||||||
</p>
|
</p>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user