Im working with a bank API for the payment.what banks want to response is he Ban Pay JavaScript will perform an HTTP redirect in the top frame to the completeUrl. what completeUrl the url i should give the bank api to send their response.in my app.component.ts
this.http.post("BankEndURL",quote,).subscribe(s=>{
//here i get quote
this.newpay=s;
//here im passing the paymentID to my service in angular to store there,because
at the end of the transaction ,if its successful i need it to show the transaction data
this.dataService.setData(s);
//here i send a quote to backend to give me a bankurl with payment data
this.http.post("SecondBakednURL",this.newpay).subscribe(s=>{
this.payaddress= s['reDirectAuthorizationHref'];
//here i open the url to redirect the user to the payment portal
window.open(this.payaddress);
here is the service i have created :
public sharedData = new BehaviorSubject<any>(null);
constructor() {}
getData(){
return this.sharedData;
}
setData(data:any){
this.sharedData.next(data);
}
and here is my receiver component,the one which the bank will hit it once the transaction is successful,im going to show the transction data of the user
constructor(private dataService:DataService) {}
ngOnInit(): void {
this.dataService.getData().pipe(
filter(data => !!data)
).subscribe(data => {
alert(data)
});
but data here returns null
In this case, getSharedData() returns the behavior subject itself, so the sensible thing to do in this case is to subscribe to it in order to receive the data that you are emitting when calling setData.
In the receiver component:
ngOnInit(): void {
this.dataService.getData().pipe(
filter(data => !!data)
).subscribe(data => {
alert(data)
});
}