-2

I have some express.js app and I have a "Pay" button in my UI.

When I click on it, I want the server to call the checkout API of Stripe and then return a response only when I get the response from the API call (card can be expired, for example).

I know it's a bad practice, but how can my response wait till the async call finishes?

And what's the right way to do such call in express.js?

alexarsh
  • 5,123
  • 12
  • 42
  • 51

1 Answers1

0

If I'm understanding correctly, mind you I'm not too experienced in express.js, but in js you use functional programming.

some_api_call(params)
   .then(isSuccessfulCallback)
   .then(getResponse)
   .catch(e => {
       console.warn(e);
   });