Я изо всех сил пытаюсь найти, как передать строку payGateR в моем OkObjectResult моему компоненту. Можете ли вы указать мне правильное направление или объяснить мне, что я делаю неправильно? В настоящее время я возвращаю объект в свойство angular payGateResponse после преобразования его в строку, чтобы избежать ошибок.
Я надеюсь, что предоставил достаточно информации. Любая помощь приветствуется!
ASP. NET Web Api
[HttpPost("PaymentDetails")]
public IActionResult PostPaymentDetails(PaymentDetails paymentDetails)
{
// Rest of Code
if (status == "OK" || status == "AUTHORIZED")
{
return Ok(new
{ payGateR = decryptResponse });
}
else
{
return NotFound();
}
}
Angular сервис
export class PaymentDetailsService {
formData: PaymentDetails;
readonly rootURL = 'https://localhost:44386/api/';
constructor(private http: HttpClient) { }
postPaymentDetails() {
return this.http.post(this.rootURL + 'order/paymentdetails', this.formData);
}
}
Angular Компонент
export class ShoppingCartFormComponent implements OnInit {
order: IOrder[];
payGate: IPayGate[];
payGateResponse: string;
cardBrands: string[] = [
'VISA',
'MasterCard'
];
constructor(private http: HttpClient,
private service: PaymentDetailsService, private toastr: ToastrService) { }
ngOnInit(): void {
}
onSubmit(form: NgForm) {
this.service.postPaymentDetails().subscribe(
res => {
this.resetForm();
this.toastr.success('Payment Successful', 'Oh yeah!');
this.payGateResponse = res.toString();
console.log(res);
},
err => {
this.toastr.error('Payment Not Successful');
this.resetForm();
console.log(err);
}
)
}