33 lines
970 B
TypeScript
33 lines
970 B
TypeScript
// 1. Shared Service (modal.service.ts)
|
|
import { HttpClient } from '@angular/common/http';
|
|
import { Injectable } from '@angular/core';
|
|
import { BehaviorSubject, Observable } from 'rxjs';
|
|
|
|
@Injectable({
|
|
providedIn: 'root',
|
|
})
|
|
export class PaymentService {
|
|
private modalVisibleSubject = new BehaviorSubject<boolean>(false);
|
|
modalVisible$: Observable<boolean> = this.modalVisibleSubject.asObservable();
|
|
private resolvePromise!: (value: boolean) => void;
|
|
constructor(private http: HttpClient) {}
|
|
openPaymentModal() {
|
|
this.modalVisibleSubject.next(true);
|
|
return new Promise<boolean>(resolve => {
|
|
this.resolvePromise = resolve;
|
|
});
|
|
}
|
|
accept(): void {
|
|
this.modalVisibleSubject.next(false);
|
|
this.resolvePromise(true);
|
|
}
|
|
|
|
reject(): void {
|
|
this.modalVisibleSubject.next(false);
|
|
this.resolvePromise(false);
|
|
}
|
|
processPayment(token: string): Observable<any> {
|
|
return this.http.post('/api/subscription', { token });
|
|
}
|
|
}
|