fetch post json

I am trying to post a JSON object to the payment gateway using Fetch API but it is giving server error. Can anyone tell me what is wrong with the code.
Payment Gateway docs - https://razorpay.com/docs/payment-gateway/web-integration/hosted/

topay is the JSON object

fetch( "https://api.razorpay.com/v1/checkout/embedded", {
 "method": "post",
 "headers": {
 "Content-Type": "application/x-www-form-urlencoded"
  },
 "body": JSON.stringify(topay)
})
.then( (httpResponse) => {
 if (httpResponse.ok) {
 return httpResponse.json();
    } else {
 return Promise.reject("Fetch did not succeed");
    }
  })
  .catch(err => console.log(err));
}

Have a look here as Shan posted his code.
https://www.wix.com/corvid/forum/community-discussion/how-to-integrate-razorpay-payment-gateway

thanks it works :slight_smile: