keep plan selection during keycloak hop
This commit is contained in:
@@ -7,6 +7,7 @@ import { switchMap } from 'rxjs';
|
||||
import { User } from '../../../../../bizmatch-server/src/models/db.model';
|
||||
import { Checkout, KeycloakUser } from '../../../../../bizmatch-server/src/models/main.model';
|
||||
import { environment } from '../../../environments/environment';
|
||||
import { AuditService } from '../../services/audit.service';
|
||||
import { UserService } from '../../services/user.service';
|
||||
import { SharedModule } from '../../shared/shared/shared.module';
|
||||
import { map2User } from '../../utils/utils';
|
||||
@@ -24,25 +25,50 @@ export class PricingComponent {
|
||||
pricingOverview: boolean | undefined = this.activatedRoute.snapshot.data['pricingOverview'] as boolean | undefined;
|
||||
keycloakUser: KeycloakUser;
|
||||
user: User;
|
||||
constructor(public keycloakService: KeycloakService, private http: HttpClient, private stripeService: StripeService, private activatedRoute: ActivatedRoute, private userService: UserService, private router: Router) {}
|
||||
constructor(
|
||||
public keycloakService: KeycloakService,
|
||||
private http: HttpClient,
|
||||
private stripeService: StripeService,
|
||||
private activatedRoute: ActivatedRoute,
|
||||
private userService: UserService,
|
||||
private router: Router,
|
||||
private auditService: AuditService,
|
||||
) {}
|
||||
|
||||
async ngOnInit() {
|
||||
const token = await this.keycloakService.getToken();
|
||||
this.keycloakUser = map2User(token);
|
||||
if (this.keycloakUser) {
|
||||
if (this.id === 'free') {
|
||||
this.user = await this.userService.getByMail(this.keycloakUser.email);
|
||||
this.user.subscriptionPlan = 'free';
|
||||
await this.userService.saveGuaranteed(this.user);
|
||||
this.router.navigate([`/account`]);
|
||||
} else if (this.id) {
|
||||
this.checkout({ priceId: atob(this.id), email: this.keycloakUser.email, name: `${this.keycloakUser.firstName} ${this.keycloakUser.lastName}` });
|
||||
} else if (!this.id && !this.pricingOverview) {
|
||||
this.user = await this.userService.getByMail(this.keycloakUser.email);
|
||||
if (this.user.subscriptionId) {
|
||||
this.user = await this.userService.getByMail(this.keycloakUser.email);
|
||||
const originalKeycloakUser = await this.userService.getKeycloakUser(this.keycloakUser.id);
|
||||
const priceId = originalKeycloakUser.attributes && originalKeycloakUser.attributes['priceID'] ? originalKeycloakUser.attributes['priceID'][0] : null;
|
||||
if (priceId) {
|
||||
originalKeycloakUser.attributes['priceID'] = null;
|
||||
await this.userService.updateKeycloakUser(originalKeycloakUser);
|
||||
}
|
||||
if (!this.user.subscriptionPlan) {
|
||||
if (this.id === 'free' || priceId === 'free') {
|
||||
this.user.subscriptionPlan = 'free';
|
||||
await this.userService.saveGuaranteed(this.user);
|
||||
this.router.navigate([`/account`]);
|
||||
} else if (this.id || priceId) {
|
||||
const base64PriceId = this.id ? this.id : priceId;
|
||||
this.checkout({ priceId: atob(base64PriceId), email: this.keycloakUser.email, name: `${this.keycloakUser.firstName} ${this.keycloakUser.lastName}` });
|
||||
}
|
||||
}
|
||||
// if (this.id === 'free' || this.keycloakUser.priceId === 'free') {
|
||||
// this.user.subscriptionPlan = 'free';
|
||||
// await this.userService.saveGuaranteed(this.user);
|
||||
// this.router.navigate([`/account`]);
|
||||
// } else if (this.id || this.keycloakUser.priceId) {
|
||||
// const priceId = this.id ? this.id : this.keycloakUser.priceId;
|
||||
// this.checkout({ priceId: atob(priceId), email: this.keycloakUser.email, name: `${this.keycloakUser.firstName} ${this.keycloakUser.lastName}` });
|
||||
// } else if (!this.id && !this.pricingOverview) {
|
||||
// this.user = await this.userService.getByMail(this.keycloakUser.email);
|
||||
// if (this.user.subscriptionId) {
|
||||
// this.router.navigate([`/account`]);
|
||||
// }
|
||||
// }
|
||||
} else {
|
||||
this.pricingOverview = false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user