Fixed checkout logic (again)

This commit is contained in:
itzMiney committed 2025-08-07 19:52:24 +02:00
1 parent 7c193d8ad7
commit 108b05c89d
2 files changed
+7 -7

No files matched your search

+1 -1
View File
@@ -36,7 +36,7 @@
<button <button
class="buy-button" class="buy-button"
*ngIf="getActivePriceId(service, activeTab[i])" *ngIf="getActivePriceId(service, activeTab[i])"
(click)="checkout(getActivePriceId(service, activeTab[i]) || '')"> (click)="checkout(getActivePriceId(service, activeTab[i])!)">
Buy Service Buy Service
</button> </button>
</div> </div>
+6 -6
View File
@@ -5,7 +5,6 @@ import {Title} from '@angular/platform-browser';
import {isPlatformBrowser, NgIf, NgFor, NgStyle} from '@angular/common'; import {isPlatformBrowser, NgIf, NgFor, NgStyle} from '@angular/common';
import {TranslatePipe, TranslateService} from '@ngx-translate/core'; import {TranslatePipe, TranslateService} from '@ngx-translate/core';
import {HttpClient} from '@angular/common/http'; import {HttpClient} from '@angular/common/http';
import {Observable, tap} from 'rxjs';
@Component({ @Component({
selector: 'app-services', selector: 'app-services',
@@ -154,16 +153,17 @@ export class ServicesComponent implements OnInit, OnDestroy, AfterViewInit {
this.vantaService.resizeVanta(this.elementId); this.vantaService.resizeVanta(this.elementId);
} }
checkout(priceId: string): Observable<any> { checkout(priceId: string): void {
return this.http.post<any>(this.apiUrl, { priceId }).pipe( this.http.post<any>(this.apiUrl, { priceId }).subscribe({
tap((response) => { next: (response) => {
if (response.url) { if (response.url) {
window.location.href = response.url; window.location.href = response.url;
} else { } else {
alert('Checkout session failed.'); alert('Checkout session failed.');
} }
}) },
); error: () => alert('Checkout session failed.')
});
} }
getActivePriceId(service: any, activeTab: string): string | null { getActivePriceId(service: any, activeTab: string): string | null {