I need to perform a form POST to a 3rd party payment provider with angular typescript and also do the redirect afterwards. If I do standard form submit through a standard html page the form submit automatically redirects to the 3rd party payment providers hosted payment page, but not when I do a HttpClient.post in angular.
I looked at observables and and injectors to see if that would help, but nothing I searched and found seemed to solve this specific problem. Though I read so many different problems and solutions between different angular versions I may have lost some obvious answer along the line.
The reason I am not doing a hidden form with hidden fields is because I need to be able to this same thing through a mobile (Ionic) app later, and I will need to use their inbuilt HttpClient along with the normal HttpClient for standard web pages.
import { Component, OnInit } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
@Component({
selector : 'app-paymenttest-page',
templateUrl : 'paymenttest.page.html',
styleUrls : ['paymenttest.page.scss']
})
export class PaymentTestPage implements OnInit {
constructor(private http : HttpClient) {
}
private void makePayment(url: str, formData: FormData): void {
let headers = new HttpHeaders({'Accept' : 'text/html' });
this.http.post(url, formData, {
headers : headers,
responseType : 'text',
})
.subscribe(
(res) => {
console.log('post res');
console.log(res);
window.location.href = res.url;
// How do I simulate a form submit redirect with res.body here?
},
(err) => {
console.log('post err');
console.log(err);
});
}
}
I expect to be able to do a 3rd party hosted page redirect, but all I am getting back is the html text response from the 3rd party. Which I also get when doing a plain html form submit, but somehow the plain html form submit also handles the redirect.
-- Edit The response I am getting is the actual HTML payload from the URL that I am posting to and is expecting to be served from that URL. So the question is how does a standard html form submit navigate to the POST url and serve the returned content from there?